Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.45 KB | None | 0 0
  1. package com.github.QVBA.Networking;
  2.  
  3. import com.github.QVBA.NBT.PlayerEntityProperties;
  4.  
  5. import net.minecraft.client.Minecraft;
  6. import net.minecraft.entity.Entity;
  7. import net.minecraft.entity.player.EntityPlayer;
  8. import io.netty.buffer.ByteBuf;
  9. import cpw.mods.fml.common.network.simpleimpl.IMessage;
  10. import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
  11. import cpw.mods.fml.common.network.simpleimpl.MessageContext;
  12.  
  13. public class Packet implements IMessage{
  14.    
  15.     private boolean skullStatus;
  16.     private int entityID;
  17.    
  18.     public Packet(){}
  19.     public Packet(EntityPlayer player) {
  20.         skullStatus = PlayerEntityProperties.get(player).isSkulled();
  21.         entityID = player.getEntityId();
  22.     }
  23.  
  24.     @Override
  25.     public void fromBytes(ByteBuf buf) {
  26.         skullStatus = buf.readBoolean();
  27.         entityID = buf.readInt();
  28.     }
  29.  
  30.     @Override
  31.     public void toBytes(ByteBuf buf) {
  32.         buf.writeBoolean(skullStatus);
  33.         buf.writeInt(entityID);
  34.        
  35.     }
  36.    
  37.     public static class PacketHandler implements IMessageHandler<Packet, IMessage> {
  38.  
  39.         @Override
  40.         public IMessage onMessage(Packet message, MessageContext ctx) {
  41.             int entityID = message.entityID;
  42.             Entity myEntity = Minecraft.getMinecraft().theWorld.getEntityByID(entityID);
  43.             if(myEntity instanceof EntityPlayer) { //Should never be null, but check anyway.
  44.                 EntityPlayer thePlayer = (EntityPlayer) myEntity;
  45.                 PlayerEntityProperties.get(thePlayer).setSkulled(message.skullStatus);
  46.             }
  47.             return null;
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement