Guest User

Untitled

a guest
Mar 13th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.10 KB | None | 0 0
  1. package com.mart.solar.common.blocks;
  2.  
  3. import com.mart.solar.Solar;
  4. import com.mart.solar.common.blocks.base.BlockBase;
  5. import com.mart.solar.common.blocks.base.BlockEnum;
  6. import com.mart.solar.common.blocks.enums.EnumMenhir;
  7. import com.mart.solar.common.blocks.enums.EnumSunBurnt;
  8. import com.mart.solar.common.tileentities.TileMenhir;
  9. import net.minecraft.block.BlockHorizontal;
  10. import net.minecraft.block.SoundType;
  11. import net.minecraft.block.material.Material;
  12. import net.minecraft.block.properties.PropertyDirection;
  13. import net.minecraft.block.state.BlockFaceShape;
  14. import net.minecraft.block.state.BlockStateContainer;
  15. import net.minecraft.block.state.IBlockState;
  16. import net.minecraft.entity.EntityLivingBase;
  17. import net.minecraft.entity.item.EntityItem;
  18. import net.minecraft.entity.player.EntityPlayer;
  19. import net.minecraft.item.ItemStack;
  20. import net.minecraft.tileentity.TileEntity;
  21. import net.minecraft.util.EnumFacing;
  22. import net.minecraft.util.EnumHand;
  23. import net.minecraft.util.Mirror;
  24. import net.minecraft.util.Rotation;
  25. import net.minecraft.util.math.AxisAlignedBB;
  26. import net.minecraft.util.math.BlockPos;
  27. import net.minecraft.world.IBlockAccess;
  28. import net.minecraft.world.World;
  29.  
  30. import javax.annotation.Nullable;
  31.  
  32. public class BlockMenhir extends BlockEnum<EnumMenhir> {
  33.  
  34. public static final PropertyDirection FACING = BlockHorizontal.FACING;
  35.  
  36. public BlockMenhir() {
  37. super(Material.ROCK, EnumMenhir.class);
  38. setUnlocalizedName(Solar.MODID + ".menhir_");
  39. setCreativeTab(Solar.solarTab);
  40.  
  41. setHardness(3.0F);
  42. setResistance(5.0F);
  43. setSoundType(SoundType.STONE);
  44. setHarvestLevel("pickaxe", 0);
  45.  
  46. setDefaultState(blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
  47. }
  48.  
  49. @Override
  50. public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  51. TileMenhir tileEntity = (TileMenhir) world.getTileEntity(pos);
  52. ItemStack heldItem = player.getHeldItem(hand);
  53.  
  54. if (world.isRemote || tileEntity == null) {
  55. return true;
  56. }
  57.  
  58. if (player.isSneaking()){
  59. player.swingArm(hand);
  60. tileEntity.extractItem(player);
  61. return true;
  62. }
  63.  
  64. if (!heldItem.isEmpty()) {
  65. tileEntity.addRune(heldItem, player, hand);
  66. return true;
  67. }
  68.  
  69. return true;
  70. }
  71.  
  72. @Override
  73. public void breakBlock(World world, BlockPos pos, IBlockState state) {
  74. TileMenhir tileEntity = (TileMenhir) world.getTileEntity(pos);
  75.  
  76. if (world.isRemote || tileEntity == null) {
  77. return;
  78. }
  79.  
  80. if (tileEntity.getItemStackHandler().getStackInSlot(0).isEmpty()) {
  81. return;
  82. }
  83.  
  84. double d0 = (double) (world.rand.nextFloat() * 0.5F) + 0.25D;
  85. double d1 = (double) (world.rand.nextFloat() * 0.5F) + 0.25D;
  86. double d2 = (double) (world.rand.nextFloat() * 0.5F) + 0.25D;
  87. EntityItem dropItem = new EntityItem(world, (double) pos.getX() + d0, (double) pos.getY() + d1, (double) pos.getZ() + d2, tileEntity.getItemStackHandler().getStackInSlot(0));
  88. dropItem.setDefaultPickupDelay();
  89. world.spawnEntity(dropItem);
  90. }
  91.  
  92. @Override
  93. public boolean hasTileEntity(IBlockState state) {
  94. return true;
  95. }
  96.  
  97. @Nullable
  98. @Override
  99. public TileEntity createTileEntity(World world, IBlockState state) {
  100. return new TileMenhir();
  101. }
  102.  
  103. @Override
  104. public boolean isFullCube(IBlockState state) {
  105. return false;
  106. }
  107.  
  108. @Override
  109. @Deprecated
  110. public boolean isOpaqueCube(IBlockState state) {
  111. return false;
  112. }
  113.  
  114. @Override
  115. public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face) {
  116. return BlockFaceShape.UNDEFINED;
  117. }
  118.  
  119. /**
  120. * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
  121. * IBlockstate
  122. */
  123. @Override
  124. public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand)
  125. {
  126. return getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
  127. }
  128.  
  129. /**
  130. * Called by ItemBlocks after a block is set in the world, to allow post-place logic
  131. */
  132. @Override
  133. public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
  134. {
  135. worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
  136. super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
  137. }
  138.  
  139. /**
  140. * Convert the given metadata into a BlockState for this Block
  141. */
  142. @Override
  143. public IBlockState getStateFromMeta(int meta)
  144. {
  145. return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
  146. }
  147.  
  148. /**
  149. * Convert the BlockState into the correct metadata value
  150. */
  151. @Override
  152. public int getMetaFromState(IBlockState state)
  153. {
  154. return state.getValue(FACING).getHorizontalIndex();
  155. }
  156.  
  157. /**
  158. * Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
  159. * blockstate.
  160. */
  161. @Override
  162. public IBlockState withRotation(IBlockState state, Rotation rot)
  163. {
  164. return state.withProperty(FACING, rot.rotate(state.getValue(FACING)));
  165. }
  166.  
  167. /**
  168. * Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
  169. * blockstate.
  170. */
  171. @Override
  172. public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
  173. {
  174. return state.withRotation(mirrorIn.toRotation(state.getValue(FACING)));
  175. }
  176.  
  177. @Override
  178. protected BlockStateContainer createBlockState()
  179. {
  180. return new BlockStateContainer(this, FACING);
  181. }
  182. }
Add Comment
Please, Sign In to add comment