Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.77 KB | None | 0 0
  1. package net.toxic.blocks;
  2.  
  3. import net.minecraft.block.Block;
  4. import net.minecraft.block.SoundType;
  5. import net.minecraft.block.material.Material;
  6. import net.minecraft.block.properties.IProperty;
  7. import net.minecraft.block.properties.PropertyBool;
  8. import net.minecraft.block.state.BlockStateContainer;
  9. import net.minecraft.block.state.IBlockState;
  10. import net.minecraft.init.Blocks;
  11. import net.minecraft.util.EnumBlockRenderType;
  12. import net.minecraft.util.EnumFacing;
  13. import net.minecraft.util.Mirror;
  14. import net.minecraft.util.math.AxisAlignedBB;
  15. import net.minecraft.util.math.BlockPos;
  16. import net.minecraft.world.IBlockAccess;
  17. import net.minecraft.world.World;
  18. import net.minecraftforge.fml.relauncher.Side;
  19. import net.minecraftforge.fml.relauncher.SideOnly;
  20.  
  21. public class BlockCable extends Block {
  22. public static final PropertyBool NORTH = PropertyBool.create("north");
  23. public static final PropertyBool EAST = PropertyBool.create("east");
  24. public static final PropertyBool SOUTH = PropertyBool.create("south");
  25. public static final PropertyBool WEST = PropertyBool.create("west");
  26. public static final PropertyBool UP = PropertyBool.create("up");
  27. public static final PropertyBool DOWN = PropertyBool.create("down");
  28. protected static final AxisAlignedBB[] BOUNDING_BOXES = new AxisAlignedBB[] { /* PUT BOUNDING BOXES HERE */ };
  29.  
  30. public BlockCable() {
  31. super(Material.IRON);
  32. this.setDefaultState(this.blockState.getBaseState().withProperty(NORTH, Boolean.valueOf(false)).withProperty(EAST, Boolean.valueOf(false)).withProperty(SOUTH, Boolean.valueOf(false)).withProperty(WEST, Boolean.valueOf(false)).withProperty(UP, Boolean.valueOf(false)).withProperty(DOWN, Boolean.valueOf(false)));
  33.  
  34. }
  35.  
  36. // public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
  37. // state = this.getActualState(state, source, pos);
  38. // return BOUNDING_BOXES[0];
  39. // }
  40.  
  41. /**
  42. * Returns the correct index into boundingBoxes, based on what the fence is connected to.
  43. */
  44. private static int getBoundingBoxIdx(IBlockState state) {
  45. int i = 0;
  46.  
  47. if (((Boolean) state.getValue(DOWN)).booleanValue()) {
  48. i |= 1 << EnumFacing.DOWN.getIndex();
  49. }
  50.  
  51. if (((Boolean) state.getValue(UP)).booleanValue()) {
  52. i |= 1 << EnumFacing.UP.getIndex();
  53. }
  54.  
  55. if (((Boolean) state.getValue(NORTH)).booleanValue()) {
  56. i |= 1 << EnumFacing.NORTH.getIndex();
  57. }
  58.  
  59. if (((Boolean) state.getValue(EAST)).booleanValue()) {
  60. i |= 1 << EnumFacing.EAST.getIndex();
  61. }
  62.  
  63. if (((Boolean) state.getValue(SOUTH)).booleanValue()) {
  64. i |= 1 << EnumFacing.SOUTH.getIndex();
  65. }
  66.  
  67. if (((Boolean) state.getValue(WEST)).booleanValue()) {
  68. i |= 1 << EnumFacing.WEST.getIndex();
  69. }
  70.  
  71. return i;
  72. }
  73.  
  74. public boolean isOpaqueCube(IBlockState state) {
  75. return false;
  76. }
  77.  
  78. public boolean isFullCube(IBlockState state) {
  79. return false;
  80. }
  81.  
  82. public boolean isPassable(IBlockAccess worldIn, BlockPos pos) {
  83. return false;
  84. }
  85.  
  86. public boolean canConnectTo(IBlockAccess worldIn, BlockPos pos, EnumFacing p_176524_3_) {
  87. IBlockState iblockstate = worldIn.getBlockState(pos);
  88. Block block = iblockstate.getBlock();
  89. boolean flag = false;
  90. return block == BlockRegistry.cable || flag;
  91. }
  92.  
  93. @SideOnly(Side.CLIENT)
  94. public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
  95. return true;
  96. }
  97.  
  98. public int getMetaFromState(IBlockState state) {
  99. return 0;
  100. }
  101.  
  102. public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
  103. return state.withProperty(NORTH, canFenceConnectTo(worldIn, pos, EnumFacing.NORTH)).withProperty(EAST, canFenceConnectTo(worldIn, pos, EnumFacing.EAST)).withProperty(SOUTH, canFenceConnectTo(worldIn, pos, EnumFacing.SOUTH)).withProperty(WEST, canFenceConnectTo(worldIn, pos, EnumFacing.WEST)).withProperty(UP, canFenceConnectTo(worldIn, pos, EnumFacing.UP)).withProperty(DOWN, canFenceConnectTo(worldIn, pos, EnumFacing.DOWN));
  104. }
  105.  
  106. /**
  107. * Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed blockstate.
  108. */
  109. public IBlockState withRotation(IBlockState state, Rotation rot) {
  110. switch (rot) {
  111. case CLOCKWISE_180:
  112. return state.withProperty(NORTH, state.getValue(SOUTH)).withProperty(EAST, state.getValue(WEST)).withProperty(SOUTH, state.getValue(NORTH)).withProperty(WEST, state.getValue(EAST));
  113. case COUNTERCLOCKWISE_90:
  114. return state.withProperty(NORTH, state.getValue(EAST)).withProperty(EAST, state.getValue(SOUTH)).withProperty(SOUTH, state.getValue(WEST)).withProperty(WEST, state.getValue(NORTH));
  115. case CLOCKWISE_90:
  116. return state.withProperty(NORTH, state.getValue(WEST)).withProperty(EAST, state.getValue(NORTH)).withProperty(SOUTH, state.getValue(EAST)).withProperty(WEST, state.getValue(SOUTH));
  117. default:
  118. return state;
  119. }
  120. }
  121.  
  122. /**
  123. * Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed blockstate.
  124. */
  125. public IBlockState withMirror(IBlockState state, Mirror mirrorIn) {
  126. switch (mirrorIn) {
  127. case LEFT_RIGHT:
  128. return state.withProperty(NORTH, state.getValue(SOUTH)).withProperty(SOUTH, state.getValue(NORTH));
  129. case FRONT_BACK:
  130. return state.withProperty(EAST, state.getValue(WEST)).withProperty(WEST, state.getValue(EAST));
  131. default:
  132. return super.withMirror(state, mirrorIn);
  133. }
  134. }
  135.  
  136. protected BlockStateContainer createBlockState() {
  137. return new BlockStateContainer(this, new IProperty[] { NORTH, EAST, WEST, SOUTH, UP, DOWN });
  138. }
  139.  
  140. /* ======================================== FORGE START ======================================== */
  141.  
  142. @Override
  143. public boolean canBeConnectedTo(IBlockAccess world, BlockPos pos, EnumFacing facing) {
  144. Block connector = world.getBlockState(pos.offset(facing)).getBlock();
  145.  
  146. if (connector instanceof BlockCable) {
  147. if (this != Blocks.NETHER_BRICK_FENCE && connector == Blocks.NETHER_BRICK_FENCE) {
  148. return false;
  149. } else if (this == Blocks.NETHER_BRICK_FENCE && connector != Blocks.NETHER_BRICK_FENCE) {
  150. return false;
  151. }
  152. return true;
  153. }
  154. return false;
  155. }
  156.  
  157. private boolean canFenceConnectTo(IBlockAccess world, BlockPos pos, EnumFacing facing) {
  158. BlockPos other = pos.offset(facing);
  159. Block block = world.getBlockState(other).getBlock();
  160. return ((BlockCable) block).canBeConnectedTo(world, other, facing.getOpposite()) || canConnectTo(world, other, facing.getOpposite());
  161. }
  162.  
  163. /* ======================================== FORGE END ======================================== */
  164.  
  165. public BlockFaceShape getBlockFaceShape(IBlockAccess p_193383_1_, IBlockState p_193383_2_, BlockPos p_193383_3_, EnumFacing p_193383_4_) {
  166. return p_193383_4_ != EnumFacing.UP && p_193383_4_ != EnumFacing.DOWN ? BlockFaceShape.MIDDLE_POLE : BlockFaceShape.CENTER;
  167. }
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement