Guest User

Untitled

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