Figure out if a block is replaceable

When a user right-clicks a certain type of block while holding a block in the hand, depending on the type (or state?) of the right-clicked block on the ground, the held block is placed either on it’s side (eg.: stone, dirt, …), or replaces the block on the ground (eg.: snow layer, tall grass, …). How can I figure out, how it will behave?

Edit:
Additionally, is it also possible to figure out whether a block would be placed when a user right-clicks it? When a user right-clicks a lever or a button, the held block isn’t placed.

There is a property called ReplaceableProperty for this purpose.

1 Like

Thanks, that works perfectly. Just one more thing:

The only way to tell is to observe the action when an interaction is made.
You can simulate a player’s actions using methods like interactBlock from InteractableVolume. (Once https://github.com/SpongePowered/SpongeCommon/pull/86 is merged)
Be sure to cancel the events caused by the simulation if you don’t want to make any changes to the world

1 Like