Guest User

block.class

a guest
Aug 1st, 2015
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. package NewDivide.NDMiscMod.blocks;
  2.  
  3. import net.minecraft.block.Block;
  4. import net.minecraft.block.material.Material;
  5. import net.minecraft.block.properties.IProperty;
  6. import net.minecraft.block.properties.PropertyBool;
  7. import net.minecraft.block.state.BlockState;
  8. import net.minecraft.block.state.IBlockState;
  9. import net.minecraft.entity.player.EntityPlayer;
  10. import net.minecraft.util.BlockPos;
  11. import net.minecraft.util.EnumFacing;
  12. import net.minecraft.util.EnumWorldBlockLayer;
  13. import net.minecraft.world.IBlockAccess;
  14. import net.minecraft.world.World;
  15. import net.minecraftforge.fml.relauncher.Side;
  16. import net.minecraftforge.fml.relauncher.SideOnly;
  17.  
  18. public class ItemBlockXray extends Block {
  19.  
  20. public static final PropertyBool NORTH = PropertyBool.create("north");
  21. public static final PropertyBool EAST = PropertyBool.create("east");
  22. public static final PropertyBool SOUTH = PropertyBool.create("south");
  23. public static final PropertyBool WEST = PropertyBool.create("west");
  24. public static final PropertyBool UP = PropertyBool.create("up");
  25. public static final PropertyBool DOWN = PropertyBool.create("down");
  26.  
  27. public ItemBlockXray(Material materialIn) {
  28. super(materialIn);
  29. this.setState(false, false, false, false, false, false);
  30. }
  31.  
  32. @Override
  33. public boolean isOpaqueCube() {
  34. return true;
  35. }
  36.  
  37. @SideOnly(Side.CLIENT)
  38. public EnumWorldBlockLayer getBlockLayer() {
  39. return EnumWorldBlockLayer.CUTOUT;
  40. }
  41.  
  42. @Override
  43. public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) {
  44. state = getActualState(state, worldIn, pos);
  45. }
  46.  
  47. @Override
  48. public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
  49. state = getActualState(state, worldIn, pos);
  50. }
  51.  
  52. @Override
  53. public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
  54.  
  55. IBlockState nextState = state;
  56.  
  57. nextState.withProperty(NORTH, canConnectTo(worldIn, pos, EnumFacing.NORTH));
  58. nextState.withProperty(EAST, canConnectTo(worldIn, pos, EnumFacing.EAST));
  59. nextState.withProperty(SOUTH, canConnectTo(worldIn, pos, EnumFacing.SOUTH));
  60. nextState.withProperty(WEST, canConnectTo(worldIn, pos, EnumFacing.WEST));
  61. nextState.withProperty(UP, canConnectTo(worldIn, pos, EnumFacing.UP));
  62. nextState.withProperty(DOWN, canConnectTo(worldIn, pos, EnumFacing.DOWN));
  63. return nextState;
  64. }
  65.  
  66. @Override
  67. public int getMetaFromState(IBlockState state) {
  68. int meta = 0;
  69. if ((Boolean) state.getProperties().get(NORTH))
  70. meta += 32;
  71. if ((Boolean) state.getProperties().get(EAST))
  72. meta += 16;
  73. if ((Boolean) state.getProperties().get(SOUTH))
  74. meta += 8;
  75. if ((Boolean) state.getProperties().get(WEST))
  76. meta += 4;
  77. if ((Boolean) state.getProperties().get(UP))
  78. meta += 2;
  79. if ((Boolean) state.getProperties().get(DOWN))
  80. meta += 1;
  81. return meta;
  82. }
  83.  
  84. @Override
  85. public IBlockState getStateFromMeta(int meta) {
  86. return this.getDefaultState()
  87. .withProperty(NORTH, ((meta - 0) / 32 == 1))
  88. .withProperty(EAST, ((meta - 32) / 16 == 1))
  89. .withProperty(SOUTH, ((meta - 48) / 8 == 1))
  90. .withProperty(WEST, ((meta - 56) / 4 == 1))
  91. .withProperty(UP, ((meta - 60) / 2 == 1))
  92. .withProperty(DOWN, ((meta - 62) / 1 == 1));
  93.  
  94. }
  95.  
  96. public void setState(boolean n, boolean e, boolean s, boolean w, boolean u, boolean d) {
  97. this.blockState.getBaseState().withProperty(NORTH, n);
  98. this.blockState.getBaseState().withProperty(EAST, e);
  99. this.blockState.getBaseState().withProperty(SOUTH, s);
  100. this.blockState.getBaseState().withProperty(WEST, w);
  101. this.blockState.getBaseState().withProperty(UP, u);
  102. this.blockState.getBaseState().withProperty(DOWN, d);
  103. }
  104.  
  105. public boolean canConnectTo(IBlockAccess world, BlockPos pos, EnumFacing dir) {
  106. return this == world.getBlockState(pos.offset(dir)).getBlock();
  107.  
  108. }
  109.  
  110. protected BlockState createBlockState() {
  111. return new BlockState(this, new IProperty[] { NORTH, EAST, SOUTH, WEST, UP, DOWN });
  112. }
  113.  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment