BlockModSlab.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package me.km.blocks;
  2. import me.km.KajetansMod;
  3. import net.minecraft.block.BlockSlab;
  4. import static net.minecraft.block.BlockSlab.HALF;
  5. import net.minecraft.block.SoundType;
  6. import net.minecraft.block.material.Material;
  7. import net.minecraft.block.properties.IProperty;
  8. import net.minecraft.block.state.BlockStateContainer;
  9. import net.minecraft.block.state.IBlockState;
  10. import net.minecraft.creativetab.CreativeTabs;
  11. import net.minecraft.item.Item;
  12. import net.minecraft.item.ItemStack;
  13. import net.minecraft.util.BlockRenderLayer;
  14. import net.minecraftforge.fml.relauncher.Side;
  15. import net.minecraftforge.fml.relauncher.SideOnly;
  16. public class BlockModSlab extends BlockSlab implements IBlockBase
  17. {
  18. protected String name;
  19. public BlockModSlab(Material material, String name, String local)
  20. {
  21. super(material);
  22. this.name = name;
  23. this.setRegistryName(name);
  24. super.setUnlocalizedName(local);
  25. super.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
  26. this.setDefaultState(this.blockState.getBaseState().withProperty(HALF, BlockSlab.EnumBlockHalf.BOTTOM));
  27. super.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
  28. super.useNeighborBrightness = true;
  29. }
  30. @Override
  31. public void registerItemModel(Item itemBlock)
  32. {
  33. KajetansMod.proxy.registerItemRenderer(itemBlock, 0, name);
  34. }
  35. @Override
  36. public BlockModSlab setSoundType(SoundType sound)
  37. {
  38. super.setSoundType(sound);
  39. return this;
  40. }
  41. @Override
  42. public IBlockState getStateFromMeta(int meta)
  43. {
  44. IBlockState iblockstate = this.getDefaultState();
  45. if(!this.isDouble())
  46. {
  47. iblockstate = iblockstate.withProperty(HALF, (meta & 8) == 0 ? BlockSlab.EnumBlockHalf.BOTTOM : BlockSlab.EnumBlockHalf.TOP);
  48. }
  49. return iblockstate;
  50. }
  51. @Override
  52. public int getMetaFromState(IBlockState state)
  53. {
  54. int i = 0;
  55. if(state.getValue(HALF) == BlockSlab.EnumBlockHalf.TOP)
  56. {
  57. i |= 8;
  58. }
  59. return i;
  60. }
  61. @Override
  62. protected BlockStateContainer createBlockState()
  63. {
  64. if(this.isDouble())
  65. {
  66. return new BlockStateContainer(this);
  67. }
  68. return new BlockStateContainer(this, new IProperty[] {HALF});
  69. }
  70. @Override
  71. public IProperty<?> getVariantProperty()
  72. {
  73. return null;
  74. }
  75. @Override
  76. public Comparable<?> getTypeForItem(ItemStack stack)
  77. {
  78. return null;
  79. }
  80. @Override
  81. public String getUnlocalizedName(int meta)
  82. {
  83. return super.getUnlocalizedName();
  84. }
  85. @Override
  86. public boolean isDouble()
  87. {
  88. return false;
  89. }
  90. @SideOnly(Side.CLIENT)
  91. @Override
  92. public BlockRenderLayer getBlockLayer()
  93. {
  94. return BlockRenderLayer.CUTOUT;
  95. }
  96. }