NOT an issue, asking a question
SgtPunishment opened this issue ยท 5 comments
When you created the carpenters block (the full block) how did you get it to change to a half slab on a click? I'm attempting to do something like this in my roadblocks mod, but it's driving me up the wall, if you have time could you hit me up on skype? TheSgtPunishment
- For simple box shape adjustments, store the block state using the block's metadata and generate the bounding box using that (meta 0 -> Full, 1 -> Slab). Define the metadata->boundingbox here: https://github.com/Mineshopper/carpentersblocks/blob/master/src/main/java/com/carpentersblocks/block/BlockCarpentersBlock.java#L110
- In your block class, override Block.onBlockActivated() to capture the right-click. In there, just change the metadata to 0 or 1 depending on what you're trying to accomplish.
- Call world.markBlockForUpdate(x, y, z) to render using the new state.
This mod relies on tile entities for it's data, but the metadata route is easier and safer.
Thanks for the response, I'm unable to implement the meta data stuff at the moment, but when I do and if it works I will thank you in the credits, also I have 2 follow-up questions, will the blocks remember the state they're in on unload/load? And if I click on one block will they all change?
Metadata is stored on a block-by-block basis, so they won't all change. Similiarly, metadata is saved with the block - any kind of change of state that the game can remember the block even exists, should keep the metadata state.
Also, don't forget to add the collision box to pool in your block class, otherwise block collision will be problematic:
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB axisAlignedBB, List list, Entity entity)
{
setBlockBoundsBasedOnState(world, x, y, z);
super.addCollisionBoxesToList(world, x, y, z, axisAlignedBB, list, entity);
}
And as for the metadata, as Syndaryl said it's already there you just need to set it using World.setBlockMetadataWithNotify()
and World.getBlockMetadata()
.
Okay, I want to say thank you to everyone that has helped me, but I'm certain I have gone wrong somewhere in the code (Multiple people working on it, code get's butchered together lol), the meta block state thingy works perfectly, but one issue we're having now, is sub blocks aren't really generating the way we would want them, and the block in the hotbar keeps changing as well