Advertisement
Eragonn14900

Untitled

Dec 6th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. @Override
  2. public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
  3. {
  4. if (worldIn.isRemote)
  5. return false;
  6.  
  7. if (playerIn.getHeldItem(hand) == null)
  8. {
  9. IBlockState newState;
  10. switch(state.getValue(BlockBookcaseMulti.TYPE))
  11. {
  12. // 2/3 full
  13. case two3:
  14. newState = state.withProperty(TYPE, EnumBookshelf.two2);
  15. break;
  16.  
  17. // 1/3 full
  18. case two2:
  19. newState = state.withProperty(TYPE, EnumBookshelf.one1);
  20. break;
  21.  
  22. //Empty
  23. default:
  24. // Can't empty an empty bookcase
  25. return false;
  26. }
  27.  
  28. worldIn.setBlockState(pos, newState);
  29. playerIn.inventory.addItemStackToInventory(new ItemStack(Items.BOOK));
  30.  
  31. return true;
  32. }
  33.  
  34. ItemStack book = new ItemStack(Items.BOOK);
  35.  
  36. if (playerIn.getHeldItemMainhand() == book)
  37. {
  38. IBlockState newState;
  39. switch (state.getValue(BlockBookcaseMulti.TYPE))
  40. {
  41. case one1:
  42. newState = state.withProperty(TYPE, EnumBookshelf.two2);
  43. break;
  44. case two2:
  45. newState = state.withProperty(TYPE, EnumBookshelf.two3);
  46. break;
  47. case two3:
  48. newState = Blocks.BOOKSHELF.getDefaultState();
  49. break;
  50. default:
  51. // For completeness
  52. return false;
  53. }
  54.  
  55. worldIn.setBlockState(pos, newState);
  56. --heldItem.stackSize;
  57. return true;
  58. }
  59.  
  60. return true;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement