Reputation: 4072
I'm writing a Minecraft module using Minecraft Forge.
I can retrieve a Block object from the world, using
Block b = world.getBlock(x,y,z);
however, now that I have the block, how do I find out the metadata? If the block is a StoneSteps block, then I want to know it's orientation, which is held in the metadata.
Similarly, how do I set this value? I can create a new block simply enough:
Block b = Blocks.stone_stairs;
but again, how do I now set this block to a particular orientation? I know you can do this when creating an ItemStack, but in this case, I want a Block object that can be passed on to world.setBlock()
.
There does not appear to be any way I can find to get and set this value.
Upvotes: 3
Views: 7671
Reputation: 775
You can use world.getBlockState(BlockPos);
for Minecraft 1.8 or getBlockMetadata(int x, int y, int z);
for Minecraft 1.7.10.
Upvotes: 1
Reputation: 2907
You can rotate the block through:
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 axis passed in (generally, it should be the "face" that was hit). Note: for mod blocks, this is up to the block and modder to decide. It is not mandated that it be a rotation around the face, but could be a rotation to orient to that face, or a visiting of possible rotations. The method should return true if the rotation was successful though.
Upvotes: 1