tigres810

Block

Feb 15th, 2019
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.22 KB | None | 0 0
  1. package com.tigres810.adventurermod.blocks.pipes;
  2.  
  3. import java.util.List;
  4. import java.util.Random;
  5.  
  6. import com.tigres810.adventurermod.Main;
  7. import com.tigres810.adventurermod.blocks.BlockBase;
  8. import com.tigres810.adventurermod.blocks.machines.tileentity.TileEntityFluxGenerator;
  9. import com.tigres810.adventurermod.blocks.pipes.tileentity.TileEntityFluxPipe;
  10. import com.tigres810.adventurermod.init.ModBlocks;
  11. import com.tigres810.adventurermod.util.Reference;
  12.  
  13. import net.minecraft.block.Block;
  14. import net.minecraft.block.BlockHorizontal;
  15. import net.minecraft.block.SoundType;
  16. import net.minecraft.block.material.Material;
  17. import net.minecraft.block.properties.IProperty;
  18. import net.minecraft.block.properties.PropertyBool;
  19. import net.minecraft.block.properties.PropertyDirection;
  20. import net.minecraft.block.properties.PropertyInteger;
  21. import net.minecraft.block.state.BlockStateContainer;
  22. import net.minecraft.block.state.IBlockState;
  23. import net.minecraft.entity.Entity;
  24. import net.minecraft.entity.EntityLivingBase;
  25. import net.minecraft.entity.item.EntityItem;
  26. import net.minecraft.entity.player.EntityPlayer;
  27. import net.minecraft.item.Item;
  28. import net.minecraft.item.ItemStack;
  29. import net.minecraft.tileentity.TileEntity;
  30. import net.minecraft.util.EnumBlockRenderType;
  31. import net.minecraft.util.EnumFacing;
  32. import net.minecraft.util.EnumHand;
  33. import net.minecraft.util.Mirror;
  34. import net.minecraft.util.Rotation;
  35. import net.minecraft.util.math.AxisAlignedBB;
  36. import net.minecraft.util.math.BlockPos;
  37. import net.minecraft.world.IBlockAccess;
  38. import net.minecraft.world.World;
  39.  
  40. public class BlockEntityFluxPipe extends BlockBase {
  41.  
  42. //public static final PropertyDirection FACING = BlockHorizontal.FACING;
  43. public static final PropertyBool UP = PropertyBool.create("up");
  44. public static final PropertyBool DOWN = PropertyBool.create("down");
  45. public static final PropertyBool NORTH = PropertyBool.create("north");
  46. public static final PropertyBool SOUTH = PropertyBool.create("south");
  47. public static final PropertyBool EAST = PropertyBool.create("east");
  48. public static final PropertyBool WEST = PropertyBool.create("west");
  49. private boolean connectedup = false;
  50. private boolean connecteddown = false;
  51. private boolean connectednorth = false;
  52. private boolean connectedsouth = false;
  53. private boolean connectedeast = false;
  54. private boolean connectedwest = false;
  55. public static final AxisAlignedBB FLUX_PIPE_BLOCK = new AxisAlignedBB(0, 0.0625 * 5, 0.0625 * 5, 0.0625 * 16, 0.0625 * 11, 0.0625 * 11);
  56. public static final AxisAlignedBB FLUX_PIPE_BLOCK1 = new AxisAlignedBB(0.0625 * 5, 0.0625 * 5, 0, 0.0625 * 11, 0.0625 * 11, 0.0625 * 16);
  57.  
  58. public BlockEntityFluxPipe(String name, Material material) {
  59. super(name, material);
  60.  
  61. //Block Meta
  62. setSoundType(SoundType.GLASS);
  63. setHardness(5.0f);
  64. setResistance(1.000f);
  65. setLightOpacity(1);
  66.  
  67. this.setDefaultState(this.getDefaultState().withProperty(UP, false).withProperty(DOWN, false).withProperty(NORTH, false).withProperty(SOUTH, false).withProperty(EAST, false).withProperty(WEST, false));
  68. }
  69.  
  70. @Override
  71. public Item getItemDropped(IBlockState state, Random rand, int fortune) {
  72.  
  73. return Item.getItemFromBlock(ModBlocks.FLUX_GENERATOR_BLOCK);
  74. }
  75.  
  76. @Override
  77. public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
  78.  
  79. return new ItemStack(ModBlocks.FLUX_GENERATOR_BLOCK);
  80. }
  81.  
  82. @Override
  83. public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
  84. if(!worldIn.isRemote) {
  85. /*
  86. IBlockState north = worldIn.getBlockState(pos.north());
  87. IBlockState south = worldIn.getBlockState(pos.south());
  88. IBlockState west = worldIn.getBlockState(pos.west());
  89. IBlockState east = worldIn.getBlockState(pos.east());
  90. EnumFacing face = (EnumFacing)state.getValue(FACING);
  91.  
  92. if (face == EnumFacing.NORTH && north.isFullBlock() && !south.isFullBlock()) face = EnumFacing.SOUTH;
  93. else if (face == EnumFacing.SOUTH && south.isFullBlock() && !north.isFullBlock()) face = EnumFacing.NORTH;
  94. else if (face == EnumFacing.WEST && west.isFullBlock() && !east.isFullBlock()) face = EnumFacing.EAST;
  95. else if (face == EnumFacing.EAST && east.isFullBlock() && !west.isFullBlock()) face = EnumFacing.WEST;
  96. worldIn.setBlockState(pos, state.withProperty(FACING, face), 2);
  97. */
  98. }
  99. }
  100.  
  101. public static void setState(boolean up, boolean down, boolean north, boolean south, boolean east, boolean west ,World worldIn, BlockPos pos) {
  102. IBlockState state = worldIn.getBlockState(pos);
  103. TileEntity tileentity = worldIn.getTileEntity(pos);
  104.  
  105. if(render == 0) worldIn.setBlockState(pos, ModBlocks.FLUX_GENERATOR_BLOCK.getDefaultState().withProperty(UP, true), 3);
  106. else worldIn.setBlockState(pos, ModBlocks.FLUX_GENERATOR_BLOCK.getDefaultState().withProperty(UP, false).withProperty(DOWN, false).withProperty(NORTH, false).withProperty(SOUTH, false).withProperty(EAST, false).withProperty(WEST, false), 3);
  107.  
  108. if(tileentity != null)
  109. {
  110. tileentity.validate();
  111. worldIn.setTileEntity(pos, tileentity);
  112. }
  113. }
  114.  
  115. @Override
  116. public void randomTick(World worldIn, BlockPos pos, IBlockState state, Random random) {
  117. for(EnumFacing face : EnumFacing.VALUES) {
  118. BlockPos pos1 = pos.offset(face);
  119. IBlockState state1 = worldIn.getBlockState(pos1);
  120. Block block = state1.getBlock();
  121. if(block == ModBlocks.FLUX_PIPE_BLOCK) {
  122. if(face.equals(EnumFacing.UP)) {
  123. if(connectedup == false) {
  124. connectedup = true;
  125. this.setState(connectedup, false, false, false, false, false, worldIn, pos1);
  126. }
  127. }
  128. }
  129. }
  130. super.randomTick(worldIn, pos, state, random);
  131. }
  132.  
  133. @Override
  134. public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) {
  135. for(EnumFacing face : EnumFacing.VALUES) {
  136. BlockPos pos1 = pos.offset(face);
  137. IBlockState state1 = worldIn.getBlockState(pos1);
  138. Block block = state1.getBlock();
  139. if(face.equals(EnumFacing.UP) && block == ModBlocks.FLUX_PIPE_BLOCK && connectedup == false) {
  140. connectedup = true;
  141. this.setState(connectedup, false, false, false, false, false, worldIn, pos1);
  142. }
  143. }
  144. super.neighborChanged(state, worldIn, pos, blockIn, fromPos);
  145. }
  146.  
  147. @Override
  148. public boolean hasTileEntity(IBlockState state) {
  149. return true;
  150. }
  151.  
  152. @Override
  153. public TileEntity createTileEntity(World world, IBlockState state) {
  154. return new TileEntityFluxPipe();
  155. }
  156.  
  157. @Override
  158. public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
  159. TileEntityFluxPipe tileentity = (TileEntityFluxPipe)worldIn.getTileEntity(pos);
  160. super.breakBlock(worldIn, pos, state);
  161. }
  162.  
  163. @Override
  164. public EnumBlockRenderType getRenderType(IBlockState state) {
  165. return EnumBlockRenderType.MODEL;
  166. }
  167.  
  168. @Override
  169. protected BlockStateContainer createBlockState() {
  170. return new BlockStateContainer(this, new IProperty[] {UP, DOWN, NORTH, SOUTH, EAST, WEST});
  171. }
  172.  
  173. /*
  174. @Override
  175. public IBlockState getStateFromMeta(int meta)
  176. {
  177. EnumFacing facing = EnumFacing.getFront(meta);
  178. if(facing.getAxis() == EnumFacing.Axis.Y) facing = EnumFacing.NORTH;
  179. return this.getDefaultState().withProperty(FACING, facing);
  180. }
  181.  
  182. @Override
  183. public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
  184. EnumFacing facing = EnumFacing.getFront(state.getValue(FACING).getIndex());
  185. if (this.getRegistryName().equals(ModBlocks.FLUX_PIPE_BLOCK.getRegistryName())) {
  186. if(facing.equals(EnumFacing.NORTH) || facing.equals(EnumFacing.SOUTH)) { return FLUX_PIPE_BLOCK1; } else { return FLUX_PIPE_BLOCK; }
  187. } else {
  188. return super.getBoundingBox(state, source, pos);
  189. }
  190. }
  191.  
  192. @Override
  193. public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox,List<AxisAlignedBB> collidingBoxes, Entity entityIn, boolean isActualState) {
  194. EnumFacing facing = EnumFacing.getFront(state.getValue(FACING).getIndex());
  195. if(facing.equals(EnumFacing.NORTH) || facing.equals(EnumFacing.SOUTH) ) {
  196. super.addCollisionBoxToList(pos, entityBox, collidingBoxes, FLUX_PIPE_BLOCK1);
  197. } else {
  198. super.addCollisionBoxToList(pos, entityBox, collidingBoxes, FLUX_PIPE_BLOCK);
  199. }
  200. }
  201. */
  202. }
Advertisement
Add Comment
Please, Sign In to add comment