How to get and set the metadata value for a block item in Minecraft?

I am writing a Minecraft module using Minecraft Forge.

I can get a Block object from the world using

Block b = world.getBlock(x,y,z);

      

however, now that I have a block, how do I find out the metadata? If the block is a StoneSteps block, then I want to know its orientation, which is stored in the metadata.

Similarly, how do I set this value? I can create a new block quite simply:

Block b = Blocks.stone_stairs;

      

but again, how do I now set this block to a specific orientation? I know you can do this when creating the ItemStack, but in this case, I need a Block object that can be passed to world.setBlock()

.

I can't seem to find to get and set this value.

+3


source to share


2 answers


You can use world.getBlockState(BlockPos);

for Minecraft 1.8 or getBlockMetadata(int x, int y, int z);

Minecraft 1.7.10.



+1


source


You can rotate the block with:

yourBlock.rotateBlock(World someWorld, int x, int y, int z, ForgeDirection axis);

      



From the docs:

Rotate the block. For vanilla blocks, this rotates around the traversed axis (usually this should be the "face" that was hit). Note: for mod blocks, it depends on the block selection and modder. It cannot be argued that this is a rotation around a face, but there may be a rotation to orientate to that face or visit possible turns. The method should return true if the rotation was successful, though.

+1


source







All Articles