Advertisement
Guest User

Untitled

a guest
Apr 29th, 2015
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.38 KB | None | 0 0
  1. package degubi.teamcraft.things.blocks;
  2.  
  3. import java.util.Random;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.block.BlockFenceGate;
  7. import net.minecraft.block.material.Material;
  8. import net.minecraft.block.properties.IProperty;
  9. import net.minecraft.block.properties.PropertyBool;
  10. import net.minecraft.block.state.BlockState;
  11. import net.minecraft.block.state.IBlockState;
  12. import net.minecraft.init.Blocks;
  13. import net.minecraft.util.AxisAlignedBB;
  14. import net.minecraft.util.BlockPos;
  15. import net.minecraft.util.EnumFacing;
  16. import net.minecraft.util.EnumWorldBlockLayer;
  17. import net.minecraft.world.ColorizerFoliage;
  18. import net.minecraft.world.EnumSkyBlock;
  19. import net.minecraft.world.IBlockAccess;
  20. import net.minecraft.world.World;
  21. import net.minecraft.world.biome.BiomeColorHelper;
  22. import net.minecraftforge.fml.relauncher.Side;
  23. import net.minecraftforge.fml.relauncher.SideOnly;
  24. import degubi.teamcraft.TeamCraft;
  25.  
  26. public class Walls extends Block{
  27. private Block blocktoget;
  28. public static final PropertyBool UP = PropertyBool.create("up");
  29. public static final PropertyBool NORTH = PropertyBool.create("north");
  30. public static final PropertyBool EAST = PropertyBool.create("east");
  31. public static final PropertyBool SOUTH = PropertyBool.create("south");
  32. public static final PropertyBool WEST = PropertyBool.create("west");
  33.  
  34. public Walls(Block block){
  35. super(block.getMaterial());
  36. setHarvestLevel("pickaxe", 1);
  37. blocktoget = block;
  38. setHardness(block.blockHardness);
  39. setStepSound(block.stepSound);
  40. setResistance(block.blockResistance);
  41. setCreativeTab(TeamCraft.tcmtabBlocks);
  42. }
  43.  
  44. @SideOnly(Side.CLIENT)
  45. public EnumWorldBlockLayer getBlockLayer() {
  46. if(blocktoget == Blocks.leaves){
  47. return EnumWorldBlockLayer.CUTOUT_MIPPED;
  48. }if(blocktoget == Blocks.ice){
  49. return EnumWorldBlockLayer.TRANSLUCENT;
  50. }
  51. return super.getBlockLayer();
  52. }
  53.  
  54. public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
  55. {
  56. return false;
  57. }
  58.  
  59. public boolean isOpaqueCube()
  60. {
  61. return false;
  62. }
  63.  
  64. public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
  65. {
  66. boolean flag = this.canConnectTo(worldIn, pos.north());
  67. boolean flag1 = this.canConnectTo(worldIn, pos.south());
  68. boolean flag2 = this.canConnectTo(worldIn, pos.west());
  69. boolean flag3 = this.canConnectTo(worldIn, pos.east());
  70. float f = 0.25F;
  71. float f1 = 0.75F;
  72. float f2 = 0.25F;
  73. float f3 = 0.75F;
  74. float f4 = 1.0F;
  75.  
  76. if (flag)
  77. {
  78. f2 = 0.0F;
  79. }
  80.  
  81. if (flag1)
  82. {
  83. f3 = 1.0F;
  84. }
  85.  
  86. if (flag2)
  87. {
  88. f = 0.0F;
  89. }
  90.  
  91. if (flag3)
  92. {
  93. f1 = 1.0F;
  94. }
  95.  
  96. if (flag && flag1 && !flag2 && !flag3)
  97. {
  98. f4 = 0.8125F;
  99. f = 0.3125F;
  100. f1 = 0.6875F;
  101. }
  102. else if (!flag && !flag1 && flag2 && flag3)
  103. {
  104. f4 = 0.8125F;
  105. f2 = 0.3125F;
  106. f3 = 0.6875F;
  107. }
  108.  
  109. this.setBlockBounds(f, 0.0F, f2, f1, f4, f3);
  110. }
  111.  
  112. public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
  113. {
  114. this.setBlockBoundsBasedOnState(worldIn, pos);
  115. this.maxY = 1.5D;
  116. return super.getCollisionBoundingBox(worldIn, pos, state);
  117. }
  118.  
  119. public boolean canConnectTo(IBlockAccess worldIn, BlockPos pos)
  120. {
  121. Block block = worldIn.getBlockState(pos).getBlock();
  122. return block == Blocks.barrier ? false : (block != this && !(block instanceof BlockFenceGate) ? (block.getMaterial().isOpaque() && block.isFullCube() ? block.getMaterial() != Material.gourd : false) : true);
  123. }
  124.  
  125. @SideOnly(Side.CLIENT)
  126. public boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
  127. {
  128. return side == EnumFacing.DOWN ? super.shouldSideBeRendered(worldIn, pos, side) : true;
  129. }
  130.  
  131. public void updateTick(World world, BlockPos pos, IBlockState state, Random rand)
  132. {
  133. if (blocktoget == Blocks.ice && world.getLightFor(EnumSkyBlock.BLOCK, pos) > 11 - this.getLightOpacity()){
  134. if (!world.provider.isSurfaceWorld()){
  135. world.setBlockToAir(pos);}
  136.  
  137. this.dropBlockAsItem(world, pos, world.getBlockState(pos), 0);
  138. world.setBlockState(pos, Blocks.water.getDefaultState());
  139. }
  140. }
  141.  
  142. public IBlockState getStateFromMeta(int meta)
  143. {
  144. return getDefaultState();
  145. }
  146.  
  147. public int getMetaFromState(IBlockState state)
  148. {
  149. return 0;
  150. }
  151.  
  152. public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
  153. {
  154. return state.withProperty(UP, Boolean.valueOf(!worldIn.isAirBlock(pos.up()))).withProperty(NORTH, Boolean.valueOf(this.canConnectTo(worldIn, pos.north()))).withProperty(EAST, Boolean.valueOf(this.canConnectTo(worldIn, pos.east()))).withProperty(SOUTH, Boolean.valueOf(this.canConnectTo(worldIn, pos.south()))).withProperty(WEST, Boolean.valueOf(this.canConnectTo(worldIn, pos.west())));
  155. }
  156.  
  157. protected BlockState createBlockState()
  158. {
  159. return new BlockState(this, new IProperty[] {UP, NORTH, EAST, WEST, SOUTH});
  160. }
  161.  
  162. @SideOnly(Side.CLIENT)
  163. public int getBlockColor()
  164. {
  165. if(blocktoget == Blocks.leaves){
  166. return ColorizerFoliage.getFoliageColor(0.5D, 1.0D);
  167. }
  168. return super.getBlockColor();
  169. }
  170.  
  171. @SideOnly(Side.CLIENT)
  172. public int getRenderColor(IBlockState state)
  173. {
  174. if(blocktoget == Blocks.leaves){
  175. ColorizerFoliage.getFoliageColorBasic();
  176. }
  177. return super.getRenderColor(state);
  178. }
  179.  
  180. @SideOnly(Side.CLIENT)
  181. public int colorMultiplier(IBlockAccess acc, BlockPos pos, int renderPass)
  182. {
  183. if(blocktoget == Blocks.leaves){
  184. if(this == TeamCraft.SpruceLeafBush){
  185. return ColorizerFoliage.getFoliageColorPine();
  186. }else if(this == TeamCraft.BirchLeafBush){
  187. return ColorizerFoliage.getFoliageColorBirch();
  188. }else{
  189. return BiomeColorHelper.getFoliageColorAtPos(acc, pos);
  190. }
  191. }
  192. return super.colorMultiplier(acc, pos, renderPass);
  193. }
  194.  
  195. public boolean canPlaceTorchOnTop(IBlockAccess world, BlockPos pos)
  196. {
  197. return true;
  198. }
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement