Advertisement
grossik

Untitled

Oct 21st, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.11 KB | None | 0 0
  1. package cz.grossik.farmcraft2.easteregg;
  2.  
  3. import java.util.Random;
  4.  
  5. import javax.annotation.Nullable;
  6.  
  7. import cz.grossik.farmcraft2.handler.ItemHandler;
  8. import net.minecraft.block.Block;
  9. import net.minecraft.block.BlockHorizontal;
  10. import net.minecraft.block.material.Material;
  11. import net.minecraft.block.properties.IProperty;
  12. import net.minecraft.block.properties.PropertyDirection;
  13. import net.minecraft.block.state.BlockStateContainer;
  14. import net.minecraft.block.state.IBlockState;
  15. import net.minecraft.entity.EntityLivingBase;
  16. import net.minecraft.entity.player.EntityPlayer;
  17. import net.minecraft.item.Item;
  18. import net.minecraft.item.ItemStack;
  19. import net.minecraft.util.EnumBlockRenderType;
  20. import net.minecraft.util.EnumFacing;
  21. import net.minecraft.util.Mirror;
  22. import net.minecraft.util.Rotation;
  23. import net.minecraft.util.math.AxisAlignedBB;
  24. import net.minecraft.util.math.BlockPos;
  25. import net.minecraft.world.IBlockAccess;
  26. import net.minecraft.world.World;
  27.  
  28. public class BlockHomerStatue extends Block {
  29.  
  30. public static final PropertyDirection FACING = BlockHorizontal.FACING;
  31. private static final AxisAlignedBB AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 2.0D, 1.0D);
  32.  
  33. public BlockHomerStatue() {
  34. super(Material.ROCK);
  35. this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
  36. setHardness(3f);
  37. setResistance(10f);
  38. }
  39.  
  40. @Override
  41. public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest)
  42. {
  43. if (state.getBlock() == this && world.getBlockState(pos.up()).getBlock() == this)
  44. world.setBlockToAir(pos.up());
  45. return world.setBlockToAir(pos);
  46. }
  47.  
  48. @Override
  49. public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
  50. {
  51. return AABB;
  52. }
  53.  
  54. public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
  55. {
  56. this.setDefaultFacing(worldIn, pos, state);
  57. }
  58.  
  59. private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state)
  60. {
  61. if (!worldIn.isRemote)
  62. {
  63. IBlockState iblockstate = worldIn.getBlockState(pos.north());
  64. IBlockState iblockstate1 = worldIn.getBlockState(pos.south());
  65. IBlockState iblockstate2 = worldIn.getBlockState(pos.west());
  66. IBlockState iblockstate3 = worldIn.getBlockState(pos.east());
  67. EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
  68.  
  69. if (enumfacing == EnumFacing.NORTH && iblockstate.isFullBlock() && !iblockstate1.isFullBlock())
  70. {
  71. enumfacing = EnumFacing.SOUTH;
  72. }
  73. else if (enumfacing == EnumFacing.SOUTH && iblockstate1.isFullBlock() && !iblockstate.isFullBlock())
  74. {
  75. enumfacing = EnumFacing.NORTH;
  76. }
  77. else if (enumfacing == EnumFacing.WEST && iblockstate2.isFullBlock() && !iblockstate3.isFullBlock())
  78. {
  79. enumfacing = EnumFacing.EAST;
  80. }
  81. else if (enumfacing == EnumFacing.EAST && iblockstate3.isFullBlock() && !iblockstate2.isFullBlock())
  82. {
  83. enumfacing = EnumFacing.WEST;
  84. }
  85. worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
  86. }
  87. }
  88.  
  89. public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
  90. {
  91. return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
  92. }
  93.  
  94. public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
  95. {
  96. worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
  97. }
  98.  
  99. @Nullable
  100. public Item getItemDropped(IBlockState state, Random rand, int fortune)
  101. {
  102. return ItemHandler.HomerStatue;
  103. }
  104.  
  105. public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
  106. {
  107. return new ItemStack(ItemHandler.HomerStatue);
  108. }
  109.  
  110. public IBlockState getStateFromMeta(int meta)
  111. {
  112. EnumFacing enumfacing = EnumFacing.getFront(meta);
  113.  
  114. if (enumfacing.getAxis() == EnumFacing.Axis.Y)
  115. {
  116. enumfacing = EnumFacing.NORTH;
  117. }
  118.  
  119. return this.getDefaultState().withProperty(FACING, enumfacing);
  120. }
  121.  
  122. public int getMetaFromState(IBlockState state)
  123. {
  124. return ((EnumFacing)state.getValue(FACING)).getIndex();
  125. }
  126.  
  127. public IBlockState withRotation(IBlockState state, Rotation rot)
  128. {
  129. return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
  130. }
  131.  
  132. public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
  133. {
  134. return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
  135. }
  136.  
  137. protected BlockStateContainer createBlockState()
  138. {
  139. return new BlockStateContainer(this, new IProperty[] {FACING});
  140. }
  141.  
  142. public EnumBlockRenderType getRenderType(IBlockState state)
  143. {
  144. return EnumBlockRenderType.MODEL;
  145. }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement