O3Bubbles09

ItemCoordCache

Jan 24th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.38 KB | None | 0 0
  1. package me.robert.teleport.items;
  2.  
  3. import java.util.List;
  4.  
  5. import net.minecraft.entity.player.EntityPlayer;
  6. import net.minecraft.item.Item;
  7. import net.minecraft.item.ItemStack;
  8. import net.minecraft.nbt.NBTTagCompound;
  9. import net.minecraft.util.BlockPos;
  10. import net.minecraft.util.EnumChatFormatting;
  11. import net.minecraft.util.EnumFacing;
  12. import net.minecraft.world.World;
  13. import net.minecraftforge.fml.relauncher.Side;
  14. import net.minecraftforge.fml.relauncher.SideOnly;
  15.  
  16. public class ItemCoordCache extends Item {
  17.  
  18.     @Override
  19.     public boolean onItemUse(ItemStack stack, EntityPlayer playerIn,
  20.             World worldIn, BlockPos pos, EnumFacing side, float hitX,
  21.             float hitY, float hitZ) {
  22.  
  23.         if (!playerIn.isSneaking()) {
  24.             if (stack.getTagCompound() == null) {
  25.                 stack.setTagCompound(new NBTTagCompound());
  26.             }
  27.  
  28.             NBTTagCompound nbt = new NBTTagCompound();
  29.             nbt.setInteger("dim", playerIn.dimension);
  30.             nbt.setInteger("posX", pos.getX());
  31.             nbt.setInteger("posY", pos.getY());
  32.             nbt.setInteger("posZ", pos.getZ());
  33.             stack.getTagCompound().setTag("coord", nbt);
  34.             stack.setStackDisplayName(EnumChatFormatting.AQUA
  35.                     + "Coordanite Cache");
  36.         }
  37.         return false;
  38.     }
  39.  
  40.     @Override
  41.     public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn,
  42.             EntityPlayer playerIn) {
  43.  
  44.         if (playerIn.isSneaking()) {
  45.             if (itemStackIn.getTagCompound() != null) {
  46.                 itemStackIn.getTagCompound().removeTag("coord");
  47.                 itemStackIn.clearCustomName();
  48.             }
  49.         }
  50.         return itemStackIn;
  51.     }
  52.  
  53.     @Override
  54.     @SideOnly(Side.CLIENT)
  55.     public void addInformation(ItemStack stack, EntityPlayer playerIn,
  56.             List tooltip, boolean advanced) {
  57.         if (stack.getTagCompound() != null) {
  58.             if (stack.getTagCompound().hasKey("coord")) {
  59.                 NBTTagCompound nbt = (NBTTagCompound) stack.getTagCompound()
  60.                         .getTag("coord");
  61.                 int dim = nbt.getInteger("dim");
  62.                 int posX = nbt.getInteger("posX");
  63.                 int posY = nbt.getInteger("posY");
  64.                 int posZ = nbt.getInteger("posZ");
  65.  
  66.                 String aqua = EnumChatFormatting.AQUA + "";
  67.                 String purple = EnumChatFormatting.DARK_PURPLE + "";
  68.                
  69.                 tooltip.add(aqua + "Dim: " + purple + dim);
  70.                 tooltip.add(aqua + "X: " + purple + posX);
  71.                 tooltip.add(aqua + "Y: " + purple + posY);
  72.                 tooltip.add(aqua + "Z: " + purple + posZ);
  73.             }
  74.         }
  75.     }
  76.  
  77.     @Override
  78.     public boolean hasEffect(ItemStack stack) {
  79.         if (stack.getTagCompound() != null) {
  80.             return stack.getTagCompound().hasKey("coord");
  81.         }
  82.         return false;
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment