Created
April 28, 2015 18:52
-
-
Save IamRob-/5bdd242e3aa852b64ebf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package iamrob.multilink.network.message; | |
| import cpw.mods.fml.common.FMLCommonHandler; | |
| 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 iamrob.multilink.item.ItemLinkHolder; | |
| import iamrob.multilink.util.LogHelper; | |
| import io.netty.buffer.ByteBuf; | |
| import net.minecraft.entity.player.EntityPlayer; | |
| import net.minecraft.item.ItemStack; | |
| public class MessageActivateBook implements IMessage, IMessageHandler<MessageActivateBook, IMessage> | |
| { | |
| public byte id; | |
| public MessageActivateBook() | |
| { | |
| } | |
| public MessageActivateBook(byte id) | |
| { | |
| this.id = id; | |
| } | |
| @Override | |
| public void fromBytes(ByteBuf buf) | |
| { | |
| id = buf.readByte(); | |
| LogHelper.info("["+ FMLCommonHandler.instance().getEffectiveSide().toString() + "] fromBytes: " + id); | |
| } | |
| @Override | |
| public void toBytes(ByteBuf buf) | |
| { | |
| LogHelper.info("["+ FMLCommonHandler.instance().getEffectiveSide().toString() + "] toBytes: " + id); | |
| buf.writeByte(id); | |
| } | |
| @Override | |
| public IMessage onMessage(MessageActivateBook message, MessageContext ctx) | |
| { | |
| EntityPlayer player = ctx.getServerHandler().playerEntity; | |
| LogHelper.info("["+ FMLCommonHandler.instance().getEffectiveSide().toString() + "] onMessage: " + id); | |
| if (player != null) { | |
| ItemStack stack = player.getHeldItem(); | |
| if (stack == null || !(stack.getItem() instanceof ItemLinkHolder)) | |
| return null; | |
| ItemLinkHolder item = (ItemLinkHolder) stack.getItem(); | |
| item.linkActivate(id, player.worldObj, player); | |
| } | |
| return null; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment