Advertisement
Eragonn14900

Untitled

Nov 28th, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.29 KB | None | 0 0
  1. package com.reactioncraft.bookcase.common;
  2.  
  3. import java.util.List;
  4. import java.util.Random;
  5.  
  6. import javax.annotation.Nullable;
  7.  
  8. import com.reactioncraft.reactioncraft;
  9. import com.reactioncraft.core.common.blocks.BlockBase;
  10. import com.reactioncraft.desert.common.EnumHireoGlyphs;
  11. import com.reactioncraft.integration.instances.IntegratedBlocks;
  12. import net.minecraft.block.material.*;
  13. import net.minecraft.block.properties.*;
  14. import net.minecraft.block.state.*;
  15. import net.minecraft.creativetab.CreativeTabs;
  16. import net.minecraft.entity.player.EntityPlayer;
  17. import net.minecraft.init.Blocks;
  18. import net.minecraft.init.Items;
  19. import net.minecraft.item.*;
  20. import net.minecraft.stats.StatList;
  21. import net.minecraft.util.BlockRenderLayer;
  22. import net.minecraft.util.EnumFacing;
  23. import net.minecraft.util.EnumHand;
  24. import net.minecraft.util.math.BlockPos;
  25. import net.minecraft.world.World;
  26. import net.minecraftforge.fml.relauncher.*;
  27.  
  28. public class BlockBookcaseMulti extends BlockBase
  29. {
  30. public static final PropertyEnum<EnumBookshelf> TYPE = PropertyEnum.<EnumBookshelf>create("type", EnumBookshelf.class);
  31.  
  32. public BlockBookcaseMulti(String name, Material materialIn)
  33. {
  34. super(materialIn, name);
  35. this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, EnumBookshelf.one1));
  36. this.setCreativeTab(reactioncraft.Reactioncraft);
  37. }
  38.  
  39. /**
  40. * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
  41. * returns the metadata of the dropped item based on the old metadata of the block.
  42. */
  43. public int damageDropped(IBlockState state)
  44. {
  45. return ((EnumBookshelf)state.getValue(TYPE)).getMetadata();
  46. }
  47.  
  48. /**
  49. * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
  50. */
  51. @SideOnly(Side.CLIENT)
  52. public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
  53. {
  54. for (EnumBookshelf types : EnumBookshelf.values())
  55. {
  56. list.add(new ItemStack(itemIn, 1, types.getMetadata()));
  57. }
  58. }
  59.  
  60. /**
  61. * Convert the BlockState into the correct metadata value
  62. */
  63. public int getMetaFromState(IBlockState state)
  64. {
  65. return ((EnumBookshelf)state.getValue(TYPE)).getMetadata();
  66. }
  67.  
  68. /**
  69. * Convert the given metadata into a BlockState for this Block
  70. */
  71. public IBlockState getStateFromMeta(int meta)
  72. {
  73. return this.getDefaultState().withProperty(TYPE, EnumBookshelf.byMetadata(meta));
  74. }
  75.  
  76. protected BlockStateContainer createBlockState()
  77. {
  78. return new BlockStateContainer(this, new IProperty[] {TYPE});
  79. }
  80.  
  81. //Change Meta
  82. public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
  83. {
  84. ItemStack stacktosubtract = new ItemStack(Items.BOOK);
  85. ItemStack stacktoadd = new ItemStack(Items.BOOK);
  86.  
  87. //Change from empty to partially filled
  88. if (IntegratedBlocks.bookcases.getDefaultState().getValue(BlockBookcaseMulti.TYPE) == EnumBookshelf.one1)
  89. {
  90. System.out.println("hi");
  91.  
  92. if(heldItem.getItem() == Items.BOOK)
  93. {
  94. System.out.println("changed into 1");
  95. worldIn.setBlockState(pos, this.blockState.getBaseState().withProperty(TYPE, EnumBookshelf.two2));
  96. --stacktosubtract.stackSize;
  97. return true;
  98. }
  99.  
  100. }
  101.  
  102. //Change from 1/3 to 2/3 filled
  103. if (IntegratedBlocks.bookcases.getDefaultState().getValue(BlockBookcaseMulti.TYPE) == EnumBookshelf.two2)
  104. {
  105. if(heldItem.getItem() == Items.BOOK)
  106. {
  107. System.out.println("changed into 2");
  108. worldIn.setBlockState(pos, this.blockState.getBaseState().withProperty(TYPE, EnumBookshelf.two3));
  109. --stacktosubtract.stackSize;
  110. return true;
  111. }
  112. }
  113.  
  114. //Change from 2/3 to filled
  115. if (IntegratedBlocks.bookcases.getDefaultState().getValue(BlockBookcaseMulti.TYPE) == EnumBookshelf.two3)
  116. {
  117. if(heldItem.getItem() == Items.BOOK)
  118. {
  119. System.out.println("changed into 3");
  120. worldIn.setBlockState(pos, this.blockState.getBaseState().withProperty(TYPE, EnumBookshelf.three1));
  121. --stacktosubtract.stackSize;
  122. return true;
  123. }
  124. }
  125.  
  126. //Change from filled to 2/3
  127. if (IntegratedBlocks.bookcases.getDefaultState().getValue(BlockBookcaseMulti.TYPE) == EnumBookshelf.three1)
  128. {
  129. if(heldItem.getItem() != Items.BOOK)
  130. {
  131. worldIn.setBlockState(pos, this.blockState.getBaseState().withProperty(TYPE, EnumBookshelf.two3));
  132. playerIn.inventory.addItemStackToInventory(stacktoadd);
  133. return true;
  134. }
  135. }
  136.  
  137. //Change from 2/3 to 1/3
  138. if (IntegratedBlocks.bookcases.getDefaultState().getValue(BlockBookcaseMulti.TYPE) == EnumBookshelf.two3)
  139. {
  140. if(heldItem.getItem() != Items.BOOK)
  141. {
  142. worldIn.setBlockState(pos, this.blockState.getBaseState().withProperty(TYPE, EnumBookshelf.two2));
  143. playerIn.inventory.addItemStackToInventory(stacktoadd);
  144. return true;
  145. }
  146. }
  147.  
  148. //Change from 1/3 to empty
  149. if (IntegratedBlocks.bookcases.getDefaultState().getValue(BlockBookcaseMulti.TYPE) == EnumBookshelf.two2)
  150. {
  151. if(heldItem.getItem() != Items.BOOK)
  152. {
  153. worldIn.setBlockState(pos, this.blockState.getBaseState().withProperty(TYPE, EnumBookshelf.one1));
  154. playerIn.inventory.addItemStackToInventory(stacktoadd);
  155. return true;
  156. }
  157. }
  158.  
  159. else
  160. {
  161. return false;
  162. }
  163. return true;
  164. }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement