Fix neforge texture validation support

This commit is contained in:
James Seibel
2025-10-07 07:43:46 -05:00
parent 8708ca3048
commit 5a9fdb3314
3 changed files with 45 additions and 16 deletions
@@ -24,6 +24,7 @@ import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
import com.seibel.distanthorizons.neoforge.wrappers.NeoforgeTextureUnwrapper;
import net.minecraft.client.renderer.LightTexture;
import org.spongepowered.asm.mixin.Final;
@@ -85,8 +86,7 @@ public class MixinLightTexture
GlTexture glTexture = (GlTexture) this.texture;
renderWrapper.setLightmapId(glTexture.glId(), clientLevel);
#else
ValidationGpuTexture gpuTexture = (ValidationGpuTexture) this.texture;
int id = ((GlTexture)(gpuTexture.getRealTexture())).glId();
int id = NeoforgeTextureUnwrapper.getGlTextureIdFromGpuTexture(this.texture);
renderWrapper.setLightmapId(id, clientLevel);
#endif
}
@@ -33,13 +33,8 @@ public class NeoforgeMinecraftRenderWrapper extends MinecraftRenderWrapper
#else
try
{
//GpuTexture depthTex = this.getRenderTarget().getDepthTexture();
//int id = ((GlTexture)depthTex.getClass().getMethod("getRealTexture").invoke(depthTex)).glId();
//return id;
ValidationGpuTexture validationTexture = (ValidationGpuTexture) this.getRenderTarget().getDepthTexture();
GlTexture glTexture = (GlTexture)validationTexture.getRealTexture();
int id = glTexture.glId();
GpuTexture gpuTexture = this.getRenderTarget().getDepthTexture();
int id = NeoforgeTextureUnwrapper.getGlTextureIdFromGpuTexture(gpuTexture);
return id;
}
catch (Exception e)
@@ -65,13 +60,8 @@ public class NeoforgeMinecraftRenderWrapper extends MinecraftRenderWrapper
#else
try
{
//GpuTexture colorTex = this.getRenderTarget().getColorTexture();
//int id = ((GlTexture)colorTex.getClass().getMethod("getRealTexture").invoke(colorTex)).glId();
//return id;
ValidationGpuTexture validationTexture = (ValidationGpuTexture) this.getRenderTarget().getColorTexture();
GlTexture glTexture = (GlTexture)validationTexture.getRealTexture();
int id = glTexture.glId();
GpuTexture gpuTexture = this.getRenderTarget().getColorTexture();
int id = NeoforgeTextureUnwrapper.getGlTextureIdFromGpuTexture(gpuTexture);
return id;
}
catch (Exception e)
@@ -0,0 +1,39 @@
package com.seibel.distanthorizons.neoforge.wrappers;
#if MC_VER < MC_1_21_9
public class NeoforgeTextureUnwrapper
{ /* not needed for older MC versions */ }
#else
import com.mojang.blaze3d.opengl.GlTexture;
import com.mojang.blaze3d.textures.GpuTexture;
import net.neoforged.neoforge.client.blaze3d.validation.ValidationGpuTexture;
public class NeoforgeTextureUnwrapper
{
/**
* if Neoforge texture validation is enabled the GlTexture object will be wrapped with a
* Neoforge specific ValidationGpuTexture object.
* This helper allows us to get the underlying OpenGL texture ID
* regardless of what Neoforge returns.
*/
public static int getGlTextureIdFromGpuTexture(GpuTexture gpuTexture) throws ClassCastException
{
GlTexture glTexture;
if (gpuTexture instanceof ValidationGpuTexture)
{
ValidationGpuTexture validationTexture = (ValidationGpuTexture) gpuTexture;
glTexture = (GlTexture)validationTexture.getRealTexture();
}
else
{
glTexture = (GlTexture) gpuTexture;
}
int id = glTexture.glId();
return id;
}
}
#endif