Advertisement
HalestormXV

Untitled

Aug 24th, 2017
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.63 KB | None | 0 0
  1. package halestormxv.eAngelus.items;
  2.  
  3. import halestormxv.eAngelus.main.Reference;
  4. import net.minecraft.block.Block;
  5. import net.minecraft.block.BlockChest;
  6. import net.minecraft.entity.player.EntityPlayer;
  7. import net.minecraft.item.Item;
  8. import net.minecraft.item.ItemStack;
  9. import net.minecraft.nbt.NBTTagCompound;
  10. import net.minecraft.tileentity.TileEntity;
  11. import net.minecraft.util.ActionResult;
  12. import net.minecraft.util.EnumActionResult;
  13. import net.minecraft.util.EnumFacing;
  14. import net.minecraft.util.EnumHand;
  15. import net.minecraft.util.math.BlockPos;
  16. import net.minecraft.util.text.TextComponentString;
  17. import net.minecraft.world.World;
  18.  
  19. /**
  20.  * Created by Blaze on 8/24/2017.
  21.  */
  22. public class MysticKeystone extends Item
  23. {
  24.     public MysticKeystone(String name)
  25.     {
  26.         super();
  27.         this.setUnlocalizedName(name);
  28.         this.setCreativeTab(Reference.eaCreativeTab);
  29.     }
  30.  
  31.     public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
  32.     {
  33.         if (!world.isRemote)
  34.         {
  35.             ItemStack stack = player.getHeldItem(hand);
  36.             Block b = world.getBlockState(pos).getBlock();
  37.             if ((b instanceof BlockChest))
  38.             {
  39.                 TileEntity tileChest = world.getTileEntity(pos);
  40.                 NBTTagCompound tileTag = tileChest.getTileData();
  41.                 if ((tileTag.hasKey("divinationLock_k_kname")) && (tileTag.getString("divinationLock_k_kname").equals(stack.getDisplayName())))
  42.                 {
  43.                     tileTag.removeTag("divinationLock_k_kname");
  44.                     tileTag.removeTag("divinationLock_k_pname");
  45.                     tileTag.removeTag("divinationLock");
  46.                     player.sendMessage(new TextComponentString("The Mystic Bindings dispel."));
  47.                 }
  48.                 else
  49.                 {
  50.                     tileTag.setString("divinationLock_k_kname", stack.getDisplayName());
  51.                     //tileTag.setString("divinationLock_k_pname", player.getPersistentID().toString());
  52.                     tileTag.setString("divinationLock_k_pname", player.getName());
  53.                     //tileTag.setString("divinationLock", player.getName());
  54.                     tileTag.setString("divinationLock", player.getName());
  55.                     player.sendMessage(new TextComponentString("Mystic Bindings have been placed on the chest."));
  56.                 }
  57.             }
  58.             else
  59.             {
  60.                 System.out.println("Not a chest silly.");
  61.             }
  62.         }
  63.         return EnumActionResult.PASS;
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement