Finding which block an attachable block relies on

May not be the best topic name, but I tried my best.

Is it possible to see if a block(such as a torch, pressure plate, door, lever, button, etc) relies on a block and if so get that block? My main goal is to from a block check if any surrounding blocks/items rely on it to stay present so I can protect the supporting block if need be.

Idk if Sponge has a direct support for that, but you could just check the 6 neighbouring blocks for what they are. May not be the prettiest code, but it’d work.

1 Like

The problem with this solution is some mods may introduce new blocks which rely on supporting blocks. This must be exposed by the server or else it would not know, for example, when to break a door when the block underneath is broken. A possible solution would be to have a config for block ids which rely on the block underneath but that does not help with blocks which can go on the side or the bottom.

Unfortunately, this information can’t be detected, without actually placing the block into the world and observing its behavior. You could scan around Vanilla blocks to see which side(s) have adjacent solid blocks, but there’s no way to know if a mod block even needs support at all.

1 Like

For some of these it is implemented for the vanilla blocks.

Specifically, for banners, signs, torches, trip wires, and trip hooks you can query whether it’s attached with Keys.ATTACHED, and in most cases, which side with Keys.CONNECTED_DIRECTION. This allows you to use Location#getBlockRelative(Direction) to find what it’s resting against.

The only issue with all of this is that mods don’t inherently have support for data, so you must either create compatibility plugins for them or have a plugin with built-in SpongeAPI support.

1 Like

Okay that makes sense, it’s unfortunate that I cannot do the same for modded blocks, but I’ll try my best to accomplish what I can with this information, thanks to all three of you.