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

Fix players being sent back through a nether portal they just used. #1610

Merged
merged 1 commit into from Dec 2, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -45,7 +45,17 @@ public MixinEntityPlayerMP(World worldIn) {
@Redirect(method = "decrementTimeUntilPortal", at = @At(value = "FIELD", target = ENTITY_PLAYER_MP_PORTAL_COOLDOWN_FIELD, opcode = Opcodes.PUTFIELD, ordinal = 0))
public void fixupPortalCooldown(EntityPlayerMP self, int modifier) {
int ticks = (int) ((IMixinRealTimeTicking) self.getEntityWorld()).getRealTimeTicks();
this.timeUntilPortal = Math.max(0, this.timeUntilPortal - ticks);
// The initially apparent function of timeUntilPortal is a cooldown for
// nether portals. However, there is a much more important use:
// preventing players from being immediately sent back to the other end
// of the portal. Since it only checks timeUntilPortal to determine
// whether the player was just in a portal, if timeUntilPortal gets set
// to 0, it assumes the player left and reentered the portal (see
// Entity.setPortal()). To prevent this, "snag" the value of
// timeUntilPortal at 1. If setPortal() does not reset it (the player
// exits the portal), modifier will become 0, indicating that it is
// OK to teleport the player.
this.timeUntilPortal = Math.max(modifier > 0 ? 1 : 0, this.timeUntilPortal - ticks);
}

}