Advertisement
Naitenne

packet

Jan 29th, 2017
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. package net.railsofwar.row.stock.packets;
  2.  
  3. import io.netty.buffer.ByteBuf;
  4. import net.minecraft.client.Minecraft;
  5. import net.minecraft.entity.Entity;
  6. import net.minecraft.nbt.NBTTagCompound;
  7. import net.minecraftforge.fml.common.network.ByteBufUtils;
  8. import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
  9. import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
  10. import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
  11.  
  12. public class PacketSendClientNBTData implements IMessage{
  13.     private int id;
  14.     private NBTTagCompound tagCompound;
  15.  
  16.     public PacketSendClientNBTData(){
  17.     }
  18.  
  19.     public PacketSendClientNBTData(int id, NBTTagCompound tagCompound){
  20.         this.id = id;
  21.         this.tagCompound = tagCompound;
  22.     }
  23.  
  24.     @Override
  25.     public void toBytes(ByteBuf buf){
  26.         buf.writeInt(id);
  27.         ByteBufUtils.writeTag(buf, tagCompound);
  28.     }
  29.  
  30.     @Override
  31.     public void fromBytes(ByteBuf buf){
  32.         this.id = buf.readInt();
  33.         this.tagCompound = ByteBufUtils.readTag(buf);
  34.     }
  35.  
  36.     public static class Handler implements IMessageHandler<PacketSendClientNBTData, IMessage>{
  37.         @Override
  38.         public IMessage onMessage(PacketSendClientNBTData message, MessageContext ctx){
  39.             Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(message.id);
  40.             if(entity != null)
  41.                 entity.readFromNBT(message.tagCompound);
  42.             return null;
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement