diff --git a/coreSubProjects b/coreSubProjects index 94304eb05..169429fe4 160000 --- a/coreSubProjects +++ b/coreSubProjects @@ -1 +1 @@ -Subproject commit 94304eb055969e1262feba280fcceea96e3bcdd5 +Subproject commit 169429fe487c3dae44c387af43c4449c9815db04 diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinClientPacketListener.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinClientPacketListener.java index 2e7716b87..2430745bb 100644 --- a/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinClientPacketListener.java +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinClientPacketListener.java @@ -7,6 +7,7 @@ import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientPacketListener; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -23,13 +24,29 @@ public class MixinClientPacketListener @Shadow private ClientLevel level; + @Unique + private ClientLevel previousLevel; + + @Inject(method = "handleLogin", at = @At("RETURN")) void onHandleLoginEnd(CallbackInfo ci) { ClientApi.INSTANCE.onClientOnlyConnected(); } @Inject(method = "handleRespawn", at = @At("HEAD")) - void onHandleRespawnStart(CallbackInfo ci) { ClientApi.INSTANCE.clientLevelUnloadEvent(ClientLevelWrapper.getWrapper(this.level)); } + void onHandleRespawnStart(CallbackInfo ci) { this.previousLevel = this.level; } @Inject(method = "handleRespawn", at = @At("RETURN")) - void onHandleRespawnEnd(CallbackInfo ci) { ClientApi.INSTANCE.clientLevelLoadEvent(ClientLevelWrapper.getWrapper(this.level)); } + void onHandleRespawnEnd(CallbackInfo ci) + { + // If the player changes dimensions the "this.level" will be changed halfway through the respawn method. + // By checking if the object references are the same, we can see if the previous level should be unloaded + // or if the player just respawned in the same level. + if (this.previousLevel != this.level) + { + ClientApi.INSTANCE.clientLevelUnloadEvent(ClientLevelWrapper.getWrapper(this.previousLevel)); + ClientApi.INSTANCE.clientLevelLoadEvent(ClientLevelWrapper.getWrapper(this.level)); + } + + this.previousLevel = null; + } #if MC_VER < MC_1_19_4 @Inject(method = "cleanup", at = @At("HEAD"))