From 7f761e415f275bf14cdf3d0c2ae5b1e8d1196798 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Tue, 12 Nov 2024 07:27:41 -0600 Subject: [PATCH] Fix potential null pointers if other mods mess with the MVM or Proj matricies --- .../api/objects/math/DhApiMat4f.java | 32 +++++++++---------- .../core/api/internal/ClientApi.java | 5 ++- .../distanthorizons/core/util/RenderUtil.java | 23 ++++++++----- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/api/src/main/java/com/seibel/distanthorizons/api/objects/math/DhApiMat4f.java b/api/src/main/java/com/seibel/distanthorizons/api/objects/math/DhApiMat4f.java index 2c05ae708..feb7594ac 100644 --- a/api/src/main/java/com/seibel/distanthorizons/api/objects/math/DhApiMat4f.java +++ b/api/src/main/java/com/seibel/distanthorizons/api/objects/math/DhApiMat4f.java @@ -88,25 +88,25 @@ public class DhApiMat4f implements IDhApiCopyable /** Expects the values of the input array to be in row major order (AKA rows then columns) */ public DhApiMat4f(float[] values) { - m00 = values[0]; - m01 = values[1]; - m02 = values[2]; - m03 = values[3]; + this.m00 = values[0]; + this.m01 = values[1]; + this.m02 = values[2]; + this.m03 = values[3]; - m10 = values[4]; - m11 = values[5]; - m12 = values[6]; - m13 = values[7]; + this.m10 = values[4]; + this.m11 = values[5]; + this.m12 = values[6]; + this.m13 = values[7]; - m20 = values[8]; - m21 = values[9]; - m22 = values[10]; - m23 = values[11]; + this.m20 = values[8]; + this.m21 = values[9]; + this.m22 = values[10]; + this.m23 = values[11]; - m30 = values[12]; - m31 = values[13]; - m32 = values[14]; - m33 = values[15]; + this.m30 = values[12]; + this.m31 = values[13]; + this.m32 = values[14]; + this.m33 = values[15]; } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/internal/ClientApi.java b/core/src/main/java/com/seibel/distanthorizons/core/api/internal/ClientApi.java index 8e5cde40a..c3d2d3369 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/internal/ClientApi.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/internal/ClientApi.java @@ -25,6 +25,7 @@ import com.seibel.distanthorizons.api.enums.rendering.EDhApiRenderPass; import com.seibel.distanthorizons.api.methods.events.abstractEvents.*; import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam; import com.seibel.distanthorizons.core.file.structure.ClientOnlySaveStructure; +import com.seibel.distanthorizons.core.logging.f3.F3Screen; import com.seibel.distanthorizons.core.pos.DhChunkPos; import com.seibel.distanthorizons.core.render.DhApiRenderProxy; import com.seibel.distanthorizons.core.render.renderer.FadeRenderer; @@ -430,7 +431,9 @@ public class ClientApi try { - if (!RenderUtil.shouldLodsRender(levelWrapper)) + // TODO write this message to the F3 menu so people can see when a different mod screws with the lightmap + String reasonLodsCannotRender = RenderUtil.shouldLodsRender(levelWrapper, renderEventParam); + if (reasonLodsCannotRender != null) { return; } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/RenderUtil.java b/core/src/main/java/com/seibel/distanthorizons/core/util/RenderUtil.java index 37dc6957f..2fdbe6d1b 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/util/RenderUtil.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/util/RenderUtil.java @@ -19,6 +19,7 @@ package com.seibel.distanthorizons.core.util; +import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam; import com.seibel.distanthorizons.core.api.internal.SharedApi; import com.seibel.distanthorizons.core.config.Config; import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector; @@ -164,37 +165,43 @@ public class RenderUtil return -1.0f; } - /** @return false if LODs shouldn't be rendered for any reason */ - public static boolean shouldLodsRender(ILevelWrapper levelWrapper) + /** @return a message if LODs shouldn't be rendered, null if the LODs can render */ + public static String shouldLodsRender(ILevelWrapper levelWrapper, DhApiRenderParam renderEventParam) { if (!MC.playerExists()) { - return false; + return "No Player Exists"; } if (levelWrapper == null) { - return false; + return "No Level Given"; } IDhClientWorld clientWorld = SharedApi.getIDhClientWorld(); if (clientWorld == null) { - return false; + return "No Client World Loaded"; } IDhClientLevel level = clientWorld.getClientLevel(levelWrapper); if (level == null) { - return false; //Level is not ready yet. + return "No Client Level Loaded"; //Level is not ready yet. } if (MC_RENDER.getLightmapWrapper(levelWrapper) == null) { - return false; + return "No Lightmap loaded"; } - return true; + if (renderEventParam.dhModelViewMatrix == null + || renderEventParam.mcModelViewMatrix == null) + { + return "No MVM or Proj Matrix Given"; + } + + return null; } }