Creepinson

block

Jun 17th, 2017
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. package me.creepinson.block;
  2.  
  3. import net.minecraft.block.BlockDirectional;
  4. import net.minecraft.block.material.Material;
  5. import net.minecraft.block.properties.IProperty;
  6. import net.minecraft.block.properties.PropertyDirection;
  7. import net.minecraft.block.state.BlockStateContainer;
  8. import net.minecraft.block.state.IBlockState;
  9. import net.minecraft.creativetab.CreativeTabs;
  10. import net.minecraft.entity.EntityLivingBase;
  11. import net.minecraft.entity.player.EntityPlayer;
  12. import net.minecraft.util.EnumBlockRenderType;
  13. import net.minecraft.util.EnumFacing;
  14. import net.minecraft.util.EnumHand;
  15. import net.minecraft.util.Mirror;
  16. import net.minecraft.util.Rotation;
  17. import net.minecraft.util.math.AxisAlignedBB;
  18. import net.minecraft.util.math.BlockPos;
  19. import net.minecraft.world.IBlockAccess;
  20. import net.minecraft.world.World;
  21.  
  22. public class CreepinoSkull extends ModBlocks {
  23. protected static final AxisAlignedBB DEFAULT_AABB = new AxisAlignedBB(0.25D, 0.0D, 0.25D, 0.75D, 0.5D, 0.75D);
  24. protected static final AxisAlignedBB NORTH_AABB = new AxisAlignedBB(0.25D, 0.25D, 0.5D, 0.75D, 0.75D, 1.0D);
  25. protected static final AxisAlignedBB SOUTH_AABB = new AxisAlignedBB(0.25D, 0.25D, 0.0D, 0.75D, 0.75D, 0.5D);
  26. protected static final AxisAlignedBB WEST_AABB = new AxisAlignedBB(0.5D, 0.25D, 0.25D, 1.0D, 0.75D, 0.75D);
  27. protected static final AxisAlignedBB EAST_AABB = new AxisAlignedBB(0.0D, 0.25D, 0.25D, 0.5D, 0.75D, 0.75D);
  28. public static final PropertyDirection FACING = BlockDirectional.FACING;
  29.  
  30. public CreepinoSkull(Material mat, String name, CreativeTabs tab, float hardness, float resistance, int harvest,
  31. String tool) {
  32. super(mat, name, tab, hardness, resistance, harvest, tool);
  33. this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
  34. }
  35.  
  36. @Override
  37. public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
  38. EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  39.  
  40. if (!worldIn.isRemote) {
  41.  
  42. }
  43.  
  44. return true;
  45. }
  46.  
  47. public boolean isOpaqueCube(IBlockState state) {
  48. return false;
  49. }
  50.  
  51. public boolean isFullCube(IBlockState state) {
  52. return false;
  53. }
  54.  
  55. @Override
  56. public EnumBlockRenderType getRenderType(IBlockState state) {
  57. return EnumBlockRenderType.MODEL;
  58. }
  59.  
  60. public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
  61. switch ((EnumFacing) state.getValue(FACING)) {
  62. default:
  63. return DEFAULT_AABB;
  64. case NORTH:
  65. return NORTH_AABB;
  66. case SOUTH:
  67. return SOUTH_AABB;
  68. case WEST:
  69. return WEST_AABB;
  70. case EAST:
  71. return EAST_AABB;
  72. }
  73. }
  74.  
  75. public IBlockState getStateFromMeta(int meta) {
  76. return this.getDefaultState().withProperty(FACING, EnumFacing.getFront(meta & 7));
  77. }
  78.  
  79. /**
  80. * Convert the BlockState into the correct metadata value
  81. */
  82. public int getMetaFromState(IBlockState state) {
  83. int i = 0;
  84. i = i | ((EnumFacing) state.getValue(FACING)).getIndex();
  85.  
  86. return i;
  87. }
  88.  
  89. public IBlockState withRotation(IBlockState state, Rotation rot) {
  90. return state.withProperty(FACING, rot.rotate((EnumFacing) state.getValue(FACING)));
  91. }
  92.  
  93. public IBlockState withMirror(IBlockState state, Mirror mirrorIn) {
  94. return state.withRotation(mirrorIn.toRotation((EnumFacing) state.getValue(FACING)));
  95. }
  96.  
  97. protected BlockStateContainer createBlockState() {
  98. return new BlockStateContainer(this, new IProperty[] { FACING });
  99. }
  100.  
  101. @Override
  102. public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY,
  103. float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
  104.  
  105. return this.blockState.getBaseState().withProperty(FACING, facing);
  106. }
  107. }
Add Comment
Please, Sign In to add comment