tigres810

Untitled

Feb 17th, 2019
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.69 KB | None | 0 0
  1. package com.tigres810.adventurermod.blocks.pipes;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Random;
  6.  
  7. import com.tigres810.adventurermod.Main;
  8. import com.tigres810.adventurermod.Interfaces.IPipeConnect;
  9. import com.tigres810.adventurermod.blocks.BlockBase;
  10. import com.tigres810.adventurermod.blocks.machines.tileentity.TileEntityFluxGenerator;
  11. import com.tigres810.adventurermod.blocks.pipes.tileentity.TileEntityFluxPipe;
  12. import com.tigres810.adventurermod.init.ModBlocks;
  13. import com.tigres810.adventurermod.util.Reference;
  14.  
  15. import net.minecraft.block.Block;
  16. import net.minecraft.block.BlockHorizontal;
  17. import net.minecraft.block.SoundType;
  18. import net.minecraft.block.material.Material;
  19. import net.minecraft.block.properties.IProperty;
  20. import net.minecraft.block.properties.PropertyBool;
  21. import net.minecraft.block.properties.PropertyDirection;
  22. import net.minecraft.block.properties.PropertyInteger;
  23. import net.minecraft.block.state.BlockStateContainer;
  24. import net.minecraft.block.state.IBlockState;
  25. import net.minecraft.client.renderer.block.statemap.IStateMapper;
  26. import net.minecraft.client.renderer.block.statemap.StateMap;
  27. import net.minecraft.entity.Entity;
  28. import net.minecraft.entity.EntityLivingBase;
  29. import net.minecraft.entity.item.EntityItem;
  30. import net.minecraft.entity.player.EntityPlayer;
  31. import net.minecraft.item.Item;
  32. import net.minecraft.item.ItemStack;
  33. import net.minecraft.tileentity.TileEntity;
  34. import net.minecraft.util.DamageSource;
  35. import net.minecraft.util.EnumBlockRenderType;
  36. import net.minecraft.util.EnumFacing;
  37. import net.minecraft.util.EnumHand;
  38. import net.minecraft.util.DamageSource;
  39. import net.minecraft.util.Mirror;
  40. import net.minecraft.util.Rotation;
  41. import net.minecraft.util.math.AxisAlignedBB;
  42. import net.minecraft.util.math.BlockPos;
  43. import net.minecraft.world.IBlockAccess;
  44. import net.minecraft.world.World;
  45.  
  46. public class BlockEntityFluxPipe extends BlockBase implements IPipeConnect {
  47.  
  48. //public static final PropertyDirection FACING = BlockHorizontal.FACING;
  49. public static final PropertyBool UP = PropertyBool.create("up");
  50. public static final PropertyBool DOWN = PropertyBool.create("down");
  51. public static final PropertyBool NORTH = PropertyBool.create("north");
  52. public static final PropertyBool SOUTH = PropertyBool.create("south");
  53. public static final PropertyBool EAST = PropertyBool.create("east");
  54. public static final PropertyBool WEST = PropertyBool.create("west");
  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.METAL);
  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. /*
  102. public static void setState(boolean up, boolean down, boolean north, boolean south, boolean east, boolean west ,World worldIn, BlockPos pos) {
  103. IBlockState state = worldIn.getBlockState(pos);
  104. TileEntity tileentity = worldIn.getTileEntity(pos);
  105.  
  106. if(render == 0) worldIn.setBlockState(pos, ModBlocks.FLUX_GENERATOR_BLOCK.getDefaultState().withProperty(UP, true), 3);
  107. 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);
  108.  
  109. if(tileentity != null)
  110. {
  111. tileentity.validate();
  112. worldIn.setTileEntity(pos, tileentity);
  113. }
  114. }
  115. */
  116.  
  117. private boolean isSideConnectable (IBlockAccess world, BlockPos pos, EnumFacing side) {
  118.  
  119. final IBlockState state = world.getBlockState(pos.offset(side));
  120. if(state==null) return false;
  121. if(!( state.getBlock() instanceof IPipeConnect)) return false;
  122. List<EnumFacing> faces = ((IPipeConnect)state.getBlock()).getConnectableSides(state);
  123. if(!faces.contains(side)) return false;
  124. return true;
  125.  
  126. }
  127.  
  128. @Override
  129. public IBlockState getActualState (IBlockState state, IBlockAccess world, BlockPos position) {
  130.  
  131. return state.withProperty(DOWN, this.isSideConnectable(world, position, EnumFacing.DOWN)).withProperty(EAST, this.isSideConnectable(world, position, EnumFacing.EAST)).withProperty(NORTH, this.isSideConnectable(world, position, EnumFacing.NORTH)).withProperty(SOUTH, this.isSideConnectable(world, position, EnumFacing.SOUTH)).withProperty(UP, this.isSideConnectable(world, position, EnumFacing.UP)).withProperty(WEST, this.isSideConnectable(world, position, EnumFacing.WEST));
  132. }
  133.  
  134.  
  135. @Override
  136. public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
  137. entityIn.attackEntityFrom(DamageSource.CACTUS, 3.0F);
  138. }
  139.  
  140. @Override
  141. public boolean hasTileEntity(IBlockState state) {
  142. return true;
  143. }
  144.  
  145. @Override
  146. public TileEntity createTileEntity(World world, IBlockState state) {
  147. return new TileEntityFluxPipe();
  148. }
  149.  
  150. @Override
  151. public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
  152. TileEntityFluxPipe tileentity = (TileEntityFluxPipe)worldIn.getTileEntity(pos);
  153. super.breakBlock(worldIn, pos, state);
  154. }
  155.  
  156. @Override
  157. public EnumBlockRenderType getRenderType(IBlockState state) {
  158. return EnumBlockRenderType.MODEL;
  159. }
  160.  
  161. @Override
  162. protected BlockStateContainer createBlockState() {
  163. return new BlockStateContainer(this, new IProperty[] {UP, DOWN, NORTH, SOUTH, EAST, WEST});
  164. }
  165.  
  166. @Override
  167. public int getMetaFromState(IBlockState state) {
  168. return 0;
  169. }
  170.  
  171.  
  172. public IBlockState getStateFromMeta(int meta)
  173. {
  174. return this.getDefaultState();
  175. }
  176.  
  177. @Override
  178. public List<EnumFacing> getConnectableSides(IBlockState state) {
  179. List<EnumFacing> faces = new ArrayList<EnumFacing>();
  180. faces.add(EnumFacing.UP);
  181. faces.add(EnumFacing.DOWN);
  182. faces.add(EnumFacing.NORTH);
  183. faces.add(EnumFacing.SOUTH);
  184. faces.add(EnumFacing.EAST);
  185. faces.add(EnumFacing.WEST);
  186. return faces;
  187. }
  188.  
  189. /*
  190. @Override
  191. public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
  192. EnumFacing facing = EnumFacing.getFront(state.getValue(FACING).getIndex());
  193. if (this.getRegistryName().equals(ModBlocks.FLUX_PIPE_BLOCK.getRegistryName())) {
  194. if(facing.equals(EnumFacing.NORTH) || facing.equals(EnumFacing.SOUTH)) { return FLUX_PIPE_BLOCK1; } else { return FLUX_PIPE_BLOCK; }
  195. } else {
  196. return super.getBoundingBox(state, source, pos);
  197. }
  198. }
  199.  
  200. @Override
  201. public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox,List<AxisAlignedBB> collidingBoxes, Entity entityIn, boolean isActualState) {
  202. EnumFacing facing = EnumFacing.getFront(state.getValue(FACING).getIndex());
  203. if(facing.equals(EnumFacing.NORTH) || facing.equals(EnumFacing.SOUTH) ) {
  204. super.addCollisionBoxToList(pos, entityBox, collidingBoxes, FLUX_PIPE_BLOCK1);
  205. } else {
  206. super.addCollisionBoxToList(pos, entityBox, collidingBoxes, FLUX_PIPE_BLOCK);
  207. }
  208. }
  209. */
  210. }
Advertisement
Add Comment
Please, Sign In to add comment