Guest User

Untitled

a guest
Dec 26th, 2015
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. package Com.gun.Packet;
  2.  
  3.  
  4. import Com.gun.gun.ItemGun;
  5. import cpw.mods.fml.common.network.ByteBufUtils;
  6. import cpw.mods.fml.common.network.simpleimpl.IMessage;
  7. import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
  8. import cpw.mods.fml.common.network.simpleimpl.MessageContext;
  9. import io.netty.buffer.ByteBuf;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.item.Item;
  12. import net.minecraft.nbt.NBTTagCompound;
  13.  
  14. public class GunFirePacket
  15. implements IMessage
  16. {
  17. private String username;
  18. private ItemGun gun;
  19. private int gunIndex;
  20.  
  21. public GunFirePacket() {}
  22.  
  23. public GunFirePacket(String username, ItemGun gun, int gunIndex)
  24. {
  25. this.username = username;
  26. this.gun = gun;
  27. this.gunIndex = gunIndex;
  28. }
  29.  
  30. public String getUsername()
  31. {
  32. return this.username;
  33. }
  34.  
  35. public ItemGun getGun()
  36. {
  37. return this.gun;
  38. }
  39.  
  40. public int getGunIndex()
  41. {
  42. return this.gunIndex;
  43. }
  44.  
  45. public void fromBytes(ByteBuf buf)
  46. {
  47. NBTTagCompound nbt = ByteBufUtils.readTag(buf);
  48.  
  49. this.username = nbt.getString("username");
  50. this.gun = ((ItemGun)Item.getItemById(nbt.getInteger("gun")));
  51. this.gunIndex = nbt.getInteger("slot");
  52. }
  53.  
  54. public void toBytes(ByteBuf buf)
  55. {
  56. NBTTagCompound nbt = new NBTTagCompound();
  57.  
  58. nbt.setString("username", getUsername());
  59. nbt.setInteger("gun", Item.getIdFromItem(getGun()));
  60. nbt.setInteger("slot", getGunIndex());
  61.  
  62. ByteBufUtils.writeTag(buf, nbt);
  63. }
  64.  
  65. public static class Handler
  66. implements IMessageHandler<GunFirePacket, IMessage>
  67. {
  68. public IMessage onMessage(GunFirePacket message, MessageContext ctx)
  69. {
  70. EntityPlayer player = PacketUtil.getPlayer(message.getUsername());
  71.  
  72.  
  73. message.getGun().fireGun(player, player.inventory.mainInventory[message.getGunIndex()], player.worldObj);
  74.  
  75.  
  76. return null;
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment