From 3bc953477f84ceee330980ad0b1af6593d099adc Mon Sep 17 00:00:00 2001 From: James58899 Date: Sat, 17 Aug 2024 21:13:48 +0800 Subject: [PATCH] Fix portal realtime mixin --- .../PortalManagerMixin_RealTime.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/spongepowered/common/mixin/realtime/world/dimension/PortalManagerMixin_RealTime.java b/src/main/java/org/spongepowered/common/mixin/realtime/world/dimension/PortalManagerMixin_RealTime.java index 92e40a206..f67790ae9 100644 --- a/src/main/java/org/spongepowered/common/mixin/realtime/world/dimension/PortalManagerMixin_RealTime.java +++ b/src/main/java/org/spongepowered/common/mixin/realtime/world/dimension/PortalManagerMixin_RealTime.java @@ -18,10 +18,10 @@ package org.spongepowered.common.mixin.realtime.world.dimension; -import net.minecraft.block.Portal; import net.minecraft.entity.Entity; import net.minecraft.server.world.ServerWorld; import net.minecraft.world.dimension.PortalManager; +import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -31,20 +31,20 @@ @Mixin(PortalManager.class) public abstract class PortalManagerMixin_RealTime { - @Shadow - private Portal portal; @Shadow private int ticksInPortal; - @Shadow - private boolean inPortal; - @Inject(method = "tick", at = @At("RETURN"), cancellable = true) + @Inject(method = "tick", at = @At(value = "FIELD", target = "Lnet/minecraft/world/dimension/PortalManager;ticksInPortal:I", opcode = Opcodes.GETFIELD)) private void realTimeImpl$adjustForRealTimePortalCounter(ServerWorld world, Entity entity, boolean canUsePortals, CallbackInfoReturnable cir) { - if (this.inPortal) { - final int ticks = (int) ((RealTimeTrackingBridge) world).realTimeBridge$getRealTimeTicks(); - this.ticksInPortal += ticks; - // FIXME: Does this still need to this.ticksInPortal++ ? - cir.setReturnValue(canUsePortals && this.ticksInPortal >= this.portal.getPortalDelay(world, entity)); + final int ticks = (int) ((RealTimeTrackingBridge) world).realTimeBridge$getRealTimeTicks() - 1; + this.ticksInPortal += Math.max(0, ticks); + } + + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/dimension/PortalManager;decayTicksInPortal()V")) + private void realTimeImpl$PortalDecayCounter(ServerWorld world, Entity entity, boolean canUsePortals, CallbackInfoReturnable cir) { + final int ticks = (int) ((RealTimeTrackingBridge) world).realTimeBridge$getRealTimeTicks() - 1; + if (ticks > 0) { + this.ticksInPortal = Math.max(0, this.ticksInPortal - ticks * 4); } } }