diff --git a/fabric/src/main/java/com/seibel/lod/fabric/mixins/client/MixinFogRenderer.java b/fabric/src/main/java/com/seibel/lod/fabric/mixins/client/MixinFogRenderer.java index cbf1e14b9..2a66e1183 100644 --- a/fabric/src/main/java/com/seibel/lod/fabric/mixins/client/MixinFogRenderer.java +++ b/fabric/src/main/java/com/seibel/lod/fabric/mixins/client/MixinFogRenderer.java @@ -74,5 +74,4 @@ public class MixinFogRenderer { #endif } } - } diff --git a/fabric/src/main/java/com/seibel/lod/fabric/mixins/client/MixinMinecraft.java b/fabric/src/main/java/com/seibel/lod/fabric/mixins/client/MixinMinecraft.java index 7c72be43e..d579534cd 100644 --- a/fabric/src/main/java/com/seibel/lod/fabric/mixins/client/MixinMinecraft.java +++ b/fabric/src/main/java/com/seibel/lod/fabric/mixins/client/MixinMinecraft.java @@ -16,6 +16,8 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; /** + * At the moment this is only used for the auto updater + * * @author coolGi */ @Mixin(Minecraft.class) diff --git a/fabric/src/main/resources/DistantHorizons.fabric.mixins.json b/fabric/src/main/resources/DistantHorizons.fabric.mixins.json index 326176c9c..f1b071f10 100644 --- a/fabric/src/main/resources/DistantHorizons.fabric.mixins.json +++ b/fabric/src/main/resources/DistantHorizons.fabric.mixins.json @@ -19,9 +19,11 @@ "client.MixinOptionsScreen", "client.MixinMinecraft", "client.MixinTextureUtil", + "mods.sodium.MixinSodiumChunkRenderer", "mods.imm_ptl_core.MixinImmersivePortalsGameRenderer" ], + "server": [], "injectors": { "defaultRequire": 1 }, diff --git a/forge/src/main/java/com/seibel/lod/forge/mixins/client/MixinClientPacketListener.java b/forge/src/main/java/com/seibel/lod/forge/mixins/client/MixinClientPacketListener.java new file mode 100644 index 000000000..9f11656c4 --- /dev/null +++ b/forge/src/main/java/com/seibel/lod/forge/mixins/client/MixinClientPacketListener.java @@ -0,0 +1,51 @@ +package com.seibel.lod.forge.mixins.client; + +import com.seibel.lod.common.wrappers.world.ClientLevelWrapper; +import com.seibel.lod.core.api.internal.ClientApi; +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.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ClientPacketListener.class) +public class MixinClientPacketListener +{ + @Shadow + private ClientLevel level; + + + + /** THIS EXPLANATION IS WRITTEN BY FABRIC. + * An explanation why we unload entities during onGameJoin: (On in our remapping name case, handleLogin(TODO: CHECK)) + * Proxies such as Waterfall may send another Game Join packet if entity meta rewrite is disabled, so we will cover ourselves. + * Velocity by default will send a Game Join packet when the player changes servers, which will create a new client world. + * Also anyone can send another GameJoinPacket at any time, so we need to watch out. + */ + @Inject(method = "handleLogin", at = @At("HEAD")) + void onHandleLoginStart(CallbackInfo ci) + { + // not the best way to notify Core that we are no longer in the previous world, but it will have to do for now + ClientApi.INSTANCE.onClientOnlyDisconnected(); + } + @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(level)); } + @Inject(method = "handleRespawn", at = @At("RETURN")) + void onHandleRespawnEnd(CallbackInfo ci) { ClientApi.INSTANCE.clientLevelLoadEvent(ClientLevelWrapper.getWrapper(level)); } + + @Inject(method = "cleanup", at = @At("HEAD")) + void onCleanupStart(CallbackInfo ci) + { + // TODO which unload method should be used? do we need both? + if (level != null) + { + ClientApi.INSTANCE.clientLevelUnloadEvent(ClientLevelWrapper.getWrapper(level)); + } + } + +} diff --git a/forge/src/main/java/com/seibel/lod/forge/mixins/client/MixinFogRenderer.java b/forge/src/main/java/com/seibel/lod/forge/mixins/client/MixinFogRenderer.java index fb7647618..c616c0ab0 100644 --- a/forge/src/main/java/com/seibel/lod/forge/mixins/client/MixinFogRenderer.java +++ b/forge/src/main/java/com/seibel/lod/forge/mixins/client/MixinFogRenderer.java @@ -42,18 +42,18 @@ import net.minecraft.world.level.material.FogType; @Mixin(FogRenderer.class) -public class MixinFogRenderer -{ - - // Using this instead of Float.MAX_VALUE because Sodium don't like it. (and copy paste in case someone in forge don't like it) +public class MixinFogRenderer { + + // Using this instead of Float.MAX_VALUE because Sodium don't like it. private static final float A_REALLY_REALLY_BIG_VALUE = 420694206942069.F; private static final float A_EVEN_LARGER_VALUE = 42069420694206942069.F; - - @Inject(at = @At("RETURN"), - method = "setupFog(Lnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/FogRenderer$FogMode;FZF)V", - remap = #if MC_1_16_5 true #else false #endif) // Remap messiness due to this being added by forge. - private static void disableSetupFog(Camera camera, FogMode fogMode, float f, boolean bl, float partTick, CallbackInfo callback) - { + + @Inject(at = @At("RETURN"), method = "setupFog") + #if PRE_MC_1_19 + private static void disableSetupFog(Camera camera, FogMode fogMode, float f, boolean bl, CallbackInfo callback) { + #else + private static void disableSetupFog(Camera camera, FogMode fogMode, float f, boolean bl, float g, CallbackInfo callback) { + #endif #if PRE_MC_1_17_1 FluidState fluidState = camera.getFluidInCamera(); boolean cameraNotInFluid = fluidState.isEmpty(); @@ -61,7 +61,7 @@ public class MixinFogRenderer FogType fogTypes = camera.getFluidInCamera(); boolean cameraNotInFluid = fogTypes == FogType.NONE; #endif - + Entity entity = camera.getEntity(); boolean isSpecialFog = (entity instanceof LivingEntity) && ((LivingEntity) entity).hasEffect(MobEffects.BLINDNESS); if (!isSpecialFog && cameraNotInFluid && fogMode == FogMode.FOG_TERRAIN diff --git a/forge/src/main/java/com/seibel/lod/forge/mixins/client/MixinLevelRenderer.java b/forge/src/main/java/com/seibel/lod/forge/mixins/client/MixinLevelRenderer.java index b99a542fc..acac44c2e 100644 --- a/forge/src/main/java/com/seibel/lod/forge/mixins/client/MixinLevelRenderer.java +++ b/forge/src/main/java/com/seibel/lod/forge/mixins/client/MixinLevelRenderer.java @@ -54,10 +54,10 @@ public class MixinLevelRenderer { @Shadow private ClientLevel level; - @Unique private static float previousPartialTicks = 0; + // TODO: Is there any reason why this is here? Can it be deleted? public MixinLevelRenderer() { throw new NullPointerException("Null cannot be cast to non-null type."); } @@ -100,6 +100,7 @@ public class MixinLevelRenderer previousPartialTicks = tickDelta; } + // TODO: Can we move this o forge's client proxy simmilar to how fabric does it @Inject(at = @At("HEAD"), method = "renderChunkLayer(Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDDLcom/mojang/math/Matrix4f;)V", cancellable = true) diff --git a/forge/src/main/java/com/seibel/lod/forge/mixins/client/MixinMinecraft.java b/forge/src/main/java/com/seibel/lod/forge/mixins/client/MixinMinecraft.java index 733383d5c..0797092b6 100644 --- a/forge/src/main/java/com/seibel/lod/forge/mixins/client/MixinMinecraft.java +++ b/forge/src/main/java/com/seibel/lod/forge/mixins/client/MixinMinecraft.java @@ -16,6 +16,8 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; /** + * At the moment this is only used for the auto updater + * * @author coolGi */ @Mixin(Minecraft.class) diff --git a/forge/src/main/java/com/seibel/lod/forge/mixins/client/MixinTextureUtil.java b/forge/src/main/java/com/seibel/lod/forge/mixins/client/MixinTextureUtil.java new file mode 100644 index 000000000..3fbc52679 --- /dev/null +++ b/forge/src/main/java/com/seibel/lod/forge/mixins/client/MixinTextureUtil.java @@ -0,0 +1,27 @@ +package com.seibel.lod.forge.mixins.client; + +import com.mojang.blaze3d.platform.GlStateManager; +import com.mojang.blaze3d.platform.TextureUtil; +import com.seibel.lod.core.config.Config; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +/** + * Sets Minecraft's LOD Bias (looks similar to mipmaps) + * + * @author coolGi + */ +@Mixin(TextureUtil.class) +public class MixinTextureUtil { + @Redirect(method = "Lcom/mojang/blaze3d/platform/TextureUtil;prepareImage(Lcom/mojang/blaze3d/platform/NativeImage$InternalGlFormat;IIII)V", + at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/GlStateManager;_texParameter(IIF)V", remap=false)) + private static void setLodBias(int target, int pname, float param) { + float biasValue = Config.Client.Graphics.AdvancedGraphics.lodBias.get().floatValue(); + if (biasValue != 0) { + // The target is GL11.GL_TEXTURE_2D + // And the pname is GL14.GL_TEXTURE_LOD_BIAS + GlStateManager._texParameter(target, pname, biasValue); + } + } +} diff --git a/forge/src/main/resources/DistantHorizons.mixins.json b/forge/src/main/resources/DistantHorizons.mixins.json index 3254ee23b..b3c80d092 100644 --- a/forge/src/main/resources/DistantHorizons.mixins.json +++ b/forge/src/main/resources/DistantHorizons.mixins.json @@ -3,18 +3,20 @@ "minVersion": "0.8", "package": "com.seibel.lod.forge.mixins", "mixins": [ - "server.unsafe.MixinThreadingDetector", + "server.unsafe.MixinThreadingDetector", "server.MixinUtilBackgroundThread", "server.MixinChunkGenerator", "server.MixinTFChunkGenerator" ], "client": [ - "client.MixinDebugScreenOverlay", - "client.MixinFogRenderer", - "client.MixinGameRenderer", - "client.MixinLevelRenderer", - "client.MixinLightmap", - "client.MixinOptionsScreen" + "client.MixinClientPacketListener", + "client.MixinDebugScreenOverlay", + "client.MixinFogRenderer", + "client.MixinGameRenderer", + "client.MixinLevelRenderer", + "client.MixinLightmap", + "client.MixinOptionsScreen", + "client.MixinTextureUtil" ], "server": [], "plugin": "com.seibel.lod.forge.mixins.ForgeMixinPlugin"