From c658269eb71b82a0becb2868e84b9540b651c81c Mon Sep 17 00:00:00 2001 From: James Seibel Date: Tue, 30 Jul 2024 17:06:55 -0500 Subject: [PATCH] Remove deprecated methods and move method to StringUtil --- .../coreapi/util/StringUtil.java | 24 +++- .../structure/ClientOnlySaveStructure.java | 4 +- .../SubDimensionLevelMatcher.java | 13 ++- .../distanthorizons/core/util/LodUtil.java | 109 +----------------- .../distanthorizons/core/util/RenderUtil.java | 100 ---------------- 5 files changed, 32 insertions(+), 218 deletions(-) diff --git a/api/src/main/java/com/seibel/distanthorizons/coreapi/util/StringUtil.java b/api/src/main/java/com/seibel/distanthorizons/coreapi/util/StringUtil.java index f57efbe15..44c94b197 100644 --- a/api/src/main/java/com/seibel/distanthorizons/coreapi/util/StringUtil.java +++ b/api/src/main/java/com/seibel/distanthorizons/coreapi/util/StringUtil.java @@ -24,12 +24,12 @@ import java.util.Arrays; /** * Miscellaneous string helper functions. - * - * @author James Seibel - * @version 2022-7-19 */ public class StringUtil { + private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray(); + + /** * Returns the n-th index of the given string.

* @@ -67,8 +67,6 @@ public class StringUtil return stringBuilder.toString(); } - - private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray(); /** * Converts the given byte array into a hex string representation.
* source: https://stackoverflow.com/a/9855338 @@ -85,4 +83,20 @@ public class StringUtil return new String(hexChars); } + /** + * Returns a shortened version of the given string that is no longer than maxLength.
+ * If null returns the empty string. + */ + public static String shortenString(String str, int maxLength) + { + if (str == null) + { + return ""; + } + else + { + return str.substring(0, Math.min(str.length(), maxLength)); + } + } + } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/file/structure/ClientOnlySaveStructure.java b/core/src/main/java/com/seibel/distanthorizons/core/file/structure/ClientOnlySaveStructure.java index 17a2c4d90..deed8d479 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/file/structure/ClientOnlySaveStructure.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/file/structure/ClientOnlySaveStructure.java @@ -26,12 +26,12 @@ import com.seibel.distanthorizons.core.config.Config; import com.seibel.distanthorizons.api.enums.config.EDhApiServerFolderNameMode; import com.seibel.distanthorizons.core.level.IServerKeyedClientLevel; import com.seibel.distanthorizons.core.util.objects.ParsedIp; -import com.seibel.distanthorizons.core.util.LodUtil; import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.world.IDimensionTypeWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper; +import com.seibel.distanthorizons.coreapi.util.StringUtil; import java.io.File; import java.util.*; @@ -138,7 +138,7 @@ public class ClientOnlySaveStructure extends AbstractSaveStructure { // use the first existing sub-dimension String folderName = folders.get(0).getName(); - LOGGER.info("Default Sub Dimension set to: [" + LodUtil.shortenString(folderName, 8) + "...]"); + LOGGER.info("Default Sub Dimension set to: [" + StringUtil.shortenString(folderName, 8) + "...]"); return folders.get(0); } else diff --git a/core/src/main/java/com/seibel/distanthorizons/core/file/subDimMatching/SubDimensionLevelMatcher.java b/core/src/main/java/com/seibel/distanthorizons/core/file/subDimMatching/SubDimensionLevelMatcher.java index 89fe2a3f4..ac8225962 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/file/subDimMatching/SubDimensionLevelMatcher.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/file/subDimMatching/SubDimensionLevelMatcher.java @@ -40,6 +40,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftCli import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper; +import com.seibel.distanthorizons.coreapi.util.StringUtil; import it.unimi.dsi.fastutil.longs.LongArrayList; import org.apache.logging.log4j.LogManager; @@ -92,7 +93,7 @@ public class SubDimensionLevelMatcher implements AutoCloseable if (potentialLevelFolders.size() == 0) { String newId = UUID.randomUUID().toString(); - LOGGER.info("No potential level files found. Creating a new sub dimension with the ID ["+LodUtil.shortenString(newId, 8)+"]..."); + LOGGER.info("No potential level files found. Creating a new sub dimension with the ID ["+ StringUtil.shortenString(newId, 8)+"]..."); this.foundLevelFile = this.CreateSubDimFolder(newId); } } @@ -207,7 +208,7 @@ public class SubDimensionLevelMatcher implements AutoCloseable SubDimCompare mostSimilarSubDim = null; for (File testLevelFolder : this.potentialLevelFolders) { - LOGGER.info("Testing level folder: [" + LodUtil.shortenString(testLevelFolder.getName(), 8) + "]"); + LOGGER.info("Testing level folder: [" + StringUtil.shortenString(testLevelFolder.getName(), 8) + "]"); FullDataSourceV2 testFullDataSource = null; try @@ -328,8 +329,8 @@ public class SubDimensionLevelMatcher implements AutoCloseable } - String subDimShortName = LodUtil.shortenString(testLevelFolder.getName(), 8); // variables are separated out for easier debugging - String equalPercent = LodUtil.shortenString(mostSimilarSubDim.getPercentEqual()+"", 5); + String subDimShortName = StringUtil.shortenString(testLevelFolder.getName(), 8); // variables are separated out for easier debugging + String equalPercent = StringUtil.shortenString(mostSimilarSubDim.getPercentEqual()+"", 5); LOGGER.info("Sub dimension ["+subDimShortName+"...] is current dimension probability: "+equalPercent+" ("+equalDataPoints+"/"+totalDataPointCount+")"); } catch (Exception e) @@ -359,7 +360,7 @@ public class SubDimensionLevelMatcher implements AutoCloseable { // we found a sub dim folder that is similar, use it - LOGGER.info("Sub Dimension set to: [" + LodUtil.shortenString(mostSimilarSubDim.folder.getName(), 8) + "...] with an equality of [" + mostSimilarSubDim.getPercentEqual() + "]"); + LOGGER.info("Sub Dimension set to: [" + StringUtil.shortenString(mostSimilarSubDim.folder.getName(), 8) + "...] with an equality of [" + mostSimilarSubDim.getPercentEqual() + "]"); return mostSimilarSubDim.folder; } else @@ -369,7 +370,7 @@ public class SubDimensionLevelMatcher implements AutoCloseable String newId = UUID.randomUUID().toString(); double highestEqualityPercent = mostSimilarSubDim != null ? mostSimilarSubDim.getPercentEqual() : 0; - String message = "No suitable sub dimension found. The highest equality was [" + LodUtil.shortenString(highestEqualityPercent + "", 5) + "]. Creating a new sub dimension with ID: " + LodUtil.shortenString(newId, 8) + "..."; + String message = "No suitable sub dimension found. The highest equality was [" + StringUtil.shortenString(highestEqualityPercent + "", 5) + "]. Creating a new sub dimension with ID: " + StringUtil.shortenString(newId, 8) + "..."; LOGGER.info(message); File folder = this.CreateSubDimFolder(newId); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/LodUtil.java b/core/src/main/java/com/seibel/distanthorizons/core/util/LodUtil.java index 8c652ebda..826ac5975 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/util/LodUtil.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/util/LodUtil.java @@ -20,7 +20,6 @@ package com.seibel.distanthorizons.core.util; import java.util.Arrays; -import java.util.Iterator; import java.util.List; import java.util.concurrent.CancellationException; import java.util.concurrent.CompletionException; @@ -41,9 +40,6 @@ import org.apache.logging.log4j.Logger; /** * This class holds methods and constants that may be used in multiple places. - * - * @author James Seibel - * @version 2022-12-5 */ public class LodUtil { @@ -51,31 +47,7 @@ public class LodUtil private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class); private static final Logger LOGGER = DhLoggerBuilder.getLogger(); - /** - * Vanilla render distances less than or equal to this will not allow partial - * overdraw. The VanillaOverdraw will either be ALWAYS or NEVER. - */ - public static final int MINIMUM_RENDER_DISTANCE_FOR_PARTIAL_OVERDRAW = 4; - /** - * Vanilla render distances less than or equal to this will cause the overdraw to - * run at a smaller fraction of the vanilla render distance. - */ - public static final int MINIMUM_RENDER_DISTANCE_FOR_FAR_OVERDRAW = 11; - - - - - /** - * alpha used when drawing chunks in debug mode - */ - public static final int DEBUG_ALPHA = 255; // 0 - 25; - - public static final int COLOR_DEBUG_BLACK = ColorUtil.rgbToInt(DEBUG_ALPHA, 0, 0, 0); - public static final int COLOR_DEBUG_WHITE = ColorUtil.rgbToInt(DEBUG_ALPHA, 255, 255, 255); - public static final int COLOR_INVISIBLE = ColorUtil.rgbToInt(0, 0, 0, 0); - - //FIXME: WE NEED MORE COLORS!!!! /** * In order of nearest to farthest:
* Red, Orange, Yellow, Green, Cyan, Blue, Magenta, white, gray, black @@ -163,62 +135,9 @@ public class LodUtil - - /** - * Gets the ServerWorld for the relevant dimension. - * - * @return null if there is no ServerWorld for the given dimension - */ - public static ILevelWrapper getServerWorldFromDimension(IDimensionTypeWrapper newDimension) - { - if (!MC_CLIENT.hasSinglePlayerServer()) - return null; - - Iterable worlds = MC_CLIENT.getAllServerWorlds(); - ILevelWrapper returnWorld = null; - - for (ILevelWrapper world : worlds) - { - if (world.getDimensionType() == newDimension) - { - returnWorld = world; - break; - } - } - - return returnWorld; - } - - - public static int computeOverdrawOffset() - { - int chunkRenderDist = MC_RENDER.getRenderDistance() + 1; - EDhApiVanillaOverdraw overdraw = EDhApiVanillaOverdraw.ALWAYS; //Config.Client.Advanced.Graphics.AdvancedGraphics.vanillaOverdraw.get(); - if (overdraw == EDhApiVanillaOverdraw.ALWAYS) return Integer.MAX_VALUE; - - int offset; - if (overdraw == EDhApiVanillaOverdraw.NEVER) - { - offset = 0; //Config.Client.Advanced.Graphics.AdvancedGraphics.overdrawOffset.get(); - } - else - { - if (chunkRenderDist < MINIMUM_RENDER_DISTANCE_FOR_FAR_OVERDRAW) - { - offset = 1; - } - else - { - offset = chunkRenderDist / 5; - } - } - - if (chunkRenderDist - offset <= 1) - { - return Integer.MAX_VALUE; - } - return offset; - } + //=========// + // methods // + //=========// /** Returns the chunk int position for the given double position */ public static int getChunkPosFromDouble(double value) { return (int) Math.floor(value / CHUNK_WIDTH); } @@ -252,27 +171,7 @@ public class LodUtil * Do not use it for deserialization or naming of objects. * @author leetom */ - public static String formatLog(String str, Object... param) - { - return LOGGER.getMessageFactory().newMessage(str, param).getFormattedMessage(); - } - - // TODO move - /** - * Returns a shortened version of the given string that is no longer than maxLength.
- * If null returns the empty string. - */ - public static String shortenString(String str, int maxLength) - { - if (str == null) - { - return ""; - } - else - { - return str.substring(0, Math.min(str.length(), maxLength)); - } - } + public static String formatLog(String str, Object... param) { return LOGGER.getMessageFactory().newMessage(str, param).getFormattedMessage(); } public static class AssertFailureException extends RuntimeException { 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 b4967d0e5..e27a1afae 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 @@ -48,93 +48,6 @@ public class RenderUtil - //=================// - // culling methods // - //=================// - - /** - * Returns if the given ChunkPos is in the loaded area of the world. - * - * @param center the center of the loaded world (probably the player's ChunkPos) - */ - public static boolean isChunkPosInLoadedArea(DhChunkPos pos, DhChunkPos center) - { - return (pos.x >= center.x - MC_RENDER.getRenderDistance() - && pos.x <= center.x + MC_RENDER.getRenderDistance()) - && - (pos.z >= center.z - MC_RENDER.getRenderDistance() - && pos.z <= center.z + MC_RENDER.getRenderDistance()); - } - - /** - * Returns if the given coordinate is in the loaded area of the world. - * - * @param centerCoordinate the center of the loaded world - */ - public static boolean isCoordinateInLoadedArea(int x, int z, int centerCoordinate) - { - return (x >= centerCoordinate - MC_RENDER.getRenderDistance() - && x <= centerCoordinate + MC_RENDER.getRenderDistance()) - && - (z >= centerCoordinate - MC_RENDER.getRenderDistance() - && z <= centerCoordinate + MC_RENDER.getRenderDistance()); - } - - /** - * Find the coordinates that are in the center half of the given - * 2D matrix, starting at (0,0) and going to (2 * lodRadius, 2 * lodRadius). - */ - public static boolean isCoordinateInNearFogArea(int i, int j, int lodRadius) - { - int halfRadius = lodRadius / 2; - - return (i >= lodRadius - halfRadius - && i <= lodRadius + halfRadius) - && - (j >= lodRadius - halfRadius - && j <= lodRadius + halfRadius); - } - - /** - * Returns true if one of the region's 4 corners is in front - * of the camera. - */ - public static boolean isRegionInViewFrustum(DhBlockPos playerBlockPos, Vec3f cameraDir, int vboRegionX, int vboRegionZ) - { - // convert the vbo position into a direction vector - // starting from the player's position - Vec3f vboVec = new Vec3f(vboRegionX * LodUtil.REGION_WIDTH, 0, vboRegionZ * LodUtil.REGION_WIDTH); - Vec3f playerVec = new Vec3f(playerBlockPos.x, playerBlockPos.y, playerBlockPos.z); - - vboVec.subtract(playerVec); - - // calculate the 4 corners - Vec3f vboSeVec = new Vec3f(vboVec.x + LodUtil.REGION_WIDTH, vboVec.y, vboVec.z + LodUtil.REGION_WIDTH); - Vec3f vboSwVec = new Vec3f(vboVec.x, vboVec.y, vboVec.z + LodUtil.REGION_WIDTH); - Vec3f vboNwVec = new Vec3f(vboVec.x, vboVec.y, vboVec.z); - Vec3f vboNeVec = new Vec3f(vboVec.x + LodUtil.REGION_WIDTH, vboVec.y, vboVec.z); - - // if any corner is visible, this region should be rendered - return isNormalizedVectorInViewFrustum(vboSeVec, cameraDir) || - isNormalizedVectorInViewFrustum(vboSwVec, cameraDir) || - isNormalizedVectorInViewFrustum(vboNwVec, cameraDir) || - isNormalizedVectorInViewFrustum(vboNeVec, cameraDir); - } - - /** - * Currently takes the dot product of the two vectors, - * but in the future could do more complicated frustum culling tests. - */ - private static boolean isNormalizedVectorInViewFrustum(Vec3f objectVector, Vec3f cameraDir) - { - // the -0.1 is to offer a slight buffer, so we are - // more likely to render LODs and thus, hopefully prevent - // flickering or odd disappearances - return objectVector.dotProduct(cameraDir) > -0.1; - } - - - //=====================// // matrix manipulation // //=====================// @@ -166,19 +79,6 @@ public class RenderUtil return mcModelViewMat.copy(); } - /** - * create and return a new combined modelView/projection matrix based on MC's modelView and projection matrices - * - * @param mcProjMat Minecraft's current projection matrix - * @param mcModelViewMat Minecraft's current model view matrix - */ - public static Mat4f createCombinedModelViewProjectionMatrix(Mat4f mcProjMat, Mat4f mcModelViewMat, float partialTicks) - { - Mat4f lodProj = createLodProjectionMatrix(mcProjMat, partialTicks); - lodProj.multiply(createLodModelViewMatrix(mcModelViewMat)); - return lodProj; - } - public static float getNearClipPlaneDistanceInBlocks(float partialTicks) { int chunkRenderDistance = MC_RENDER.getRenderDistance();