Skip to content

Commit

Permalink
build: try to fix realtime patch
Browse files Browse the repository at this point in the history
- portal tick moved from entity to portal manager
  • Loading branch information
jimchen5209 committed Aug 9, 2024
1 parent e89d6c2 commit 16e1c58
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* OKTW Galaxy Project
* Copyright (C) 2018-2023
* Copyright (C) 2018-2024
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
Expand Down Expand Up @@ -58,8 +58,6 @@ public abstract class EntityMixin_RealTime {
public int timeUntilRegen;
@Shadow
protected int ridingCooldown;
@Shadow
protected int netherPortalTime;

@Shadow
public abstract World getWorld();
Expand All @@ -86,20 +84,4 @@ public abstract class EntityMixin_RealTime {
final int ticks = (int) ((RealTimeTrackingBridge) this.getWorld()).realTimeBridge$getRealTimeTicks();
this.ridingCooldown = Math.max(0, this.ridingCooldown - ticks);
}

@Redirect(method = "tickPortal",
at = @At(
value = "FIELD",
target = "Lnet/minecraft/entity/Entity;netherPortalTime:I",
opcode = Opcodes.PUTFIELD, ordinal = 0
),
slice = @Slice(
from = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getMaxNetherPortalTime()I"),
to = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;resetPortalCooldown()V")
)
)
private void realTimeImpl$adjustForRealTimePortalCounter(final Entity self, final int modifier) {
final int ticks = (int) ((RealTimeTrackingBridge) this.getWorld()).realTimeBridge$getRealTimeTicks();
this.netherPortalTime += ticks;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* OKTW Galaxy Project
* Copyright (C) 2018-2024
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

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.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.common.bridge.RealTimeTrackingBridge;

@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)
private void realTimeImpl$adjustForRealTimePortalCounter(ServerWorld world, Entity entity, boolean canUsePortals, CallbackInfoReturnable<Boolean> 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));
}
}
}
3 changes: 2 additions & 1 deletion src/main/resources/sponge.realtime.mixin.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"server.MinecraftServerMixin_RealTime",
"server.network.ServerPlayerInteractionManagerMixin_RealTime",
"server.network.ServerPlayNetworkHandlerMixin_RealTime",
"world.WorldMixin_RealTime"
"world.WorldMixin_RealTime",
"world.dimension.PortalManagerMixin_RealTime"
],
"server": [
],
Expand Down

0 comments on commit 16e1c58

Please sign in to comment.