@pcm1k opened this Pull Request on October 8th 2021 First_time_contributor

This should fix issue #475.

@sudofox commented on October 12th 2021

Out of curiosity (and unfamiliarity with Fabric API) how does this fix work?

@pcm1k commented on October 12th 2021

Out of curiosity (and unfamiliarity with Fabric API) how does this fix work?

For reference, the relevant code looks something like:

super.tick();
if (this.hasVehicle()) {
    this.networkHandler.sendPacket(new PlayerMoveC2SPacket.LookAndOnGround(this.getYaw(), this.getPitch(), this.onGround));
    this.networkHandler.sendPacket(new PlayerInputC2SPacket(this.sidewaysSpeed, this.forwardSpeed, this.input.jumping, this.input.sneaking));
    final Entity aqa2 = this.getRootVehicle();
    if (aqa2 != this && aqa2.isLogicalSideForUpdatingMovement()) {
        this.networkHandler.sendPacket(new VehicleMoveC2SPacket(aqa2));
    }
}
else {
    this.sendMovementPackets();
}

The problem is that sendMovementPackets() is never called if we are riding a vehicle.

The first part is:

<a class='mention' href='https://github.com/Inject'>@Inject</a>(at = <a class='mention' href='https://github.com/At'>@At</a>(value = "INVOKE",
    target = "Lnet/minecraft/client/network/AbstractClientPlayerEntity;tick()V",
    ordinal = 0,
    shift = Shift.AFTER), method = "tick()V")

This injects our code right after the "super.tick()" call.

The second part is:

<a class='mention' href='https://github.com/Inject'>@Inject</a>(at = <a class='mention' href='https://github.com/At'>@At</a>(value = "INVOKE",
    target = "Lnet/minecraft/client/network/ClientPlayerEntity;sendMovementPackets()V",
    ordinal = 0,
    shift = Shift.BY,
    by = 2), method = "tick()V")

This injects our code 2 instructions after the "this.sendMovementPackets()" call, outside of the "else" block.