From ef87a4e5951c8a7f69820848c91a47a57b758b14 Mon Sep 17 00:00:00 2001 From: Ran <43445785+Ran-Mewo@users.noreply.github.com> Date: Fri, 26 Jul 2024 00:17:15 +1000 Subject: [PATCH] Attempt to migrate most of the codebase to newer versions of Java --- .../com/seibel/distanthorizons/api/DhApi.java | 19 +- .../enums/rendering/EDhApiDebugRendering.java | 37 +-- .../enums/rendering/EDhApiRendererMode.java | 28 +- .../api/objects/DhApiResult.java | 6 +- .../DependencyInjection/ApiEventInjector.java | 3 +- .../DependencyInjector.java | 8 +- .../OverridePriorityListContainer.java | 4 +- core/build.gradle | 2 +- .../client/DhApiAmbientOcclusionConfig.java | 14 +- .../config/client/DhApiDebuggingConfig.java | 10 +- .../config/client/DhApiFarFogConfig.java | 12 +- .../client/DhApiGenericRenderingConfig.java | 6 +- .../config/client/DhApiGraphicsConfig.java | 40 +-- .../config/client/DhApiHeightFogConfig.java | 18 +- .../client/DhApiMultiThreadingConfig.java | 6 +- .../config/client/DhApiMultiplayerConfig.java | 4 +- .../client/DhApiNoiseTextureConfig.java | 8 +- .../methods/data/DhApiTerrainDataRepo.java | 6 +- .../core/api/internal/SharedApi.java | 6 +- .../distanthorizons/core/config/Config.java | 36 +-- .../core/config/ConfigBase.java | 6 +- .../core/config/NumberUtil.java | 4 +- .../QuickRenderToggleConfigEventHandler.java | 4 +- .../ResetConfigEventHandler.java | 2 +- .../AbstractPresetConfigEventHandler.java | 4 +- ...RenderQualityPresetConfigEventHandler.java | 12 +- .../ThreadPresetConfigEventHandler.java | 18 +- .../config/file/ConfigTypeConverters.java | 2 +- .../core/config/gui/EmbeddedFrameUtil.java | 35 +- .../fullData/FullDataPointIdMap.java | 3 +- .../fullData/sources/FullDataSourceV2.java | 3 +- .../render/bufferBuilding/BufferQuad.java | 34 +- .../bufferBuilding/CubicLodTemplate.java | 73 ++--- .../render/bufferBuilding/LodQuadBuilder.java | 16 +- .../render/columnViews/ColumnArrayView.java | 2 +- .../core/enums/EDhDirection.java | 61 ++-- .../FullDataSourceProviderV2.java | 10 +- .../GeneratedFullDataSourceProvider.java | 11 +- .../structure/ClientOnlySaveStructure.java | 39 +-- .../core/generation/BatchGenerator.java | 20 +- .../core/generation/DhLightingEngine.java | 4 +- .../core/generation/WorldGenerationQueue.java | 26 +- .../core/jar/DarkModeDetector.java | 20 +- .../distanthorizons/core/jar/JarMain.java | 2 +- .../distanthorizons/core/jar/JarUtils.java | 17 +- .../core/jar/gui/BaseJFrame.java | 4 +- .../core/jar/installer/GitlabGetter.java | 2 +- .../core/jar/installer/ModrinthGetter.java | 14 +- .../core/jar/updater/SelfUpdater.java | 19 +- .../core/logging/ConfigBasedLogger.java | 2 +- .../core/logging/ConfigBasedSpamLogger.java | 2 +- .../core/logging/SpamReducedLogger.java | 4 +- .../core/pos/DhBlockPos2D.java | 3 +- .../distanthorizons/core/pos/Pos2D.java | 3 +- .../core/render/fog/LodFogConfig.java | 56 ++-- .../core/render/glObject/GLEnums.java | 298 ++++++------------ .../core/render/glObject/buffer/GLBuffer.java | 2 +- .../texture/EDhDepthBufferFormat.java | 98 ++---- .../generic/GenericObjectRenderer.java | 13 +- .../core/sql/repo/AbstractDhRepo.java | 25 +- .../distanthorizons/core/util/ColorUtil.java | 22 +- .../distanthorizons/core/util/LodUtil.java | 2 +- .../util/RenderDataPointReducingList.java | 36 +-- .../distanthorizons/core/util/ThreadUtil.java | 4 +- .../gridList/EdgeDistanceBooleanGrid.java | 6 +- .../util/objects/DummyRunExecutorService.java | 4 +- .../core/util/objects/EventTimer.java | 8 +- .../core/util/objects/SortedArraySet.java | 4 +- .../core/util/objects/StatsMap.java | 4 +- .../dataStreams/DhDataInputStream.java | 18 +- .../objects/dataStreams/LzmaArrayCache.java | 4 +- .../core/util/objects/quadTree/QuadNode.java | 20 +- .../core/util/objects/quadTree/QuadTree.java | 2 +- .../core/util/threading/ConfigThreadPool.java | 4 +- .../chunk/ChunkLightStorage.java | 2 +- .../minecraft/IMinecraftRenderWrapper.java | 2 +- .../modAccessor/AbstractOptifineAccessor.java | 24 +- 77 files changed, 546 insertions(+), 866 deletions(-) diff --git a/api/src/main/java/com/seibel/distanthorizons/api/DhApi.java b/api/src/main/java/com/seibel/distanthorizons/api/DhApi.java index 79f67940b..8dcfc4749 100644 --- a/api/src/main/java/com/seibel/distanthorizons/api/DhApi.java +++ b/api/src/main/java/com/seibel/distanthorizons/api/DhApi.java @@ -60,16 +60,15 @@ public class DhApi * * Note: Don't use this string in your code. It may change and is only for reference. */ - public static final String READ_ME = - "If you don't see Javadocs something is wrong. \n" + - "If you are only using the full DH Mod in your build script, you won't have access to our javadocs and could potentially call into unsafe code. \n" + - "\n" + - "Please use the API jar in your build script as a compile time dependency " + - "and the full DH jar as a runtime dependency. \n" + - "\n" + - "Please refer to the example API project or the DH Developer Wiki for additional information " + - "and suggested setup. \n" + // DH Dev note: no links were included to prevent link rot. - ""; + public static final String READ_ME = + """ + If you don't see Javadocs something is wrong. + If you are only using the full DH Mod in your build script, you won't have access to our javadocs and could potentially call into unsafe code. + + Please use the API jar in your build script as a compile time dependency and the full DH jar as a runtime dependency. + + Please refer to the example API project or the DH Developer Wiki for additional information and suggested setup. + """; // DH Dev note: no links were included to prevent link rot. public static String readMe() { return READ_ME; } /** diff --git a/api/src/main/java/com/seibel/distanthorizons/api/enums/rendering/EDhApiDebugRendering.java b/api/src/main/java/com/seibel/distanthorizons/api/enums/rendering/EDhApiDebugRendering.java index 938493bb6..42f876093 100644 --- a/api/src/main/java/com/seibel/distanthorizons/api/enums/rendering/EDhApiDebugRendering.java +++ b/api/src/main/java/com/seibel/distanthorizons/api/enums/rendering/EDhApiDebugRendering.java @@ -56,34 +56,23 @@ public enum EDhApiDebugRendering public static EDhApiDebugRendering next(EDhApiDebugRendering type) { - switch (type) - { - case OFF: - return SHOW_DETAIL; - case SHOW_DETAIL: - return SHOW_BLOCK_MATERIAL; - case SHOW_BLOCK_MATERIAL: - return SHOW_OVERLAPPING_QUADS; - case SHOW_OVERLAPPING_QUADS: - return SHOW_RENDER_SOURCE_FLAG; - default: - return OFF; - } + return switch (type) { + case OFF -> SHOW_DETAIL; + case SHOW_DETAIL -> SHOW_BLOCK_MATERIAL; + case SHOW_BLOCK_MATERIAL -> SHOW_OVERLAPPING_QUADS; + case SHOW_OVERLAPPING_QUADS -> SHOW_RENDER_SOURCE_FLAG; + default -> OFF; + }; } public static EDhApiDebugRendering previous(EDhApiDebugRendering type) { - switch (type) - { - case OFF: - return SHOW_RENDER_SOURCE_FLAG; - case SHOW_RENDER_SOURCE_FLAG: - return SHOW_OVERLAPPING_QUADS; - case SHOW_OVERLAPPING_QUADS: - return SHOW_DETAIL; - default: - return OFF; - } + return switch (type) { + case OFF -> SHOW_RENDER_SOURCE_FLAG; + case SHOW_RENDER_SOURCE_FLAG -> SHOW_OVERLAPPING_QUADS; + case SHOW_OVERLAPPING_QUADS -> SHOW_DETAIL; + default -> OFF; + }; } } diff --git a/api/src/main/java/com/seibel/distanthorizons/api/enums/rendering/EDhApiRendererMode.java b/api/src/main/java/com/seibel/distanthorizons/api/enums/rendering/EDhApiRendererMode.java index 2a216a281..982b0be30 100644 --- a/api/src/main/java/com/seibel/distanthorizons/api/enums/rendering/EDhApiRendererMode.java +++ b/api/src/main/java/com/seibel/distanthorizons/api/enums/rendering/EDhApiRendererMode.java @@ -42,29 +42,21 @@ public enum EDhApiRendererMode /** Used by the config GUI to cycle through the available rendering options */ public static EDhApiRendererMode next(EDhApiRendererMode type) { - switch (type) - { - case DEFAULT: - return DEBUG; - case DEBUG: - return DISABLED; - default: - return DEFAULT; - } + return switch (type) { + case DEFAULT -> DEBUG; + case DEBUG -> DISABLED; + default -> DEFAULT; + }; } /** Used by the config GUI to cycle through the available rendering options */ public static EDhApiRendererMode previous(EDhApiRendererMode type) { - switch (type) - { - case DEFAULT: - return DISABLED; - case DEBUG: - return DEFAULT; - default: - return DEBUG; - } + return switch (type) { + case DEFAULT -> DISABLED; + case DEBUG -> DEFAULT; + default -> DEBUG; + }; } } diff --git a/api/src/main/java/com/seibel/distanthorizons/api/objects/DhApiResult.java b/api/src/main/java/com/seibel/distanthorizons/api/objects/DhApiResult.java index 9d84ca0de..aafc2fdd9 100644 --- a/api/src/main/java/com/seibel/distanthorizons/api/objects/DhApiResult.java +++ b/api/src/main/java/com/seibel/distanthorizons/api/objects/DhApiResult.java @@ -59,12 +59,12 @@ public class DhApiResult public static DhApiResult createSuccess() { return new DhApiResult<>(true, ""); } - public static DhApiResult createSuccess(Pt payload) { return new DhApiResult(true, "", payload); } + public static DhApiResult createSuccess(Pt payload) { return new DhApiResult<>(true, "", payload); } // There is no createSuccess(String message) method because it would be too easy to confuse with createSuccess(Pt payload) when returning null - public static DhApiResult createSuccess(String message, Pt payload) { return new DhApiResult(true, message, payload); } + public static DhApiResult createSuccess(String message, Pt payload) { return new DhApiResult<>(true, message, payload); } // there is no createFail() since all fail results should give a reason for their failure public static DhApiResult createFail(String message) { return new DhApiResult<>(false, message); } - public static DhApiResult createFail(String message, Pt payload) { return new DhApiResult(false, message, payload); } + public static DhApiResult createFail(String message, Pt payload) { return new DhApiResult<>(false, message, payload); } } diff --git a/api/src/main/java/com/seibel/distanthorizons/coreapi/DependencyInjection/ApiEventInjector.java b/api/src/main/java/com/seibel/distanthorizons/coreapi/DependencyInjection/ApiEventInjector.java index 386ab2aef..35684bad6 100644 --- a/api/src/main/java/com/seibel/distanthorizons/coreapi/DependencyInjection/ApiEventInjector.java +++ b/api/src/main/java/com/seibel/distanthorizons/coreapi/DependencyInjection/ApiEventInjector.java @@ -163,9 +163,8 @@ public class ApiEventInjector extends DependencyInjector implements DhApiEventParam eventParam = createEventParamWrapper(event, input); event.fireEvent(eventParam); - if (eventParam instanceof DhApiCancelableEventParam) + if (eventParam instanceof DhApiCancelableEventParam cancelableEventParam) { - DhApiCancelableEventParam cancelableEventParam = (DhApiCancelableEventParam) eventParam; cancelEvent |= cancelableEventParam.isEventCanceled(); } diff --git a/api/src/main/java/com/seibel/distanthorizons/coreapi/DependencyInjection/DependencyInjector.java b/api/src/main/java/com/seibel/distanthorizons/coreapi/DependencyInjection/DependencyInjector.java index ab3aa09fe..8e53f2cd3 100644 --- a/api/src/main/java/com/seibel/distanthorizons/coreapi/DependencyInjection/DependencyInjector.java +++ b/api/src/main/java/com/seibel/distanthorizons/coreapi/DependencyInjection/DependencyInjector.java @@ -87,7 +87,7 @@ public class DependencyInjector implements IDepe // make sure the hashSet has an array to hold the dependency if (!this.dependencies.containsKey(dependencyInterface)) { - this.dependencies.put(dependencyInterface, new ArrayList()); + this.dependencies.put(dependencyInterface, new ArrayList<>()); } // add the dependency @@ -134,7 +134,7 @@ public class DependencyInjector implements IDepe @Override public T get(Class interfaceClass) throws ClassCastException { - return (T) this.getInternalLogic(interfaceClass, false).get(0); + return (T) this.getInternalLogic(interfaceClass, false).getFirst(); } @Override @@ -146,7 +146,7 @@ public class DependencyInjector implements IDepe @Override public T get(Class interfaceClass, boolean allowIncompleteDependencies) throws ClassCastException { - return (T) this.getInternalLogic(interfaceClass, allowIncompleteDependencies).get(0); + return (T) this.getInternalLogic(interfaceClass, allowIncompleteDependencies).getFirst(); } /** @@ -175,7 +175,7 @@ public class DependencyInjector implements IDepe // return an empty list to prevent null pointers - ArrayList emptyList = new ArrayList(); + ArrayList emptyList = new ArrayList<>(); emptyList.add(null); return emptyList; } diff --git a/api/src/main/java/com/seibel/distanthorizons/coreapi/DependencyInjection/OverridePriorityListContainer.java b/api/src/main/java/com/seibel/distanthorizons/coreapi/DependencyInjection/OverridePriorityListContainer.java index 143259ee8..d8ca0c480 100644 --- a/api/src/main/java/com/seibel/distanthorizons/coreapi/DependencyInjection/OverridePriorityListContainer.java +++ b/api/src/main/java/com/seibel/distanthorizons/coreapi/DependencyInjection/OverridePriorityListContainer.java @@ -64,14 +64,14 @@ public class OverridePriorityListContainer implements IBindable else { // last item should have the highest priority - return this.overridePairList.get(this.overridePairList.size() - 1).override; + return this.overridePairList.getLast().override; } } public IDhApiOverrideable getOverrideWithHighestPriority() { if (this.overridePairList.size() != 0) { - return this.overridePairList.get(0).override; + return this.overridePairList.getFirst().override; } else { diff --git a/core/build.gradle b/core/build.gradle index 6c59948a3..0b794ccb1 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -50,5 +50,5 @@ dependencies { // All of these dependencies are in Vanilla Minecraft, but we nee } artifacts { - downgradedArtifact apiDowngrade // Setup the configuration downgradedArtifact to be the `apiDowngrade` which downgrades the core to a specified Java version + downgradedArtifact shadeDowngradedApi // Setup the configuration downgradedArtifact to be the `shadeDowngradedApi` which downgrades the core to a specified Java version } \ No newline at end of file diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiAmbientOcclusionConfig.java b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiAmbientOcclusionConfig.java index 4afc661f8..d47f939b1 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiAmbientOcclusionConfig.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiAmbientOcclusionConfig.java @@ -35,30 +35,30 @@ public class DhApiAmbientOcclusionConfig implements IDhApiAmbientOcclusionConfig @Override public IDhApiConfigValue enabled() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Ssao.enabled); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Ssao.enabled); } @Override public IDhApiConfigValue sampleCount() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Ssao.sampleCount); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Ssao.sampleCount); } @Override public IDhApiConfigValue radius() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Ssao.radius); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Ssao.radius); } @Override public IDhApiConfigValue strength() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Ssao.strength); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Ssao.strength); } @Override public IDhApiConfigValue bias() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Ssao.bias); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Ssao.bias); } @Override public IDhApiConfigValue minLight() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Ssao.minLight); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Ssao.minLight); } @Override public IDhApiConfigValue blurRadius() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Ssao.blurRadius); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Ssao.blurRadius); } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiDebuggingConfig.java b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiDebuggingConfig.java index 925dfc3da..cf9f4f625 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiDebuggingConfig.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiDebuggingConfig.java @@ -34,18 +34,18 @@ public class DhApiDebuggingConfig implements IDhApiDebuggingConfig public IDhApiConfigValue debugRendering() - { return new DhApiConfigValue(Config.Client.Advanced.Debugging.debugRendering); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Debugging.debugRendering); } public IDhApiConfigValue debugKeybindings() - { return new DhApiConfigValue(Config.Client.Advanced.Debugging.enableDebugKeybindings); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Debugging.enableDebugKeybindings); } public IDhApiConfigValue renderWireframe() - { return new DhApiConfigValue(Config.Client.Advanced.Debugging.renderWireframe); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Debugging.renderWireframe); } public IDhApiConfigValue lodOnlyMode() - { return new DhApiConfigValue(Config.Client.Advanced.Debugging.lodOnlyMode); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Debugging.lodOnlyMode); } public IDhApiConfigValue debugWireframeRendering() - { return new DhApiConfigValue(Config.Client.Advanced.Debugging.DebugWireframe.enableRendering); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Debugging.DebugWireframe.enableRendering); } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiFarFogConfig.java b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiFarFogConfig.java index 0393ccbdb..37d740cee 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiFarFogConfig.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiFarFogConfig.java @@ -35,26 +35,26 @@ public class DhApiFarFogConfig implements IDhApiFarFogConfig @Override public IDhApiConfigValue farFogStartDistance() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Fog.AdvancedFog.farFogStart); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.farFogStart); } @Override public IDhApiConfigValue farFogEndDistance() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Fog.AdvancedFog.farFogEnd); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.farFogEnd); } @Override public IDhApiConfigValue farFogMinThickness() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Fog.AdvancedFog.farFogMin); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.farFogMin); } @Override public IDhApiConfigValue farFogMaxThickness() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Fog.AdvancedFog.farFogMax); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.farFogMax); } @Override public IDhApiConfigValue farFogFalloff() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Fog.AdvancedFog.farFogFalloff); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.farFogFalloff); } @Override public IDhApiConfigValue farFogDensity() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Fog.AdvancedFog.farFogDensity); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.farFogDensity); } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiGenericRenderingConfig.java b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiGenericRenderingConfig.java index f7fded3e5..76780a48c 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiGenericRenderingConfig.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiGenericRenderingConfig.java @@ -35,12 +35,12 @@ public class DhApiGenericRenderingConfig implements IDhApiGenericRenderingConfig @Override public IDhApiConfigValue renderingEnabled() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.GenericRendering.enableRendering); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.GenericRendering.enableRendering); } @Override public IDhApiConfigValue beaconRenderingEnabled() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.GenericRendering.enableBeaconRendering); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.GenericRendering.enableBeaconRendering); } @Override public IDhApiConfigValue cloudRenderingEnabled() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.GenericRendering.enableCloudRendering); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.GenericRendering.enableCloudRendering); } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiGraphicsConfig.java b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiGraphicsConfig.java index ef4f66c74..0756b29a0 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiGraphicsConfig.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiGraphicsConfig.java @@ -56,15 +56,15 @@ public class DhApiGraphicsConfig implements IDhApiGraphicsConfig @Override public IDhApiConfigValue chunkRenderDistance() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Quality.lodChunkRenderDistanceRadius); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Quality.lodChunkRenderDistanceRadius); } @Override public IDhApiConfigValue renderingEnabled() - { return new DhApiConfigValue(Config.Client.quickEnableRendering); } + { return new DhApiConfigValue<>(Config.Client.quickEnableRendering); } @Override public IDhApiConfigValue renderingMode() - { return new DhApiConfigValue(Config.Client.Advanced.Debugging.rendererMode); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Debugging.rendererMode); } @@ -74,27 +74,27 @@ public class DhApiGraphicsConfig implements IDhApiGraphicsConfig @Override public IDhApiConfigValue maxHorizontalResolution() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Quality.maxHorizontalResolution); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Quality.maxHorizontalResolution); } @Override public IDhApiConfigValue verticalQuality() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Quality.verticalQuality); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Quality.verticalQuality); } @Override public IDhApiConfigValue horizontalQuality() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Quality.horizontalQuality); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Quality.horizontalQuality); } @Override public IDhApiConfigValue transparency() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Quality.transparency); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Quality.transparency); } @Override public IDhApiConfigValue blocksToAvoid() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Quality.blocksToIgnore); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Quality.blocksToIgnore); } @Override public IDhApiConfigValue tintWithAvoidedBlocks() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Quality.tintWithAvoidedBlocks); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Quality.tintWithAvoidedBlocks); } // TODO re-implement // @Override @@ -109,47 +109,47 @@ public class DhApiGraphicsConfig implements IDhApiGraphicsConfig @Override public IDhApiConfigValue overdrawPreventionRadius() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.AdvancedGraphics.overdrawPrevention); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.AdvancedGraphics.overdrawPrevention); } @Override public IDhApiConfigValue brightnessMultiplier() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.AdvancedGraphics.brightnessMultiplier); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.AdvancedGraphics.brightnessMultiplier); } @Override public IDhApiConfigValue saturationMultiplier() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.AdvancedGraphics.saturationMultiplier); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.AdvancedGraphics.saturationMultiplier); } @Override public IDhApiConfigValue caveCullingEnabled() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.AdvancedGraphics.enableCaveCulling); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.AdvancedGraphics.enableCaveCulling); } @Override public IDhApiConfigValue caveCullingHeight() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.AdvancedGraphics.caveCullingHeight); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.AdvancedGraphics.caveCullingHeight); } @Override public IDhApiConfigValue earthCurvatureRatio() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.AdvancedGraphics.earthCurveRatio); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.AdvancedGraphics.earthCurveRatio); } @Override public IDhApiConfigValue lodOnlyMode() - { return new DhApiConfigValue(Config.Client.Advanced.Debugging.lodOnlyMode); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Debugging.lodOnlyMode); } @Override public IDhApiConfigValue lodBias() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.AdvancedGraphics.lodBias); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.AdvancedGraphics.lodBias); } @Override public IDhApiConfigValue lodShading() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.AdvancedGraphics.lodShading); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.AdvancedGraphics.lodShading); } @Override public IDhApiConfigValue disableFrustumCulling() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.AdvancedGraphics.disableFrustumCulling); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.AdvancedGraphics.disableFrustumCulling); } @Override public IDhApiConfigValue disableShadowFrustumCulling() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.AdvancedGraphics.disableShadowPassFrustumCulling); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.AdvancedGraphics.disableShadowPassFrustumCulling); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiHeightFogConfig.java b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiHeightFogConfig.java index ecd1090a2..91000b277 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiHeightFogConfig.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiHeightFogConfig.java @@ -37,38 +37,38 @@ public class DhApiHeightFogConfig implements IDhApiHeightFogConfig @Override public IDhApiConfigValue heightFogMixMode() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogMixMode); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogMixMode); } @Override public IDhApiConfigValue heightFogMode() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogMode); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogMode); } @Override public IDhApiConfigValue heightFogBaseHeight() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogBaseHeight); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogBaseHeight); } @Override public IDhApiConfigValue heightFogStartingHeightPercent() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogStart); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogStart); } @Override public IDhApiConfigValue heightFogEndingHeightPercent() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogEnd); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogEnd); } @Override public IDhApiConfigValue heightFogMinThickness() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogMin); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogMin); } @Override public IDhApiConfigValue heightFogMaxThickness() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogMax); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogMax); } @Override public IDhApiConfigValue heightFogFalloff() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogFalloff); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogFalloff); } @Override public IDhApiConfigValue heightFogDensity() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogDensity); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.Fog.AdvancedFog.HeightFog.heightFogDensity); } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiMultiThreadingConfig.java b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiMultiThreadingConfig.java index ebd8f1eba..6121b922e 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiMultiThreadingConfig.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiMultiThreadingConfig.java @@ -34,14 +34,14 @@ public class DhApiMultiThreadingConfig implements IDhApiMultiThreadingConfig @Override public IDhApiConfigValue worldGeneratorThreads() - { return new DhApiConfigValue(Config.Client.Advanced.MultiThreading.numberOfWorldGenerationThreads); } + { return new DhApiConfigValue<>(Config.Client.Advanced.MultiThreading.numberOfWorldGenerationThreads); } @Override public IDhApiConfigValue fileHandlerThreads() - { return new DhApiConfigValue(Config.Client.Advanced.MultiThreading.numberOfFileHandlerThreads); } + { return new DhApiConfigValue<>(Config.Client.Advanced.MultiThreading.numberOfFileHandlerThreads); } @Override public IDhApiConfigValue lodBuilderThreads() - { return new DhApiConfigValue(Config.Client.Advanced.MultiThreading.numberOfLodBuilderThreads); } + { return new DhApiConfigValue<>(Config.Client.Advanced.MultiThreading.numberOfLodBuilderThreads); } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiMultiplayerConfig.java b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiMultiplayerConfig.java index 1c16671d0..c422789dd 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiMultiplayerConfig.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiMultiplayerConfig.java @@ -34,9 +34,9 @@ public class DhApiMultiplayerConfig implements IDhApiMultiplayerConfig public IDhApiConfigValue folderSavingMode() - { return new DhApiConfigValue(Config.Client.Advanced.Multiplayer.serverFolderNameMode); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Multiplayer.serverFolderNameMode); } public IDhApiConfigValue multiverseSimilarityRequirement() - { return new DhApiConfigValue(Config.Client.Advanced.Multiplayer.multiverseSimilarityRequiredPercent); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Multiplayer.multiverseSimilarityRequiredPercent); } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiNoiseTextureConfig.java b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiNoiseTextureConfig.java index 1b344e292..4d2d6b766 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiNoiseTextureConfig.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiNoiseTextureConfig.java @@ -34,18 +34,18 @@ public class DhApiNoiseTextureConfig implements IDhApiNoiseTextureConfig @Override public IDhApiConfigValue noiseEnabled() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.NoiseTextureSettings.noiseEnabled); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.NoiseTextureSettings.noiseEnabled); } @Override public IDhApiConfigValue noiseSteps() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.NoiseTextureSettings.noiseSteps); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.NoiseTextureSettings.noiseSteps); } @Override public IDhApiConfigValue noiseIntensity() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.NoiseTextureSettings.noiseIntensity); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.NoiseTextureSettings.noiseIntensity); } @Override public IDhApiConfigValue noiseDropoff() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.NoiseTextureSettings.noiseDropoff); } + { return new DhApiConfigValue<>(Config.Client.Advanced.Graphics.NoiseTextureSettings.noiseDropoff); } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/data/DhApiTerrainDataRepo.java b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/data/DhApiTerrainDataRepo.java index cf7d337c0..d25d803e2 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/data/DhApiTerrainDataRepo.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/data/DhApiTerrainDataRepo.java @@ -187,22 +187,20 @@ public class DhApiTerrainDataRepo implements IDhApiTerrainDataRepo return DhApiResult.createFail("Unable to get terrain data before the world has loaded."); } - if (!(levelWrapper instanceof ILevelWrapper)) + if (!(levelWrapper instanceof ILevelWrapper coreLevelWrapper)) { // custom level wrappers aren't supported, // the API user must get a level wrapper from our code somewhere return DhApiResult.createFail("Unsupported [" + IDhApiLevelWrapper.class.getSimpleName() + "] implementation, only the core class [" + IDhLevel.class.getSimpleName() + "] is a valid parameter."); } - ILevelWrapper coreLevelWrapper = (ILevelWrapper) levelWrapper; - if (!(apiDataCache instanceof DhApiTerrainDataCache)) + if (!(apiDataCache instanceof DhApiTerrainDataCache dataCache)) { // custom level wrappers aren't supported, // the API user must get a level wrapper from our code somewhere return DhApiResult.createFail("Unsupported [" + IDhApiTerrainDataCache.class.getSimpleName() + "] implementation, only the core class [" + DhApiTerrainDataCache.class.getSimpleName() + "] is a valid parameter."); } - DhApiTerrainDataCache dataCache = (DhApiTerrainDataCache) apiDataCache; IDhLevel level = currentWorld.getLevel(coreLevelWrapper); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java b/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java index 11fda5913..584006f3c 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java @@ -172,11 +172,10 @@ public class SharedApi AbstractDhWorld dhWorld = SharedApi.getAbstractDhWorld(); if (dhWorld == null) { - if (level instanceof IClientLevelWrapper) + if (level instanceof IClientLevelWrapper clientLevel) { // If the client world isn't loaded yet, keep track of which chunks were loaded so we can use them later. // This may happen if the client world and client level load events happen out of order - IClientLevelWrapper clientLevel = (IClientLevelWrapper) level; ClientApi.INSTANCE.waitingChunkByClientLevelAndPos.replace(new Pair<>(clientLevel, chunkWrapper.getChunkPos()), chunkWrapper); } @@ -187,10 +186,9 @@ public class SharedApi IDhLevel dhLevel = dhWorld.getLevel(level); if (dhLevel == null) { - if (level instanceof IClientLevelWrapper) + if (level instanceof IClientLevelWrapper clientLevel) { // the client level isn't loaded yet - IClientLevelWrapper clientLevel = (IClientLevelWrapper) level; ClientApi.INSTANCE.waitingChunkByClientLevelAndPos.replace(new Pair<>(clientLevel, chunkWrapper.getChunkPos()), chunkWrapper); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java b/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java index a2c786984..f76b5d81a 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java @@ -867,8 +867,8 @@ public class Config static { - ignoredRenderBlockCsv.addListener(new ConfigChangeListener(Config.Client.Advanced.LodBuilding.ignoredRenderBlockCsv, - (blockCsv) -> + ignoredRenderBlockCsv.addListener(new ConfigChangeListener<>(Config.Client.Advanced.LodBuilding.ignoredRenderBlockCsv, + (blockCsv) -> { IWrapperFactory wrapperFactory = SingletonInjector.INSTANCE.get(IWrapperFactory.class); if (wrapperFactory != null) @@ -878,8 +878,8 @@ public class Config } })); - ignoredRenderCaveBlockCsv.addListener(new ConfigChangeListener(Config.Client.Advanced.LodBuilding.ignoredRenderCaveBlockCsv, - (blockCsv) -> + ignoredRenderCaveBlockCsv.addListener(new ConfigChangeListener<>(Config.Client.Advanced.LodBuilding.ignoredRenderCaveBlockCsv, + (blockCsv) -> { IWrapperFactory wrapperFactory = SingletonInjector.INSTANCE.get(IWrapperFactory.class); if (wrapperFactory != null) @@ -1497,27 +1497,25 @@ public class Config .build(); public static ConfigEntry> listTest = new ConfigEntry.Builder>() - .set(new ArrayList(Arrays.asList("option 1", "option 2", "option 3"))) + .set(new ArrayList<>(Arrays.asList("option 1", "option 2", "option 3"))) .build(); public static ConfigEntry> mapTest = new ConfigEntry.Builder>() - .set(new HashMap()) + .set(new HashMap<>()) .build(); - public static ConfigUIButton uiButtonTest = new ConfigUIButton(() -> - { - new Thread(() -> - { - if (!GraphicsEnvironment.isHeadless()) + public static ConfigUIButton uiButtonTest = new ConfigUIButton(() -> + new Thread(() -> { - JOptionPane.showMessageDialog(null, "Button pressed!", "UITester dialog", JOptionPane.INFORMATION_MESSAGE); - } - else - { - LOGGER.info("button pressed!"); - } - }); - }); + if (!GraphicsEnvironment.isHeadless()) + { + JOptionPane.showMessageDialog(null, "Button pressed!", "UITester dialog", JOptionPane.INFORMATION_MESSAGE); + } + else + { + LOGGER.info("button pressed!"); + } + })); public static ConfigCategory categoryTest = new ConfigCategory.Builder().set(CategoryTest.class).build(); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/ConfigBase.java b/core/src/main/java/com/seibel/distanthorizons/core/config/ConfigBase.java index 6980d531f..7b17d9fad 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/ConfigBase.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/ConfigBase.java @@ -77,7 +77,7 @@ public class ConfigBase *
Map *
HashMap */ - public static final List> acceptableInputs = new ArrayList>() + public static final List> acceptableInputs = new ArrayList<>() {{ add(Boolean.class); add(Byte.class); @@ -149,7 +149,7 @@ public class ConfigBase LOGGER.warn(exception); } - AbstractConfigType entry = entries.get(entries.size() - 1); + AbstractConfigType entry = entries.getLast(); entry.category = category; entry.name = field.getName(); entry.configBase = this; @@ -160,7 +160,7 @@ public class ConfigBase { LOGGER.error("Invalid variable type at [" + (category.isEmpty() ? "" : category + ".") + field.getName() + "]."); LOGGER.error("Type [" + entry.getType() + "] is not one of these types [" + acceptableInputs.toString() + "]"); - entries.remove(entries.size() - 1); // Delete the entry if it is invalid so the game can still run + entries.removeLast(); // Delete the entry if it is invalid so the game can still run } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/NumberUtil.java b/core/src/main/java/com/seibel/distanthorizons/core/config/NumberUtil.java index b23bcb450..48bba1ac4 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/NumberUtil.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/NumberUtil.java @@ -32,7 +32,7 @@ import java.util.Map; public class NumberUtil { // Is there no better way of doing this? - public static Map, Number> minValues = new HashMap, Number>() + public static Map, Number> minValues = new HashMap<>() {{ put(Byte.class, Byte.MIN_VALUE); put(Short.class, Short.MIN_VALUE); @@ -41,7 +41,7 @@ public class NumberUtil put(Double.class, Double.MIN_VALUE); put(Float.class, Float.MIN_VALUE); }}; - public static Map, Number> maxValues = new HashMap, Number>() + public static Map, Number> maxValues = new HashMap<>() {{ put(Byte.class, Byte.MAX_VALUE); put(Short.class, Short.MAX_VALUE); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/QuickRenderToggleConfigEventHandler.java b/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/QuickRenderToggleConfigEventHandler.java index 8b6f3cb6d..e0146b626 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/QuickRenderToggleConfigEventHandler.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/QuickRenderToggleConfigEventHandler.java @@ -35,8 +35,8 @@ public class QuickRenderToggleConfigEventHandler /** private since we only ever need one handler at a time */ private QuickRenderToggleConfigEventHandler() { - this.quickRenderChangeListener = new ConfigChangeListener<>(Config.Client.quickEnableRendering, (val) -> { Config.Client.Advanced.Debugging.rendererMode.set(Config.Client.quickEnableRendering.get() ? EDhApiRendererMode.DEFAULT : EDhApiRendererMode.DISABLED); }); - this.rendererModeChangeListener = new ConfigChangeListener<>(Config.Client.Advanced.Debugging.rendererMode, (val) -> { Config.Client.quickEnableRendering.set(Config.Client.Advanced.Debugging.rendererMode.get() != EDhApiRendererMode.DISABLED); }); + this.quickRenderChangeListener = new ConfigChangeListener<>(Config.Client.quickEnableRendering, (val) -> Config.Client.Advanced.Debugging.rendererMode.set(Config.Client.quickEnableRendering.get() ? EDhApiRendererMode.DEFAULT : EDhApiRendererMode.DISABLED)); + this.rendererModeChangeListener = new ConfigChangeListener<>(Config.Client.Advanced.Debugging.rendererMode, (val) -> Config.Client.quickEnableRendering.set(Config.Client.Advanced.Debugging.rendererMode.get() != EDhApiRendererMode.DISABLED)); } /** diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/ResetConfigEventHandler.java b/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/ResetConfigEventHandler.java index 05b14eca9..60f1c5f9d 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/ResetConfigEventHandler.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/ResetConfigEventHandler.java @@ -32,7 +32,7 @@ public class ResetConfigEventHandler /** private since we only ever need one handler at a time */ private ResetConfigEventHandler() { - this.configChangeListener = new ConfigChangeListener<>(Config.Client.ResetConfirmation.resetAllSettings, (resetSettings) -> { doStuff(resetSettings); }); + this.configChangeListener = new ConfigChangeListener<>(Config.Client.ResetConfirmation.resetAllSettings, this::doStuff); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/presets/AbstractPresetConfigEventHandler.java b/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/presets/AbstractPresetConfigEventHandler.java index 5e8b9ce71..8528005f9 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/presets/AbstractPresetConfigEventHandler.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/presets/AbstractPresetConfigEventHandler.java @@ -57,7 +57,7 @@ public abstract class AbstractPresetConfigEventHandler this.onConfigUiClosed()); + configGui.addOnScreenChangeListener(this::onConfigUiClosed); } @@ -216,7 +216,7 @@ public abstract class AbstractPresetConfigEventHandler drawResolution = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.Graphics.Quality.maxHorizontalResolution, - new HashMap() + new HashMap<>() {{ this.put(EDhApiQualityPreset.MINIMUM, EDhApiMaxHorizontalResolution.TWO_BLOCKS); this.put(EDhApiQualityPreset.LOW, EDhApiMaxHorizontalResolution.BLOCK); @@ -50,7 +50,7 @@ public class RenderQualityPresetConfigEventHandler extends AbstractPresetConfigE this.put(EDhApiQualityPreset.EXTREME, EDhApiMaxHorizontalResolution.BLOCK); }}); private final ConfigEntryWithPresetOptions verticalQuality = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.Graphics.Quality.verticalQuality, - new HashMap() + new HashMap<>() {{ this.put(EDhApiQualityPreset.MINIMUM, EDhApiVerticalQuality.HEIGHT_MAP); this.put(EDhApiQualityPreset.LOW, EDhApiVerticalQuality.LOW); @@ -59,7 +59,7 @@ public class RenderQualityPresetConfigEventHandler extends AbstractPresetConfigE this.put(EDhApiQualityPreset.EXTREME, EDhApiVerticalQuality.EXTREME); }}); private final ConfigEntryWithPresetOptions horizontalQuality = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.Graphics.Quality.horizontalQuality, - new HashMap() + new HashMap<>() {{ this.put(EDhApiQualityPreset.MINIMUM, EDhApiHorizontalQuality.LOWEST); this.put(EDhApiQualityPreset.LOW, EDhApiHorizontalQuality.LOW); @@ -68,7 +68,7 @@ public class RenderQualityPresetConfigEventHandler extends AbstractPresetConfigE this.put(EDhApiQualityPreset.EXTREME, EDhApiHorizontalQuality.EXTREME); }}); private final ConfigEntryWithPresetOptions transparency = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.Graphics.Quality.transparency, - new HashMap() + new HashMap<>() {{ this.put(EDhApiQualityPreset.MINIMUM, EDhApiTransparency.DISABLED); this.put(EDhApiQualityPreset.LOW, EDhApiTransparency.DISABLED); // should be fake if/when fake is fixed @@ -77,7 +77,7 @@ public class RenderQualityPresetConfigEventHandler extends AbstractPresetConfigE this.put(EDhApiQualityPreset.EXTREME, EDhApiTransparency.COMPLETE); }}); private final ConfigEntryWithPresetOptions ssaoEnabled = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.Graphics.Ssao.enabled, - new HashMap() + new HashMap<>() {{ this.put(EDhApiQualityPreset.MINIMUM, false); this.put(EDhApiQualityPreset.LOW, false); @@ -106,7 +106,7 @@ public class RenderQualityPresetConfigEventHandler extends AbstractPresetConfigE for (ConfigEntryWithPresetOptions config : this.configList) { // ignore try-using, the listener should only ever be added once and should never be removed - new ConfigChangeListener<>(config.configEntry, (val) -> { this.onConfigValueChanged(); }); + new ConfigChangeListener<>(config.configEntry, (val) -> this.onConfigValueChanged()); } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/presets/ThreadPresetConfigEventHandler.java b/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/presets/ThreadPresetConfigEventHandler.java index 54d27d419..d98356442 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/presets/ThreadPresetConfigEventHandler.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/presets/ThreadPresetConfigEventHandler.java @@ -42,7 +42,7 @@ public class ThreadPresetConfigEventHandler extends AbstractPresetConfigEventHan public static int getWorldGenDefaultThreadCount() { return getThreadCountByPercent(0.1); } private final ConfigEntryWithPresetOptions worldGenThreadCount = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.MultiThreading.numberOfWorldGenerationThreads, - new HashMap() + new HashMap<>() {{ this.put(EDhApiThreadPreset.MINIMAL_IMPACT, 1); this.put(EDhApiThreadPreset.LOW_IMPACT, getWorldGenDefaultThreadCount()); @@ -52,7 +52,7 @@ public class ThreadPresetConfigEventHandler extends AbstractPresetConfigEventHan }}); public static double getWorldGenDefaultRunTimeRatio() { return 0.5; } private final ConfigEntryWithPresetOptions worldGenRunTime = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.MultiThreading.runTimeRatioForWorldGenerationThreads, - new HashMap() + new HashMap<>() {{ this.put(EDhApiThreadPreset.MINIMAL_IMPACT, 0.1); this.put(EDhApiThreadPreset.LOW_IMPACT, getWorldGenDefaultRunTimeRatio()); @@ -64,7 +64,7 @@ public class ThreadPresetConfigEventHandler extends AbstractPresetConfigEventHan public static int getFileHandlerDefaultThreadCount() { return getThreadCountByPercent(0.1); } private final ConfigEntryWithPresetOptions fileHandlerThreadCount = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.MultiThreading.numberOfFileHandlerThreads, - new HashMap() + new HashMap<>() {{ this.put(EDhApiThreadPreset.MINIMAL_IMPACT, 1); this.put(EDhApiThreadPreset.LOW_IMPACT, getFileHandlerDefaultThreadCount()); @@ -74,7 +74,7 @@ public class ThreadPresetConfigEventHandler extends AbstractPresetConfigEventHan }}); public static double getFileHandlerDefaultRunTimeRatio() { return 0.5; } private final ConfigEntryWithPresetOptions fileHandlerRunTime = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.MultiThreading.runTimeRatioForFileHandlerThreads, - new HashMap() + new HashMap<>() {{ this.put(EDhApiThreadPreset.MINIMAL_IMPACT, 0.25); this.put(EDhApiThreadPreset.LOW_IMPACT, getFileHandlerDefaultRunTimeRatio()); @@ -86,7 +86,7 @@ public class ThreadPresetConfigEventHandler extends AbstractPresetConfigEventHan public static int getUpdatePropagatorDefaultThreadCount() { return getThreadCountByPercent(0.10); } private final ConfigEntryWithPresetOptions UpdatePropagatorThreadCount = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.MultiThreading.numberOfUpdatePropagatorThreads, - new HashMap() + new HashMap<>() {{ this.put(EDhApiThreadPreset.MINIMAL_IMPACT, 1); this.put(EDhApiThreadPreset.LOW_IMPACT, getUpdatePropagatorDefaultThreadCount()); @@ -96,7 +96,7 @@ public class ThreadPresetConfigEventHandler extends AbstractPresetConfigEventHan }}); public static double getUpdatePropagatorDefaultRunTimeRatio() { return 0.25; } private final ConfigEntryWithPresetOptions UpdatePropagatorRunTime = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.MultiThreading.runTimeRatioForUpdatePropagatorThreads, - new HashMap() + new HashMap<>() {{ this.put(EDhApiThreadPreset.MINIMAL_IMPACT, 0.1); this.put(EDhApiThreadPreset.LOW_IMPACT, getUpdatePropagatorDefaultRunTimeRatio()); @@ -108,7 +108,7 @@ public class ThreadPresetConfigEventHandler extends AbstractPresetConfigEventHan public static int getLodBuilderDefaultThreadCount() { return getThreadCountByPercent(0.1); } private final ConfigEntryWithPresetOptions lodBuilderThreadCount = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.MultiThreading.numberOfLodBuilderThreads, - new HashMap() + new HashMap<>() {{ this.put(EDhApiThreadPreset.MINIMAL_IMPACT, 1); this.put(EDhApiThreadPreset.LOW_IMPACT, getLodBuilderDefaultThreadCount()); @@ -118,7 +118,7 @@ public class ThreadPresetConfigEventHandler extends AbstractPresetConfigEventHan }}); public static double getLodBuilderDefaultRunTimeRatio() { return 0.25; } private final ConfigEntryWithPresetOptions lodBuilderRunTime = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.MultiThreading.runTimeRatioForLodBuilderThreads, - new HashMap() + new HashMap<>() {{ this.put(EDhApiThreadPreset.MINIMAL_IMPACT, 0.1); this.put(EDhApiThreadPreset.LOW_IMPACT, getLodBuilderDefaultRunTimeRatio()); @@ -153,7 +153,7 @@ public class ThreadPresetConfigEventHandler extends AbstractPresetConfigEventHan for (ConfigEntryWithPresetOptions config : this.configList) { // ignore try-using, the listeners should only ever be added once and should never be removed - new ConfigChangeListener<>(config.configEntry, (val) -> { this.onConfigValueChanged(); }); + new ConfigChangeListener<>(config.configEntry, (val) -> this.onConfigValueChanged()); } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/file/ConfigTypeConverters.java b/core/src/main/java/com/seibel/distanthorizons/core/config/file/ConfigTypeConverters.java index 57418ad80..8475381eb 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/file/ConfigTypeConverters.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/file/ConfigTypeConverters.java @@ -35,7 +35,7 @@ import java.util.Map; public class ConfigTypeConverters { // Once you've made a converter add it to here where the first value is the type you want to convert and the 2nd value is the converter - public static final Map, ConverterBase> convertObjects = new HashMap, ConverterBase>() + public static final Map, ConverterBase> convertObjects = new HashMap<>() {{ this.put(Short.class, new ShortConverter()); this.put(Long.class, new LongConverter()); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/gui/EmbeddedFrameUtil.java b/core/src/main/java/com/seibel/distanthorizons/core/config/gui/EmbeddedFrameUtil.java index 46e90981b..c1703a42b 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/gui/EmbeddedFrameUtil.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/gui/EmbeddedFrameUtil.java @@ -73,33 +73,28 @@ public final class EmbeddedFrameUtil private static String getEmbeddedFrameImpl() { - switch (EPlatform.get()) + return switch (EPlatform.get()) { - case LINUX: - return "sun.awt.X11.XEmbeddedFrame"; - case WINDOWS: - return "sun.awt.windows.WEmbeddedFrame"; - case MACOS: - return "sun.lwawt.macosx.CViewEmbeddedFrame"; - default: - throw new IllegalStateException(); - } + case LINUX -> "sun.awt.X11.XEmbeddedFrame"; + case WINDOWS -> "sun.awt.windows.WEmbeddedFrame"; + case MACOS -> "sun.lwawt.macosx.CViewEmbeddedFrame"; + default -> throw new IllegalStateException(); + }; } private static long getEmbeddedFrameHandle(long window) { - switch (EPlatform.get()) + return switch (EPlatform.get()) { - case LINUX: - return glfwGetX11Window(window); - case WINDOWS: - return glfwGetWin32Window(window); - case MACOS: + case LINUX -> glfwGetX11Window(window); + case WINDOWS -> glfwGetWin32Window(window); + case MACOS -> + { long objc_msgSend = ObjCRuntime.getLibrary().getFunctionAddress("objc_msgSend"); - return invokePPP(glfwGetCocoaWindow(window), sel_getUid("contentView"), objc_msgSend); - default: - throw new IllegalStateException(); - } + yield invokePPP(glfwGetCocoaWindow(window), sel_getUid("contentView"), objc_msgSend); + } + default -> throw new IllegalStateException(); + }; } public static Frame embeddedFrameCreate(long window) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/FullDataPointIdMap.java b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/FullDataPointIdMap.java index 5cb41981e..93fc1e000 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/FullDataPointIdMap.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/FullDataPointIdMap.java @@ -516,10 +516,9 @@ public class FullDataPointIdMap if (otherObj == this) return true; - if (!(otherObj instanceof Entry)) + if (!(otherObj instanceof Entry other)) return false; - Entry other = (Entry) otherObj; return other.biome.getSerialString().equals(this.biome.getSerialString()) && other.blockState.getSerialString().equals(this.blockState.getSerialString()); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/FullDataSourceV2.java b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/FullDataSourceV2.java index a727c05c5..36924527d 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/FullDataSourceV2.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/FullDataSourceV2.java @@ -927,11 +927,10 @@ public class FullDataSourceV2 implements IDataSource @Override public boolean equals(Object obj) { - if (!(obj instanceof FullDataSourceV2)) + if (!(obj instanceof FullDataSourceV2 other)) { return false; } - FullDataSourceV2 other = (FullDataSourceV2) obj; if (other.pos != this.pos) { diff --git a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/render/bufferBuilding/BufferQuad.java b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/render/bufferBuilding/BufferQuad.java index 8392c25c3..e14faa9d1 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/render/bufferBuilding/BufferQuad.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/render/bufferBuilding/BufferQuad.java @@ -99,33 +99,23 @@ public final class BufferQuad if (compareDirection == BufferMergeDirectionEnum.EastWest) { - switch (this.direction.getAxis()) + return switch (this.direction.getAxis()) { - case X: - return threeDimensionalCompare(this.x, this.y, this.z, quad.x, quad.y, quad.z); - case Y: - return threeDimensionalCompare(this.y, this.z, this.x, quad.y, quad.z, quad.x); - case Z: - return threeDimensionalCompare(this.z, this.y, this.x, quad.z, quad.y, quad.x); - - default: - throw new IllegalArgumentException("Invalid Axis enum: " + this.direction.getAxis()); - } + case X -> threeDimensionalCompare(this.x, this.y, this.z, quad.x, quad.y, quad.z); + case Y -> threeDimensionalCompare(this.y, this.z, this.x, quad.y, quad.z, quad.x); + case Z -> threeDimensionalCompare(this.z, this.y, this.x, quad.z, quad.y, quad.x); + default -> throw new IllegalArgumentException("Invalid Axis enum: " + this.direction.getAxis()); + }; } else { - switch (this.direction.getAxis()) + return switch (this.direction.getAxis()) { - case X: - return threeDimensionalCompare(this.x, this.z, this.y, quad.x, quad.z, quad.y); - case Y: - return threeDimensionalCompare(this.y, this.x, this.z, quad.y, quad.x, quad.z); - case Z: - return threeDimensionalCompare(this.z, this.x, this.y, quad.z, quad.x, quad.y); - - default: - throw new IllegalArgumentException("Invalid Axis enum: " + this.direction.getAxis()); - } + case X -> threeDimensionalCompare(this.x, this.z, this.y, quad.x, quad.z, quad.y); + case Y -> threeDimensionalCompare(this.y, this.x, this.z, quad.y, quad.x, quad.z); + case Z -> threeDimensionalCompare(this.z, this.x, this.y, quad.z, quad.x, quad.y); + default -> throw new IllegalArgumentException("Invalid Axis enum: " + this.direction.getAxis()); + }; } } /** diff --git a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/render/bufferBuilding/CubicLodTemplate.java b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/render/bufferBuilding/CubicLodTemplate.java index a45fb2ec4..a6f43b273 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/render/bufferBuilding/CubicLodTemplate.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/render/bufferBuilding/CubicLodTemplate.java @@ -97,61 +97,28 @@ public class CubicLodTemplate case SHOW_BLOCK_MATERIAL: { - switch (EDhApiBlockMaterial.getFromIndex(blockMaterialId)) + color = switch (EDhApiBlockMaterial.getFromIndex(blockMaterialId)) { - case UNKNOWN: - case AIR: // shouldn't normally be rendered, but just in case - color = ColorUtil.HOT_PINK; - break; - - case LEAVES: - color = ColorUtil.DARK_GREEN; - break; - case STONE: - color = ColorUtil.GRAY; - break; - case WOOD: - color = ColorUtil.BROWN; - break; - case METAL: - color = ColorUtil.DARK_GRAY; - break; - case DIRT: - color = ColorUtil.LIGHT_BROWN; - break; - case LAVA: - color = ColorUtil.ORANGE; - break; - case DEEPSLATE: - color = ColorUtil.BLACK; - break; - case SNOW: - color = ColorUtil.WHITE; - break; - case SAND: - color = ColorUtil.TAN; - break; - case TERRACOTTA: - color = ColorUtil.DARK_ORANGE; - break; - case NETHER_STONE: - color = ColorUtil.DARK_RED; - break; - case WATER: - color = ColorUtil.BLUE; - break; - case GRASS: - color = ColorUtil.GREEN; - break; - case ILLUMINATED: - color = ColorUtil.YELLOW; - break; - - default: + case UNKNOWN, AIR -> // shouldn't normally be rendered, but just in case + ColorUtil.HOT_PINK; + case LEAVES -> ColorUtil.DARK_GREEN; + case STONE -> ColorUtil.GRAY; + case WOOD -> ColorUtil.BROWN; + case METAL -> ColorUtil.DARK_GRAY; + case DIRT -> ColorUtil.LIGHT_BROWN; + case LAVA -> ColorUtil.ORANGE; + case DEEPSLATE -> ColorUtil.BLACK; + case SNOW -> ColorUtil.WHITE; + case SAND -> ColorUtil.TAN; + case TERRACOTTA -> ColorUtil.DARK_ORANGE; + case NETHER_STONE -> ColorUtil.DARK_RED; + case WATER -> ColorUtil.BLUE; + case GRASS -> ColorUtil.GREEN; + case ILLUMINATED -> ColorUtil.YELLOW; + default -> // undefined color - color = ColorUtil.CYAN; - break; - } + ColorUtil.CYAN; + }; fullBright = true; break; diff --git a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/render/bufferBuilding/LodQuadBuilder.java b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/render/bufferBuilding/LodQuadBuilder.java index ab3605bdd..4b23bb380 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/render/bufferBuilding/LodQuadBuilder.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/render/bufferBuilding/LodQuadBuilder.java @@ -168,8 +168,8 @@ public class LodQuadBuilder ArrayList quadList = (this.doTransparency && ColorUtil.getAlpha(color) < 255) ? this.transparentQuads[dir.ordinal()] : this.opaqueQuads[dir.ordinal()]; if (!quadList.isEmpty() && ( - quadList.get(quadList.size() - 1).tryMerge(quad, BufferMergeDirectionEnum.EastWest) - || quadList.get(quadList.size() - 1).tryMerge(quad, BufferMergeDirectionEnum.NorthSouthOrUpDown)) + quadList.getLast().tryMerge(quad, BufferMergeDirectionEnum.EastWest) + || quadList.getLast().tryMerge(quad, BufferMergeDirectionEnum.NorthSouthOrUpDown)) ) { this.premergeCount++; @@ -196,8 +196,8 @@ public class LodQuadBuilder // attempt to merge this quad with adjacent ones if (!quadList.isEmpty() && ( - quadList.get(quadList.size() - 1).tryMerge(quad, BufferMergeDirectionEnum.EastWest) - || quadList.get(quadList.size() - 1).tryMerge(quad, BufferMergeDirectionEnum.NorthSouthOrUpDown)) + quadList.getLast().tryMerge(quad, BufferMergeDirectionEnum.EastWest) + || quadList.getLast().tryMerge(quad, BufferMergeDirectionEnum.NorthSouthOrUpDown)) ) { this.premergeCount++; @@ -215,8 +215,8 @@ public class LodQuadBuilder ArrayList qs = (doTransparency && ColorUtil.getAlpha(color) < 255) ? transparentQuads[EDhDirection.DOWN.ordinal()] : opaqueQuads[EDhDirection.DOWN.ordinal()]; if (!qs.isEmpty() && - (qs.get(qs.size() - 1).tryMerge(quad, BufferMergeDirectionEnum.EastWest) - || qs.get(qs.size() - 1).tryMerge(quad, BufferMergeDirectionEnum.NorthSouthOrUpDown)) + (qs.getLast().tryMerge(quad, BufferMergeDirectionEnum.EastWest) + || qs.getLast().tryMerge(quad, BufferMergeDirectionEnum.NorthSouthOrUpDown)) ) { premergeCount++; @@ -434,7 +434,7 @@ public class LodQuadBuilder public Iterator makeOpaqueVertexBuffers() { - return new Iterator() + return new Iterator<>() { final ByteBuffer bb = ByteBuffer.allocateDirect(ColumnRenderBuffer.FULL_SIZED_BUFFER) .order(ByteOrder.nativeOrder()); @@ -502,7 +502,7 @@ public class LodQuadBuilder public Iterator makeTransparentVertexBuffers() { - return new Iterator() + return new Iterator<>() { final ByteBuffer bb = ByteBuffer.allocateDirect(ColumnRenderBuffer.FULL_SIZED_BUFFER) .order(ByteOrder.nativeOrder()); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/render/columnViews/ColumnArrayView.java b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/render/columnViews/ColumnArrayView.java index 88bd337b3..8c4d06574 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/render/columnViews/ColumnArrayView.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/render/columnViews/ColumnArrayView.java @@ -199,7 +199,7 @@ public final class ColumnArrayView implements IColumnDataView for (int i = offset; i < end; i++) { long element = a.getLong(i); - int elementHash = (int) (element ^ (element >>> 32)); + int elementHash = Long.hashCode(element); result = 31 * result + elementHash; } return result; diff --git a/core/src/main/java/com/seibel/distanthorizons/core/enums/EDhDirection.java b/core/src/main/java/com/seibel/distanthorizons/core/enums/EDhDirection.java index 757200b18..e3b5f8e4c 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/enums/EDhDirection.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/enums/EDhDirection.java @@ -98,9 +98,7 @@ public enum EDhDirection private static final EDhDirection[] VALUES = values(); private static final Map BY_NAME = Arrays.stream(VALUES).collect(Collectors.toMap(EDhDirection::getName, (p_199787_0_) -> - { - return p_199787_0_; - })); + p_199787_0_)); // private static final LodDirection[] BY_3D_DATA = Arrays.stream(VALUES).sorted(Comparator.comparingInt((p_199790_0_) -> // { @@ -247,36 +245,26 @@ public enum EDhDirection public EDhDirection getClockWise() { - switch (this) + return switch (this) { - case NORTH: - return EAST; - case SOUTH: - return WEST; - case WEST: - return NORTH; - case EAST: - return SOUTH; - default: - throw new IllegalStateException("Unable to get Y-rotated facing of " + this); - } + case NORTH -> EAST; + case SOUTH -> WEST; + case WEST -> NORTH; + case EAST -> SOUTH; + default -> throw new IllegalStateException("Unable to get Y-rotated facing of " + this); + }; } public EDhDirection getCounterClockWise() { - switch (this) + return switch (this) { - case NORTH: - return WEST; - case SOUTH: - return EAST; - case WEST: - return SOUTH; - case EAST: - return NORTH; - default: - throw new IllegalStateException("Unable to get CCW facing of " + this); - } + case NORTH -> WEST; + case SOUTH -> EAST; + case WEST -> SOUTH; + case EAST -> NORTH; + default -> throw new IllegalStateException("Unable to get CCW facing of " + this); + }; } public String getName() @@ -317,16 +305,11 @@ public enum EDhDirection public static EDhDirection fromAxisAndDirection(EDhDirection.Axis p_211699_0_, EDhDirection.AxisDirection p_211699_1_) { - switch (p_211699_0_) - { - case X: - return p_211699_1_ == EDhDirection.AxisDirection.POSITIVE ? EAST : WEST; - case Y: - return p_211699_1_ == EDhDirection.AxisDirection.POSITIVE ? UP : DOWN; - case Z: - default: - return p_211699_1_ == EDhDirection.AxisDirection.POSITIVE ? SOUTH : NORTH; - } + return switch (p_211699_0_) { + case X -> p_211699_1_ == AxisDirection.POSITIVE ? EAST : WEST; + case Y -> p_211699_1_ == AxisDirection.POSITIVE ? UP : DOWN; + default -> p_211699_1_ == AxisDirection.POSITIVE ? SOUTH : NORTH; + }; } // public float toYRot() @@ -436,9 +419,7 @@ public enum EDhDirection private static final EDhDirection.Axis[] VALUES = values(); private static final Map BY_NAME = Arrays.stream(VALUES).collect(Collectors.toMap(EDhDirection.Axis::getName, (p_199785_0_) -> - { - return p_199785_0_; - })); + p_199785_0_)); private final String name; Axis(String name) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/FullDataSourceProviderV2.java b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/FullDataSourceProviderV2.java index a4ff3cbb0..3ca1dc915 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/FullDataSourceProviderV2.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/FullDataSourceProviderV2.java @@ -125,10 +125,10 @@ public class FullDataSourceProviderV2 // start migrating any legacy data sources present in the background this.migrationThreadPool = ThreadUtil.makeRateLimitedThreadPool(1, MIGRATION_THREAD_NAME_PREFIX +"["+dimensionName+"]", Config.Client.Advanced.MultiThreading.runTimeRatioForUpdatePropagatorThreads.get(), Thread.MIN_PRIORITY, (Semaphore)null); - this.migrationThreadPool.execute(() -> this.convertLegacyDataSources()); + this.migrationThreadPool.execute(this::convertLegacyDataSources); this.updateQueueProcessor = ThreadUtil.makeSingleThreadPool("Parent Update Queue ["+dimensionName+"]"); - this.updateQueueProcessor.execute(() -> this.runUpdateQueue()); + this.updateQueueProcessor.execute(this::runUpdateQueue); } @@ -604,12 +604,12 @@ public class FullDataSourceProviderV2 public void debugRender(DebugRenderer renderer) { this.lockedPosSet - .forEach((pos) -> { renderer.renderBox(new DebugRenderer.Box(pos, -32f, 74f, 0.15f, Color.PINK)); }); + .forEach((pos) -> renderer.renderBox(new DebugRenderer.Box(pos, -32f, 74f, 0.15f, Color.PINK))); this.queuedUpdateCountsByPos - .forEach((pos, updateCountRef) -> { renderer.renderBox(new DebugRenderer.Box(pos, -32f, 80f + (updateCountRef.get() * 16f), 0.20f, Color.WHITE)); }); + .forEach((pos, updateCountRef) -> renderer.renderBox(new DebugRenderer.Box(pos, -32f, 80f + (updateCountRef.get() * 16f), 0.20f, Color.WHITE))); this.parentUpdatingPosSet - .forEach((pos) -> { renderer.renderBox(new DebugRenderer.Box(pos, -32f, 80f, 0.20f, Color.MAGENTA)); }); + .forEach((pos) -> renderer.renderBox(new DebugRenderer.Box(pos, -32f, 80f, 0.20f, Color.MAGENTA))); } @Override diff --git a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/GeneratedFullDataSourceProvider.java b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/GeneratedFullDataSourceProvider.java index 37c6ee221..1a4651619 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/GeneratedFullDataSourceProvider.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/GeneratedFullDataSourceProvider.java @@ -111,7 +111,7 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im // if the generation task was split up into smaller positions, add the on-complete event to them for (CompletableFuture siblingFuture : genTaskResult.childFutures) { - siblingFuture.whenComplete((siblingGenTaskResult, siblingEx) -> this.onWorldGenTaskComplete(siblingGenTaskResult, siblingEx)); + siblingFuture.whenComplete(this::onWorldGenTaskComplete); } } @@ -215,7 +215,7 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im GenTask genTask = new GenTask(genPos); CompletableFuture worldGenFuture = worldGenQueue.submitGenTask(genPos, (byte) (DhSectionPos.getDetailLevel(genPos) - DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL), genTask); - worldGenFuture.whenComplete((genTaskResult, ex) -> this.onWorldGenTaskComplete(genTaskResult, ex)); + worldGenFuture.whenComplete(this::onWorldGenTaskComplete); return true; } @@ -362,7 +362,7 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im super.debugRender(renderer); this.delayedFullDataSourceSaveCache.dataSourceByPosition - .forEach((pos, dataSource) -> { renderer.renderBox(new DebugRenderer.Box(pos, -32f, 80f, 0.20f, Color.green.darker())); }); + .forEach((pos, dataSource) -> renderer.renderBox(new DebugRenderer.Box(pos, -32f, 80f, 0.20f, Color.green.darker()))); } @@ -387,10 +387,7 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im @Override public Consumer getChunkDataConsumer() { - return (chunkSizedFullDataSource) -> - { - GeneratedFullDataSourceProvider.this.delayedFullDataSourceSaveCache.queueDataSourceForUpdateAndSave(chunkSizedFullDataSource); - }; + return GeneratedFullDataSourceProvider.this.delayedFullDataSourceSaveCache::queueDataSourceForUpdateAndSave; } } private void onDataSourceSave(FullDataSourceV2 fullDataSource) 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..bf1211a55 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 @@ -85,9 +85,8 @@ public class ClientOnlySaveStructure extends AbstractSaveStructure return this.levelWrapperToFileMap.computeIfAbsent(levelWrapper, (newLevelWrapper) -> { // Use the server provided key if one was provided - if (newLevelWrapper instanceof IServerKeyedClientLevel) + if (newLevelWrapper instanceof IServerKeyedClientLevel keyedClientLevel) { - IServerKeyedClientLevel keyedClientLevel = (IServerKeyedClientLevel) newLevelWrapper; LOGGER.info("Loading level " + newLevelWrapper.getDimensionType().getDimensionName() + " with key: " + keyedClientLevel.getServerLevelKey()); // This world was identified by the server directly, so we can know for sure which folder to use. return new File(getSaveStructureFolderPath() + File.separatorChar + keyedClientLevel.getServerLevelKey()); @@ -95,9 +94,8 @@ public class ClientOnlySaveStructure extends AbstractSaveStructure // use multiverse matching if enabled and in multiplayer (the server should already know where the player is) - if (newLevelWrapper instanceof IClientLevelWrapper && Config.Client.Advanced.Multiplayer.multiverseSimilarityRequiredPercent.get() != 0) + if (newLevelWrapper instanceof IClientLevelWrapper newClientLevelWrapper && Config.Client.Advanced.Multiplayer.multiverseSimilarityRequiredPercent.get() != 0) { - IClientLevelWrapper newClientLevelWrapper = (IClientLevelWrapper) newLevelWrapper; // create the matcher if one doesn't exist if (this.subDimMatcher == null || !this.subDimMatcher.isFindingLevel(newClientLevelWrapper)) @@ -134,12 +132,12 @@ public class ClientOnlySaveStructure extends AbstractSaveStructure private File getLevelFolderWithoutSimilarityMatching(ILevelWrapper level) { List folders = this.getDhDataFoldersForDimension(level.getDimensionType()); - if (!folders.isEmpty() && folders.get(0) != null) + if (!folders.isEmpty() && folders.getFirst() != null) { // use the first existing sub-dimension - String folderName = folders.get(0).getName(); + String folderName = folders.getFirst().getName(); LOGGER.info("Default Sub Dimension set to: [" + LodUtil.shortenString(folderName, 8) + "...]"); - return folders.get(0); + return folders.getFirst(); } else { @@ -270,27 +268,14 @@ public class ClientOnlySaveStructure extends AbstractSaveStructure // generate the folder name - String folderName; - switch (folderNameMode) + String folderName = switch (folderNameMode) { - default: - case NAME_ONLY: - folderName = serverName; - break; - case IP_ONLY: - folderName = serverIpCleaned; - break; - - case NAME_IP: - folderName = serverName + ", IP " + serverIpCleaned; - break; - case NAME_IP_PORT: - folderName = serverName + ", IP " + serverIpCleaned + (serverPortCleaned.length() != 0 ? ("-" + serverPortCleaned) : ""); - break; - case NAME_IP_PORT_MC_VERSION: - folderName = serverName + ", IP " + serverIpCleaned + (serverPortCleaned.length() != 0 ? ("-" + serverPortCleaned) : "") + ", GameVersion " + serverMcVersion; - break; - } + default -> serverName; + case IP_ONLY -> serverIpCleaned; + case NAME_IP -> serverName + ", IP " + serverIpCleaned; + case NAME_IP_PORT -> serverName + ", IP " + serverIpCleaned + (serverPortCleaned.length() != 0 ? ("-" + serverPortCleaned) : ""); + case NAME_IP_PORT_MC_VERSION -> serverName + ", IP " + serverIpCleaned + (serverPortCleaned.length() != 0 ? ("-" + serverPortCleaned) : "") + ", GameVersion " + serverMcVersion; + }; // PercentEscaper makes the characters all part of the standard alphameric character set // This fixes some issues when the server is named something in other languages diff --git a/core/src/main/java/com/seibel/distanthorizons/core/generation/BatchGenerator.java b/core/src/main/java/com/seibel/distanthorizons/core/generation/BatchGenerator.java index 598687bfe..5dd895ccb 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/generation/BatchGenerator.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/generation/BatchGenerator.java @@ -109,23 +109,17 @@ public class BatchGenerator implements IDhApiWorldGenerator int chunkPosMinX, int chunkPosMinZ, byte granularity, byte targetDataDetail, EDhApiDistantGeneratorMode generatorMode, ExecutorService worldGeneratorThreadPool, Consumer resultConsumer) { - EDhApiWorldGenerationStep targetStep = null; - switch (generatorMode) + EDhApiWorldGenerationStep targetStep = switch (generatorMode) { - case PRE_EXISTING_ONLY: // Only load in existing chunks. Note: this requires the biome generation step in order for biomes to be properly initialized. - //case BIOME_ONLY: // No blocks. Require fake height in LodBuilder - targetStep = EDhApiWorldGenerationStep.BIOMES; - break; + case PRE_EXISTING_ONLY -> // Only load in existing chunks. Note: this requires the biome generation step in order for biomes to be properly initialized. + //case BIOME_ONLY: // No blocks. Require fake height in LodBuilder + EDhApiWorldGenerationStep.BIOMES; //case BIOME_ONLY_SIMULATE_HEIGHT: // targetStep = EDhApiWorldGenerationStep.NOISE; // Stone only. Requires a fake surface // break; - case SURFACE: - targetStep = EDhApiWorldGenerationStep.SURFACE; - break; - case FEATURES: - targetStep = EDhApiWorldGenerationStep.FEATURES; - break; - } + case SURFACE -> EDhApiWorldGenerationStep.SURFACE; + case FEATURES -> EDhApiWorldGenerationStep.FEATURES; + }; int genChunkSize = BitShiftUtil.powerOfTwo(granularity - 4); // minus 4 is equal to dividing by 16 to convert to chunk scale diff --git a/core/src/main/java/com/seibel/distanthorizons/core/generation/DhLightingEngine.java b/core/src/main/java/com/seibel/distanthorizons/core/generation/DhLightingEngine.java index c160ef482..8e5382c65 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/generation/DhLightingEngine.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/generation/DhLightingEngine.java @@ -49,8 +49,8 @@ public class DhLightingEngine * Since these objects are always mutated anyway, using a {@link ThreadLocal} will allow us to * only create as many of these {@link DhBlockPos} as necessary. */ - private static final ThreadLocal PRIMARY_BLOCK_POS_REF = ThreadLocal.withInitial(() -> new DhBlockPos()); - private static final ThreadLocal SECONDARY_BLOCK_POS_REF = ThreadLocal.withInitial(() -> new DhBlockPos()); + private static final ThreadLocal PRIMARY_BLOCK_POS_REF = ThreadLocal.withInitial(DhBlockPos::new); + private static final ThreadLocal SECONDARY_BLOCK_POS_REF = ThreadLocal.withInitial(DhBlockPos::new); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/generation/WorldGenerationQueue.java b/core/src/main/java/com/seibel/distanthorizons/core/generation/WorldGenerationQueue.java index f03394a07..d9dde6c89 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/generation/WorldGenerationQueue.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/generation/WorldGenerationQueue.java @@ -428,18 +428,16 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb { EDhApiDistantGeneratorMode generatorMode = Config.Client.Advanced.WorldGenerator.distantGeneratorMode.get(); EDhApiWorldGeneratorReturnType returnType = this.generator.getReturnType(); - switch (returnType) + return switch (returnType) { - case VANILLA_CHUNKS: - { - return this.generator.generateChunks( + case VANILLA_CHUNKS -> this.generator.generateChunks( chunkPosMin.x, chunkPosMin.z, granularity, targetDataDetail, generatorMode, ThreadPoolUtil.getWorldGenExecutor(), - (Object[] generatedObjectArray) -> + (Object[] generatedObjectArray) -> { try { @@ -454,11 +452,8 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb Config.Client.Advanced.WorldGenerator.enableDistantGeneration.set(false); } } - ); - } - case API_CHUNKS: - { - return this.generator.generateApiChunks( + ); + case API_CHUNKS -> this.generator.generateApiChunks( chunkPosMin.x, chunkPosMin.z, granularity, @@ -483,14 +478,13 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb Config.Client.Advanced.WorldGenerator.enableDistantGeneration.set(false); } } - ); - } - default: + ); + default -> { Config.Client.Advanced.WorldGenerator.enableDistantGeneration.set(false); throw new AssertFailureException("Unknown return type: " + returnType); } - } + }; } @@ -616,8 +610,8 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb @Override public void debugRender(DebugRenderer renderer) { - this.waitingTasks.keySet().forEach((pos) -> { renderer.renderBox(new DebugRenderer.Box(pos, -32f, 64f, 0.05f, Color.blue)); }); - this.inProgressGenTasksByLodPos.forEach((pos, t) -> { renderer.renderBox(new DebugRenderer.Box(pos, -32f, 64f, 0.05f, Color.red)); }); + this.waitingTasks.keySet().forEach((pos) -> renderer.renderBox(new DebugRenderer.Box(pos, -32f, 64f, 0.05f, Color.blue))); + this.inProgressGenTasksByLodPos.forEach((pos, t) -> renderer.renderBox(new DebugRenderer.Box(pos, -32f, 64f, 0.05f, Color.red))); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/jar/DarkModeDetector.java b/core/src/main/java/com/seibel/distanthorizons/core/jar/DarkModeDetector.java index e6cdc8c61..850803229 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/jar/DarkModeDetector.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/jar/DarkModeDetector.java @@ -40,20 +40,14 @@ public class DarkModeDetector public static boolean isDarkMode() { - switch (EPlatform.get()) + return switch (EPlatform.get()) { - case WINDOWS: - return isWindowsDarkMode(); - case MACOS: - return isMacOsDarkMode(); - case LINUX: - // Most Unix(-like) distros also use a lot of the same things as Linux (like desktop environments and window managers) - case BSD: - case UNIX: - return checkLinuxDark(); - default: - return false; - } + case WINDOWS -> isWindowsDarkMode(); + case MACOS -> isMacOsDarkMode(); + // Most Unix(-like) distros also use a lot of the same things as Linux (like desktop environments and window managers) + case LINUX, BSD, UNIX -> checkLinuxDark(); + default -> false; + }; } // Needs checking as I dont use Mac diff --git a/core/src/main/java/com/seibel/distanthorizons/core/jar/JarMain.java b/core/src/main/java/com/seibel/distanthorizons/core/jar/JarMain.java index 48857c0d3..194c378ae 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/jar/JarMain.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/jar/JarMain.java @@ -131,7 +131,7 @@ public class JarMain // Selected download - AtomicReference downloadID = new AtomicReference(""); + AtomicReference downloadID = new AtomicReference<>(""); // This is for the panel to show the update description diff --git a/core/src/main/java/com/seibel/distanthorizons/core/jar/JarUtils.java b/core/src/main/java/com/seibel/distanthorizons/core/jar/JarUtils.java index f607b98fb..cfc080cbc 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/jar/JarUtils.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/jar/JarUtils.java @@ -175,17 +175,12 @@ public class JarUtils @Deprecated public static OperatingSystem getOperatingSystem() { // Get the os and turn it into that enum - switch (EPlatform.get()) - { - case WINDOWS: - return OperatingSystem.WINDOWS; - case LINUX: - return OperatingSystem.LINUX; - case MACOS: - return OperatingSystem.MACOS; - default: - return OperatingSystem.NONE; - } + return switch (EPlatform.get()) { + case WINDOWS -> OperatingSystem.WINDOWS; + case LINUX -> OperatingSystem.LINUX; + case MACOS -> OperatingSystem.MACOS; + default -> OperatingSystem.NONE; + }; } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/jar/gui/BaseJFrame.java b/core/src/main/java/com/seibel/distanthorizons/core/jar/gui/BaseJFrame.java index 25c2908de..f45c1a450 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/jar/gui/BaseJFrame.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/jar/gui/BaseJFrame.java @@ -89,7 +89,7 @@ public class BaseJFrame extends JFrame final BufferedReader br = new BufferedReader(isr) ) { - List col = Collections.unmodifiableList(new ArrayList<>(Arrays.asList(br.lines().toArray()))); + List col = List.of(br.lines().toArray()); for (Object obj : col) { langsToChoose.add(((String) obj).replaceAll("\\.json", "")); @@ -101,7 +101,7 @@ public class BaseJFrame extends JFrame } // Creates the box - JComboBox languageBox = new JComboBox(new DefaultComboBoxModel(langsToChoose.toArray())); + JComboBox languageBox = new JComboBox<>(new DefaultComboBoxModel(langsToChoose.toArray())); languageBox.setSelectedIndex(langsToChoose.indexOf(Locale.getDefault().toString().toLowerCase())); languageBox.addActionListener(e -> { Locale.setDefault(Locale.forLanguageTag(languageBox.getSelectedItem().toString())); // Change lang on update diff --git a/core/src/main/java/com/seibel/distanthorizons/core/jar/installer/GitlabGetter.java b/core/src/main/java/com/seibel/distanthorizons/core/jar/installer/GitlabGetter.java index e35396cee..2ebf667e3 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/jar/installer/GitlabGetter.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/jar/installer/GitlabGetter.java @@ -133,7 +133,7 @@ public class GitlabGetter public static void main(String[] args) { GitlabGetter gitlabGetter = new GitlabGetter(); - System.out.println(gitlabGetter.getDownloads(gitlabGetter.projectPipelines.get(0).get("id"))); + System.out.println(gitlabGetter.getDownloads(gitlabGetter.projectPipelines.getFirst().get("id"))); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/jar/installer/ModrinthGetter.java b/core/src/main/java/com/seibel/distanthorizons/core/jar/installer/ModrinthGetter.java index 6580e7f4b..b661ea61c 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/jar/installer/ModrinthGetter.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/jar/installer/ModrinthGetter.java @@ -72,8 +72,8 @@ public class ModrinthGetter downloadUrl.put(workingID, new URL( ((Config) - ((ArrayList) currentRelease.get("files")) - .get(0)) + ((ArrayList) currentRelease.get("files")) + .getFirst()) .get("url") .toString() )); @@ -112,7 +112,7 @@ public class ModrinthGetter { try { - return mcVerToReleaseID.get(mcVer).get(0); + return mcVerToReleaseID.get(mcVer).getFirst(); } catch (Exception e) { @@ -121,17 +121,17 @@ public class ModrinthGetter } public static String getLatestNameForVersion(String mcVer) { - return releaseNames.get(mcVerToReleaseID.get(mcVer).get(0)); + return releaseNames.get(mcVerToReleaseID.get(mcVer).getFirst()); } public static URL getLatestDownloadForVersion(String mcVer) { - return downloadUrl.get(mcVerToReleaseID.get(mcVer).get(0)); + return downloadUrl.get(mcVerToReleaseID.get(mcVer).getFirst()); } public static String getLatestShaForVersion(String mcVer) { return (((ArrayList) idToJson.get( - mcVerToReleaseID.get(mcVer).get(0) - ).get("files")).get(0).get("hashes.sha1") + mcVerToReleaseID.get(mcVer).getFirst() + ).get("files")).getFirst().get("hashes.sha1") .toString()); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/jar/updater/SelfUpdater.java b/core/src/main/java/com/seibel/distanthorizons/core/jar/updater/SelfUpdater.java index e07752a2f..0271c61eb 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/jar/updater/SelfUpdater.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/jar/updater/SelfUpdater.java @@ -136,7 +136,7 @@ public class SelfUpdater { if (GitlabGetter.INSTANCE.projectPipelines.size() == 0) return false; - com.electronwill.nightconfig.core.Config pipeline = GitlabGetter.INSTANCE.projectPipelines.get(0); + com.electronwill.nightconfig.core.Config pipeline = GitlabGetter.INSTANCE.projectPipelines.getFirst(); if (!pipeline.get("ref").equals(ModJarInfo.Git_Branch)) { @@ -186,16 +186,13 @@ public class SelfUpdater } public static boolean updateMod(String minecraftVersion, File file) { - boolean returnValue = false; - switch (Config.Client.Advanced.AutoUpdater.updateBranch.get()) + boolean returnValue = switch (Config.Client.Advanced.AutoUpdater.updateBranch.get()) { - case STABLE: - returnValue = updateStableMod(minecraftVersion, file); - break; - case NIGHTLY: - returnValue = updateNightlyMod(minecraftVersion, file); - break; + case STABLE -> updateStableMod(minecraftVersion, file); + case NIGHTLY -> updateNightlyMod(minecraftVersion, file); + default -> false; }; + ; return returnValue; } @@ -253,7 +250,7 @@ public class SelfUpdater File mergedZip = file.getParentFile().toPath().resolve("merged.zip").toFile(); - WebDownloader.downloadAsFile(GitlabGetter.INSTANCE.getDownloads(GitlabGetter.INSTANCE.projectPipelines.get(0).get("id")).get(minecraftVersion), mergedZip); + WebDownloader.downloadAsFile(GitlabGetter.INSTANCE.getDownloads(GitlabGetter.INSTANCE.projectPipelines.getFirst().get("id")).get(minecraftVersion), mergedZip); ZipInputStream zis = new ZipInputStream(new FileInputStream(mergedZip)); ZipEntry zipEntry = zis.getNextEntry(); @@ -301,7 +298,7 @@ public class SelfUpdater } catch (Exception e) { - LOGGER.warn("Failed to update " + ModInfo.READABLE_NAME + " to version " + GitlabGetter.INSTANCE.projectPipelines.get(0).get("sha")); + LOGGER.warn("Failed to update " + ModInfo.READABLE_NAME + " to version " + GitlabGetter.INSTANCE.projectPipelines.getFirst().get("sha")); e.printStackTrace(); return false; } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/logging/ConfigBasedLogger.java b/core/src/main/java/com/seibel/distanthorizons/core/logging/ConfigBasedLogger.java index e55283313..e3ca4af0c 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/logging/ConfigBasedLogger.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/logging/ConfigBasedLogger.java @@ -38,7 +38,7 @@ public class ConfigBasedLogger public static final List> loggers - = Collections.synchronizedList(new LinkedList>()); + = Collections.synchronizedList(new LinkedList<>()); public static synchronized void updateAll() { diff --git a/core/src/main/java/com/seibel/distanthorizons/core/logging/ConfigBasedSpamLogger.java b/core/src/main/java/com/seibel/distanthorizons/core/logging/ConfigBasedSpamLogger.java index 82f9258dc..87db771cb 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/logging/ConfigBasedSpamLogger.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/logging/ConfigBasedSpamLogger.java @@ -38,7 +38,7 @@ public class ConfigBasedSpamLogger private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class); public static final List> loggers - = Collections.synchronizedList(new LinkedList>()); + = Collections.synchronizedList(new LinkedList<>()); public static synchronized void updateAll(boolean flush) { diff --git a/core/src/main/java/com/seibel/distanthorizons/core/logging/SpamReducedLogger.java b/core/src/main/java/com/seibel/distanthorizons/core/logging/SpamReducedLogger.java index 8717016f4..e744c07a2 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/logging/SpamReducedLogger.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/logging/SpamReducedLogger.java @@ -35,7 +35,7 @@ public class SpamReducedLogger private static final Logger LOGGER = LogManager.getLogger(MethodHandles.lookup().lookupClass().getSimpleName()); public static final List> loggers - = Collections.synchronizedList(new LinkedList>()); + = Collections.synchronizedList(new LinkedList<>()); public static synchronized void flushAll() { @@ -53,7 +53,7 @@ public class SpamReducedLogger public SpamReducedLogger(int maxLogPerSec) { maxLogCount = maxLogPerSec; - loggers.add(new WeakReference(this)); + loggers.add(new WeakReference<>(this)); } public void reset() diff --git a/core/src/main/java/com/seibel/distanthorizons/core/pos/DhBlockPos2D.java b/core/src/main/java/com/seibel/distanthorizons/core/pos/DhBlockPos2D.java index c6f8c1906..40955679b 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/pos/DhBlockPos2D.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/pos/DhBlockPos2D.java @@ -85,9 +85,8 @@ public class DhBlockPos2D @Override public boolean equals(Object obj) { - if (obj instanceof DhBlockPos2D) + if (obj instanceof DhBlockPos2D other) { - DhBlockPos2D other = (DhBlockPos2D) obj; return this.x == other.x && this.z == other.z; } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/pos/Pos2D.java b/core/src/main/java/com/seibel/distanthorizons/core/pos/Pos2D.java index 09988fcee..6d704d031 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/pos/Pos2D.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/pos/Pos2D.java @@ -80,9 +80,8 @@ public class Pos2D { if (otherObj == this) return true; - if (otherObj instanceof Pos2D) + if (otherObj instanceof Pos2D otherPos) { - Pos2D otherPos = (Pos2D) otherObj; return this.x == otherPos.x && this.y == otherPos.y; } return false; diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/fog/LodFogConfig.java b/core/src/main/java/com/seibel/distanthorizons/core/render/fog/LodFogConfig.java index 8e0873b93..29a6dff28 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/fog/LodFogConfig.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/fog/LodFogConfig.java @@ -179,15 +179,19 @@ public class LodFogConfig if (farFogSetting == null) { - str.append("\n" + - "float getFarFogThickness(float dist) { return 0.0; } \n" + - "float getHeightFogThickness(float dist) { return 0.0; } \n" + - "float calculateFarFogDepth(float horizontal, float dist, float uNearFogStart) { return 0.0; } \n" + - "float calculateHeightFogDepth(float vertical, float realY) { return 0.0; } \n" + - "float mixFogThickness(float near, float far, float height) \n" + - "{ \n" + - " return 0.0; \n" + - "} \n\n"); + str.append(""" + + float getFarFogThickness(float dist) { return 0.0; } + float getHeightFogThickness(float dist) { return 0.0; } + float calculateFarFogDepth(float horizontal, float dist, float uNearFogStart) { return 0.0; } + float calculateHeightFogDepth(float vertical, float realY) { return 0.0; } + float mixFogThickness(float near, float far, float height) + { + return 0.0; + } + + + """); } else { @@ -269,18 +273,13 @@ public class LodFogConfig private static String getFarFogMethod(EDhApiFogFalloff fogType) { - switch (fogType) + return switch (fogType) { - case LINEAR: - return "return linearFog(dist, farFogStart, farFogLength, farFogMin, farFogRange);\n"; - case EXPONENTIAL: - return "return exponentialFog(dist, farFogStart, farFogLength, farFogMin, farFogRange, farFogDensity);\n"; - case EXPONENTIAL_SQUARED: - return "return exponentialSquaredFog(dist, farFogStart, farFogLength, farFogMin, farFogRange, farFogDensity);\n"; - - default: - throw new IllegalArgumentException("FogType [" + fogType + "] not implemented for [getFarFogMethod]."); - } + case LINEAR -> "return linearFog(dist, farFogStart, farFogLength, farFogMin, farFogRange);\n"; + case EXPONENTIAL -> "return exponentialFog(dist, farFogStart, farFogLength, farFogMin, farFogRange, farFogDensity);\n"; + case EXPONENTIAL_SQUARED -> "return exponentialSquaredFog(dist, farFogStart, farFogLength, farFogMin, farFogRange, farFogDensity);\n"; + default -> throw new IllegalArgumentException("FogType [" + fogType + "] not implemented for [getFarFogMethod]."); + }; } private static String getHeightDepthMethod(EDhApiHeightFogMode heightMode, float heightFogHeight) @@ -317,18 +316,13 @@ public class LodFogConfig */ private static String getHeightFogMethod(EDhApiFogFalloff fogType) { - switch (fogType) + return switch (fogType) { - case LINEAR: - return " return linearFog(dist, heightFogStart, heightFogLength, heightFogMin, heightFogRange);\n"; - case EXPONENTIAL: - return " return exponentialFog(dist, heightFogStart, heightFogLength, heightFogMin, heightFogRange, heightFogDensity);\n"; - case EXPONENTIAL_SQUARED: - return " return exponentialSquaredFog(dist, heightFogStart, heightFogLength, heightFogMin, heightFogRange, heightFogDensity);\n"; - - default: - throw new IllegalArgumentException("FogType [" + fogType + "] not implemented for [getHeightFogMethod]."); - } + case LINEAR -> " return linearFog(dist, heightFogStart, heightFogLength, heightFogMin, heightFogRange);\n"; + case EXPONENTIAL -> " return exponentialFog(dist, heightFogStart, heightFogLength, heightFogMin, heightFogRange, heightFogDensity);\n"; + case EXPONENTIAL_SQUARED -> " return exponentialSquaredFog(dist, heightFogStart, heightFogLength, heightFogMin, heightFogRange, heightFogDensity);\n"; + default -> throw new IllegalArgumentException("FogType [" + fogType + "] not implemented for [getHeightFogMethod]."); + }; } /** diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/GLEnums.java b/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/GLEnums.java index c55dd0d3f..a7ed522fb 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/GLEnums.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/GLEnums.java @@ -27,213 +27,109 @@ public class GLEnums public static String getString(int glEnum) { - // blend stuff - switch (glEnum) + return switch (glEnum) { - case GL_ZERO: - return "GL_ZERO"; - case GL_ONE: - return "GL_ONE"; - case GL_SRC_COLOR: - return "GL_SRC_COLOR"; - case GL_ONE_MINUS_SRC_COLOR: - return "GL_ONE_MINUS_SRC_COLOR"; - case GL_DST_COLOR: - return "GL_DST_COLOR"; - case GL_ONE_MINUS_DST_COLOR: - return "GL_ONE_MINUS_DST_COLOR"; - case GL_SRC_ALPHA: - return "GL_SRC_ALPHA"; - case GL_ONE_MINUS_SRC_ALPHA: - return "GL_ONE_MINUS_SRC_ALPHA"; - case GL_DST_ALPHA: - return "GL_DST_ALPHA"; - case GL_ONE_MINUS_DST_ALPHA: - return "GL_ONE_MINUS_DST_ALPHA"; - case GL_CONSTANT_COLOR: - return "GL_CONSTANT_COLOR"; - case GL_ONE_MINUS_CONSTANT_COLOR: - return "GL_ONE_MINUS_CONSTANT_COLOR"; - case GL_CONSTANT_ALPHA: - return "GL_CONSTANT_ALPHA"; - case GL_ONE_MINUS_CONSTANT_ALPHA: - return "GL_ONE_MINUS_CONSTANT_ALPHA"; - default: - } - - // shader stuff - switch (glEnum) - { - case GL_VERTEX_SHADER: - return "GL_VERTEX_SHADER"; - case GL_GEOMETRY_SHADER: - return "GL_GEOMETRY_SHADER"; - case GL_FRAGMENT_SHADER: - return "GL_FRAGMENT_SHADER"; - default: - } - - // stencil stuff - switch (glEnum) - { - case GL_KEEP: - return "GL_KEEP"; - case GL_ZERO: - return "GL_ZERO"; - case GL_REPLACE: - return "GL_REPLACE"; - case GL_INCR: - return "GL_INCR"; - case GL_DECR: - return "GL_DECR"; - case GL_INVERT: - return "GL_INVERT"; - case GL_INCR_WRAP: - return "GL_INCR_WRAP"; - case GL_DECR_WRAP: - return "GL_DECR_WRAP"; - default: - } - - // depth stuff - switch (glEnum) - { - case GL_NEVER: - return "GL_NEVER"; - case GL_LESS: - return "GL_LESS"; - case GL_EQUAL: - return "GL_EQUAL"; - case GL_LEQUAL: - return "GL_LEQUAL"; - case GL_GREATER: - return "GL_GREATER"; - case GL_NOTEQUAL: - return "GL_NOTEQUAL"; - case GL_GEQUAL: - return "GL_GEQUAL"; - case GL_ALWAYS: - return "GL_ALWAYS"; - default: - } - - // Texture binding points - switch (glEnum) - { - case GL_TEXTURE0: - return "GL_TEXTURE0"; - case GL_TEXTURE1: - return "GL_TEXTURE1"; - case GL_TEXTURE2: - return "GL_TEXTURE2"; - case GL_TEXTURE3: - return "GL_TEXTURE3"; - case GL_TEXTURE4: - return "GL_TEXTURE4"; - case GL_TEXTURE5: - return "GL_TEXTURE5"; - case GL_TEXTURE6: - return "GL_TEXTURE6"; - case GL_TEXTURE7: - return "GL_TEXTURE7"; - case GL_TEXTURE8: - return "GL_TEXTURE8"; - case GL_TEXTURE9: - return "GL_TEXTURE9"; - case GL_TEXTURE10: - return "GL_TEXTURE10"; - case GL_TEXTURE11: - return "GL_TEXTURE11"; - case GL_TEXTURE12: - return "GL_TEXTURE12"; - case GL_TEXTURE13: - return "GL_TEXTURE13"; - case GL_TEXTURE14: - return "GL_TEXTURE14"; - case GL_TEXTURE15: - return "GL_TEXTURE15"; - case GL_TEXTURE16: - return "GL_TEXTURE16"; - case GL_TEXTURE17: - return "GL_TEXTURE17"; - case GL_TEXTURE18: - return "GL_TEXTURE18"; - case GL_TEXTURE19: - return "GL_TEXTURE19"; - case GL_TEXTURE20: - return "GL_TEXTURE20"; - case GL_TEXTURE21: - return "GL_TEXTURE21"; - case GL_TEXTURE22: - return "GL_TEXTURE22"; - case GL_TEXTURE23: - return "GL_TEXTURE23"; - case GL_TEXTURE24: - return "GL_TEXTURE24"; - case GL_TEXTURE25: - return "GL_TEXTURE25"; - case GL_TEXTURE26: - return "GL_TEXTURE26"; - case GL_TEXTURE27: - return "GL_TEXTURE27"; - case GL_TEXTURE28: - return "GL_TEXTURE28"; - case GL_TEXTURE29: - return "GL_TEXTURE29"; - case GL_TEXTURE30: - return "GL_TEXTURE30"; - case GL_TEXTURE31: - return "GL_TEXTURE31"; - default: - } - - // Polygon modes - switch (glEnum) - { - case GL_POINT: - return "GL_POINT"; - case GL_LINE: - return "GL_LINE"; - case GL_FILL: - return "GL_FILL"; - default: - } - - // Culling modes - switch (glEnum) - { - case GL_FRONT: - return "GL_FRONT"; - case GL_BACK: - return "GL_BACK"; - case GL_FRONT_AND_BACK: - return "GL_FRONT_AND_BACK"; - default: - } - - return "GL_UNKNOWN(" + glEnum + ")"; + // Zero + case GL_ZERO -> "GL_ZERO"; + + // blend stuff + case GL_ONE -> "GL_ONE"; + case GL_SRC_COLOR -> "GL_SRC_COLOR"; + case GL_ONE_MINUS_SRC_COLOR -> "GL_ONE_MINUS_SRC_COLOR"; + case GL_DST_COLOR -> "GL_DST_COLOR"; + case GL_ONE_MINUS_DST_COLOR -> "GL_ONE_MINUS_DST_COLOR"; + case GL_SRC_ALPHA -> "GL_SRC_ALPHA"; + case GL_ONE_MINUS_SRC_ALPHA -> "GL_ONE_MINUS_SRC_ALPHA"; + case GL_DST_ALPHA -> "GL_DST_ALPHA"; + case GL_ONE_MINUS_DST_ALPHA -> "GL_ONE_MINUS_DST_ALPHA"; + case GL_CONSTANT_COLOR -> "GL_CONSTANT_COLOR"; + case GL_ONE_MINUS_CONSTANT_COLOR -> "GL_ONE_MINUS_CONSTANT_COLOR"; + case GL_CONSTANT_ALPHA -> "GL_CONSTANT_ALPHA"; + case GL_ONE_MINUS_CONSTANT_ALPHA -> "GL_ONE_MINUS_CONSTANT_ALPHA"; + + // shader stuff + case GL_VERTEX_SHADER -> "GL_VERTEX_SHADER"; + case GL_GEOMETRY_SHADER -> "GL_GEOMETRY_SHADER"; + case GL_FRAGMENT_SHADER -> "GL_FRAGMENT_SHADER"; + + // stencil stuff + case GL_KEEP -> "GL_KEEP"; + case GL_REPLACE -> "GL_REPLACE"; + case GL_INCR -> "GL_INCR"; + case GL_DECR -> "GL_DECR"; + case GL_INVERT -> "GL_INVERT"; + case GL_INCR_WRAP -> "GL_INCR_WRAP"; + case GL_DECR_WRAP -> "GL_DECR_WRAP"; + + // depth stuff + case GL_NEVER -> "GL_NEVER"; + case GL_LESS -> "GL_LESS"; + case GL_EQUAL -> "GL_EQUAL"; + case GL_LEQUAL -> "GL_LEQUAL"; + case GL_GREATER -> "GL_GREATER"; + case GL_NOTEQUAL -> "GL_NOTEQUAL"; + case GL_GEQUAL -> "GL_GEQUAL"; + case GL_ALWAYS -> "GL_ALWAYS"; + + // Texture binding points + case GL_TEXTURE0 -> "GL_TEXTURE0"; + case GL_TEXTURE1 -> "GL_TEXTURE1"; + case GL_TEXTURE2 -> "GL_TEXTURE2"; + case GL_TEXTURE3 -> "GL_TEXTURE3"; + case GL_TEXTURE4 -> "GL_TEXTURE4"; + case GL_TEXTURE5 -> "GL_TEXTURE5"; + case GL_TEXTURE6 -> "GL_TEXTURE6"; + case GL_TEXTURE7 -> "GL_TEXTURE7"; + case GL_TEXTURE8 -> "GL_TEXTURE8"; + case GL_TEXTURE9 -> "GL_TEXTURE9"; + case GL_TEXTURE10 -> "GL_TEXTURE10"; + case GL_TEXTURE11 -> "GL_TEXTURE11"; + case GL_TEXTURE12 -> "GL_TEXTURE12"; + case GL_TEXTURE13 -> "GL_TEXTURE13"; + case GL_TEXTURE14 -> "GL_TEXTURE14"; + case GL_TEXTURE15 -> "GL_TEXTURE15"; + case GL_TEXTURE16 -> "GL_TEXTURE16"; + case GL_TEXTURE17 -> "GL_TEXTURE17"; + case GL_TEXTURE18 -> "GL_TEXTURE18"; + case GL_TEXTURE19 -> "GL_TEXTURE19"; + case GL_TEXTURE20 -> "GL_TEXTURE20"; + case GL_TEXTURE21 -> "GL_TEXTURE21"; + case GL_TEXTURE22 -> "GL_TEXTURE22"; + case GL_TEXTURE23 -> "GL_TEXTURE23"; + case GL_TEXTURE24 -> "GL_TEXTURE24"; + case GL_TEXTURE25 -> "GL_TEXTURE25"; + case GL_TEXTURE26 -> "GL_TEXTURE26"; + case GL_TEXTURE27 -> "GL_TEXTURE27"; + case GL_TEXTURE28 -> "GL_TEXTURE28"; + case GL_TEXTURE29 -> "GL_TEXTURE29"; + case GL_TEXTURE30 -> "GL_TEXTURE30"; + case GL_TEXTURE31 -> "GL_TEXTURE31"; + + + // Polygon modes + case GL_POINT -> "GL_POINT"; + case GL_LINE -> "GL_LINE"; + case GL_FILL -> "GL_FILL"; + + // Culling modes + case GL_FRONT -> "GL_FRONT"; + case GL_BACK -> "GL_BACK"; + case GL_FRONT_AND_BACK -> "GL_FRONT_AND_BACK"; + default -> "GL_UNKNOWN(" + glEnum + ")"; + }; } public static int getTypeSize(int glTypeEnum) { - switch (glTypeEnum) + return switch (glTypeEnum) { - case GL_BYTE: - case GL_UNSIGNED_BYTE: - return 1; - case GL_SHORT: - case GL_UNSIGNED_SHORT: - return 2; - case GL_INT: - case GL_UNSIGNED_INT: - return 4; - case GL_FLOAT: - return 4; - case GL_DOUBLE: - return 8; - default: - throw new IllegalArgumentException("Unknown type enum: " + getString(glTypeEnum)); - } + case GL_BYTE, GL_UNSIGNED_BYTE -> 1; + case GL_SHORT, GL_UNSIGNED_SHORT -> 2; + case GL_INT, GL_UNSIGNED_INT -> 4; + case GL_FLOAT -> 4; + case GL_DOUBLE -> 8; + default -> throw new IllegalArgumentException("Unknown type enum: " + getString(glTypeEnum)); + }; } } \ No newline at end of file diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/buffer/GLBuffer.java b/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/buffer/GLBuffer.java index bdfee1f4b..9c6c8801b 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/buffer/GLBuffer.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/buffer/GLBuffer.java @@ -70,7 +70,7 @@ public class GLBuffer implements AutoCloseable // constructors // //==============// - static { CLEANUP_THREAD.execute(() -> runPhantomReferenceCleanupLoop()); } + static { CLEANUP_THREAD.execute(GLBuffer::runPhantomReferenceCleanupLoop); } public GLBuffer(boolean isBufferStorage) { this.create(isBufferStorage); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/EDhDepthBufferFormat.java b/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/EDhDepthBufferFormat.java index 537ea939a..78693f812 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/EDhDepthBufferFormat.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/EDhDepthBufferFormat.java @@ -4,6 +4,8 @@ import org.jetbrains.annotations.Nullable; import org.lwjgl.opengl.GL30C; import org.lwjgl.opengl.GL43C; +import java.util.Objects; + public enum EDhDepthBufferFormat { DEPTH(false), @@ -26,88 +28,56 @@ public enum EDhDepthBufferFormat @Nullable public static EDhDepthBufferFormat fromGlEnum(int glenum) { - switch (glenum) + return switch (glenum) { - case GL30C.GL_DEPTH_COMPONENT: - return EDhDepthBufferFormat.DEPTH; - case GL30C.GL_DEPTH_COMPONENT16: - return EDhDepthBufferFormat.DEPTH16; - case GL30C.GL_DEPTH_COMPONENT24: - return EDhDepthBufferFormat.DEPTH24; - case GL30C.GL_DEPTH_COMPONENT32: - return EDhDepthBufferFormat.DEPTH32; - case GL30C.GL_DEPTH_COMPONENT32F: - return EDhDepthBufferFormat.DEPTH32F; - case GL30C.GL_DEPTH_STENCIL: - return EDhDepthBufferFormat.DEPTH_STENCIL; - case GL30C.GL_DEPTH24_STENCIL8: - return EDhDepthBufferFormat.DEPTH24_STENCIL8; - case GL30C.GL_DEPTH32F_STENCIL8: - return EDhDepthBufferFormat.DEPTH32F_STENCIL8; - default: - return null; - } + case GL30C.GL_DEPTH_COMPONENT -> EDhDepthBufferFormat.DEPTH; + case GL30C.GL_DEPTH_COMPONENT16 -> EDhDepthBufferFormat.DEPTH16; + case GL30C.GL_DEPTH_COMPONENT24 -> EDhDepthBufferFormat.DEPTH24; + case GL30C.GL_DEPTH_COMPONENT32 -> EDhDepthBufferFormat.DEPTH32; + case GL30C.GL_DEPTH_COMPONENT32F -> EDhDepthBufferFormat.DEPTH32F; + case GL30C.GL_DEPTH_STENCIL -> EDhDepthBufferFormat.DEPTH_STENCIL; + case GL30C.GL_DEPTH24_STENCIL8 -> EDhDepthBufferFormat.DEPTH24_STENCIL8; + case GL30C.GL_DEPTH32F_STENCIL8 -> EDhDepthBufferFormat.DEPTH32F_STENCIL8; + default -> null; + }; } public static EDhDepthBufferFormat fromGlEnumOrDefault(int glenum) { EDhDepthBufferFormat format = fromGlEnum(glenum); - if (format == null) - { - // yolo, just assume it's GL_DEPTH_COMPONENT - return EDhDepthBufferFormat.DEPTH; - } - return format; + // yolo, just assume it's GL_DEPTH_COMPONENT + return Objects.requireNonNullElse(format, EDhDepthBufferFormat.DEPTH); } public int getGlInternalFormat() { - switch (this) + return switch (this) { - case DEPTH: - return GL30C.GL_DEPTH_COMPONENT; - case DEPTH16: - return GL30C.GL_DEPTH_COMPONENT16; - case DEPTH24: - return GL30C.GL_DEPTH_COMPONENT24; - case DEPTH32: - return GL30C.GL_DEPTH_COMPONENT32; - case DEPTH32F: - return GL30C.GL_DEPTH_COMPONENT32F; - case DEPTH_STENCIL: - return GL30C.GL_DEPTH_STENCIL; - case DEPTH24_STENCIL8: - return GL30C.GL_DEPTH24_STENCIL8; - case DEPTH32F_STENCIL8: - return GL30C.GL_DEPTH32F_STENCIL8; - } + case DEPTH -> GL30C.GL_DEPTH_COMPONENT; + case DEPTH16 -> GL30C.GL_DEPTH_COMPONENT16; + case DEPTH24 -> GL30C.GL_DEPTH_COMPONENT24; + case DEPTH32 -> GL30C.GL_DEPTH_COMPONENT32; + case DEPTH32F -> GL30C.GL_DEPTH_COMPONENT32F; + case DEPTH_STENCIL -> GL30C.GL_DEPTH_STENCIL; + case DEPTH24_STENCIL8 -> GL30C.GL_DEPTH24_STENCIL8; + case DEPTH32F_STENCIL8 -> GL30C.GL_DEPTH32F_STENCIL8; + }; - throw new AssertionError("unreachable"); } public int getGlType() { return isCombinedStencil() ? GL30C.GL_DEPTH_STENCIL : GL30C.GL_DEPTH_COMPONENT; } public int getGlFormat() { - switch (this) - { - case DEPTH: - case DEPTH16: - return GL43C.GL_UNSIGNED_SHORT; - case DEPTH24: - case DEPTH32: - return GL43C.GL_UNSIGNED_INT; - case DEPTH32F: - return GL30C.GL_FLOAT; - case DEPTH_STENCIL: - case DEPTH24_STENCIL8: - return GL30C.GL_UNSIGNED_INT_24_8; - case DEPTH32F_STENCIL8: - return GL30C.GL_FLOAT_32_UNSIGNED_INT_24_8_REV; - } - - throw new AssertionError("unreachable"); - } + return switch (this) { + case DEPTH, DEPTH16 -> GL43C.GL_UNSIGNED_SHORT; + case DEPTH24, DEPTH32 -> GL43C.GL_UNSIGNED_INT; + case DEPTH32F -> GL30C.GL_FLOAT; + case DEPTH_STENCIL, DEPTH24_STENCIL8 -> GL30C.GL_UNSIGNED_INT_24_8; + case DEPTH32F_STENCIL8 -> GL30C.GL_FLOAT_32_UNSIGNED_INT_24_8_REV; + }; + + } public boolean isCombinedStencil() { return combinedStencil; } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/GenericObjectRenderer.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/GenericObjectRenderer.java index b3768548d..28fe4ea25 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/GenericObjectRenderer.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/GenericObjectRenderer.java @@ -308,8 +308,8 @@ public class GenericObjectRenderer implements IDhApiCustomRenderRegister { blockPos.y = 140f; - Color newColor = (massRelativePosBoxGroup.get(0).color == Color.RED) ? Color.RED.darker() : Color.RED; - massRelativePosBoxGroup.forEach((box) -> { box.color = newColor; }); + Color newColor = (massRelativePosBoxGroup.getFirst().color == Color.RED) ? Color.RED.darker() : Color.RED; + massRelativePosBoxGroup.forEach((box) -> box.color = newColor); massRelativePosBoxGroup.triggerBoxChange(); } @@ -327,14 +327,13 @@ public class GenericObjectRenderer implements IDhApiCustomRenderRegister @Override public void add(IDhApiRenderableBoxGroup iBoxGroup) throws IllegalArgumentException { - if (!(iBoxGroup instanceof RenderableBoxGroup)) + if (!(iBoxGroup instanceof RenderableBoxGroup boxGroup)) { throw new IllegalArgumentException("Box group must be of type ["+ RenderableBoxGroup.class.getSimpleName()+"], type received: ["+(iBoxGroup != null ? iBoxGroup.getClass() : "NULL")+"]."); } - RenderableBoxGroup boxGroup = (RenderableBoxGroup) iBoxGroup; - - - long id = boxGroup.getId(); + + + long id = boxGroup.getId(); if (this.boxGroupById.containsKey(id)) { throw new IllegalArgumentException("A box group with the ID [" + id + "] is already present."); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/sql/repo/AbstractDhRepo.java b/core/src/main/java/com/seibel/distanthorizons/core/sql/repo/AbstractDhRepo.java index 63ab8953d..329630645 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/sql/repo/AbstractDhRepo.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/sql/repo/AbstractDhRepo.java @@ -289,7 +289,7 @@ public abstract class AbstractDhRepo> implemen try { List> objectList = this.query(sql); - return !objectList.isEmpty() ? objectList.get(0) : null; + return !objectList.isEmpty() ? objectList.getFirst() : null; } catch (DbConnectionClosedException e) { @@ -512,7 +512,7 @@ public abstract class AbstractDhRepo> implemen for (int columnIndex = 1; columnIndex <= resultColumnCount; columnIndex++) // column indices start at 1 { String columnName = resultMetaData.getColumnName(columnIndex); - if (columnName == null || columnName.equals("")) + if (columnName == null || columnName.isEmpty()) { throw new RuntimeException("SQL result set is missing a column name for column ["+resultMetaData.getTableName(columnIndex)+"."+columnIndex+"]."); } @@ -521,22 +521,13 @@ public abstract class AbstractDhRepo> implemen // some values need explicit conversion // Example: Long values that are within the bounds of an int would automatically be incorrectly returned as "Integer" objects String columnType = resultMetaData.getColumnTypeName(columnIndex).toUpperCase(); - Object columnValue; - switch (columnType) + Object columnValue = switch (columnType) { - case "BIGINT": - columnValue = resultSet.getLong(columnIndex); - break; - case "SMALLINT": - columnValue = resultSet.getShort(columnIndex); - break; - case "TINYINT": - columnValue = resultSet.getByte(columnIndex); - break; - default: - columnValue = resultSet.getObject(columnIndex); - break; - } + case "BIGINT" -> resultSet.getLong(columnIndex); + case "SMALLINT" -> resultSet.getShort(columnIndex); + case "TINYINT" -> resultSet.getByte(columnIndex); + default -> resultSet.getObject(columnIndex); + }; object.put(columnName, columnValue); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/ColorUtil.java b/core/src/main/java/com/seibel/distanthorizons/core/util/ColorUtil.java index 6e4b3acc9..7f14b52ac 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/util/ColorUtil.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/util/ColorUtil.java @@ -179,21 +179,15 @@ public class ColorUtil float q = v * (1f - s * f); float t = v * (1f - s * (1f - f)); - switch (i) + return switch (i) { - case 0: - return ColorUtil.rgbToInt(a, v, t, p); - case 1: - return ColorUtil.rgbToInt(a, q, v, p); - case 2: - return ColorUtil.rgbToInt(a, p, v, t); - case 3: - return ColorUtil.rgbToInt(a, p, q, v); - case 4: - return ColorUtil.rgbToInt(a, t, p, v); - default: - return ColorUtil.rgbToInt(a, v, p, q); // case 5 - } + case 0 -> ColorUtil.rgbToInt(a, v, t, p); + case 1 -> ColorUtil.rgbToInt(a, q, v, p); + case 2 -> ColorUtil.rgbToInt(a, p, v, t); + case 3 -> ColorUtil.rgbToInt(a, p, q, v); + case 4 -> ColorUtil.rgbToInt(a, t, p, v); + default -> ColorUtil.rgbToInt(a, v, p, q); // case 5 + }; } /** Returns the hex value for the Alpha, Red, Green, and Blue channels. */ 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 ad9de0b90..54ff01589 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 @@ -233,7 +233,7 @@ public class LodUtil Iterator posIter = MC_RENDER.getVanillaRenderedChunks().iterator(); - return new EdgeDistanceBooleanGrid(new Iterator() + return new EdgeDistanceBooleanGrid(new Iterator<>() { @Override public boolean hasNext() diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/RenderDataPointReducingList.java b/core/src/main/java/com/seibel/distanthorizons/core/util/RenderDataPointReducingList.java index 773707bad..f1562aa5a 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/util/RenderDataPointReducingList.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/util/RenderDataPointReducingList.java @@ -452,18 +452,14 @@ public class RenderDataPointReducingList 0, size, // comparator - (int index1, int index2) -> - { - return Integer.compare( - this.getSize(this.getSortingIndex(index1)), - this.getSize(this.getSortingIndex(index2)) - ); - }, + (int index1, int index2) -> + Integer.compare( + this.getSize(this.getSortingIndex(index1)), + this.getSize(this.getSortingIndex(index2)) + ), // swapper - (int index1, int index2) -> - { - ShortArrays.swap(array, index1, index2); - } + (int index1, int index2) -> + ShortArrays.swap(array, index1, index2) ); } @@ -479,18 +475,14 @@ public class RenderDataPointReducingList 0, size, // comparator - (int index1, int index2) -> - { - return Integer.compare( - this.getMinY(this.getSortingIndex(index1)), - this.getMinY(this.getSortingIndex(index2)) - ); - }, + (int index1, int index2) -> + Integer.compare( + this.getMinY(this.getSortingIndex(index1)), + this.getMinY(this.getSortingIndex(index2)) + ), // swapper - (int index1, int index2) -> - { - ShortArrays.swap(array, index1, index2); - } + (int index1, int index2) -> + ShortArrays.swap(array, index1, index2) ); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/ThreadUtil.java b/core/src/main/java/com/seibel/distanthorizons/core/util/ThreadUtil.java index 7c5339d7c..8cce7a799 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/util/ThreadUtil.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/util/ThreadUtil.java @@ -72,7 +72,7 @@ public class ThreadUtil RateLimitedThreadPoolExecutor executor = makeRateLimitedThreadPool(poolSize, runTimeRatioConfigEntry.get(), threadFactory, activeThreadCountSemaphore); - ConfigChangeListener changeListener = new ConfigChangeListener<>(runTimeRatioConfigEntry, (newRunTimeRatio) -> { executor.runTimeRatio = newRunTimeRatio; }); + ConfigChangeListener changeListener = new ConfigChangeListener<>(runTimeRatioConfigEntry, (newRunTimeRatio) -> executor.runTimeRatio = newRunTimeRatio); THREAD_CHANGE_LISTENERS_BY_THREAD_NAME.put(threadFactory.threadName, changeListener); return executor; @@ -102,7 +102,7 @@ public class ThreadUtil // ThreadPoolExecutor vs the more generic ExecutorService return new ThreadPoolExecutor(/*corePoolSize*/ poolSize, /*maxPoolSize*/ poolSize, 0L, TimeUnit.MILLISECONDS, - new LinkedBlockingQueue(), + new LinkedBlockingQueue<>(), new DhThreadFactory(name, priority)); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/gridList/EdgeDistanceBooleanGrid.java b/core/src/main/java/com/seibel/distanthorizons/core/util/gridList/EdgeDistanceBooleanGrid.java index c6f3dbcd5..a35fbdc2f 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/util/gridList/EdgeDistanceBooleanGrid.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/util/gridList/EdgeDistanceBooleanGrid.java @@ -70,7 +70,7 @@ public class EdgeDistanceBooleanGrid extends PosArrayGridList { if (edgeCache != null) return; - edgeCache = new ArrayGridList(gridSize, (ox, oy) -> { + edgeCache = new ArrayGridList<>(gridSize, (ox, oy) -> { BoolType b = get(ox + getOffsetX(), oy + getOffsetY()); return b == null ? -1 : 0; }); @@ -79,9 +79,7 @@ public class EdgeDistanceBooleanGrid extends PosArrayGridList while (!isDone[0]) { isDone[0] = true; - edgeCache.forEachPos((ox, oy) -> { - isDone[0] &= updatePos(edgeCache, ox, oy); - }); + edgeCache.forEachPos((ox, oy) -> isDone[0] &= updatePos(edgeCache, ox, oy)); } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/objects/DummyRunExecutorService.java b/core/src/main/java/com/seibel/distanthorizons/core/util/objects/DummyRunExecutorService.java index 407cf3673..6369dcdb7 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/util/objects/DummyRunExecutorService.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/util/objects/DummyRunExecutorService.java @@ -50,7 +50,7 @@ public class DummyRunExecutorService implements ExecutorService public List shutdownNow() { shutdownCalled = true; - return new ArrayList(); + return new ArrayList<>(); } @Override @@ -116,7 +116,7 @@ public class DummyRunExecutorService implements ExecutorService @Override public List> invokeAll(Collection> tasks) { - List> futures = new ArrayList>(tasks.size()); + List> futures = new ArrayList<>(tasks.size()); for (Callable t : tasks) { futures.add(submit(t)); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/objects/EventTimer.java b/core/src/main/java/com/seibel/distanthorizons/core/util/objects/EventTimer.java index 8b6b28b09..75b56c399 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/util/objects/EventTimer.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/util/objects/EventTimer.java @@ -48,9 +48,9 @@ public class EventTimer public void nextEvent(String name) { long timeNs = System.nanoTime(); - if (lastEventNs != -1 && !events.isEmpty() && events.get(events.size() - 1).timeNs == -1) + if (lastEventNs != -1 && !events.isEmpty() && events.getLast().timeNs == -1) { - events.get(events.size() - 1).timeNs = timeNs - lastEventNs; + events.getLast().timeNs = timeNs - lastEventNs; } lastEventNs = timeNs; events.add(new Event(name)); @@ -59,9 +59,9 @@ public class EventTimer public void complete() { long timeNs = System.nanoTime(); - if (lastEventNs != -1 && !events.isEmpty() && events.get(events.size() - 1).timeNs == -1) + if (lastEventNs != -1 && !events.isEmpty() && events.getLast().timeNs == -1) { - events.get(events.size() - 1).timeNs = timeNs - lastEventNs; + events.getLast().timeNs = timeNs - lastEventNs; } lastEventNs = -1; } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/objects/SortedArraySet.java b/core/src/main/java/com/seibel/distanthorizons/core/util/objects/SortedArraySet.java index 4e388eb86..875a12ae9 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/util/objects/SortedArraySet.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/util/objects/SortedArraySet.java @@ -61,13 +61,13 @@ public class SortedArraySet implements SortedSet @Override public E first() { - return list.get(0); + return list.getFirst(); } @Override public E last() { - return list.get(list.size() - 1); + return list.getLast(); } @Override diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/objects/StatsMap.java b/core/src/main/java/com/seibel/distanthorizons/core/util/objects/StatsMap.java index 476c4f1e1..b8efd364a 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/util/objects/StatsMap.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/util/objects/StatsMap.java @@ -25,8 +25,8 @@ import java.util.TreeMap; public class StatsMap { - final TreeMap longMap = new TreeMap(); - final TreeMap bytesMap = new TreeMap(); + final TreeMap longMap = new TreeMap<>(); + final TreeMap bytesMap = new TreeMap<>(); /** * diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/objects/dataStreams/DhDataInputStream.java b/core/src/main/java/com/seibel/distanthorizons/core/util/objects/dataStreams/DhDataInputStream.java index f04e2b283..5bc6b1f34 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/util/objects/dataStreams/DhDataInputStream.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/util/objects/dataStreams/DhDataInputStream.java @@ -53,19 +53,15 @@ public class DhDataInputStream extends DataInputStream { try { - switch (compressionMode) + return switch (compressionMode) { - case UNCOMPRESSED: - return stream; - case LZ4: - return new LZ4FrameInputStream(stream); - case LZMA2: + case UNCOMPRESSED -> stream; + case LZ4 -> new LZ4FrameInputStream(stream); + case LZMA2 -> // Note: all LZMA/XZ compressors can be decompressed using this same InputStream - return new XZInputStream(stream); - - default: - throw new IllegalArgumentException("No compressor defined for [" + compressionMode + "]"); - } + new XZInputStream(stream); + default -> throw new IllegalArgumentException("No compressor defined for [" + compressionMode + "]"); + }; } catch (Error e) { diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/objects/dataStreams/LzmaArrayCache.java b/core/src/main/java/com/seibel/distanthorizons/core/util/objects/dataStreams/LzmaArrayCache.java index 5c982130c..476182c73 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/util/objects/dataStreams/LzmaArrayCache.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/util/objects/dataStreams/LzmaArrayCache.java @@ -58,7 +58,7 @@ public class LzmaArrayCache extends ArrayCache return new byte[size]; } - byte[] array = cacheList.remove(cacheList.size()-1); + byte[] array = cacheList.removeLast(); if (array == null) { return new byte[size]; @@ -102,7 +102,7 @@ public class LzmaArrayCache extends ArrayCache return new int[size]; } - int[] array = cacheList.remove(cacheList.size()-1); + int[] array = cacheList.removeLast(); if (array == null) { return new int[size]; diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/objects/quadTree/QuadNode.java b/core/src/main/java/com/seibel/distanthorizons/core/util/objects/quadTree/QuadNode.java index 142251213..6f9bfad81 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/util/objects/quadTree/QuadNode.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/util/objects/quadTree/QuadNode.java @@ -124,20 +124,14 @@ public class QuadNode */ public QuadNode getChildByIndex(int child0to3) throws IllegalArgumentException { - switch (child0to3) + return switch (child0to3) { - case 0: - return nwChild; - case 1: - return swChild; - case 2: - return neChild; - case 3: - return seChild; - - default: - throw new IllegalArgumentException("child0to3 must be between 0 and 3"); - } + case 0 -> nwChild; + case 1 -> swChild; + case 2 -> neChild; + case 3 -> seChild; + default -> throw new IllegalArgumentException("child0to3 must be between 0 and 3"); + }; } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/objects/quadTree/QuadTree.java b/core/src/main/java/com/seibel/distanthorizons/core/util/objects/quadTree/QuadTree.java index 8bd84e060..b4b057525 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/util/objects/quadTree/QuadTree.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/util/objects/quadTree/QuadTree.java @@ -141,7 +141,7 @@ public class QuadTree return null; } - topQuadNode = new QuadNode(rootPos, this.treeMaxDetailLevel); + topQuadNode = new QuadNode<>(rootPos, this.treeMaxDetailLevel); boolean successfullyAdded = this.topRingList.set(ringListPosX, ringListPosZ, topQuadNode); if (!successfullyAdded) { diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/threading/ConfigThreadPool.java b/core/src/main/java/com/seibel/distanthorizons/core/util/threading/ConfigThreadPool.java index 108d41415..94fbe42d4 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/util/threading/ConfigThreadPool.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/util/threading/ConfigThreadPool.java @@ -56,8 +56,8 @@ public class ConfigThreadPool this.activeThreadCountSemaphore = activeThreadCountSemaphore; this.threadCountConfig = threadCountConfig; - this.threadCountConfigListener = new ConfigChangeListener<>(threadCountConfig, - (threadCount) -> { this.setThreadPoolSize(threadCount); }); + this.threadCountConfigListener = new ConfigChangeListener<>(threadCountConfig, + this::setThreadPoolSize); this.runTimeRatioConfig = runTimeRatioConfig; this.setThreadPoolSize(threadCountConfig.get()); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/chunk/ChunkLightStorage.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/chunk/ChunkLightStorage.java index 73ced41be..989362485 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/chunk/ChunkLightStorage.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/chunk/ChunkLightStorage.java @@ -247,7 +247,7 @@ public class ChunkLightStorage } else { - return recycled.remove(recycled.size() - 1); + return recycled.removeLast(); } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/minecraft/IMinecraftRenderWrapper.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/minecraft/IMinecraftRenderWrapper.java index 2fc860772..20601cf06 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/minecraft/IMinecraftRenderWrapper.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/minecraft/IMinecraftRenderWrapper.java @@ -130,7 +130,7 @@ public interface IMinecraftRenderWrapper extends IBindable int chunkDist2Mul4 = chunkDist * chunkDist * 4; // add every position within render distance - HashSet renderedPos = new HashSet(); + HashSet renderedPos = new HashSet<>(); for (int deltaChunkX = -chunkDist; deltaChunkX <= chunkDist; deltaChunkX++) { for (int deltaChunkZ = -chunkDist; deltaChunkZ <= chunkDist; deltaChunkZ++) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/modAccessor/AbstractOptifineAccessor.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/modAccessor/AbstractOptifineAccessor.java index 4355e790b..9ef0375b1 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/modAccessor/AbstractOptifineAccessor.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/modAccessor/AbstractOptifineAccessor.java @@ -96,19 +96,17 @@ public abstract class AbstractOptifineAccessor implements IOptifineAccessor e.printStackTrace(); } - switch (returnNum) - { - default: - case 0: // optifine's "default" option, - // it should never be used, so default to fog Enabled - - // normal options - case 1: // fast - case 2: // fancy - return EDhApiFogDrawMode.FOG_ENABLED; - case 3: // off - return EDhApiFogDrawMode.FOG_DISABLED; - } + return switch (returnNum) + { // optifine's "default" option, + // it should never be used, so default to fog Enabled + + // normal options + // fast + default -> // fancy + EDhApiFogDrawMode.FOG_ENABLED; + case 3 -> // off + EDhApiFogDrawMode.FOG_DISABLED; + }; } @Override