Advertisement
Guest User

Untitled

a guest
May 23rd, 2015
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. package degubi.teamcraft.things.blocks;
  2.  
  3. import net.minecraft.block.Block;
  4. import net.minecraft.block.BlockDirectional;
  5. import net.minecraft.block.material.Material;
  6. import net.minecraft.block.properties.IProperty;
  7. import net.minecraft.block.state.BlockState;
  8. import net.minecraft.block.state.IBlockState;
  9. import net.minecraft.init.Blocks;
  10. import net.minecraft.util.AxisAlignedBB;
  11. import net.minecraft.util.BlockPos;
  12. import net.minecraft.util.EnumFacing;
  13. import net.minecraft.util.EnumWorldBlockLayer;
  14. import net.minecraft.world.IBlockAccess;
  15. import net.minecraft.world.World;
  16. import net.minecraftforge.fml.relauncher.Side;
  17. import net.minecraftforge.fml.relauncher.SideOnly;
  18. import degubi.teamcraft.TeamCraft;
  19.  
  20. public class BlockHalfBlocks extends BlockDirectional{
  21. private int number;
  22.  
  23. public BlockHalfBlocks(int count, Block infBlock) {
  24. super(Material.wood);
  25. setDefaultState(blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
  26. number = count;
  27. setStepSound(infBlock.stepSound);
  28. setHardness(infBlock.blockHardness);
  29. setResistance(infBlock.blockResistance);
  30. setCreativeTab(TeamCraft.tcmtabBlocks);
  31. setUnlocalizedName("HalfBlock" + number);
  32. if(infBlock == Blocks.ice || infBlock == Blocks.packed_ice){
  33. slipperiness = 0.98F;
  34. }
  35.  
  36. }
  37.  
  38. @SideOnly(Side.CLIENT)
  39. public EnumWorldBlockLayer getBlockLayer() {
  40. return number > 15 && number < 33 || number == 39 ? EnumWorldBlockLayer.TRANSLUCENT : EnumWorldBlockLayer.CUTOUT;
  41. }
  42.  
  43. public IBlockState getStateFromMeta(int meta)
  44. {
  45. EnumFacing enumfacing = EnumFacing.getFront(meta);
  46.  
  47. if (enumfacing.getAxis() == EnumFacing.Axis.Y)
  48. {
  49. enumfacing = EnumFacing.NORTH;
  50. }
  51.  
  52. return this.getDefaultState().withProperty(FACING, enumfacing);
  53. }
  54.  
  55. public int getMetaFromState(IBlockState state)
  56. {
  57. return ((EnumFacing)state.getValue(FACING)).getIndex();
  58. }
  59.  
  60. protected BlockState createBlockState()
  61. {
  62. return new BlockState(this, new IProperty[] {FACING});
  63. }
  64.  
  65. public boolean isOpaqueCube(){return false;}
  66.  
  67. public void setBlockBoundsForItemRender() {
  68. setBlockBounds(0.0F, 0.0F, 0.25F, 1.0F, 1.0F, 0.75F);
  69. }
  70.  
  71. public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
  72. {
  73. this.setBlockBoundsBasedOnState(worldIn, pos);
  74. return super.getCollisionBoundingBox(worldIn, pos, state);
  75. }
  76.  
  77. public void setBlockBoundsBasedOnState(IBlockAccess acc, BlockPos pos)
  78. {
  79. IBlockState iblockstate = acc.getBlockState(pos);
  80. int meta = acc.getBlockState(pos).getBlock().getMetaFromState(iblockstate);
  81. if(meta == 3){
  82. setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.5F);
  83. }else if(meta == 5){
  84. setBlockBounds(0.0F, 0.0F, 0.0F, 0.5F, 1.0F, 1.0F);
  85. }else if(meta == 4){
  86. setBlockBounds(0.5F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
  87. }else{
  88. setBlockBounds(0.0F, 0.0F, 0.5F, 1.0F, 1.0F, 1.0F);
  89. }
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement