Advertisement
Guest User

v2JavaIMessageMinecraftHelp

a guest
Nov 4th, 2015
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.90 KB | None | 0 0
  1. public class ItemPersonalTeleporter extends Item
  2. {
  3.     @Override//This meathod sets the pos etc...
  4.     public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
  5.     {
  6.         if (!worldIn.isRemote)
  7.         {
  8.             if(!playerIn.isSneaking())
  9.             {
  10.                 if(stack.getTagCompound() == null)
  11.                 {
  12.                     stack.setTagCompound(new NBTTagCompound());
  13.                 }
  14.                 if (Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) && stack.getItemDamage() < stack.getMaxDamage())//Set coords (ctrl)
  15.                 {
  16.                     NBTTagCompound nbt = new NBTTagCompound();
  17.                     nbt.setInteger("dim", playerIn.dimension);
  18.                     nbt.setInteger("posX", pos.getX());
  19.                     nbt.setInteger("posY", pos.getY());
  20.                     nbt.setInteger("posZ", pos.getZ());
  21.                     stack.getTagCompound().setTag("coords", nbt);
  22.                     stack.setStackDisplayName(EnumChatFormatting.DARK_PURPLE + "Personal Teleporter");
  23.                     playerIn.addChatMessage(new ChatComponentText("Coordinates set, press shift + control and right click to clear them, press shift and right click to teleport."));
  24.                     System.out.println(
  25.                             "\nItem can damage: " + stack.isItemStackDamageable() +
  26.                             "\nDamage: " + stack.getItemDamage() +
  27.                             "\nMax Damage: " + stack.getMaxDamage() +
  28.                             "\nDamage: " + stack.getItemDamage()
  29.                             );
  30.                     stack.damageItem(1, playerIn);
  31.                     List<CoordEntry> toolTip = new ArrayList<CoordEntry>();
  32.                     addInformation(stack, playerIn, toolTip, true);
  33.                    
  34.                     if (stack.getItemDamage() >= stack.getMaxDamage())
  35.                     {
  36.                         playerIn.addChatMessage(new ChatComponentText("Battery has run out"));
  37.                         clearCoords(stack, worldIn, playerIn);
  38.                     }
  39.                     else
  40.                     {
  41.                         playerIn.addChatMessage(new ChatComponentText("Press control and click on a block to store the coordinates"));
  42.                     }
  43.                     Random rand = new Random();
  44.                     String UID = "" + rand.nextDouble();
  45.                     System.out.println("UID: " + UID);
  46.                    
  47.                     //IMessage msg = new SimplePacket.SimpleMessage(8450, true);
  48.                     //PacketHandler.net.sendToServer(msg);
  49.                    
  50.                 }
  51.                 else
  52.                 {
  53.                     if (stack.getItemDamage() >= stack.getMaxDamage())
  54.                     {
  55.                         playerIn.addChatMessage(new ChatComponentText("Battery has run out"));
  56.                         clearCoords(stack, worldIn, playerIn);
  57.                     }
  58.                     else
  59.                     {
  60.                         playerIn.addChatMessage(new ChatComponentText("Press control and click on a block to store the coordinates"));
  61.                     }
  62.                 }
  63.                
  64.             }
  65.         }
  66.        
  67.         return false;
  68.     }
  69.    
  70.     @Override//Clears the item coords
  71.     public ItemStack onItemRightClick(ItemStack stack, World worldIn, EntityPlayer playerIn)
  72.     {
  73.         //if (!worldIn.isRemote)
  74.         {
  75.             if (playerIn.isSneaking() && !Keyboard.isKeyDown(Keyboard.KEY_LCONTROL))
  76.             {
  77.                 if(stack.getTagCompound() == null)
  78.                 {
  79.                     stack.setTagCompound(new NBTTagCompound());
  80.                 }
  81.                 if(stack.getTagCompound().hasKey("coords") && !Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) && stack.getItemDamage() < stack.getMaxDamage())//Teleport player control+shift
  82.                 {
  83.                     System.out.println(
  84.                             "\nItem can damage: " + stack.isItemStackDamageable() +
  85.                             "\nDamage: " + stack.getItemDamage() +
  86.                             "\nMax Damage: " + stack.getMaxDamage() +
  87.                             "\nDamage: " + stack.getItemDamage()
  88.                             );
  89.                     NBTTagCompound nbt = (NBTTagCompound) stack.getTagCompound().getTag("coords");
  90.                     int dim = nbt.getInteger("dim");
  91.                     int X = nbt.getInteger("posX");
  92.                     int Y = nbt.getInteger("posY");
  93.                     int Z = nbt.getInteger("posZ");
  94.                     drawParticles.Teleport(worldIn, playerIn.getPosition().getX(), playerIn.getPosition().getY(), playerIn.getPosition().getZ());
  95.                     playerIn.setPositionAndUpdate(X+0.5, Y+1, Z+0.5);
  96.                     drawParticles.Teleport(worldIn, playerIn.getPosition().getX(), playerIn.getPosition().getY(), playerIn.getPosition().getZ());
  97.                     System.out.println("\nTeleported " + playerIn + " to: " + "X: " + Z + " Y: " + Y + " Z: " + Z);
  98.                    
  99.                     stack.damageItem(1, playerIn);
  100.                     if (stack.getItemDamage() >= stack.getMaxDamage())
  101.                     {
  102.                         playerIn.addChatMessage(new ChatComponentText("Battery has run out"));
  103.                     }
  104.                     else
  105.                     {
  106.                         playerIn.addChatMessage(new ChatComponentText("Press control and click on a block to store the coordinates"));
  107.                     }                  
  108.                 }
  109.                 else
  110.                 {
  111.                     System.out.println("\nCould not teleport because no teleport was set or not pressing control");
  112.                 }
  113.             }
  114.             if(playerIn.isSneaking() && Keyboard.isKeyDown(Keyboard.KEY_LCONTROL))
  115.             {
  116.                 clearCoords(stack, worldIn, playerIn);
  117.             }
  118.         }
  119.         return stack;
  120.     }
  121.     public static ItemStack clearCoords(ItemStack stack, World worldIn, EntityPlayer playerIn)
  122.     {
  123.         //if (!worldIn.isRemote)
  124.         {
  125.         if(stack.getTagCompound() != null)
  126.         {
  127.             stack.getTagCompound().removeTag("coords");
  128.             stack.clearCustomName();
  129.         }
  130.         }
  131.         return stack;
  132.     }
  133.    
  134.     @Override
  135.     @SideOnly(Side.CLIENT)//stores the coords and notifies the player
  136.     public void addInformation(ItemStack stack, EntityPlayer playerIn, List toolTip, boolean advanced)
  137.     {
  138.         if(stack.getTagCompound() != null)
  139.         {
  140.             if(stack.getTagCompound().hasKey("coords"))
  141.             {
  142.                 System.out.println("\nStoring coords.");
  143.                 NBTTagCompound nbt = (NBTTagCompound) stack.getTagCompound().getTag("coords");
  144.                 int dim = nbt.getInteger("dim");
  145.                 int posX = nbt.getInteger("posX");
  146.                 int posY = nbt.getInteger("posY");
  147.                 int posZ = nbt.getInteger("posZ");
  148.                 toolTip.add("Dimension: " + dim + " X: " + posX + " Y: " + posY + " Z: " + posZ);
  149.                
  150.                 //ItemStack k = new ItemStack(testItems.test_item, 2);
  151.                 //k.damageItem(stack.getItemDamage() + 1, playerIn);
  152.             }
  153.             else
  154.             {
  155.                 System.out.println("\nTag compound did not have \"coords\"");
  156.             }
  157.         }
  158.         else
  159.         {
  160.             System.out.println("\nTag compound was null.");
  161.         }
  162.     }
  163.    
  164.     @Override
  165.     @SideOnly(Side.CLIENT)
  166.     public boolean hasEffect(ItemStack stack)
  167.     {
  168.         if(stack.getTagCompound() != null)
  169.         {
  170.             return stack.getTagCompound().hasKey("coords");
  171.         }
  172.         return false;
  173.     }
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement