Sponge icon indicating copy to clipboard operation
Sponge copied to clipboard

MoveEntityEvent does not fire for moving in vehicle

Open whimxiqal opened this issue 3 years ago • 6 comments

Affected Product(s)

SpongeVanilla

Version

spongevanilla-1.16.5-8.0.0-RC1055-universal

Operating System

Windows

Java Version

17.0.1

Plugins/Mods

Nope

Describe the bug

It seems that the MoveEntityEvent does not fire when a user moves in a vehicle (tested with boats and horses).

These is a gist of latest.log with some comments. I moved around next to the boat, got in the boat, moved around again, and got out, and moved around again. In the period of moving around, there were no MoveEntityEvent events fired.

Link to logs

https://gist.github.com/pietelite/b7a117524c793aca46174b6d507e2271

whimxiqal avatar Jan 27 '22 20:01 whimxiqal

@Faithcaio has found that this is because SpongeCommonEventFactory.callNaturalMoveEntityEvent is getting called but the delta is too small for Sponge to consider firing a MoveEntityEvent.

whimxiqal avatar Jan 27 '22 20:01 whimxiqal

Update: It's not at the above method. The mixin method ServerGamePacketListenerImplMixin.impl$callMoveEntityEvent is what seems to pass through the packet and, when riding a boat, the execution dies here because this is false:

https://github.com/SpongePowered/Sponge/blob/bf5f2da0f33d9e47b79706a2b8da92f8863a3a54/src/mixins/java/org/spongepowered/common/mixin/core/server/network/ServerGamePacketListenerImplMixin.java#L281

It's because packetInAccessor.accessor$hasPos() is false when riding a boat. I'm not knowledgeable of mixins and packets, though, so I'm not entirely sure how to fix this.

whimxiqal avatar Jan 27 '22 23:01 whimxiqal

Update: I think the thing I found above isn't supposed to work because of how Minecraft sends packets. I'm not sure though.

Instead, I found this completely unused utility method... https://github.com/SpongePowered/Sponge/blob/bf5f2da0f33d9e47b79706a2b8da92f8863a3a54/src/main/java/org/spongepowered/common/event/tracking/TrackingUtil.java#L152

I think it's supposed to be called right after here? https://github.com/SpongePowered/Sponge/blob/bf5f2da0f33d9e47b79706a2b8da92f8863a3a54/src/mixins/java/org/spongepowered/common/mixin/tracker/server/level/ServerLevelMixin_Tracker.java#L172

I tried inserting the following to see if I could ask Sponge to tick passengers and I think it's working, but I'll test some more:

for (Entity passenger : entity.getPassengers()) {
    TrackingUtil.tickRidingEntity(passenger);
}

whimxiqal avatar Jan 28 '22 00:01 whimxiqal

What is actually happening here is that when a entity is being ridden its not actually moved inside the entity ticking but inside the ServerboundMoveVehiclePacket packet. So when we get to the SpongeCommonEventFactory.callNaturalMoveEntityEvent where we would normally fire the move events, we do nothing as we haven't observed any movement.

aromaa avatar Jan 28 '22 04:01 aromaa

I'm not sure where to start with fixing this, then. Someone more knowledgeable than I in packets will need to look at this.

whimxiqal avatar Jan 29 '22 03:01 whimxiqal

I think you want something like https://github.com/SpongePowered/Sponge/pull/3612 - not got a chance to test it at the moment but if you're feeling adventurous, pull and compile that PR and see if that helps you.

dualspiral avatar Jan 29 '22 13:01 dualspiral