2016-06-07 18:50:41 -04:00
|
|
|
package WayofTime.bloodmagic.network;
|
|
|
|
|
|
|
|
import WayofTime.bloodmagic.item.sigil.ItemSigilHolding;
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
|
|
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
|
|
|
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public class SigilHoldingPacketProcessor implements IMessage, IMessageHandler<SigilHoldingPacketProcessor, IMessage> {
|
2016-06-07 18:50:41 -04:00
|
|
|
private int slot;
|
|
|
|
private int mode;
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public SigilHoldingPacketProcessor() {
|
2016-06-07 18:50:41 -04:00
|
|
|
}
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public SigilHoldingPacketProcessor(int slot, int mode) {
|
2016-06-07 18:50:41 -04:00
|
|
|
this.slot = slot;
|
|
|
|
this.mode = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public void toBytes(ByteBuf buffer) {
|
2016-06-07 18:50:41 -04:00
|
|
|
buffer.writeInt(slot);
|
|
|
|
buffer.writeInt(mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public void fromBytes(ByteBuf buffer) {
|
2016-06-07 18:50:41 -04:00
|
|
|
slot = buffer.readInt();
|
|
|
|
mode = buffer.readInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public IMessage onMessage(SigilHoldingPacketProcessor message, MessageContext ctx) {
|
2017-02-20 13:47:36 -08:00
|
|
|
ItemStack itemStack = ItemStack.EMPTY;
|
2016-06-07 18:50:41 -04:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
if (message.slot > -1 && message.slot < 9) {
|
2017-08-14 20:53:42 -07:00
|
|
|
itemStack = ctx.getServerHandler().player.inventory.getStackInSlot(message.slot);
|
2016-06-07 18:50:41 -04:00
|
|
|
}
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
if (!itemStack.isEmpty()) {
|
2016-06-17 16:01:03 -07:00
|
|
|
ItemSigilHolding.cycleToNextSigil(itemStack, message.mode);
|
2016-06-07 18:50:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|