diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftRenderWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftRenderWrapper.java index b1a2a0604..a4651ae75 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftRenderWrapper.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftRenderWrapper.java @@ -25,6 +25,7 @@ import java.nio.FloatBuffer; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import com.mojang.blaze3d.pipeline.RenderTarget; @@ -105,7 +106,7 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper * In the case of immersive portals multiple levels may be active at once, causing conflicting lightmaps.
* Requiring the use of multiple {@link LightMapWrapper}. */ - public HashMap lightmapByDimensionType = new HashMap<>(); + public ConcurrentHashMap lightmapByDimensionType = new ConcurrentHashMap<>(); /** * Holds the render buffer that should be used when displaying levels to the screen. @@ -405,11 +406,8 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper // so this will have to do for now IDimensionTypeWrapper dimensionType = level.getDimensionType(); - if (!this.lightmapByDimensionType.containsKey(dimensionType)) - { - this.lightmapByDimensionType.put(dimensionType, new LightMapWrapper()); - } - this.lightmapByDimensionType.get(dimensionType).uploadLightmap(lightPixels); + LightMapWrapper wrapper = this.lightmapByDimensionType.compute(dimensionType, (dimType, oldWrapper) -> new LightMapWrapper()); + wrapper.uploadLightmap(lightPixels); } } diff --git a/coreSubProjects b/coreSubProjects index c83140a2d..8ecd5dd9c 160000 --- a/coreSubProjects +++ b/coreSubProjects @@ -1 +1 @@ -Subproject commit c83140a2d002022f938e5521a495764c0e435b56 +Subproject commit 8ecd5dd9cbf57f0e8ba7cbaa75289d5270176027 diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinDynamicTexture.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinDynamicTexture.java deleted file mode 100644 index 881da29c2..000000000 --- a/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinDynamicTexture.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * This file is part of the Distant Horizons mod - * licensed under the GNU LGPL v3 License. - * - * Copyright (C) 2020-2023 James Seibel - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.seibel.distanthorizons.fabric.mixins.client; - - -import com.mojang.blaze3d.platform.NativeImage; -import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftRenderWrapper; -import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector; -import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper; -import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper; -import com.seibel.distanthorizons.common.util.ILightTextureMarker; -import net.minecraft.client.renderer.texture.DynamicTexture; -import org.spongepowered.asm.mixin.Final; -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; - -@Mixin(DynamicTexture.class) -public class MixinDynamicTexture implements ILightTextureMarker -{ - /** Used to prevent accidentally using other dynamic textures as a lightmap */ - @Unique - private boolean isLightTexture = false; - - @Shadow - @Final - private NativeImage pixels; - - @Inject(method = "upload()V", at = @At("HEAD")) - public void updateLightTexture(CallbackInfo ci) - { - // since the light map is always updated on the client render thread we should be able to access the client level at the same time - IMinecraftClientWrapper mc = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class); - if (!this.isLightTexture - || mc == null - || mc.getWrappedClientLevel() == null - ) - { - return; - } - - //ApiShared.LOGGER.info("Lightmap update"); - IClientLevelWrapper clientLevel = mc.getWrappedClientLevel(); - MinecraftRenderWrapper.INSTANCE.updateLightmap(this.pixels, clientLevel); - } - - public void markLightTexture() { this.isLightTexture = true; } - -} diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinLightTexture.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinLightTexture.java index db9c56535..f09edc1f5 100644 --- a/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinLightTexture.java +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinLightTexture.java @@ -20,9 +20,14 @@ package com.seibel.distanthorizons.fabric.mixins.client; -import com.seibel.distanthorizons.common.util.ILightTextureMarker; +import com.mojang.blaze3d.platform.NativeImage; + +import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftRenderWrapper; +import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector; +import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper; +import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper; import net.minecraft.client.renderer.LightTexture; -import net.minecraft.client.renderer.texture.DynamicTexture; + import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -35,13 +40,20 @@ public class MixinLightTexture { @Shadow @Final - private DynamicTexture lightTexture; + private NativeImage lightPixels; - @Inject(method = "", at = @At("RETURN")) - public void markLightTexture(CallbackInfo ci) + + @Inject(method = "updateLightTexture(F)V", at = @At("RETURN")) + public void updateLightTexture(float partialTicks, CallbackInfo ci) { - // - ((ILightTextureMarker) this.lightTexture).markLightTexture(); + IMinecraftClientWrapper mc = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class); + if (mc == null || mc.getWrappedClientLevel() == null) + { + return; + } + + IClientLevelWrapper clientLevel = mc.getWrappedClientLevel(); + MinecraftRenderWrapper.INSTANCE.updateLightmap(this.lightPixels, clientLevel); } } diff --git a/fabric/src/main/resources/DistantHorizons.fabric.mixins.json b/fabric/src/main/resources/DistantHorizons.fabric.mixins.json index 90f0add34..38fab22fe 100644 --- a/fabric/src/main/resources/DistantHorizons.fabric.mixins.json +++ b/fabric/src/main/resources/DistantHorizons.fabric.mixins.json @@ -14,7 +14,6 @@ "client.MixinFogRenderer", "client.MixinGameRenderer", "client.MixinLevelRenderer", - "client.MixinDynamicTexture", "client.MixinLightTexture", "client.MixinOptionsScreen", "client.MixinMinecraft", diff --git a/forge/src/main/java/com/seibel/distanthorizons/forge/mixins/client/MixinDynamicTexture.java b/forge/src/main/java/com/seibel/distanthorizons/forge/mixins/client/MixinDynamicTexture.java deleted file mode 100644 index 36bf97035..000000000 --- a/forge/src/main/java/com/seibel/distanthorizons/forge/mixins/client/MixinDynamicTexture.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * This file is part of the Distant Horizons mod - * licensed under the GNU LGPL v3 License. - * - * Copyright (C) 2020-2023 James Seibel - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.seibel.distanthorizons.forge.mixins.client; - - -import com.mojang.blaze3d.platform.NativeImage; - -import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftRenderWrapper; -import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector; -import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper; -import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper; -import com.seibel.distanthorizons.common.util.ILightTextureMarker; - -import net.minecraft.client.renderer.texture.DynamicTexture; - -import org.spongepowered.asm.mixin.Final; -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; - -import org.jetbrains.annotations.Nullable; - -@Mixin(DynamicTexture.class) -public abstract class MixinDynamicTexture implements ILightTextureMarker -{ - /** Used to prevent accidentally using other dynamic textures as a lightmap */ - @Unique - private boolean isLightTexture = false; - - @Shadow - @Final - private NativeImage pixels; - - @Inject(method = "upload()V", at = @At("HEAD")) - public void updateLightTexture(CallbackInfo ci) - { - // since the light map is always updated on the client render thread we should be able to access the client level at the same time - IMinecraftClientWrapper mc = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class); - if (!this.isLightTexture - || mc == null - || mc.getWrappedClientLevel() == null - ) - { - return; - } - - //ApiShared.LOGGER.info("Lightmap update"); - IClientLevelWrapper clientLevel = mc.getWrappedClientLevel(); - MinecraftRenderWrapper.INSTANCE.updateLightmap(this.pixels, clientLevel); - } - - public void markLightTexture() { this.isLightTexture = true; } - -} diff --git a/forge/src/main/java/com/seibel/distanthorizons/forge/mixins/client/MixinLightTexture.java b/forge/src/main/java/com/seibel/distanthorizons/forge/mixins/client/MixinLightTexture.java index f350a1754..215f7f7d3 100644 --- a/forge/src/main/java/com/seibel/distanthorizons/forge/mixins/client/MixinLightTexture.java +++ b/forge/src/main/java/com/seibel/distanthorizons/forge/mixins/client/MixinLightTexture.java @@ -20,10 +20,13 @@ package com.seibel.distanthorizons.forge.mixins.client; -import com.seibel.distanthorizons.common.util.ILightTextureMarker; +import com.mojang.blaze3d.platform.NativeImage; +import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftRenderWrapper; +import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector; +import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper; +import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper; import net.minecraft.client.renderer.LightTexture; -import net.minecraft.client.renderer.texture.DynamicTexture; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -35,11 +38,22 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(LightTexture.class) public class MixinLightTexture { - @Shadow - @Final - private DynamicTexture lightTexture; + @Shadow + @Final + private NativeImage lightPixels; - @Inject(method = "", at = @At("RETURN")) - public void markLightTexture(CallbackInfo ci) { ((ILightTextureMarker) this.lightTexture).markLightTexture(); } + + @Inject(method = "updateLightTexture(F)V", at = @At("RETURN")) + public void updateLightTexture(float partialTicks, CallbackInfo ci) + { + IMinecraftClientWrapper mc = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class); + if (mc == null || mc.getWrappedClientLevel() == null) + { + return; + } + + IClientLevelWrapper clientLevel = mc.getWrappedClientLevel(); + MinecraftRenderWrapper.INSTANCE.updateLightmap(this.lightPixels, clientLevel); + } } diff --git a/forge/src/main/resources/DistantHorizons.forge.mixins.json b/forge/src/main/resources/DistantHorizons.forge.mixins.json index e0f4d1feb..c7b69cbaf 100644 --- a/forge/src/main/resources/DistantHorizons.forge.mixins.json +++ b/forge/src/main/resources/DistantHorizons.forge.mixins.json @@ -13,7 +13,6 @@ "client.MixinFogRenderer", "client.MixinGameRenderer", "client.MixinLevelRenderer", - "client.MixinDynamicTexture", "client.MixinLightTexture", "client.MixinOptionsScreen", "client.MixinTextureUtil" diff --git a/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/client/MixinDynamicTexture.java b/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/client/MixinDynamicTexture.java deleted file mode 100644 index 7151fe912..000000000 --- a/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/client/MixinDynamicTexture.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * This file is part of the Distant Horizons mod - * licensed under the GNU LGPL v3 License. - * - * Copyright (C) 2020-2023 James Seibel - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.seibel.distanthorizons.neoforge.mixins.client; - - -import com.mojang.blaze3d.platform.NativeImage; - -import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftRenderWrapper; -import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector; -import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper; -import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper; -import com.seibel.distanthorizons.common.util.ILightTextureMarker; - -import net.minecraft.client.renderer.texture.DynamicTexture; - -import org.spongepowered.asm.mixin.Final; -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; - -@Mixin(DynamicTexture.class) -public abstract class MixinDynamicTexture implements ILightTextureMarker -{ - /** Used to prevent accidentally using other dynamic textures as a lightmap */ - @Unique - private boolean isLightTexture = false; - - @Shadow - #if MC_VER >= MC_1_20_4 - (remap = false) - #endif - @Final - private NativeImage pixels; - - @Inject(method = "upload()V", at = @At("HEAD")) - public void updateLightTexture(CallbackInfo ci) - { - // since the light map is always updated on the client render thread we should be able to access the client level at the same time - IMinecraftClientWrapper mc = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class); - if (!this.isLightTexture - || mc == null - || mc.getWrappedClientLevel() == null - ) - { - return; - } - - //ApiShared.LOGGER.info("Lightmap update"); - IClientLevelWrapper clientLevel = mc.getWrappedClientLevel(); - MinecraftRenderWrapper.INSTANCE.updateLightmap(this.pixels, clientLevel); - } - - public void markLightTexture() { this.isLightTexture = true; } - -} diff --git a/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/client/MixinLightTexture.java b/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/client/MixinLightTexture.java index 0d59818d2..5ae06aec8 100644 --- a/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/client/MixinLightTexture.java +++ b/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/client/MixinLightTexture.java @@ -20,10 +20,13 @@ package com.seibel.distanthorizons.neoforge.mixins.client; -import com.seibel.distanthorizons.common.util.ILightTextureMarker; +import com.mojang.blaze3d.platform.NativeImage; +import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftRenderWrapper; +import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector; +import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper; +import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper; import net.minecraft.client.renderer.LightTexture; -import net.minecraft.client.renderer.texture.DynamicTexture; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -36,13 +39,21 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; public class MixinLightTexture { @Shadow - #if MC_VER >= MC_1_20_4 - (remap = false) - #endif @Final - private DynamicTexture lightTexture; + private NativeImage lightPixels; - @Inject(method = "", at = @At("RETURN")) - public void markLightTexture(CallbackInfo ci) { ((ILightTextureMarker) this.lightTexture).markLightTexture(); } + + @Inject(method = "updateLightTexture(F)V", at = @At("RETURN")) + public void updateLightTexture(float partialTicks, CallbackInfo ci) + { + IMinecraftClientWrapper mc = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class); + if (mc == null || mc.getWrappedClientLevel() == null) + { + return; + } + + IClientLevelWrapper clientLevel = mc.getWrappedClientLevel(); + MinecraftRenderWrapper.INSTANCE.updateLightmap(this.lightPixels, clientLevel); + } } diff --git a/neoforge/src/main/resources/DistantHorizons.neoforge.mixins.json b/neoforge/src/main/resources/DistantHorizons.neoforge.mixins.json index 296dc1e4d..5efe0dba6 100644 --- a/neoforge/src/main/resources/DistantHorizons.neoforge.mixins.json +++ b/neoforge/src/main/resources/DistantHorizons.neoforge.mixins.json @@ -13,7 +13,6 @@ "client.MixinFogRenderer", "client.MixinGameRenderer", "client.MixinLevelRenderer", - "client.MixinDynamicTexture", "client.MixinLightTexture", "client.MixinOptionsScreen", "client.MixinTextureUtil"