Posted August 6, 20178 yr I'm having a problem with directional slabs. They kind of reset the direction when I create a double slab. I have a totally working slabs class, from this tutorial:https://www.youtube.com/watch?v=il-BQaPxQSA&index=25&list=PLpKu3PfwdqHRA8aoa4RAzO9camNR9Tm45 And a directional block class which is basically the vanilla furnace. I am tryinmg to merge these. The purspose is to make asphalt slabs, for roads. The half slabs works perfectly, the line in the middle of the texture is always pointing in the right direction. But when I put another one on top of a bottom slab, to make the double slab, It always points in the same direction, it somehow loses the state/meta data for FACING. I have been trying to find out why for a while now, so I will be very grateful if someone can figure it out. This is my base class: Spoiler public abstract class SlabBase extends BlockSlab { public static final PropertyDirection FACING = BlockHorizontal.FACING; public SlabBase(String unlocalizedName) { super(Material.IRON); this.setUnlocalizedName(unlocalizedName); this.setCreativeTab(Main.tabBirchware); this.setRegistryName(new ResourceLocation(Ref.MODID,unlocalizedName)); this.setHardness(1); this.setResistance(2); this.useNeighborBrightness = true; IBlockState state; if (!this.isDouble()) state = this.blockState.getBaseState().withProperty(FACING,EnumFacing.NORTH).withProperty(HALF,EnumBlockHalf.BOTTOM); else state = this.blockState.getBaseState().withProperty(FACING,EnumFacing.NORTH); this.setDefaultState(state); } @Override public String getUnlocalizedName(int meta) { return this.getUnlocalizedName(); } @Override public IProperty<?> getVariantProperty() { return HALF; } @Override public Comparable<?> getTypeForItem(ItemStack stack) { return EnumBlockHalf.BOTTOM; } @Override public int damageDropped(IBlockState state) { return 0; } @Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this,new IProperty[]{FACING,HALF}); } @Override public IBlockState getStateFromMeta(int meta) { EnumFacing enumfacing = EnumFacing.getFront(meta & 7); if (enumfacing.getAxis() == EnumFacing.Axis.Y) { enumfacing = EnumFacing.NORTH; } IBlockState state = this.getDefaultState().withProperty(FACING,enumfacing.values()[meta & 7]); if (!this.isDouble()) state = state.withProperty(HALF,(meta & 8) == 0 ? EnumBlockHalf.BOTTOM : EnumBlockHalf.TOP); return state; } @Override public int getMetaFromState(IBlockState state) { int meta = 0; meta = ((EnumFacing)state.getValue(FACING)).getIndex(); if (isDouble()) meta |= 8; return meta; } @Override public IBlockState onBlockPlaced(World worldIn,BlockPos pos,EnumFacing facing,float hitX,float hitY,float hitZ,int meta,EntityLivingBase placer) { Boolean bTop; if (facing == EnumFacing.DOWN) bTop = true; // Under a block. else if (facing == EnumFacing.UP ) bTop = false; // On a block. else bTop = (double)hitY > 0.5D; // Any side, hitY is where you clicked. if (!this.isDouble()) return this.getDefaultState().withProperty(FACING,placer.getHorizontalFacing().getOpposite()).withProperty(HALF,bTop ? EnumBlockHalf.TOP : EnumBlockHalf.BOTTOM); else return this.getDefaultState().withProperty(FACING,placer.getHorizontalFacing().getOpposite()); } @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { // Meta debugging. if ((playerIn.isSneaking()) && (!worldIn.isRemote)) { Logg.info("onBlockActivated Meta: " + getMetaFromState(state)); return true; } return false; } } And these are the three slab classes: Spoiler public abstract class SlabAsphaltLine extends SlabBase { SlabAsphaltLine(String unlocalizedName) { super(unlocalizedName); } @Override public Item getItemDropped(IBlockState state, Random rand, int fortune) { return Item.getItemFromBlock(slabAsphaltLineHalf); } } public class SlabAsphaltLineHalf extends SlabAsphaltLine { public SlabAsphaltLineHalf(String unlocalizedName) { super(unlocalizedName); } @Override public boolean isDouble() { return false; } } public class SlabAsphaltLineDouble extends SlabAsphaltLine { public SlabAsphaltLineDouble(String unlocalizedName) { super(unlocalizedName); } @Override public boolean isDouble() { return true; } } Edited August 6, 20178 yr by birch
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.