summaryrefslogtreecommitdiff
path: root/src/main/java/darkknight/jewelrycraft/network/PacketRequestSetSlot.java
blob: b7fd8eb52a9554550f61fdf8e9a68a35e8ad2552 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
 * 
 */
package darkknight.jewelrycraft.network;

import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import darkknight.jewelrycraft.client.gui.container.ContainerJewelryModifier;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.ItemStack;

/**
 * @author Sorin
 *
 */
public class PacketRequestSetSlot implements IMessage, IMessageHandler<PacketRequestSetSlot, IMessage> {
	ItemStack stack;

	public PacketRequestSetSlot() {
	}

	public PacketRequestSetSlot(ItemStack stack) {
		this.stack = stack;
	}

	/**
	 * @param message
	 * @param ctx
	 * @return
	 */
	@Override
	public IMessage onMessage(PacketRequestSetSlot message, MessageContext ctx) {
		if (ctx.getServerHandler().playerEntity.openContainer instanceof ContainerJewelryModifier) {
			((ContainerJewelryModifier) ctx.getServerHandler().playerEntity.openContainer).modInv
					.setInventorySlotContents(36, message.stack);
		}
		return null;
	}

	/**
	 * @param buf
	 */
	@Override
	public void fromBytes(ByteBuf buf) {
		stack = ByteBufUtils.readItemStack(buf);
	}

	/**
	 * @param buf
	 */
	@Override
	public void toBytes(ByteBuf buf) {
		ByteBufUtils.writeItemStack(buf, stack);
	}
}