Preventing Water Spread

I’ve used IRC a bit already for this issue, but I’m trying to cancel water flow conditionally. Currently, I’m listening to NotifyNeighborBlockEvent. It’s irrelevant, but for my conditional logic I’m getting the source block location with blockSnapshot.getLocation().get() and the location where the water will flow with blockSnapshot.getLocation().get().add(direction.toVector3d()).

I see directions are supposed to be filtered with NotifyNeighborBlockEvent.filterDirections(java.util.function.Predicate<org.spongepowered.api.util.Direction> predicate). It’s really cool how it takes a predicate and props to the designer. When I try to use it, I’m getting java.lang.AbstractMethodError: org.spongepowered.api.event.impl.NotifyNeighborBlockEvent$Impl.filterDirections(Ljava/util/function/Predicate;)V, which I presume means it’s just not implemented in my current version (spongeforge-1.8.9-1890-4.2.0-BETA-1484).

My version is a bit behind, due to mod restrictions. Is this correct? Has it been implemented in the latest version? If so, which version? I’m sorry if this is a lot to ask, but I feel like one of the active Sponge devs would know this info well.

Is there a different way I could replicate this desired behavior in the mean time? It’s pretty vital in my plugin :frowning2:

Lastly, what’s the difference between Direciton.EAST_NORTHEAST and Direction.NORTH_NORTHEAST? Looking at the source code, I see it’s new Vector3d(C.S8, 0, -C.C8) versus new Vector3d(C.C8, 0, -C.S8, but I’m not sure I’m grasping the logic behind this trigonometry. Thank you!

Regarding your last question: If you picture the compass wheel as a unit circle (east is 0°, north is 90°, northeast is 45°, etc), east-northeast is 22.5° and north-northeast is 67.5°. Read east-northeast as being the eastern half of northeast. By the same token, east-east-northeast would be 11.25° and north-east-northeast would be 33.75°.

1 Like

Found another way to do it through IRC, so this is solved. Just remove the directions in the neighbors map.

Actually, I’m trying this and it’s not preventing water from flowing in the given direction. I’m running it as event.getNeighbors().remove(directionHere) and verified the correct directions are removed. I’m able to prevent a redstone torch from notifying a redstone rail, however water still flows. Please see this gif I made. http://imgur.com/kHO7hLN @blood since you’ve been helping me! Is there something special I need to do with water?

Here’s some code I wrote for a similar question

1 Like

Thank you @simon816! Does the BlockSnapshot root hold the original source block location of the flow? And the event holds the new location?

Yes. The root object (from the Cause) is the block that caused a Place event - the original source water block in this case.
The event describes the block that is being proposed to be placed.

1 Like

And if I want to get the previous block of the flow it would be the last cause? And why is this different from the NotifyNeighborEvent? I was under the impression if the block is not notified by the water it will not flow there…

NotifyNeighborEvent is just used for triggering behavior in already-existing blocks (e.g. it triggers sand and gravel to fall). Air doesn’t have any special behavior to turn to water when water is placed next to it; water has that behavior, so NotifyNeighborEvent doesn’t affect the spread.

1 Like