Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make PreMotionEvent and PostMotionEvent work with vehicles (fixes #475) #476

Closed
wants to merge 1 commit into from

Conversation

pcm1k
Copy link
Contributor

@pcm1k pcm1k commented Oct 8, 2021

This should fix issue #475.

Copy link

@InfinitePower563 InfinitePower563 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes a small bug effectively.

@sudofox
Copy link
Contributor

sudofox commented Oct 12, 2021

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

@pcm1k
Copy link
Contributor Author

pcm1k commented Oct 12, 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:

@Inject(at = @At(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:

@Inject(at = @At(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.

ThisTestUser added a commit to ThisTestUser/Wurst7 that referenced this pull request Feb 6, 2023
ThisTestUser added a commit to ThisTestUser/Wurst7 that referenced this pull request Mar 13, 2023
ThisTestUser added a commit to ThisTestUser/Wurst7 that referenced this pull request Jun 10, 2023
Copy link

This pull request has been open for a while with no recent activity. If you're still working on this or waiting for a review, please add a comment or commit within the next 7 days to keep it open. Otherwise, the pull request will be automatically closed to free up time for other tasks.

Pull requests should be closed if:

  • They have been superseded by another pull request
  • They are out of scope or don't align with the project
  • They have become obsolete due to other changes
  • They have bugs or conflicts that won't be resolved

@ThisTestUser
Copy link
Contributor

Still relevant. A lot of mods don't work on vehicles (like KillAura), and this mod fixes this.

Copy link

This pull request has been open for a while with no recent activity. If you're still working on this or waiting for a review, please add a comment or commit within the next 7 days to keep it open. Otherwise, the pull request will be automatically closed to free up time for other tasks.

Pull requests should be closed if:

  • They have been superseded by another pull request
  • They are out of scope or don't align with the project
  • They have become obsolete due to other changes
  • They have bugs or conflicts that won't be resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants