Advertisement
shane020482

full rot

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