Advertisement
Guest User

IMessageMinecraftPacketSenderHelp

a guest
Nov 4th, 2015
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.74 KB | None | 0 0
  1. @Override//This meathod sets the pos etc...
  2. public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
  3. {
  4.     if (!worldIn.isRemote)
  5.     {
  6.         if(!playerIn.isSneaking())
  7.         {
  8.             if(stack.getTagCompound() == null)
  9.             {
  10.                 stack.setTagCompound(new NBTTagCompound());
  11.             }
  12.             if (Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) && stack.getItemDamage() < stack.getMaxDamage())//Set coords (ctrl)
  13.             {
  14.                 NBTTagCompound nbt = new NBTTagCompound();
  15.                 nbt.setInteger("dim", playerIn.dimension);
  16.                 nbt.setInteger("posX", pos.getX());
  17.                 nbt.setInteger("posY", pos.getY());
  18.                 nbt.setInteger("posZ", pos.getZ());
  19.                 stack.getTagCompound().setTag("coords", nbt);
  20.                 stack.setStackDisplayName(EnumChatFormatting.DARK_PURPLE + "Personal Teleporter");
  21.                 playerIn.addChatMessage(new ChatComponentText("Coordinates set, press shift + control and right click to clear them, press shift and right click to teleport."));
  22.                 System.out.println(
  23.                         "\nItem can damage: " + stack.isItemStackDamageable() +
  24.                         "\nDamage: " + stack.getItemDamage() +
  25.                         "\nMax Damage: " + stack.getMaxDamage() +
  26.                         "\nDamage: " + stack.getItemDamage()
  27.                         );
  28.                 stack.damageItem(1, playerIn);
  29.                 if (stack.getItemDamage() >= stack.getMaxDamage())
  30.                 {
  31.                     playerIn.addChatMessage(new ChatComponentText("Battery has run out"));
  32.                     clearCoords(stack, worldIn, playerIn);
  33.                 }
  34.                 else
  35.                 {
  36.                     playerIn.addChatMessage(new ChatComponentText("Press control and click on a block to store the coordinates"));
  37.                 }
  38.                 Random rand = new Random();
  39.                 String UID = "" + rand.nextDouble();
  40.                 System.out.println("UID: " + UID);             
  41.             }
  42.             else
  43.             {
  44.                 if (stack.getItemDamage() >= stack.getMaxDamage())
  45.                 {
  46.                     playerIn.addChatMessage(new ChatComponentText("Battery has run out"));
  47.                     clearCoords(stack, worldIn, playerIn);
  48.                 }
  49.                 else
  50.                 {
  51.                     playerIn.addChatMessage(new ChatComponentText("Press control and click on a block to store the coordinates"));
  52.                 }
  53.             }
  54.         }
  55.     }      
  56.     return false;
  57. }
  58.  
  59.  
  60. //My modified basic packet
  61.     @Override
  62.     public IMessage onMessage(SimpleMessage message, MessageContext ctx)
  63.     {
  64.       // just to make sure that the side is correct
  65.       if (ctx.side.isClient())
  66.       {
  67.         int integer = message.simpleInt;
  68.         boolean bool = message.simpleBool;
  69.         System.out.println(
  70.                 "\nItems recieved on client: " +
  71.                 "\nInt: " + integer +
  72.                 "\nbool: " + bool
  73.                 );
  74.       }
  75.      if (ctx.side.isServer())
  76.       {
  77.         int integer = message.simpleInt;
  78.         boolean bool = message.simpleBool;
  79.         System.out.println(
  80.                 "\nItems recieved on Server: " +
  81.                 "\nInt: " + integer +
  82.                 "\nbool: " + bool
  83.                 );
  84.       }
  85.       return message;
  86.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement