Posted December 17, 201410 yr Hello, I seem to be having some trouble with the blockstate for one of my blocks. I have 2 properties, one being a PropertyDirection (north, east, south, west) and PropertyInteger (Min: 0 and Max: 16). They are both used to determine the json file for the render. The problem that I am having is that the properties are going "berserk" when I place and interact with the block down in the world. I understand that each state needs a unique id and I have wrote that correctly in the method getMetaFromState. getStateFromMeta also returns back the correct state. Below is all relevant code and a video showing the problem. Any help is appreciated! BlockBath: package com.mrcrayfish.furniture.blocks; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyInteger; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.util.MathHelper; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.relauncher.Side; import com.mrcrayfish.furniture.FurnitureBlocks; import com.mrcrayfish.furniture.FurnitureItems; public class BlockBath extends BlockFurniture { public static final PropertyInteger WATER_LEVEL = PropertyInteger.create("level", 0, 16); public BlockBath(Material material) { super(material); setHardness(1.0F); setStepSound(Block.soundTypeStone); this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(WATER_LEVEL, Integer.valueOf(0))); } @Override public String getHarvestTool(IBlockState state) { return null; } @Override public boolean isOpaqueCube() { return false; } @Override public boolean isFullCube() { return false; } @Override public Item getItemDropped(IBlockState state, Random rand, int fortune) { return FurnitureItems.itemBath; } @Override public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos) { return new ItemStack(FurnitureItems.itemBath); } @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ) { world.setBlockState(pos, getDefaultState().withProperty(FACING, state.getValue(FACING)).withProperty(WATER_LEVEL, MathHelper.clamp_int(((Integer) state.getValue(WATER_LEVEL)).intValue() + 1, 0, 16))); return true; } @Override public IBlockState onBlockPlaced(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { IBlockState state = super.onBlockPlaced(world, pos, facing, hitX, hitY, hitZ, meta, placer); return state.withProperty(WATER_LEVEL, Integer.valueOf(0)); } @Override public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { world.setBlockState(pos.offset(placer.getHorizontalFacing()), FurnitureBlocks.bath_2.getDefaultState().withProperty(FACING, state.getValue(FACING)).withProperty(WATER_LEVEL, state.getValue(WATER_LEVEL))); } @Override public IBlockState getStateFromMeta(int meta) { EnumFacing facing = EnumFacing.getHorizontal(meta / 17); Integer water_level = new Integer((int) (meta - (Math.floor(meta / 17) * 17)) ); if (FMLCommonHandler.instance().getSide() == Side.CLIENT) { System.out.println("getStateFromMeta"); System.out.println("Meta: " + meta); System.out.println("Facing: " + facing.getHorizontalIndex()); System.out.println("Water Level: " + water_level.intValue()); } return this.getDefaultState().withProperty(FACING, facing).withProperty(WATER_LEVEL, water_level.intValue()); } @Override public int getMetaFromState(IBlockState state) { if (FMLCommonHandler.instance().getSide() == Side.CLIENT) { System.out.println("getMetaFromState"); System.out.println("Facing: " + ((EnumFacing) state.getValue(FACING)).getHorizontalIndex()); System.out.println("Water Level: " + ((Integer) state.getValue(WATER_LEVEL)).intValue()); System.out.println("Returning: " + (((EnumFacing) state.getValue(FACING)).getHorizontalIndex() * 17 + ((Integer) state.getValue(WATER_LEVEL)).intValue())); } return ((EnumFacing) state.getValue(FACING)).getHorizontalIndex() * 17 + ((Integer) state.getValue(WATER_LEVEL)).intValue(); } @Override protected BlockState createBlockState() { return new BlockState(this, new IProperty[] { FACING, WATER_LEVEL }); } public static boolean canPlaceBath(World world, BlockPos pos, EnumFacing facing) { return (world.isAirBlock(pos) && world.isAirBlock(pos.offset(facing, 1))); } } BlockFurniture package com.mrcrayfish.furniture.blocks; import net.minecraft.block.Block; import net.minecraft.block.BlockStairs; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; public class BlockFurniture extends Block { public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL); public BlockFurniture(Material material) { super(material); this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); } @Override public boolean isOpaqueCube() { return false; } @Override public boolean isFullCube() { return false; } @Override public IBlockState onBlockPlaced(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { IBlockState state = super.onBlockPlaced(world, pos, facing, hitX, hitY, hitZ, meta, placer); return state.withProperty(FACING, placer.getHorizontalFacing()); } @Override public int getMetaFromState(IBlockState state) { return ((EnumFacing) state.getValue(FACING)).getHorizontalIndex(); } @Override public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta)); } @Override protected BlockState createBlockState() { return new BlockState(this, new IProperty[] { FACING }); } } ItemBath package com.mrcrayfish.furniture.items; import net.minecraft.block.Block; import net.minecraft.block.BlockSnow; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; import com.mrcrayfish.furniture.FurnitureBlocks; import com.mrcrayfish.furniture.blocks.BlockBath; public class ItemBath extends Item { private BlockBath block = (BlockBath) FurnitureBlocks.bath_1; public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) { IBlockState iblockstate = world.getBlockState(pos); Block block = iblockstate.getBlock(); if (block == Blocks.snow_layer && ((Integer) iblockstate.getValue(BlockSnow.LAYERS)).intValue() < 1) { side = EnumFacing.UP; } else if (!block.isReplaceable(world, pos)) { pos = pos.offset(side); } if (!player.canPlayerEdit(pos, side, stack)) { return false; } else if (stack.stackSize == 0) { return false; } else { if (BlockBath.canPlaceBath(world, pos, player.getHorizontalFacing())) { IBlockState bathBottomState = this.block.onBlockPlaced(world, pos, side, hitX, hitY, hitZ, 0, player); if (world.setBlockState(pos, bathBottomState, 3)) { bathBottomState = world.getBlockState(pos); if (bathBottomState.getBlock() == this.block) { ItemBlock.setTileEntityNBT(world, pos, stack); bathBottomState.getBlock().onBlockPlacedBy(world, pos, bathBottomState, player, stack); } world.playSoundEffect((double) ((float) pos.getX() + 0.5F), (double) ((float) pos.getY() + 0.5F), (double) ((float) pos.getZ() + 0.5F), this.block.stepSound.getPlaceSound(), (this.block.stepSound.getVolume() + 1.0F) / 2.0F, this.block.stepSound.getFrequency() * 0.8F); --stack.stackSize; return true; } } return false; } } } blockstates/bath_bottom.json { "variants": { "facing=north,level=0": {"model": "cfm:bath_bottom_0_pre", "y": 270}, "facing=north,level=1": {"model": "cfm:bath_bottom_1_pre", "y": 270}, "facing=north,level=2": {"model": "cfm:bath_bottom_2_pre", "y": 270}, "facing=north,level=3": {"model": "cfm:bath_bottom_3_pre", "y": 270}, "facing=north,level=4": {"model": "cfm:bath_bottom_4_pre", "y": 270}, "facing=north,level=5": {"model": "cfm:bath_bottom_5_pre", "y": 270}, "facing=north,level=6": {"model": "cfm:bath_bottom_6_pre", "y": 270}, "facing=north,level=7": {"model": "cfm:bath_bottom_7_pre", "y": 270}, "facing=north,level=8": {"model": "cfm:bath_bottom_8_pre", "y": 270}, "facing=north,level=9": {"model": "cfm:bath_bottom_9_pre", "y": 270}, "facing=north,level=10": {"model": "cfm:bath_bottom_10_pre", "y": 270}, "facing=north,level=11": {"model": "cfm:bath_bottom_11_pre", "y": 270}, "facing=north,level=12": {"model": "cfm:bath_bottom_12_pre", "y": 270}, "facing=north,level=13": {"model": "cfm:bath_bottom_13_pre", "y": 270}, "facing=north,level=14": {"model": "cfm:bath_bottom_14_pre", "y": 270}, "facing=north,level=15": {"model": "cfm:bath_bottom_15_pre", "y": 270}, "facing=north,level=16": {"model": "cfm:bath_bottom_16_pre", "y": 270}, "facing=east,level=0": {"model": "cfm:bath_bottom_0_pre"}, "facing=east,level=1": {"model": "cfm:bath_bottom_1_pre"}, "facing=east,level=2": {"model": "cfm:bath_bottom_2_pre"}, "facing=east,level=3": {"model": "cfm:bath_bottom_3_pre"}, "facing=east,level=4": {"model": "cfm:bath_bottom_4_pre"}, "facing=east,level=5": {"model": "cfm:bath_bottom_5_pre"}, "facing=east,level=6": {"model": "cfm:bath_bottom_6_pre"}, "facing=east,level=7": {"model": "cfm:bath_bottom_7_pre"}, "facing=east,level=8": {"model": "cfm:bath_bottom_8_pre"}, "facing=east,level=9": {"model": "cfm:bath_bottom_9_pre"}, "facing=east,level=10": {"model": "cfm:bath_bottom_10_pre"}, "facing=east,level=11": {"model": "cfm:bath_bottom_11_pre"}, "facing=east,level=12": {"model": "cfm:bath_bottom_12_pre"}, "facing=east,level=13": {"model": "cfm:bath_bottom_13_pre"}, "facing=east,level=14": {"model": "cfm:bath_bottom_14_pre"}, "facing=east,level=15": {"model": "cfm:bath_bottom_15_pre"}, "facing=east,level=16": {"model": "cfm:bath_bottom_16_pre"}, "facing=south,level=0": {"model": "cfm:bath_bottom_0_pre", "y": 90}, "facing=south,level=1": {"model": "cfm:bath_bottom_1_pre", "y": 90}, "facing=south,level=2": {"model": "cfm:bath_bottom_2_pre", "y": 90}, "facing=south,level=3": {"model": "cfm:bath_bottom_3_pre", "y": 90}, "facing=south,level=4": {"model": "cfm:bath_bottom_4_pre", "y": 90}, "facing=south,level=5": {"model": "cfm:bath_bottom_5_pre", "y": 90}, "facing=south,level=6": {"model": "cfm:bath_bottom_6_pre", "y": 90}, "facing=south,level=7": {"model": "cfm:bath_bottom_7_pre", "y": 90}, "facing=south,level=8": {"model": "cfm:bath_bottom_8_pre", "y": 90}, "facing=south,level=9": {"model": "cfm:bath_bottom_9_pre", "y": 90}, "facing=south,level=10": {"model": "cfm:bath_bottom_10_pre", "y": 90}, "facing=south,level=11": {"model": "cfm:bath_bottom_11_pre", "y": 90}, "facing=south,level=12": {"model": "cfm:bath_bottom_12_pre", "y": 90}, "facing=south,level=13": {"model": "cfm:bath_bottom_13_pre", "y": 90}, "facing=south,level=14": {"model": "cfm:bath_bottom_14_pre", "y": 90}, "facing=south,level=15": {"model": "cfm:bath_bottom_15_pre", "y": 90}, "facing=south,level=16": {"model": "cfm:bath_bottom_16_pre", "y": 90}, "facing=west,level=0": {"model": "cfm:bath_bottom_0_pre", "y": 180}, "facing=west,level=1": {"model": "cfm:bath_bottom_1_pre", "y": 180}, "facing=west,level=2": {"model": "cfm:bath_bottom_2_pre", "y": 180}, "facing=west,level=3": {"model": "cfm:bath_bottom_3_pre", "y": 180}, "facing=west,level=4": {"model": "cfm:bath_bottom_4_pre", "y": 180}, "facing=west,level=5": {"model": "cfm:bath_bottom_5_pre", "y": 180}, "facing=west,level=6": {"model": "cfm:bath_bottom_6_pre", "y": 180}, "facing=west,level=7": {"model": "cfm:bath_bottom_7_pre", "y": 180}, "facing=west,level=8": {"model": "cfm:bath_bottom_8_pre", "y": 180}, "facing=west,level=9": {"model": "cfm:bath_bottom_9_pre", "y": 180}, "facing=west,level=10": {"model": "cfm:bath_bottom_10_pre", "y": 180}, "facing=west,level=11": {"model": "cfm:bath_bottom_11_pre", "y": 180}, "facing=west,level=12": {"model": "cfm:bath_bottom_12_pre", "y": 180}, "facing=west,level=13": {"model": "cfm:bath_bottom_13_pre", "y": 180}, "facing=west,level=14": {"model": "cfm:bath_bottom_14_pre", "y": 180}, "facing=west,level=15": {"model": "cfm:bath_bottom_15_pre", "y": 180}, "facing=west,level=16": {"model": "cfm:bath_bottom_16_pre", "y": 180} } } blockstates/bath_top.json { "variants": { "facing=north,level=0": {"model": "cfm:bath_top_0_pre", "y": 270}, "facing=north,level=1": {"model": "cfm:bath_top_1_pre", "y": 270}, "facing=north,level=2": {"model": "cfm:bath_top_2_pre", "y": 270}, "facing=north,level=3": {"model": "cfm:bath_top_3_pre", "y": 270}, "facing=north,level=4": {"model": "cfm:bath_top_4_pre", "y": 270}, "facing=north,level=5": {"model": "cfm:bath_top_5_pre", "y": 270}, "facing=north,level=6": {"model": "cfm:bath_top_6_pre", "y": 270}, "facing=north,level=7": {"model": "cfm:bath_top_7_pre", "y": 270}, "facing=north,level=8": {"model": "cfm:bath_top_8_pre", "y": 270}, "facing=north,level=9": {"model": "cfm:bath_top_9_pre", "y": 270}, "facing=north,level=10": {"model": "cfm:bath_top_10_pre", "y": 270}, "facing=north,level=11": {"model": "cfm:bath_top_11_pre", "y": 270}, "facing=north,level=12": {"model": "cfm:bath_top_12_pre", "y": 270}, "facing=north,level=13": {"model": "cfm:bath_top_13_pre", "y": 270}, "facing=north,level=14": {"model": "cfm:bath_top_14_pre", "y": 270}, "facing=north,level=15": {"model": "cfm:bath_top_15_pre", "y": 270}, "facing=north,level=16": {"model": "cfm:bath_top_16_pre", "y": 270}, "facing=east,level=0": {"model": "cfm:bath_top_0_pre"}, "facing=east,level=1": {"model": "cfm:bath_top_1_pre"}, "facing=east,level=2": {"model": "cfm:bath_top_2_pre"}, "facing=east,level=3": {"model": "cfm:bath_top_3_pre"}, "facing=east,level=4": {"model": "cfm:bath_top_4_pre"}, "facing=east,level=5": {"model": "cfm:bath_top_5_pre"}, "facing=east,level=6": {"model": "cfm:bath_top_6_pre"}, "facing=east,level=7": {"model": "cfm:bath_top_7_pre"}, "facing=east,level=8": {"model": "cfm:bath_top_8_pre"}, "facing=east,level=9": {"model": "cfm:bath_top_9_pre"}, "facing=east,level=10": {"model": "cfm:bath_top_10_pre"}, "facing=east,level=11": {"model": "cfm:bath_top_11_pre"}, "facing=east,level=12": {"model": "cfm:bath_top_12_pre"}, "facing=east,level=13": {"model": "cfm:bath_top_13_pre"}, "facing=east,level=14": {"model": "cfm:bath_top_14_pre"}, "facing=east,level=15": {"model": "cfm:bath_top_15_pre"}, "facing=east,level=16": {"model": "cfm:bath_top_16_pre"}, "facing=south,level=0": {"model": "cfm:bath_top_0_pre", "y": 90}, "facing=south,level=1": {"model": "cfm:bath_top_1_pre", "y": 90}, "facing=south,level=2": {"model": "cfm:bath_top_2_pre", "y": 90}, "facing=south,level=3": {"model": "cfm:bath_top_3_pre", "y": 90}, "facing=south,level=4": {"model": "cfm:bath_top_4_pre", "y": 90}, "facing=south,level=5": {"model": "cfm:bath_top_5_pre", "y": 90}, "facing=south,level=6": {"model": "cfm:bath_top_6_pre", "y": 90}, "facing=south,level=7": {"model": "cfm:bath_top_7_pre", "y": 90}, "facing=south,level=8": {"model": "cfm:bath_top_8_pre", "y": 90}, "facing=south,level=9": {"model": "cfm:bath_top_9_pre", "y": 90}, "facing=south,level=10": {"model": "cfm:bath_top_10_pre", "y": 90}, "facing=south,level=11": {"model": "cfm:bath_top_11_pre", "y": 90}, "facing=south,level=12": {"model": "cfm:bath_top_12_pre", "y": 90}, "facing=south,level=13": {"model": "cfm:bath_top_13_pre", "y": 90}, "facing=south,level=14": {"model": "cfm:bath_top_14_pre", "y": 90}, "facing=south,level=15": {"model": "cfm:bath_top_15_pre", "y": 90}, "facing=south,level=16": {"model": "cfm:bath_top_16_pre", "y": 90}, "facing=west,level=0": {"model": "cfm:bath_top_0_pre", "y": 180}, "facing=west,level=1": {"model": "cfm:bath_top_1_pre", "y": 180}, "facing=west,level=2": {"model": "cfm:bath_top_2_pre", "y": 180}, "facing=west,level=3": {"model": "cfm:bath_top_3_pre", "y": 180}, "facing=west,level=4": {"model": "cfm:bath_top_4_pre", "y": 180}, "facing=west,level=5": {"model": "cfm:bath_top_5_pre", "y": 180}, "facing=west,level=6": {"model": "cfm:bath_top_6_pre", "y": 180}, "facing=west,level=7": {"model": "cfm:bath_top_7_pre", "y": 180}, "facing=west,level=8": {"model": "cfm:bath_top_8_pre", "y": 180}, "facing=west,level=9": {"model": "cfm:bath_top_9_pre", "y": 180}, "facing=west,level=10": {"model": "cfm:bath_top_10_pre", "y": 180}, "facing=west,level=11": {"model": "cfm:bath_top_11_pre", "y": 180}, "facing=west,level=12": {"model": "cfm:bath_top_12_pre", "y": 180}, "facing=west,level=13": {"model": "cfm:bath_top_13_pre", "y": 180}, "facing=west,level=14": {"model": "cfm:bath_top_14_pre", "y": 180}, "facing=west,level=15": {"model": "cfm:bath_top_15_pre", "y": 180}, "facing=west,level=16": {"model": "cfm:bath_top_16_pre", "y": 180} } } Video:
December 17, 201410 yr Author Thank you. That limits block models quite a bit Hopefully someone will implement ISBRH in future but for now I'm going to try to use a TE and TESR to render the water level.
December 17, 201410 yr Author Ahh, I'm stupid. Just discovered I can use getActualState to get TileEntity data then parse to BlockState for block models. I just got confused because I thought I was limited to 16 unique state, but now I've found that method, I can do a lot more.
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.