Eragonn14900

Untitled

Dec 6th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. @SubscribeEvent //Turn Regular Bookcase into my partially empty one
  2. public void onPlayerClickEvent(RightClickBlock event)
  3. {
  4. EnumHand hand = event.getHand();
  5. ItemStack stacktoAdd = new ItemStack(Items.BOOK);
  6. ItemStack stack = event.getEntityPlayer().getHeldItem(hand);
  7. final IBlockState set2 = IntegratedBlocks.bookcases.getDefaultState().withProperty(BlockBookcaseMulti.TYPE, EnumBookshelf.two3); // 2/3 full
  8.  
  9. if (!event.getWorld().isRemote)
  10. {
  11. if (event.getEntity() instanceof EntityPlayer)
  12. {
  13. //If Hand is empty //If Block is a bookshelf
  14. if (stack == null && event.getWorld().getBlockState(event.getPos()).getBlock() == Blocks.BOOKSHELF)
  15. {
  16. //Set block to 2/3 full bookcase
  17. event.getWorld().setBlockState(event.getPos(), set2);
  18. //Add Book to inventory
  19. event.getEntityPlayer().inventory.addItemStackToInventory(stacktoAdd);
  20. System.out.println("Hey i changed back");//Notify Console
  21. }
  22. if (stack != null && event.getWorld().getBlockState(event.getPos()).getBlock() == Blocks.BOOKSHELF)
  23. {
  24. //Cancel event if you have an item in your hand
  25. event.isCanceled();
  26. }
  27. }
  28. }
  29. }
Add Comment
Please, Sign In to add comment