Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ItemPersonalTeleporter extends Item
- {
- @Override//This meathod sets the pos etc...
- public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
- {
- if (!worldIn.isRemote)
- {
- if(!playerIn.isSneaking())
- {
- if(stack.getTagCompound() == null)
- {
- stack.setTagCompound(new NBTTagCompound());
- }
- if (Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) && stack.getItemDamage() < stack.getMaxDamage())//Set coords (ctrl)
- {
- NBTTagCompound nbt = new NBTTagCompound();
- nbt.setInteger("dim", playerIn.dimension);
- nbt.setInteger("posX", pos.getX());
- nbt.setInteger("posY", pos.getY());
- nbt.setInteger("posZ", pos.getZ());
- stack.getTagCompound().setTag("coords", nbt);
- stack.setStackDisplayName(EnumChatFormatting.DARK_PURPLE + "Personal Teleporter");
- playerIn.addChatMessage(new ChatComponentText("Coordinates set, press shift + control and right click to clear them, press shift and right click to teleport."));
- System.out.println(
- "\nItem can damage: " + stack.isItemStackDamageable() +
- "\nDamage: " + stack.getItemDamage() +
- "\nMax Damage: " + stack.getMaxDamage() +
- "\nDamage: " + stack.getItemDamage()
- );
- stack.damageItem(1, playerIn);
- List<CoordEntry> toolTip = new ArrayList<CoordEntry>();
- addInformation(stack, playerIn, toolTip, true);
- if (stack.getItemDamage() >= stack.getMaxDamage())
- {
- playerIn.addChatMessage(new ChatComponentText("Battery has run out"));
- clearCoords(stack, worldIn, playerIn);
- }
- else
- {
- playerIn.addChatMessage(new ChatComponentText("Press control and click on a block to store the coordinates"));
- }
- Random rand = new Random();
- String UID = "" + rand.nextDouble();
- System.out.println("UID: " + UID);
- //IMessage msg = new SimplePacket.SimpleMessage(8450, true);
- //PacketHandler.net.sendToServer(msg);
- }
- else
- {
- if (stack.getItemDamage() >= stack.getMaxDamage())
- {
- playerIn.addChatMessage(new ChatComponentText("Battery has run out"));
- clearCoords(stack, worldIn, playerIn);
- }
- else
- {
- playerIn.addChatMessage(new ChatComponentText("Press control and click on a block to store the coordinates"));
- }
- }
- }
- }
- return false;
- }
- @Override//Clears the item coords
- public ItemStack onItemRightClick(ItemStack stack, World worldIn, EntityPlayer playerIn)
- {
- //if (!worldIn.isRemote)
- {
- if (playerIn.isSneaking() && !Keyboard.isKeyDown(Keyboard.KEY_LCONTROL))
- {
- if(stack.getTagCompound() == null)
- {
- stack.setTagCompound(new NBTTagCompound());
- }
- if(stack.getTagCompound().hasKey("coords") && !Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) && stack.getItemDamage() < stack.getMaxDamage())//Teleport player control+shift
- {
- System.out.println(
- "\nItem can damage: " + stack.isItemStackDamageable() +
- "\nDamage: " + stack.getItemDamage() +
- "\nMax Damage: " + stack.getMaxDamage() +
- "\nDamage: " + stack.getItemDamage()
- );
- NBTTagCompound nbt = (NBTTagCompound) stack.getTagCompound().getTag("coords");
- int dim = nbt.getInteger("dim");
- int X = nbt.getInteger("posX");
- int Y = nbt.getInteger("posY");
- int Z = nbt.getInteger("posZ");
- drawParticles.Teleport(worldIn, playerIn.getPosition().getX(), playerIn.getPosition().getY(), playerIn.getPosition().getZ());
- playerIn.setPositionAndUpdate(X+0.5, Y+1, Z+0.5);
- drawParticles.Teleport(worldIn, playerIn.getPosition().getX(), playerIn.getPosition().getY(), playerIn.getPosition().getZ());
- System.out.println("\nTeleported " + playerIn + " to: " + "X: " + Z + " Y: " + Y + " Z: " + Z);
- stack.damageItem(1, playerIn);
- if (stack.getItemDamage() >= stack.getMaxDamage())
- {
- playerIn.addChatMessage(new ChatComponentText("Battery has run out"));
- }
- else
- {
- playerIn.addChatMessage(new ChatComponentText("Press control and click on a block to store the coordinates"));
- }
- }
- else
- {
- System.out.println("\nCould not teleport because no teleport was set or not pressing control");
- }
- }
- if(playerIn.isSneaking() && Keyboard.isKeyDown(Keyboard.KEY_LCONTROL))
- {
- clearCoords(stack, worldIn, playerIn);
- }
- }
- return stack;
- }
- public static ItemStack clearCoords(ItemStack stack, World worldIn, EntityPlayer playerIn)
- {
- //if (!worldIn.isRemote)
- {
- if(stack.getTagCompound() != null)
- {
- stack.getTagCompound().removeTag("coords");
- stack.clearCustomName();
- }
- }
- return stack;
- }
- @Override
- @SideOnly(Side.CLIENT)//stores the coords and notifies the player
- public void addInformation(ItemStack stack, EntityPlayer playerIn, List toolTip, boolean advanced)
- {
- if(stack.getTagCompound() != null)
- {
- if(stack.getTagCompound().hasKey("coords"))
- {
- System.out.println("\nStoring coords.");
- NBTTagCompound nbt = (NBTTagCompound) stack.getTagCompound().getTag("coords");
- int dim = nbt.getInteger("dim");
- int posX = nbt.getInteger("posX");
- int posY = nbt.getInteger("posY");
- int posZ = nbt.getInteger("posZ");
- toolTip.add("Dimension: " + dim + " X: " + posX + " Y: " + posY + " Z: " + posZ);
- //ItemStack k = new ItemStack(testItems.test_item, 2);
- //k.damageItem(stack.getItemDamage() + 1, playerIn);
- }
- else
- {
- System.out.println("\nTag compound did not have \"coords\"");
- }
- }
- else
- {
- System.out.println("\nTag compound was null.");
- }
- }
- @Override
- @SideOnly(Side.CLIENT)
- public boolean hasEffect(ItemStack stack)
- {
- if(stack.getTagCompound() != null)
- {
- return stack.getTagCompound().hasKey("coords");
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement