shane020482

full rot method

May 27th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. public class yourblock extends Block
  2. {
  3.  
  4. public static final PropertyDirection FACING = BlockDirectional.FACING;
  5.  
  6. public BlockFullRotBase(String name, Material material)
  7. {
  8. super(material);
  9. setUnlocalizedName(name);
  10. setRegistryName(name);
  11.  
  12. }
  13.  
  14. @Override
  15. public BlockRenderLayer getBlockLayer()
  16. {
  17. return BlockRenderLayer.CUTOUT_MIPPED;
  18. }
  19.  
  20. @Override
  21. public boolean isOpaqueCube(IBlockState state)
  22. {
  23. return false;
  24. }
  25.  
  26. @Override
  27. public boolean isFullBlock(IBlockState state)
  28. {
  29. return false;
  30. }
  31.  
  32.  
  33.  
  34.  
  35.  
  36. public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
  37. {
  38. super.onBlockAdded(worldIn, pos, state);
  39. this.setDefaultDirection(worldIn, pos, state);
  40. }
  41.  
  42. private void setDefaultDirection(World worldIn, BlockPos pos, IBlockState state)
  43. {
  44. if (!worldIn.isRemote)
  45. {
  46. EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
  47. boolean flag = worldIn.getBlockState(pos.north()).isFullBlock();
  48. boolean flag1 = worldIn.getBlockState(pos.south()).isFullBlock();
  49.  
  50. if (enumfacing == EnumFacing.NORTH && flag && !flag1)
  51. {
  52. enumfacing = EnumFacing.SOUTH;
  53. }
  54. else if (enumfacing == EnumFacing.SOUTH && flag1 && !flag)
  55. {
  56. enumfacing = EnumFacing.NORTH;
  57. }
  58. else
  59. {
  60. boolean flag2 = worldIn.getBlockState(pos.west()).isFullBlock();
  61. boolean flag3 = worldIn.getBlockState(pos.east()).isFullBlock();
  62.  
  63. if (enumfacing == EnumFacing.WEST && flag2 && !flag3)
  64. {
  65. enumfacing = EnumFacing.EAST;
  66. }
  67. else if (enumfacing == EnumFacing.EAST && flag3 && !flag2)
  68. {
  69. enumfacing = EnumFacing.WEST;
  70. }
  71. }
  72.  
  73. worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
  74. }
  75. }
  76.  
  77.  
  78.  
  79.  
  80. public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
  81. {
  82. return this.getDefaultState().withProperty(FACING, EnumFacing.getDirectionFromEntityLiving(pos, placer));
  83. }
  84.  
  85. public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
  86. {
  87. worldIn.setBlockState(pos, state.withProperty(FACING, EnumFacing.getDirectionFromEntityLiving(pos, placer)), 2);
  88.  
  89.  
  90. }
  91.  
  92.  
  93. public IBlockState getStateFromMeta(int meta)
  94. {
  95. return this.getDefaultState().withProperty(FACING, EnumFacing.getFront(meta & 7));
  96. }
  97.  
  98.  
  99. public int getMetaFromState(IBlockState state)
  100. {
  101. int i = 0;
  102. i = i | ((EnumFacing)state.getValue(FACING)).getIndex();
  103.  
  104.  
  105.  
  106. return i;
  107. }
  108.  
  109.  
  110. public IBlockState withRotation(IBlockState state, Rotation rot)
  111. {
  112. return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
  113. }
  114.  
  115.  
  116. public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
  117. {
  118. return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
  119. }
  120.  
  121. protected BlockStateContainer createBlockState()
  122. {
  123. return new BlockStateContainer(this, new IProperty[] {FACING});
  124. }
  125.  
  126.  
  127. }
Advertisement
Add Comment
Please, Sign In to add comment