From db0b37b5232a16b16d85456f118b5ee6805cb5c7 Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Thu, 19 Sep 2024 23:28:30 -0700 Subject: [PATCH 1/6] minimap highlight shader --- .../xaeroplus/feature/render/DrawManager.java | 51 ++++++++++++++++++- .../feature/render/HighlightDrawBuffer.java | 19 +++---- .../mixin/client/MixinMinimapFBORenderer.java | 9 +++- .../client/MixinSupportXaeroWorldmap.java | 18 +++++-- settings.gradle.kts | 2 +- 5 files changed, 81 insertions(+), 18 deletions(-) diff --git a/common/src/main/java/xaeroplus/feature/render/DrawManager.java b/common/src/main/java/xaeroplus/feature/render/DrawManager.java index e1e49032..7c951a3e 100644 --- a/common/src/main/java/xaeroplus/feature/render/DrawManager.java +++ b/common/src/main/java/xaeroplus/feature/render/DrawManager.java @@ -83,6 +83,24 @@ public synchronized void drawMinimapFeatures( -(chunkZ * 64) - (tileZ * 16) - insideZ, 0); matrixStack.scale(16f, 16f, 1f); + if (XaeroPlusSettingRegistry.highlightShader.getValue()) { + drawMinimapFeaturesShader(matrixStack); + } else { + drawMinimapFeaturesImmediate(minViewMapTileChunkCoordX, maxViewMapTileChunkCoordX, minViewMapTileChunkCoordZ, maxViewMapTileChunkCoordZ, + matrixStack, overlayBufferBuilder, helper); + } + matrixStack.popPose(); + } + + public synchronized void drawMinimapFeaturesImmediate( + int minViewMapTileChunkCoordX, + int maxViewMapTileChunkCoordX, + int minViewMapTileChunkCoordZ, + int maxViewMapTileChunkCoordZ, + final PoseStack matrixStack, + final VertexConsumer overlayBufferBuilder, + MinimapRendererHelper helper + ) { var matrix = matrixStack.last().pose(); for (int i = 0; i < sortedKeySet.size(); i++) { var k = sortedKeySet.get(i); @@ -111,7 +129,36 @@ public synchronized void drawMinimapFeatures( ); } } - matrixStack.popPose(); + } + + public synchronized void drawMinimapFeaturesShader( + final PoseStack matrixStack + ) { + XaeroPlusShaders.ensureShaders(); + var shader = XaeroPlusShaders.HIGHLIGHT_SHADER; + if (shader == null) return; + shader.setWorldMapViewMatrix(matrixStack.last().pose()); + RenderSystem.enableBlend(); + for (int i = 0; i < sortedKeySet.size(); i++) { + var k = sortedKeySet.get(i); + if (k == null) continue; + var feature = chunkHighlightDrawFeatures.get(k); + if (feature == null) continue; + int color = feature.colorInt(); + var a = ColorHelper.getA(color); + if (a == 0.0f) return; + var r = ColorHelper.getR(color); + var g = ColorHelper.getG(color); + var b = ColorHelper.getB(color); + shader.setHighlightColor(r, g, b, a); + var highlights = feature.getChunkHighlights(); + var drawBuffer = feature.getHighlightDrawBuffer(); + if (drawBuffer.needsRefresh()) { + drawBuffer.refresh(highlights); + } + drawBuffer.render(); + } + RenderSystem.disableBlend(); } public synchronized void drawWorldMapFeatures( @@ -140,6 +187,8 @@ public synchronized void drawWorldMapFeaturesShader( if (shader == null) return; matrixStack.pushPose(); matrixStack.translate(-flooredCameraX, -flooredCameraZ, 1.0f); + matrixStack.scale(16f, -16f, 1f); + matrixStack.translate(0, -1, 0); shader.setWorldMapViewMatrix(matrixStack.last().pose()); matrixStack.popPose(); RenderSystem.enableBlend(); diff --git a/common/src/main/java/xaeroplus/feature/render/HighlightDrawBuffer.java b/common/src/main/java/xaeroplus/feature/render/HighlightDrawBuffer.java index 2ee567f3..54252aee 100644 --- a/common/src/main/java/xaeroplus/feature/render/HighlightDrawBuffer.java +++ b/common/src/main/java/xaeroplus/feature/render/HighlightDrawBuffer.java @@ -30,17 +30,14 @@ public void refresh(LongList highlights) { long highlight = highlights.getLong(j); var chunkPosX = ChunkUtils.longToChunkX(highlight); var chunkPosZ = ChunkUtils.longToChunkZ(highlight); - var blockPosX = ChunkUtils.chunkCoordToCoord(chunkPosX); - var blockPosZ = ChunkUtils.chunkCoordToCoord(chunkPosZ); - var chunkSize = 16; - float x1 = blockPosX; - float x2 = blockPosX + chunkSize; - float y1 = blockPosZ; - float y2 = blockPosZ + chunkSize; - bufferBuilder.vertex(x1, y1, 0.0F).endVertex(); - bufferBuilder.vertex(x2, y1, 0.0F).endVertex(); - bufferBuilder.vertex(x2, y2, 0.0F).endVertex(); - bufferBuilder.vertex(x1, y2, 0.0F).endVertex(); + float x1 = chunkPosX; + float x2 = chunkPosX + 1; + float y1 = chunkPosZ; + float y2 = chunkPosZ + 1; + bufferBuilder.vertex(x1, y2, 0F).endVertex(); + bufferBuilder.vertex(x2, y2, 0F).endVertex(); + bufferBuilder.vertex(x2, y1, 0F).endVertex(); + bufferBuilder.vertex(x1, y1, 0F).endVertex(); } if (vertexBuffer == null || vertexBuffer.isInvalid()) { close(); diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinMinimapFBORenderer.java b/common/src/main/java/xaeroplus/mixin/client/MixinMinimapFBORenderer.java index 30080fd0..8f4ca030 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinMinimapFBORenderer.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinMinimapFBORenderer.java @@ -1,5 +1,7 @@ package xaeroplus.mixin.client; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import com.llamalad7.mixinextras.sugar.Local; import com.llamalad7.mixinextras.sugar.Share; import com.llamalad7.mixinextras.sugar.ref.LocalIntRef; @@ -19,6 +21,8 @@ import xaero.common.graphics.CustomRenderTypes; import xaero.common.graphics.CustomVertexConsumers; import xaero.common.graphics.ImprovedFramebuffer; +import xaero.common.graphics.renderer.multitexture.MultiTextureRenderTypeRenderer; +import xaero.common.graphics.renderer.multitexture.MultiTextureRenderTypeRendererProvider; import xaero.common.graphics.shader.MinimapShaders; import xaero.common.minimap.MinimapProcessor; import xaero.common.minimap.render.MinimapFBORenderer; @@ -231,11 +235,11 @@ public void redirectModelViewDraw(final MinimapRendererHelper instance, final Po this.helper.drawMyTexturedModalRect(matrixStack, -scaledSize.get(), -scaledSize.get(), 0, 0, scaledSizeM, scaledSizeM, scaledSizeM, scaledSizeM); } - @Inject(method = "renderChunksToFBO", at = @At( + @WrapOperation(method = "renderChunksToFBO", at = @At( value = "INVOKE", target = "Lxaero/common/graphics/renderer/multitexture/MultiTextureRenderTypeRendererProvider;draw(Lxaero/common/graphics/renderer/multitexture/MultiTextureRenderTypeRenderer;)V" )) - public void drawMinimapFeaturesCaveMode(final MinimapSession minimapSession, final GuiGraphics guiGraphics, final MinimapProcessor minimap, final Player player, final Entity renderEntity, final double playerX, final double playerZ, final double playerDimDiv, final double mapDimensionScale, final int bufferSize, final int viewW, final float sizeFix, final float partial, final int level, final boolean retryIfError, final boolean useWorldMap, final boolean lockedNorth, final int shape, final double ps, final double pc, final boolean cave, final boolean circle, final CustomVertexConsumers cvc, final CallbackInfo ci, + public void drawMinimapFeaturesCaveMode(final MultiTextureRenderTypeRendererProvider instance, final MultiTextureRenderTypeRenderer renderer, final Operation original, @Local(name = "xFloored") int xFloored, @Local(name = "zFloored") int zFloored, @Local(name = "overlayBufferBuilder") VertexConsumer overlayBufferBuilder, @@ -245,6 +249,7 @@ public void drawMinimapFeaturesCaveMode(final MinimapSession minimapSession, fin @Local(name = "minZ") int minZRef, @Local(name = "maxZ") int maxZRef ) { + original.call(instance, renderer); int mapX = xFloored >> 4; int mapZ = zFloored >> 4; int chunkX = mapX >> 2; diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinSupportXaeroWorldmap.java b/common/src/main/java/xaeroplus/mixin/client/MixinSupportXaeroWorldmap.java index d01248b6..cd582732 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinSupportXaeroWorldmap.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinSupportXaeroWorldmap.java @@ -65,7 +65,7 @@ public void setupTransparentMMBgBuffer(final PoseStack matrixStack, final int mi value = "INVOKE", target = "Lxaero/common/mods/SupportXaeroWorldmap;prepareMapTexturedRect(Lorg/joml/Matrix4f;FFIIFFLxaero/map/region/MapTileChunk;Lxaero/common/graphics/renderer/multitexture/MultiTextureRenderTypeRenderer;Lxaero/common/graphics/renderer/multitexture/MultiTextureRenderTypeRenderer;Lxaero/common/minimap/render/MinimapRendererHelper;)V" ), remap = false) - public void renderTransparentMMBg(final PoseStack matrixStack, final int minX, final int maxX, final int minZ, final int maxZ, final int minViewX, final int maxViewX, final int minViewZ, final int maxViewZ, final MapProcessor mapProcessor, final int renderedCaveLayer, final boolean shouldRequestLoading, final boolean reloadEverything, final int globalReloadVersion, final int globalRegionCacheHashCode, final int globalCaveStart, final int globalCaveDepth, final boolean playerIsMoving, final boolean noCaveMaps, final boolean slimeChunks, final int chunkX, final int chunkZ, final int tileX, final int tileZ, final int insideX, final int insideZ, final Long seed, final MultiTextureRenderTypeRenderer mapWithLightRenderer, final MultiTextureRenderTypeRenderer mapNoLightRenderer, final MinimapRendererHelper helper, final VertexConsumer overlayBufferBuilder, final CallbackInfo ci, + public void buildTransparentMMBg(final PoseStack matrixStack, final int minX, final int maxX, final int minZ, final int maxZ, final int minViewX, final int maxViewX, final int minViewZ, final int maxViewZ, final MapProcessor mapProcessor, final int renderedCaveLayer, final boolean shouldRequestLoading, final boolean reloadEverything, final int globalReloadVersion, final int globalRegionCacheHashCode, final int globalCaveStart, final int globalCaveDepth, final boolean playerIsMoving, final boolean noCaveMaps, final boolean slimeChunks, final int chunkX, final int chunkZ, final int tileX, final int tileZ, final int insideX, final int insideZ, final Long seed, final MultiTextureRenderTypeRenderer mapWithLightRenderer, final MultiTextureRenderTypeRenderer mapNoLightRenderer, final MinimapRendererHelper helper, final VertexConsumer overlayBufferBuilder, final CallbackInfo ci, @Share("bgBufferBuilder") LocalRef bgBufferBuilderRef, @Local(name = "drawX") int drawX, @Local(name = "drawZ") int drawZ, @@ -89,8 +89,21 @@ public boolean hideSlimeChunksWhileDimSwitched(SupportXaeroWorldmap instance, Ma } @Inject(method = "renderChunks", at = @At("RETURN"), remap = false) - public void drawXPFeatures(final PoseStack matrixStack, final int minX, final int maxX, final int minZ, final int maxZ, final int minViewX, final int maxViewX, final int minViewZ, final int maxViewZ, final MapProcessor mapProcessor, final int renderedCaveLayer, final boolean shouldRequestLoading, final boolean reloadEverything, final int globalReloadVersion, final int globalRegionCacheHashCode, final int globalCaveStart, final int globalCaveDepth, final boolean playerIsMoving, final boolean noCaveMaps, final boolean slimeChunks, final int chunkX, final int chunkZ, final int tileX, final int tileZ, final int insideX, final int insideZ, final Long seed, final MultiTextureRenderTypeRenderer mapWithLightRenderer, final MultiTextureRenderTypeRenderer mapNoLightRenderer, final MinimapRendererHelper helper, final VertexConsumer overlayBufferBuilder, final CallbackInfo ci, + public void drawTransparentMMBackground(final PoseStack matrixStack, final int minX, final int maxX, final int minZ, final int maxZ, final int minViewX, final int maxViewX, final int minViewZ, final int maxViewZ, final MapProcessor mapProcessor, final int renderedCaveLayer, final boolean shouldRequestLoading, final boolean reloadEverything, final int globalReloadVersion, final int globalRegionCacheHashCode, final int globalCaveStart, final int globalCaveDepth, final boolean playerIsMoving, final boolean noCaveMaps, final boolean slimeChunks, final int chunkX, final int chunkZ, final int tileX, final int tileZ, final int insideX, final int insideZ, final Long seed, final MultiTextureRenderTypeRenderer mapWithLightRenderer, final MultiTextureRenderTypeRenderer mapNoLightRenderer, final MinimapRendererHelper helper, final VertexConsumer overlayBufferBuilder, final CallbackInfo ci, @Share("bgTesselator") LocalRef bgTesselatorRef) { + if (XaeroPlusSettingRegistry.transparentMinimapBackground.getValue()) bgTesselatorRef.get().end(); + } + + @Inject(method = "drawMinimap", at = @At(value = "RETURN"), remap = false) + public void drawXPShaderFeatures(final MinimapSession minimapSession, final PoseStack matrixStack, final MinimapRendererHelper helper, final int xFloored, final int zFloored, final int minViewX, final int minViewZ, final int maxViewX, final int maxViewZ, final boolean zooming, final double zoom, final double mapDimensionScale, final VertexConsumer overlayBufferBuilder, final MultiTextureRenderTypeRendererProvider multiTextureRenderTypeRenderers, final CallbackInfo ci) { + int mapX = xFloored >> 4; + int mapZ = zFloored >> 4; + int chunkX = mapX >> 2; + int chunkZ = mapZ >> 2; + int tileX = mapX & 3; + int tileZ = mapZ & 3; + int insideX = xFloored & 15; + int insideZ = zFloored & 15; Globals.drawManager.drawMinimapFeatures( minViewX, maxViewX, @@ -105,7 +118,6 @@ public void drawXPFeatures(final PoseStack matrixStack, final int minX, final in matrixStack, overlayBufferBuilder, helper); - if (XaeroPlusSettingRegistry.transparentMinimapBackground.getValue()) bgTesselatorRef.get().end(); } @Inject(method = "tryToGetMultiworldId", at = @At( diff --git a/settings.gradle.kts b/settings.gradle.kts index 8baf7636..48efb038 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -8,7 +8,7 @@ pluginManagement { } } gradle.extra.apply { - set("mod_version", "2.24") + set("mod_version", "2.24.1") set("maven_group", "xaeroplus") set("archives_base_name", "XaeroPlus") set("minecraft_version", "1.20.1") From f64284dab912262b5ceb1df9fe0da24067486f41 Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Mon, 23 Sep 2024 22:27:22 -0700 Subject: [PATCH 2/6] fix minimap highlight shader flipped axis --- .../xaeroplus/feature/render/DrawFeature.java | 23 +++++++++++++++---- .../xaeroplus/feature/render/DrawManager.java | 17 +++++++------- .../feature/render/HighlightDrawBuffer.java | 14 +++++++++++ 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/common/src/main/java/xaeroplus/feature/render/DrawFeature.java b/common/src/main/java/xaeroplus/feature/render/DrawFeature.java index 382867d0..aba5552e 100644 --- a/common/src/main/java/xaeroplus/feature/render/DrawFeature.java +++ b/common/src/main/java/xaeroplus/feature/render/DrawFeature.java @@ -13,7 +13,8 @@ public class DrawFeature { private final AsyncLoadingCache chunkRenderCache; private final ChunkHighlightProvider chunkHighlightProvider; - private final HighlightDrawBuffer highlightDrawBuffer = new HighlightDrawBuffer(); + private final HighlightDrawBuffer worldMapDrawBuffer = new HighlightDrawBuffer(true); + private final HighlightDrawBuffer minimapDrawBuffer = new HighlightDrawBuffer(false); public DrawFeature(ChunkHighlightProvider chunkHighlightProvider) { this.chunkHighlightProvider = chunkHighlightProvider; @@ -25,7 +26,7 @@ private AsyncLoadingCache createChunkHighlightRenderCache(final .expireAfterWrite(10, TimeUnit.SECONDS) .refreshAfterWrite(500, TimeUnit.MILLISECONDS) .executor(Globals.cacheRefreshExecutorService.get()) - .removalListener((k, v, cause) -> getHighlightDrawBuffer().markStale()) + .removalListener((k, v, cause) -> markDrawBuffersStale()) // only one key .buildAsync(k -> loadFeatureHighlightsInWindow(chunkHighlightProvider)); } @@ -58,7 +59,21 @@ public LongList getChunkHighlights() { return chunkRenderCache.get(0L).getNow(LongList.of()); } - public HighlightDrawBuffer getHighlightDrawBuffer() { - return this.highlightDrawBuffer; + public HighlightDrawBuffer getWorldMapDrawBuffer() { + return this.worldMapDrawBuffer; + } + + public HighlightDrawBuffer getMinimapDrawBuffer() { + return this.minimapDrawBuffer; + } + + public void markDrawBuffersStale() { + worldMapDrawBuffer.markStale(); + minimapDrawBuffer.markStale(); + } + + public void closeDrawBuffers() { + worldMapDrawBuffer.close(); + minimapDrawBuffer.close(); } } diff --git a/common/src/main/java/xaeroplus/feature/render/DrawManager.java b/common/src/main/java/xaeroplus/feature/render/DrawManager.java index 7c951a3e..1f949a09 100644 --- a/common/src/main/java/xaeroplus/feature/render/DrawManager.java +++ b/common/src/main/java/xaeroplus/feature/render/DrawManager.java @@ -40,7 +40,7 @@ public synchronized void unregisterChunkHighlightProvider(String id) { sortedKeySet.remove(id); DrawFeature feature = chunkHighlightDrawFeatures.remove(id); if (feature != null) { - Minecraft.getInstance().execute(() -> feature.getHighlightDrawBuffer().close()); + Minecraft.getInstance().execute(feature::closeDrawBuffers); } } @@ -107,6 +107,7 @@ public synchronized void drawMinimapFeaturesImmediate( if (k == null) continue; var feature = chunkHighlightDrawFeatures.get(k); if (feature == null) continue; + feature.closeDrawBuffers(); int color = feature.colorInt(); var a = ColorHelper.getA(color); if (a == 0.0f) return; @@ -152,7 +153,7 @@ public synchronized void drawMinimapFeaturesShader( var b = ColorHelper.getB(color); shader.setHighlightColor(r, g, b, a); var highlights = feature.getChunkHighlights(); - var drawBuffer = feature.getHighlightDrawBuffer(); + var drawBuffer = feature.getMinimapDrawBuffer(); if (drawBuffer.needsRefresh()) { drawBuffer.refresh(highlights); } @@ -187,8 +188,7 @@ public synchronized void drawWorldMapFeaturesShader( if (shader == null) return; matrixStack.pushPose(); matrixStack.translate(-flooredCameraX, -flooredCameraZ, 1.0f); - matrixStack.scale(16f, -16f, 1f); - matrixStack.translate(0, -1, 0); + matrixStack.scale(16f, 16f, 1f); shader.setWorldMapViewMatrix(matrixStack.last().pose()); matrixStack.popPose(); RenderSystem.enableBlend(); @@ -205,10 +205,11 @@ public synchronized void drawWorldMapFeaturesShader( var b = ColorHelper.getB(color); shader.setHighlightColor(r, g, b, a); var highlights = feature.getChunkHighlights(); - if (feature.getHighlightDrawBuffer().needsRefresh()) { - feature.getHighlightDrawBuffer().refresh(highlights); + var drawBuffer = feature.getWorldMapDrawBuffer(); + if (drawBuffer.needsRefresh()) { + drawBuffer.refresh(highlights); } - feature.getHighlightDrawBuffer().render(); + drawBuffer.render(); } RenderSystem.disableBlend(); } @@ -231,7 +232,7 @@ public synchronized void drawWorldMapFeaturesImmediate( if (k == null) continue; var feature = chunkHighlightDrawFeatures.get(k); if (feature == null) continue; - feature.getHighlightDrawBuffer().close(); + feature.closeDrawBuffers(); int color = feature.colorInt(); var a = ColorHelper.getA(color); if (a == 0.0f) return; diff --git a/common/src/main/java/xaeroplus/feature/render/HighlightDrawBuffer.java b/common/src/main/java/xaeroplus/feature/render/HighlightDrawBuffer.java index 54252aee..d000bb24 100644 --- a/common/src/main/java/xaeroplus/feature/render/HighlightDrawBuffer.java +++ b/common/src/main/java/xaeroplus/feature/render/HighlightDrawBuffer.java @@ -12,6 +12,15 @@ public class HighlightDrawBuffer { private boolean stale = true; @Nullable private VertexBuffer vertexBuffer = null; + // todo: it'd be REALLY nice if we could share these buffers across the worldmap AND minimap + // but i need to figure out some solution to the coordinates being flipped on the worldmap (to match the mc world's coordinate system) + // if i apply a flip to the model view matrix it fails to draw as the quad vertex ordering needs to be in CCW order + // so unless that can fixed the only solution i see is to draw to a new fbo, flip the fbo, and then draw that on top + private final boolean flipped; + + public HighlightDrawBuffer(boolean flipped) { + this.flipped = flipped; + } public boolean needsRefresh() { return vertexBuffer == null || vertexBuffer.isInvalid() || stale; @@ -34,6 +43,11 @@ public void refresh(LongList highlights) { float x2 = chunkPosX + 1; float y1 = chunkPosZ; float y2 = chunkPosZ + 1; + if (flipped) { + float t = y1; + y1 = y2; + y2 = t; + } bufferBuilder.vertex(x1, y2, 0F).endVertex(); bufferBuilder.vertex(x2, y2, 0F).endVertex(); bufferBuilder.vertex(x2, y1, 0F).endVertex(); From 34dec1825579c0b33fdc7925b31b09b9a845de95 Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Mon, 23 Sep 2024 23:40:19 -0700 Subject: [PATCH 3/6] share vertex buffer and flip as needed on refresh --- .../xaeroplus/feature/render/DrawFeature.java | 17 +++---- .../xaeroplus/feature/render/DrawManager.java | 44 ++++++++----------- .../feature/render/HighlightDrawBuffer.java | 26 +++-------- .../feature/render/HighlightShader.java | 10 ++--- .../shaders/core/xaeroplus/highlights.json | 2 +- .../shaders/core/xaeroplus/highlights.vsh | 4 +- 6 files changed, 39 insertions(+), 64 deletions(-) diff --git a/common/src/main/java/xaeroplus/feature/render/DrawFeature.java b/common/src/main/java/xaeroplus/feature/render/DrawFeature.java index aba5552e..ab239296 100644 --- a/common/src/main/java/xaeroplus/feature/render/DrawFeature.java +++ b/common/src/main/java/xaeroplus/feature/render/DrawFeature.java @@ -13,8 +13,7 @@ public class DrawFeature { private final AsyncLoadingCache chunkRenderCache; private final ChunkHighlightProvider chunkHighlightProvider; - private final HighlightDrawBuffer worldMapDrawBuffer = new HighlightDrawBuffer(true); - private final HighlightDrawBuffer minimapDrawBuffer = new HighlightDrawBuffer(false); + private final HighlightDrawBuffer drawBuffer = new HighlightDrawBuffer(); public DrawFeature(ChunkHighlightProvider chunkHighlightProvider) { this.chunkHighlightProvider = chunkHighlightProvider; @@ -59,21 +58,15 @@ public LongList getChunkHighlights() { return chunkRenderCache.get(0L).getNow(LongList.of()); } - public HighlightDrawBuffer getWorldMapDrawBuffer() { - return this.worldMapDrawBuffer; - } - - public HighlightDrawBuffer getMinimapDrawBuffer() { - return this.minimapDrawBuffer; + public HighlightDrawBuffer getDrawBuffer() { + return this.drawBuffer; } public void markDrawBuffersStale() { - worldMapDrawBuffer.markStale(); - minimapDrawBuffer.markStale(); + drawBuffer.markStale(); } public void closeDrawBuffers() { - worldMapDrawBuffer.close(); - minimapDrawBuffer.close(); + drawBuffer.close(); } } diff --git a/common/src/main/java/xaeroplus/feature/render/DrawManager.java b/common/src/main/java/xaeroplus/feature/render/DrawManager.java index 1f949a09..bf0dfd7a 100644 --- a/common/src/main/java/xaeroplus/feature/render/DrawManager.java +++ b/common/src/main/java/xaeroplus/feature/render/DrawManager.java @@ -138,7 +138,7 @@ public synchronized void drawMinimapFeaturesShader( XaeroPlusShaders.ensureShaders(); var shader = XaeroPlusShaders.HIGHLIGHT_SHADER; if (shader == null) return; - shader.setWorldMapViewMatrix(matrixStack.last().pose()); + shader.setMapViewMatrix(matrixStack.last().pose()); RenderSystem.enableBlend(); for (int i = 0; i < sortedKeySet.size(); i++) { var k = sortedKeySet.get(i); @@ -153,9 +153,9 @@ public synchronized void drawMinimapFeaturesShader( var b = ColorHelper.getB(color); shader.setHighlightColor(r, g, b, a); var highlights = feature.getChunkHighlights(); - var drawBuffer = feature.getMinimapDrawBuffer(); - if (drawBuffer.needsRefresh()) { - drawBuffer.refresh(highlights); + var drawBuffer = feature.getDrawBuffer(); + if (drawBuffer.needsRefresh(false)) { + drawBuffer.refresh(highlights, false); } drawBuffer.render(); } @@ -172,25 +172,24 @@ public synchronized void drawWorldMapFeatures( final PoseStack matrixStack, final VertexConsumer overlayBuffer ) { + matrixStack.pushPose(); + matrixStack.translate(-flooredCameraX, -flooredCameraZ, 1.0f); + matrixStack.scale(16f, 16f, 1f); if (XaeroPlusSettingRegistry.highlightShader.getValue()) - drawWorldMapFeaturesShader(flooredCameraX, flooredCameraZ, matrixStack); + drawWorldMapFeaturesShader(matrixStack); else - drawWorldMapFeaturesImmediate(minBlockX, maxBlockX, minBlockZ, maxBlockZ, flooredCameraX, flooredCameraZ, matrixStack, overlayBuffer); + drawWorldMapFeaturesImmediate(minBlockX, maxBlockX, minBlockZ, maxBlockZ, + matrixStack, overlayBuffer); + matrixStack.popPose(); } public synchronized void drawWorldMapFeaturesShader( - final int flooredCameraX, - final int flooredCameraZ, final PoseStack matrixStack ) { XaeroPlusShaders.ensureShaders(); var shader = XaeroPlusShaders.HIGHLIGHT_SHADER; if (shader == null) return; - matrixStack.pushPose(); - matrixStack.translate(-flooredCameraX, -flooredCameraZ, 1.0f); - matrixStack.scale(16f, 16f, 1f); - shader.setWorldMapViewMatrix(matrixStack.last().pose()); - matrixStack.popPose(); + shader.setMapViewMatrix(matrixStack.last().pose()); RenderSystem.enableBlend(); for (int i = 0; i < sortedKeySet.size(); i++) { var k = sortedKeySet.get(i); @@ -205,9 +204,9 @@ public synchronized void drawWorldMapFeaturesShader( var b = ColorHelper.getB(color); shader.setHighlightColor(r, g, b, a); var highlights = feature.getChunkHighlights(); - var drawBuffer = feature.getWorldMapDrawBuffer(); - if (drawBuffer.needsRefresh()) { - drawBuffer.refresh(highlights); + var drawBuffer = feature.getDrawBuffer(); + if (drawBuffer.needsRefresh(true)) { + drawBuffer.refresh(highlights, true); } drawBuffer.render(); } @@ -219,13 +218,9 @@ public synchronized void drawWorldMapFeaturesImmediate( final double maxBlockX, final double minBlockZ, final double maxBlockZ, - final int flooredCameraX, - final int flooredCameraZ, final PoseStack matrixStack, final VertexConsumer overlayBuffer ) { - matrixStack.pushPose(); - matrixStack.translate(-flooredCameraX, -flooredCameraZ, 0); var matrix = matrixStack.last().pose(); for (int i = 0; i < sortedKeySet.size(); i++) { var k = sortedKeySet.get(i); @@ -248,10 +243,10 @@ public synchronized void drawWorldMapFeaturesImmediate( var blockZ = ChunkUtils.chunkCoordToCoord(chunkPosZ); if (blockX < minBlockX - 32 || blockX > maxBlockX) continue; if (blockZ < minBlockZ - 32 || blockZ > maxBlockZ) continue; - final float left = (float) ChunkUtils.chunkCoordToCoord(chunkPosX); - final float top = (float) ChunkUtils.chunkCoordToCoord(chunkPosZ); - final float right = left + 16; - final float bottom = top + 16; + final float left = chunkPosX; + final float top = chunkPosZ; + final float right = left + 1; + final float bottom = top + 1; MinimapBackgroundDrawHelper.fillIntoExistingBuffer( matrix, overlayBuffer, left, top, right, bottom, @@ -259,6 +254,5 @@ public synchronized void drawWorldMapFeaturesImmediate( ); } } - matrixStack.popPose(); } } diff --git a/common/src/main/java/xaeroplus/feature/render/HighlightDrawBuffer.java b/common/src/main/java/xaeroplus/feature/render/HighlightDrawBuffer.java index d000bb24..51be6e5e 100644 --- a/common/src/main/java/xaeroplus/feature/render/HighlightDrawBuffer.java +++ b/common/src/main/java/xaeroplus/feature/render/HighlightDrawBuffer.java @@ -12,22 +12,15 @@ public class HighlightDrawBuffer { private boolean stale = true; @Nullable private VertexBuffer vertexBuffer = null; - // todo: it'd be REALLY nice if we could share these buffers across the worldmap AND minimap - // but i need to figure out some solution to the coordinates being flipped on the worldmap (to match the mc world's coordinate system) - // if i apply a flip to the model view matrix it fails to draw as the quad vertex ordering needs to be in CCW order - // so unless that can fixed the only solution i see is to draw to a new fbo, flip the fbo, and then draw that on top - private final boolean flipped; + private boolean flipped = false; - public HighlightDrawBuffer(boolean flipped) { - this.flipped = flipped; + public boolean needsRefresh(boolean needsFlip) { + return vertexBuffer == null || vertexBuffer.isInvalid() || stale || flipped != needsFlip; } - public boolean needsRefresh() { - return vertexBuffer == null || vertexBuffer.isInvalid() || stale; - } - - public void refresh(LongList highlights) { + public void refresh(LongList highlights, boolean needsFlip) { stale = false; + flipped = needsFlip; if (highlights.isEmpty()) { close(); return; @@ -41,13 +34,8 @@ public void refresh(LongList highlights) { var chunkPosZ = ChunkUtils.longToChunkZ(highlight); float x1 = chunkPosX; float x2 = chunkPosX + 1; - float y1 = chunkPosZ; - float y2 = chunkPosZ + 1; - if (flipped) { - float t = y1; - y1 = y2; - y2 = t; - } + float y1 = needsFlip ? chunkPosZ + 1 : chunkPosZ; + float y2 = needsFlip ? chunkPosZ : chunkPosZ + 1; bufferBuilder.vertex(x1, y2, 0F).endVertex(); bufferBuilder.vertex(x2, y2, 0F).endVertex(); bufferBuilder.vertex(x2, y1, 0F).endVertex(); diff --git a/common/src/main/java/xaeroplus/feature/render/HighlightShader.java b/common/src/main/java/xaeroplus/feature/render/HighlightShader.java index 362e5e81..ba69ef37 100644 --- a/common/src/main/java/xaeroplus/feature/render/HighlightShader.java +++ b/common/src/main/java/xaeroplus/feature/render/HighlightShader.java @@ -12,7 +12,7 @@ public class HighlightShader extends ShaderInstance { public final Uniform highlightColor = getUniform("HighlightColor"); - public final Uniform worldMapViewMatrix = getUniform("WorldMapViewMatrix"); + public final Uniform mapViewMatrix = getUniform("MapViewMatrix"); public HighlightShader(final ResourceProvider resourceProvider) throws IOException { super(resourceProvider, "xaeroplus/highlights", DefaultVertexFormat.POSITION); @@ -26,11 +26,11 @@ public void setHighlightColor(float r, float g, float b, float a) { highlightColor.set(new Vector4f(r, g, b, a)); } - public void setWorldMapViewMatrix(Matrix4f transform) { - if (worldMapViewMatrix == null) { - XaeroPlus.LOGGER.error("worldmapTransform is null"); + public void setMapViewMatrix(Matrix4f transform) { + if (mapViewMatrix == null) { + XaeroPlus.LOGGER.error("mapViewMatrix is null"); return; } - worldMapViewMatrix.set(transform); + mapViewMatrix.set(transform); } } diff --git a/common/src/main/resources/assets/minecraft/shaders/core/xaeroplus/highlights.json b/common/src/main/resources/assets/minecraft/shaders/core/xaeroplus/highlights.json index eac29173..190ffe99 100644 --- a/common/src/main/resources/assets/minecraft/shaders/core/xaeroplus/highlights.json +++ b/common/src/main/resources/assets/minecraft/shaders/core/xaeroplus/highlights.json @@ -7,7 +7,7 @@ "uniforms": [ { "name": "ModelViewMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] }, { "name": "ProjMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] }, - { "name": "WorldMapViewMatrix", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] }, + { "name": "MapViewMatrix", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] }, { "name": "HighlightColor", "type": "float", "count": 4, "values": [ 1.0, 1.0, 1.0, 1.0 ] } ], "blend": { diff --git a/common/src/main/resources/assets/minecraft/shaders/core/xaeroplus/highlights.vsh b/common/src/main/resources/assets/minecraft/shaders/core/xaeroplus/highlights.vsh index 1021d9fe..621f18db 100644 --- a/common/src/main/resources/assets/minecraft/shaders/core/xaeroplus/highlights.vsh +++ b/common/src/main/resources/assets/minecraft/shaders/core/xaeroplus/highlights.vsh @@ -4,8 +4,8 @@ in vec3 Position; uniform mat4 ModelViewMat; uniform mat4 ProjMat; -uniform mat4 WorldMapViewMatrix; +uniform mat4 MapViewMatrix; void main() { - gl_Position = ProjMat * ModelViewMat * WorldMapViewMatrix * vec4(Position, 1.0); + gl_Position = ProjMat * ModelViewMat * MapViewMatrix * vec4(Position, 1.0); } From f0b912abacf5835e582bf097a02301408ea7853a Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:39:41 -0700 Subject: [PATCH 4/6] gradle 8.10.2 --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0aaefbca..df97d72b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME From 31b5d8c501611ba917ee4edb0d99c14ce81d3e1d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:41:08 -0700 Subject: [PATCH 5/6] Bump com.gradleup.shadow from 8.3.0 to 8.3.2 (#169) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index aa5d1d6a..852b17ca 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ import net.fabricmc.loom.api.LoomGradleExtensionAPI plugins { id("architectury-plugin") version "3.4-SNAPSHOT" id("dev.architectury.loom") version "1.7-SNAPSHOT" apply false - id("com.gradleup.shadow") version "8.3.0" apply false + id("com.gradleup.shadow") version "8.3.2" apply false idea } From bc7e6d46720632c66a5258dbc0f2555405881c33 Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Thu, 26 Sep 2024 20:22:06 -0700 Subject: [PATCH 6/6] settings refactor should remove some static init oddities and make it straightforward for other mods to add their own settings --- common/src/main/java/xaeroplus/Globals.java | 23 +- common/src/main/java/xaeroplus/XaeroPlus.java | 10 + .../GuiXaeroPlusChunkHighlightSettings.java | 6 +- .../GuiXaeroPlusWorldMapSettings.java | 11 +- .../xaeroplus/feature/render/DrawManager.java | 6 +- .../client/MixinBuiltInInfoDisplays.java | 4 +- .../mixin/client/MixinClientEvents.java | 6 +- .../mixin/client/MixinCommonGuiSettings.java | 19 +- .../mixin/client/MixinCommonInternet.java | 4 +- .../mixin/client/MixinControlsHandler.java | 8 +- .../client/MixinGuiEntityRadarSettings.java | 6 +- .../xaeroplus/mixin/client/MixinGuiMap.java | 30 +- .../mixin/client/MixinGuiMinimapMain.java | 6 +- .../MixinGuiMinimapOverlaysSettings.java | 6 +- .../client/MixinGuiWaypointSettings.java | 6 +- .../mixin/client/MixinGuiWaypoints.java | 4 +- .../mixin/client/MixinGuiWaypointsList.java | 4 +- .../client/MixinImprovedFramebuffer.java | 6 +- .../mixin/client/MixinKeyEventHandler.java | 6 +- .../mixin/client/MixinLeveledRegion.java | 6 +- .../xaeroplus/mixin/client/MixinMapPixel.java | 8 +- .../mixin/client/MixinMapProcessor.java | 4 +- .../mixin/client/MixinMapSaveLoad.java | 8 +- .../mixin/client/MixinMapTileChunk.java | 4 +- .../mixin/client/MixinMapWriter.java | 38 +- .../mixin/client/MixinMinimapFBORenderer.java | 6 +- .../mixin/client/MixinMinimapModSettings.java | 49 +- .../mixin/client/MixinMinimapOption.java | 10 +- .../mixin/client/MixinMinimapRenderer.java | 10 +- .../client/MixinMinimapViewSettings.java | 6 +- .../client/MixinMinimapWorldStateUpdater.java | 4 +- .../xaeroplus/mixin/client/MixinOverlay.java | 4 +- .../xaeroplus/mixin/client/MixinPatreon.java | 4 +- .../client/MixinRadarRenderProvider.java | 6 +- .../client/MixinSupportXaeroMinimap.java | 4 +- .../client/MixinSupportXaeroWorldmap.java | 8 +- .../mixin/client/MixinWaypointReader.java | 10 +- .../client/MixinWaypointSharingHandler.java | 6 +- .../client/MixinWaypointsIngameRenderer.java | 10 +- .../mixin/client/MixinWorldDataReader.java | 4 +- .../client/MixinWorldMapGuiSettings.java | 19 +- .../mixin/client/MixinWorldMapInternet.java | 4 +- .../client/MixinWorldMapModSettings.java | 34 +- .../mixin/client/MixinWorldMapOption.java | 10 +- .../mixin/client/mc/MixinGlStateManager.java | 4 +- .../mixin/client/mc/MixinMinecraftClient.java | 4 +- .../mixin/client/mc/MixinWorldRenderer.java | 4 +- .../java/xaeroplus/module/ModuleManager.java | 26 +- .../xaeroplus/module/impl/FpsLimiter.java | 4 +- .../java/xaeroplus/module/impl/Highways.java | 6 +- .../module/impl/LiquidNewChunks.java | 12 +- .../java/xaeroplus/module/impl/OldBiomes.java | 6 +- .../java/xaeroplus/module/impl/OldChunks.java | 6 +- .../module/impl/PaletteNewChunks.java | 6 +- .../module/impl/PortalSkipDetection.java | 20 +- .../java/xaeroplus/module/impl/Portals.java | 6 +- .../xaeroplus/module/impl/WorldTools.java | 6 +- .../xaeroplus/settings/BooleanSetting.java | 145 ++++ .../xaeroplus/settings/DoubleSetting.java | 168 +++++ .../java/xaeroplus/settings/EnumSetting.java | 169 +++++ .../java/xaeroplus/settings/SettingHooks.java | 122 +++ .../xaeroplus/settings/SettingLocation.java | 12 + .../xaeroplus/settings/SettingRegistry.java | 82 ++ .../java/xaeroplus/settings/Settings.java | 709 ++++++++++++++++++ .../settings/XaeroPlusBooleanSetting.java | 124 --- .../settings/XaeroPlusEnumSetting.java | 142 ---- .../settings/XaeroPlusFloatSetting.java | 138 ---- .../settings/XaeroPlusModSettingsHooks.java | 196 ----- .../xaeroplus/settings/XaeroPlusSetting.java | 30 +- .../settings/XaeroPlusSettingRegistry.java | 700 ----------------- .../XaeroPlusSettingsReflectionHax.java | 251 ------- .../xaeroplus/util/DataFolderResolveUtil.java | 8 +- .../xaeroplus/fabric/XaeroPlusFabric.java | 15 +- .../mixin/client/MixinSodium6OptionsGUI.java | 28 +- .../mixin/client/MixinSodiumOptionsGUI.java | 28 +- .../forge/XaeroPlusEmbeddiumOptionsInit.java | 28 +- .../java/xaeroplus/forge/XaeroPlusForge.java | 43 +- .../mixin/client/MixinSodium6OptionsGUI.java | 28 +- 78 files changed, 1769 insertions(+), 1954 deletions(-) create mode 100644 common/src/main/java/xaeroplus/settings/BooleanSetting.java create mode 100644 common/src/main/java/xaeroplus/settings/DoubleSetting.java create mode 100644 common/src/main/java/xaeroplus/settings/EnumSetting.java create mode 100644 common/src/main/java/xaeroplus/settings/SettingHooks.java create mode 100644 common/src/main/java/xaeroplus/settings/SettingLocation.java create mode 100644 common/src/main/java/xaeroplus/settings/SettingRegistry.java create mode 100644 common/src/main/java/xaeroplus/settings/Settings.java delete mode 100644 common/src/main/java/xaeroplus/settings/XaeroPlusBooleanSetting.java delete mode 100644 common/src/main/java/xaeroplus/settings/XaeroPlusEnumSetting.java delete mode 100644 common/src/main/java/xaeroplus/settings/XaeroPlusFloatSetting.java delete mode 100644 common/src/main/java/xaeroplus/settings/XaeroPlusModSettingsHooks.java delete mode 100644 common/src/main/java/xaeroplus/settings/XaeroPlusSettingRegistry.java delete mode 100644 common/src/main/java/xaeroplus/settings/XaeroPlusSettingsReflectionHax.java diff --git a/common/src/main/java/xaeroplus/Globals.java b/common/src/main/java/xaeroplus/Globals.java index a532ca61..2ad738c5 100644 --- a/common/src/main/java/xaeroplus/Globals.java +++ b/common/src/main/java/xaeroplus/Globals.java @@ -8,9 +8,7 @@ import xaero.map.core.XaeroWorldMapCore; import xaeroplus.event.ClientPlaySessionFinalizedEvent; import xaeroplus.feature.render.DrawManager; -import xaeroplus.settings.XaeroPlusSetting; -import xaeroplus.settings.XaeroPlusSettingRegistry; -import xaeroplus.settings.XaeroPlusSettingsReflectionHax; +import xaeroplus.settings.Settings; import java.io.ByteArrayOutputStream; import java.util.concurrent.ExecutorService; @@ -26,7 +24,7 @@ public class Globals { public static final DrawManager drawManager = new DrawManager(); // cache and only update this on new world loads public static boolean nullOverworldDimensionFolder = false; - public static XaeroPlusSettingRegistry.DataFolderResolutionMode dataFolderResolutionMode = XaeroPlusSettingRegistry.DataFolderResolutionMode.IP; + public static Settings.DataFolderResolutionMode dataFolderResolutionMode = Settings.DataFolderResolutionMode.IP; public static int minimapScaleMultiplier = 1; public static int minimapSizeMultiplier = 1; public static boolean shouldResetFBO = false; @@ -60,15 +58,14 @@ public static ResourceKey getCurrentDimensionId() { .setDaemon(true) .build())); - public static void onAllSettingsLoaded() { - XaeroPlusSettingsReflectionHax.ALL_SETTINGS.get().forEach(XaeroPlusSetting::init); - nullOverworldDimensionFolder = XaeroPlusSettingRegistry.nullOverworldDimensionFolder.getValue(); - dataFolderResolutionMode = XaeroPlusSettingRegistry.dataFolderResolutionMode.getValue(); - minimapScaleMultiplier = (int) XaeroPlusSettingRegistry.minimapScaleMultiplierSetting.getValue(); - minimapSizeMultiplier = (int) XaeroPlusSettingRegistry.minimapSizeMultiplierSetting.getValue(); + public static void initStickySettings() { + nullOverworldDimensionFolder = Settings.REGISTRY.nullOverworldDimensionFolder.get(); + dataFolderResolutionMode = Settings.REGISTRY.dataFolderResolutionMode.get(); + minimapScaleMultiplier = Settings.REGISTRY.minimapScaleMultiplierSetting.getAsInt(); + minimapSizeMultiplier = Settings.REGISTRY.minimapSizeMultiplierSetting.getAsInt(); XaeroPlus.EVENT_BUS.registerConsumer((e) -> { - nullOverworldDimensionFolder = XaeroPlusSettingRegistry.nullOverworldDimensionFolder.getValue(); - dataFolderResolutionMode = XaeroPlusSettingRegistry.dataFolderResolutionMode.getValue(); + nullOverworldDimensionFolder = Settings.REGISTRY.nullOverworldDimensionFolder.get(); + dataFolderResolutionMode = Settings.REGISTRY.dataFolderResolutionMode.get(); }, ClientPlaySessionFinalizedEvent.class); } @@ -99,7 +96,7 @@ public static void setNullOverworldDimFolderIfAble(final boolean b) { } } - public static void setDataFolderResolutionModeIfAble(XaeroPlusSettingRegistry.DataFolderResolutionMode mode) { + public static void setDataFolderResolutionModeIfAble(Settings.DataFolderResolutionMode mode) { try { var currentWMSession = XaeroWorldMapCore.currentSession; var currentMMSession = HudSession.getCurrentSession(); diff --git a/common/src/main/java/xaeroplus/XaeroPlus.java b/common/src/main/java/xaeroplus/XaeroPlus.java index 0c6a7b59..ed7852b5 100644 --- a/common/src/main/java/xaeroplus/XaeroPlus.java +++ b/common/src/main/java/xaeroplus/XaeroPlus.java @@ -5,13 +5,23 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import xaero.map.platform.Services; +import xaeroplus.settings.Settings; +import xaeroplus.settings.XaeroPlusSetting; import java.io.File; import java.util.concurrent.atomic.AtomicBoolean; +import static xaeroplus.settings.SettingHooks.loadXPSettings; + public class XaeroPlus { public static final Logger LOGGER = LoggerFactory.getLogger("XaeroPlus"); public static final LambdaManager EVENT_BUS = LambdaManager.basic(new LambdaMetaFactoryGenerator()); public static final AtomicBoolean initialized = new AtomicBoolean(false); public static final File configFile = Services.PLATFORM.getConfigDir().resolve("xaeroplus.txt").toFile(); + + public static void initializeSettings() { + loadXPSettings(); + Settings.REGISTRY.getAllSettings().forEach(XaeroPlusSetting::init); + Globals.initStickySettings(); + } } diff --git a/common/src/main/java/xaeroplus/feature/extensions/GuiXaeroPlusChunkHighlightSettings.java b/common/src/main/java/xaeroplus/feature/extensions/GuiXaeroPlusChunkHighlightSettings.java index 8afe326f..4b51093f 100644 --- a/common/src/main/java/xaeroplus/feature/extensions/GuiXaeroPlusChunkHighlightSettings.java +++ b/common/src/main/java/xaeroplus/feature/extensions/GuiXaeroPlusChunkHighlightSettings.java @@ -4,14 +4,14 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; import xaero.map.gui.GuiSettings; -import xaero.map.gui.ISettingEntry; import xaero.map.gui.ScreenSwitchSettingEntry; -import xaeroplus.settings.XaeroPlusSettingsReflectionHax; +import xaeroplus.settings.SettingLocation; +import xaeroplus.settings.Settings; public class GuiXaeroPlusChunkHighlightSettings extends GuiSettings { public GuiXaeroPlusChunkHighlightSettings(Screen parent, Screen escapeScreen) { super(Component.translatable("gui.xaeroplus.chunk_highlight_settings"), parent, escapeScreen); - this.entries = XaeroPlusSettingsReflectionHax.getChunkHighlightConfigSettingEntries().toArray(new ISettingEntry[0]); + this.entries = Settings.REGISTRY.getWorldmapConfigSettingEntries(SettingLocation.CHUNK_HIGHLIGHTS); } @Override diff --git a/common/src/main/java/xaeroplus/feature/extensions/GuiXaeroPlusWorldMapSettings.java b/common/src/main/java/xaeroplus/feature/extensions/GuiXaeroPlusWorldMapSettings.java index a22ec5e2..7338b713 100644 --- a/common/src/main/java/xaeroplus/feature/extensions/GuiXaeroPlusWorldMapSettings.java +++ b/common/src/main/java/xaeroplus/feature/extensions/GuiXaeroPlusWorldMapSettings.java @@ -6,18 +6,19 @@ import xaero.map.gui.GuiSettings; import xaero.map.gui.ISettingEntry; import xaero.map.gui.ScreenSwitchSettingEntry; -import xaeroplus.settings.XaeroPlusSettingsReflectionHax; +import xaeroplus.settings.SettingLocation; +import xaeroplus.settings.Settings; public class GuiXaeroPlusWorldMapSettings extends GuiSettings { public GuiXaeroPlusWorldMapSettings(Screen parent, Screen escapeScreen) { super(Component.translatable("gui.xaeroplus.world_map_settings"), parent, escapeScreen); - var mainSettingsEntries = XaeroPlusSettingsReflectionHax.getWorldMapConfigSettingEntries(); + var mainSettingsEntries = Settings.REGISTRY.getWorldmapConfigSettingEntries(SettingLocation.WORLD_MAP_MAIN); var chunkHighlightSettingSwitchEntry = GuiXaeroPlusChunkHighlightSettings.getScreenSwitchSettingEntry(parent); - this.entries = new ISettingEntry[mainSettingsEntries.size() + 1]; + this.entries = new ISettingEntry[mainSettingsEntries.length + 1]; this.entries[0] = chunkHighlightSettingSwitchEntry; - for (int i = 0; i < mainSettingsEntries.size(); i++) { - this.entries[i + 1] = mainSettingsEntries.get(i); + for (int i = 0; i < mainSettingsEntries.length; i++) { + this.entries[i + 1] = mainSettingsEntries[i]; } } diff --git a/common/src/main/java/xaeroplus/feature/render/DrawManager.java b/common/src/main/java/xaeroplus/feature/render/DrawManager.java index bf0dfd7a..a1cc54e6 100644 --- a/common/src/main/java/xaeroplus/feature/render/DrawManager.java +++ b/common/src/main/java/xaeroplus/feature/render/DrawManager.java @@ -11,7 +11,7 @@ import xaeroplus.XaeroPlus; import xaeroplus.event.DimensionSwitchEvent; import xaeroplus.event.XaeroWorldChangeEvent; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import xaeroplus.util.ChunkUtils; import xaeroplus.util.ColorHelper; @@ -83,7 +83,7 @@ public synchronized void drawMinimapFeatures( -(chunkZ * 64) - (tileZ * 16) - insideZ, 0); matrixStack.scale(16f, 16f, 1f); - if (XaeroPlusSettingRegistry.highlightShader.getValue()) { + if (Settings.REGISTRY.highlightShader.get()) { drawMinimapFeaturesShader(matrixStack); } else { drawMinimapFeaturesImmediate(minViewMapTileChunkCoordX, maxViewMapTileChunkCoordX, minViewMapTileChunkCoordZ, maxViewMapTileChunkCoordZ, @@ -175,7 +175,7 @@ public synchronized void drawWorldMapFeatures( matrixStack.pushPose(); matrixStack.translate(-flooredCameraX, -flooredCameraZ, 1.0f); matrixStack.scale(16f, 16f, 1f); - if (XaeroPlusSettingRegistry.highlightShader.getValue()) + if (Settings.REGISTRY.highlightShader.get()) drawWorldMapFeaturesShader(matrixStack); else drawWorldMapFeaturesImmediate(minBlockX, maxBlockX, minBlockZ, maxBlockZ, diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinBuiltInInfoDisplays.java b/common/src/main/java/xaeroplus/mixin/client/MixinBuiltInInfoDisplays.java index 452f6de1..5d891627 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinBuiltInInfoDisplays.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinBuiltInInfoDisplays.java @@ -10,7 +10,7 @@ import xaero.common.minimap.info.BuiltInInfoDisplays; import xaero.common.minimap.info.render.compile.InfoDisplayCompiler; import xaero.hud.minimap.world.MinimapWorld; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import xaeroplus.util.ChunkUtils; @Mixin(value = BuiltInInfoDisplays.class, remap = false) @@ -21,7 +21,7 @@ public class MixinBuiltInInfoDisplays { target = "Lxaero/common/minimap/info/render/compile/InfoDisplayCompiler;addWords(ILjava/lang/String;)V")) private static void hideAutoSubworldInfoWhenOwAutoWaypointsEnabled(final InfoDisplayCompiler instance, final int lineWidth, final String text, final Operation original, @Local(name = "currentWorld") MinimapWorld currentWorld) { - if (XaeroPlusSettingRegistry.owAutoWaypointDimension.getValue()) { + if (Settings.REGISTRY.owAutoWaypointDimension.get()) { ResourceKey actualDimension = ChunkUtils.getActualDimension(); if (actualDimension == Level.NETHER && currentWorld.getDimId() == Level.OVERWORLD) return; } diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinClientEvents.java b/common/src/main/java/xaeroplus/mixin/client/MixinClientEvents.java index 7e4bb397..2d3c8699 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinClientEvents.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinClientEvents.java @@ -12,14 +12,14 @@ import xaero.common.events.ClientEvents; import xaero.common.minimap.waypoints.WaypointSharingHandler; import xaeroplus.XaeroPlus; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; @Mixin(value = ClientEvents.class, remap = false) public abstract class MixinClientEvents { @Inject(method = "handleClientSystemChatReceivedEvent", at = @At("HEAD"), cancellable = true) public void onSystemChatReceived(final Component component, final CallbackInfoReturnable cir) { if (component == null) return; - if (XaeroPlusSettingRegistry.disableReceivingWaypoints.getValue()) { + if (Settings.REGISTRY.disableReceivingWaypoints.get()) { // cancelling at head so we avoid hitting the logic to parse the waypoint string cir.setReturnValue(false); // false will show the raw message in chat to the player } @@ -28,7 +28,7 @@ public void onSystemChatReceived(final Component component, final CallbackInfoRe @Inject(method = "handleClientPlayerChatReceivedEvent", at = @At("HEAD"), cancellable = true) public void onPlayerChatReceived(final ChatType.Bound chatType, final Component component, final GameProfile gameProfile, final CallbackInfoReturnable cir) { if (component == null) return; - if (XaeroPlusSettingRegistry.disableReceivingWaypoints.getValue()) { + if (Settings.REGISTRY.disableReceivingWaypoints.get()) { // cancelling at head so we avoid hitting the logic to parse the waypoint string cir.setReturnValue(false); // false will show the raw message in chat to the player } diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinCommonGuiSettings.java b/common/src/main/java/xaeroplus/mixin/client/MixinCommonGuiSettings.java index 612700cc..3b1d6a22 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinCommonGuiSettings.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinCommonGuiSettings.java @@ -22,13 +22,10 @@ import xaero.common.misc.KeySortableByOther; import xaero.common.settings.ModOptions; import xaeroplus.XaeroPlus; -import xaeroplus.settings.XaeroPlusSetting; -import xaeroplus.settings.XaeroPlusSettingRegistry; -import xaeroplus.settings.XaeroPlusSettingsReflectionHax; +import xaeroplus.settings.Settings; import java.lang.reflect.Field; import java.util.ArrayList; -import java.util.Optional; @Mixin(value = GuiSettings.class, remap = false) public abstract class MixinCommonGuiSettings extends ScreenBase { @@ -50,7 +47,7 @@ protected MixinCommonGuiSettings(final IXaeroMinimap modMain, final Screen paren public void adjustEntriesPerPage(final CallbackInfo ci) { this.xaeroPlus$settingEntryWidth = 200; // default width this.entriesPerPage = 12; // fills height = 240 - if (XaeroPlusSettingRegistry.expandSettingEntries.getValue()) { + if (Settings.REGISTRY.expandSettingEntries.get()) { if (this.height > 350) { int extraRows = Math.min((height - 240) / 50, 6); this.entriesPerPage = 12 + (2 * extraRows); @@ -65,7 +62,7 @@ public void adjustEntriesPerPage(final CallbackInfo ci) { value = "RETURN" )) public void adjustForwardBackButtonPositionsForExtraRows(final CallbackInfo ci) { - if (!XaeroPlusSettingRegistry.expandSettingEntries.getValue()) return; + if (!Settings.REGISTRY.expandSettingEntries.get()) return; int extraRows = (this.entriesPerPage - 12) / 2; int yAdjust = (extraRows * 24); this.nextButton.setY(this.nextButton.getY() + yAdjust); @@ -89,11 +86,9 @@ public boolean settingListToRenderRedirect(final ArrayList instance, final Objec option.setAccessible(true); ModOptions modOptions = (ModOptions) option.get(settingEntry); String settingName = modOptions.getEnumString(); - Optional foundSetting = XaeroPlusSettingsReflectionHax.ALL_MINIMAP_SETTINGS.get().stream() - .filter(s -> s.getSettingName().equals(settingName)) - .findFirst(); - if (foundSetting.isPresent()) { - if (!foundSetting.get().isVisible()) { + var xpSetting = Settings.REGISTRY.getSettingByName(settingName); + if (xpSetting != null) { + if (!xpSetting.isVisible()) { // skip adding setting return false; } @@ -123,7 +118,7 @@ public boolean settingListToRenderRedirect(final ArrayList instance, final Objec ) public AbstractWidget adjustSettingEntryWidth(final ISettingEntry instance, final int x, final int y, final int w, final boolean canEditIngameSettings, final Operation original, @Local(name = "i") int i) { - if (!XaeroPlusSettingRegistry.expandSettingEntries.getValue()) return original.call(instance, x, y, w, canEditIngameSettings); + if (!Settings.REGISTRY.expandSettingEntries.get()) return original.call(instance, x, y, w, canEditIngameSettings); int xOffset = ((i % 2 == 0) ? -1 : 1) * ((xaeroPlus$settingEntryWidth - 200) / 2); return original.call(instance, x + xOffset, y, xaeroPlus$settingEntryWidth, canEditIngameSettings); } diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinCommonInternet.java b/common/src/main/java/xaeroplus/mixin/client/MixinCommonInternet.java index 8c468aa8..e130b987 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinCommonInternet.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinCommonInternet.java @@ -6,13 +6,13 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import xaero.common.IXaeroMinimap; import xaero.common.misc.Internet; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; @Mixin(value = Internet.class, remap = false) public class MixinCommonInternet { @Inject(method = "checkModVersion", at = @At("HEAD"), cancellable = true, remap = false) private static void disableInternetAccessCheck(final IXaeroMinimap modMain, final CallbackInfo ci) { - if (XaeroPlusSettingRegistry.disableXaeroInternetAccess.getValue()) ci.cancel(); + if (Settings.REGISTRY.disableXaeroInternetAccess.get()) ci.cancel(); } } diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinControlsHandler.java b/common/src/main/java/xaeroplus/mixin/client/MixinControlsHandler.java index a234bb5a..06c31d31 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinControlsHandler.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinControlsHandler.java @@ -6,8 +6,8 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import xaero.common.controls.ControlsHandler; -import xaeroplus.settings.XaeroPlusBooleanSetting; -import xaeroplus.settings.XaeroPlusSettingsReflectionHax; +import xaeroplus.settings.BooleanSetting; +import xaeroplus.settings.Settings; @Mixin(value = ControlsHandler.class, remap = false) public class MixinControlsHandler { @@ -15,9 +15,9 @@ public class MixinControlsHandler { @Inject(method = "keyDown", at = @At("RETURN")) public void keyDown(KeyMapping kb, boolean tickEnd, boolean isRepeat, CallbackInfo ci) { if (!tickEnd) { - XaeroPlusBooleanSetting setting = XaeroPlusSettingsReflectionHax.keybindingMapSupplier.get().get(kb); + BooleanSetting setting = Settings.REGISTRY.getKeybindingSetting(kb); if (setting == null) return; - setting.setValue(!setting.getValue()); + setting.setValue(!setting.get()); } } } diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinGuiEntityRadarSettings.java b/common/src/main/java/xaeroplus/mixin/client/MixinGuiEntityRadarSettings.java index b9272fde..51a45e7b 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinGuiEntityRadarSettings.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinGuiEntityRadarSettings.java @@ -11,7 +11,8 @@ import xaero.common.gui.GuiEntityRadarSettings; import xaero.common.gui.GuiMinimapSettings; import xaero.common.gui.ISettingEntry; -import xaeroplus.settings.XaeroPlusSettingsReflectionHax; +import xaeroplus.settings.SettingLocation; +import xaeroplus.settings.Settings; @Mixin(value = GuiEntityRadarSettings.class, remap = false) public abstract class MixinGuiEntityRadarSettings extends GuiMinimapSettings { @@ -22,8 +23,7 @@ public MixinGuiEntityRadarSettings(final IXaeroMinimap modMain, final Component @Inject(method = "", at = @At("RETURN")) public void init(final IXaeroMinimap modMain, final Screen backScreen, final Screen escScreen, final CallbackInfo ci) { - final ConfigSettingEntry[] configSettingEntries = XaeroPlusSettingsReflectionHax.getMinimapEntityRadarSettingEntries() - .toArray(new ConfigSettingEntry[0]); + final ConfigSettingEntry[] configSettingEntries = Settings.REGISTRY.getMinimapConfigSettingEntries(SettingLocation.MINIMAP_ENTITY_RADAR); final int oldLen = this.entries.length; final int newLen = configSettingEntries.length; final int totalNewLen = oldLen + configSettingEntries.length; diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinGuiMap.java b/common/src/main/java/xaeroplus/mixin/client/MixinGuiMap.java index f5d3ae89..b7fc4cb7 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinGuiMap.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinGuiMap.java @@ -49,7 +49,7 @@ import xaero.map.world.MapDimension; import xaeroplus.Globals; import xaeroplus.XaeroPlus; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import xaeroplus.util.BaritoneExecutor; import xaeroplus.util.BaritoneHelper; import xaeroplus.util.ChunkUtils; @@ -114,7 +114,7 @@ protected MixinGuiMap(final Screen parent, final Screen escape, final Component value = "CONSTANT", args = "doubleValue=0.0625")) public double customMinZoom(final double original) { - return XaeroPlusSettingRegistry.worldMapMinZoomSetting.getValue() / 10.0f; + return Settings.REGISTRY.worldMapMinZoomSetting.get() / 10.0f; } @Inject(method = "init", at = @At(value = "RETURN"), remap = true) @@ -169,12 +169,12 @@ public void customInitGui(CallbackInfo ci) { @Override protected void onExit(Screen screen) { - if (!XaeroPlusSettingRegistry.persistMapDimensionSwitchSetting.getValue()) { + if (!Settings.REGISTRY.persistMapDimensionSwitchSetting.get()) { try { var actualDimension = ChunkUtils.getActualDimension(); if (Globals.getCurrentDimensionId() != actualDimension) { Globals.switchToDimension(actualDimension); - if (!XaeroPlusSettingRegistry.radarWhileDimensionSwitchedSetting.getValue()) { + if (!Settings.REGISTRY.radarWhileDimensionSwitchedSetting.get()) { WorldMap.settings.minimapRadar = true; } } @@ -192,7 +192,7 @@ protected void onExit(Screen screen) { shift = At.Shift.AFTER ), remap = true) public void toggleRadarWhileDimensionSwitched(final GuiGraphics guiGraphics, final int scaledMouseX, final int scaledMouseY, final float partialTicks, final CallbackInfo ci, @Local(name = "currentFutureDim") MapDimension currentFutureDim) { - if (!XaeroPlusSettingRegistry.radarWhileDimensionSwitchedSetting.getValue()) { + if (!Settings.REGISTRY.radarWhileDimensionSwitchedSetting.get()) { WorldMap.settings.minimapRadar = currentFutureDim.getDimId() == ChunkUtils.getActualDimension(); } } @@ -310,7 +310,7 @@ public boolean hideArrowOnF1(boolean original) { ordinal = 0 ), index = 2) public String renderCrossDimensionCursorCoordinates(final String original) { - if (!XaeroPlusSettingRegistry.crossDimensionCursorCoordinates.getValue()) return original; + if (!Settings.REGISTRY.crossDimensionCursorCoordinates.get()) return original; ResourceKey dim = getCurrentDimensionId(); if (!(dim == OVERWORLD || dim == NETHER)) return original; double dimDiv = dim == NETHER @@ -331,7 +331,7 @@ public void showRenderDistanceWorldMap(final GuiGraphics guiGraphics, final int @Local(name = "renderTypeBuffers") MultiBufferSource.BufferSource renderTypeBuffers, @Local(name = "matrixStack") PoseStack matrixStack) { Minecraft mc = Minecraft.getInstance(); - if (XaeroPlusSettingRegistry.showRenderDistanceWorldMapSetting.getValue() && !mc.options.hideGui) { + if (Settings.REGISTRY.showRenderDistanceWorldMapSetting.get() && !mc.options.hideGui) { if (mc.level.dimension() == Globals.getCurrentDimensionId()) { final int viewDistance = mc.options.serverRenderDistance; int width = viewDistance * 2 + 1; @@ -440,7 +440,7 @@ public boolean hideMoreRenderedStringsOnF1(final GuiGraphics guiGraphics, final @Inject(method = "onDimensionToggleButton", at = @At(value = "RETURN")) public void onDimensionToggleAfter(final Button b, final CallbackInfo ci) { - if (!XaeroPlusSettingRegistry.radarWhileDimensionSwitchedSetting.getValue()) { + if (!Settings.REGISTRY.radarWhileDimensionSwitchedSetting.get()) { WorldMap.settings.minimapRadar = mapProcessor.getMapWorld().getFutureDimensionId() == ChunkUtils.getActualDimension(); } } @@ -523,13 +523,13 @@ public void onInputPress(final int code, final int scanCode, final int modifiers } } if (BaritoneHelper.isBaritonePresent()) { - if (XaeroPlusSettingRegistry.worldMapBaritoneGoalHereKeybindSetting.getKeyBinding().matches(code, scanCode)) { + if (Settings.REGISTRY.worldMapBaritoneGoalHereKeybindSetting.getKeyBinding().matches(code, scanCode)) { BaritoneExecutor.goal(mouseBlockPosX, mouseBlockPosZ); cir.setReturnValue(true); - } else if (XaeroPlusSettingRegistry.worldMapBaritonePathHereKeybindSetting.getKeyBinding().matches(code, scanCode)) { + } else if (Settings.REGISTRY.worldMapBaritonePathHereKeybindSetting.getKeyBinding().matches(code, scanCode)) { BaritoneExecutor.path(mouseBlockPosX, mouseBlockPosZ); cir.setReturnValue(true); - } else if (BaritoneHelper.isBaritoneElytraPresent() && XaeroPlusSettingRegistry.worldMapBaritoneElytraHereKeybindSetting.getKeyBinding().matches(code, scanCode)) { + } else if (BaritoneHelper.isBaritoneElytraPresent() && Settings.REGISTRY.worldMapBaritoneElytraHereKeybindSetting.getKeyBinding().matches(code, scanCode)) { BaritoneExecutor.elytra(mouseBlockPosX, mouseBlockPosZ); cir.setReturnValue(true); } @@ -548,13 +548,13 @@ public void getRightClickOptionsInject(final CallbackInfoReturnable ((AccessorRightClickOption) option).getName().equals("gui.xaero_right_click_map_share_location")); } } diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinGuiMinimapMain.java b/common/src/main/java/xaeroplus/mixin/client/MixinGuiMinimapMain.java index 34292e9b..87632cf7 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinGuiMinimapMain.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinGuiMinimapMain.java @@ -12,7 +12,8 @@ import xaero.common.gui.GuiMinimapMain; import xaero.common.gui.GuiSettings; import xaero.common.gui.ISettingEntry; -import xaeroplus.settings.XaeroPlusSettingsReflectionHax; +import xaeroplus.settings.SettingLocation; +import xaeroplus.settings.Settings; @Mixin(value = GuiMinimapMain.class, remap = false) public abstract class MixinGuiMinimapMain extends GuiSettings { @@ -28,8 +29,7 @@ public MixinGuiMinimapMain(final IXaeroMinimap modMain, final Component title, f at = @At("RETURN"), remap = true) // $REMAP public void init(final IXaeroMinimap modMain, final Screen par1GuiScreen, final Screen escScreen, final CallbackInfo ci) { - final ConfigSettingEntry[] configSettingEntries = XaeroPlusSettingsReflectionHax.getMinimapMainConfigSettingEntries() - .toArray(new ConfigSettingEntry[0]); + final ConfigSettingEntry[] configSettingEntries = Settings.REGISTRY.getMinimapConfigSettingEntries(SettingLocation.MINIMAP_MAIN); final int oldLen = this.mainEntries.length; final int newLen = configSettingEntries.length; final int totalNewLen = oldLen + configSettingEntries.length; diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinGuiMinimapOverlaysSettings.java b/common/src/main/java/xaeroplus/mixin/client/MixinGuiMinimapOverlaysSettings.java index fc60f1b9..b161fba9 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinGuiMinimapOverlaysSettings.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinGuiMinimapOverlaysSettings.java @@ -11,7 +11,8 @@ import xaero.common.gui.GuiMinimapOverlaysSettings; import xaero.common.gui.GuiSettings; import xaero.common.gui.ISettingEntry; -import xaeroplus.settings.XaeroPlusSettingsReflectionHax; +import xaeroplus.settings.SettingLocation; +import xaeroplus.settings.Settings; @Mixin(value = GuiMinimapOverlaysSettings.class, remap = false) public abstract class MixinGuiMinimapOverlaysSettings extends GuiSettings { @@ -22,8 +23,7 @@ public MixinGuiMinimapOverlaysSettings(final IXaeroMinimap modMain, final Compon @Inject(method = "", at = @At("RETURN")) public void init(final IXaeroMinimap modMain, final Screen backScreen, final Screen escScreen, final CallbackInfo ci) { - final ConfigSettingEntry[] configSettingEntries = XaeroPlusSettingsReflectionHax.getMinimapOverlayConfigSettingEntries() - .toArray(new ConfigSettingEntry[0]); + final ConfigSettingEntry[] configSettingEntries = Settings.REGISTRY.getMinimapConfigSettingEntries(SettingLocation.MINIMAP_OVERLAYS); final int oldLen = this.entries.length; final int newLen = configSettingEntries.length; final int totalNewLen = oldLen + configSettingEntries.length; diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinGuiWaypointSettings.java b/common/src/main/java/xaeroplus/mixin/client/MixinGuiWaypointSettings.java index 38cbe0fa..13650a7f 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinGuiWaypointSettings.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinGuiWaypointSettings.java @@ -11,7 +11,8 @@ import xaero.common.gui.GuiMinimapSettings; import xaero.common.gui.GuiWaypointSettings; import xaero.common.gui.ISettingEntry; -import xaeroplus.settings.XaeroPlusSettingsReflectionHax; +import xaeroplus.settings.SettingLocation; +import xaeroplus.settings.Settings; @Mixin(value = GuiWaypointSettings.class, remap = false) public class MixinGuiWaypointSettings extends GuiMinimapSettings { @@ -21,8 +22,7 @@ public MixinGuiWaypointSettings(final IXaeroMinimap modMain, final Component tit @Inject(method = "", at = @At("RETURN")) public void init(final IXaeroMinimap modMain, final Screen backScreen, final Screen escScreen, final CallbackInfo ci) { - final ConfigSettingEntry[] configSettingEntries = XaeroPlusSettingsReflectionHax.getMinimapWaypointConfigSettingEntries() - .toArray(new ConfigSettingEntry[0]); + final ConfigSettingEntry[] configSettingEntries = Settings.REGISTRY.getMinimapConfigSettingEntries(SettingLocation.MINIMAP_WAYPOINTS); final int oldLen = this.entries.length; final int newLen = configSettingEntries.length; final int totalNewLen = oldLen + configSettingEntries.length; diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinGuiWaypoints.java b/common/src/main/java/xaeroplus/mixin/client/MixinGuiWaypoints.java index 6e16b226..486db9ba 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinGuiWaypoints.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinGuiWaypoints.java @@ -24,7 +24,7 @@ import xaero.common.misc.KeySortableByOther; import xaero.hud.minimap.module.MinimapSession; import xaero.hud.minimap.world.MinimapWorld; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import java.util.ArrayList; import java.util.Collections; @@ -123,7 +123,7 @@ public void drawScreenInject(final GuiGraphics guiGraphics, final int mouseX, fi @Redirect(method = "updateButtons", at = @At(value = "INVOKE", target = "Lxaero/common/gui/GuiWaypoints;isOneSelected()Z")) public boolean shareButtonRedirect(final GuiWaypoints instance) { - if (XaeroPlusSettingRegistry.disableWaypointSharing.getValue()) return false; + if (Settings.REGISTRY.disableWaypointSharing.get()) return false; return isOneSelected(); } diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinGuiWaypointsList.java b/common/src/main/java/xaeroplus/mixin/client/MixinGuiWaypointsList.java index bc63afd9..7b94a3d5 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinGuiWaypointsList.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinGuiWaypointsList.java @@ -17,7 +17,7 @@ import xaero.common.minimap.waypoints.Waypoint; import xaero.hud.minimap.waypoint.set.WaypointSet; import xaero.hud.minimap.world.MinimapWorld; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import java.text.NumberFormat; @@ -70,7 +70,7 @@ public void shiftIconsLeft(final GuiGraphics guiGraphics, final Waypoint w, fina target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch()V" ), remap = true) public void drawWaypointDistances(final GuiGraphics guiGraphics, final Waypoint w, final int x, final int y, final CallbackInfo ci) { - if (XaeroPlusSettingRegistry.showWaypointDistances.getValue()) { + if (Settings.REGISTRY.showWaypointDistances.get()) { Entity renderViewEntity = Minecraft.getInstance().getCameraEntity(); final double playerX = renderViewEntity.getX(); final double playerZ = renderViewEntity.getZ(); diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinImprovedFramebuffer.java b/common/src/main/java/xaeroplus/mixin/client/MixinImprovedFramebuffer.java index 0aec1995..1c6475fb 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinImprovedFramebuffer.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinImprovedFramebuffer.java @@ -7,7 +7,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import xaero.common.graphics.ImprovedFramebuffer; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; @Mixin(value = ImprovedFramebuffer.class) public class MixinImprovedFramebuffer { @@ -17,7 +17,7 @@ public class MixinImprovedFramebuffer { target = "Lxaero/common/graphics/ImprovedFramebuffer;detectOptifineFBOs()V" )) public void wrapDetectOptifineFBOs(final Operation original) { - if (!XaeroPlusSettingRegistry.minimapFpsLimiter.getValue()) original.call(); + if (!Settings.REGISTRY.minimapFpsLimiter.get()) original.call(); } @WrapOperation(method = "beginWrite", at = @At( @@ -25,7 +25,7 @@ public void wrapDetectOptifineFBOs(final Operation original) { target = "Lcom/mojang/blaze3d/platform/GlStateManager;_glBindFramebuffer(II)V" ), remap = false) private static void redirectBindFramebuffer(final int i, final int j, final Operation original) { - if (!XaeroPlusSettingRegistry.minimapFpsLimiter.getValue()) original.call(i, j); + if (!Settings.REGISTRY.minimapFpsLimiter.get()) original.call(i, j); // sidestep our redirect mixin in GlStateManager to allow xaero to bind and render to its custom FBOs RenderSystem.assertOnRenderThreadOrInit(); GL30.glBindFramebuffer(i, j); diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinKeyEventHandler.java b/common/src/main/java/xaeroplus/mixin/client/MixinKeyEventHandler.java index cf5f3c0c..eecf0ab6 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinKeyEventHandler.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinKeyEventHandler.java @@ -8,15 +8,15 @@ import xaero.common.IXaeroMinimap; import xaero.common.XaeroMinimapSession; import xaero.common.controls.event.KeyEventHandler; -import xaeroplus.settings.XaeroPlusSettingsReflectionHax; +import xaeroplus.settings.Settings; @Mixin(value = KeyEventHandler.class, remap = false) public class MixinKeyEventHandler { private static boolean init = false; @Inject(method = "onKeyInput", at = @At("HEAD")) public void onKeyInputInject(final Minecraft mc, final IXaeroMinimap modMain, final XaeroMinimapSession minimapSession, final CallbackInfo ci) { - if (init || XaeroPlusSettingsReflectionHax.keybindsSupplier.get().isEmpty()) return; + if (init) return; init = true; - modMain.getControlsRegister().keybindings.addAll(XaeroPlusSettingsReflectionHax.keybindsSupplier.get()); + modMain.getControlsRegister().keybindings.addAll(Settings.REGISTRY.getKeybindings()); } } diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinLeveledRegion.java b/common/src/main/java/xaeroplus/mixin/client/MixinLeveledRegion.java index 003a09d6..c9e74a74 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinLeveledRegion.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinLeveledRegion.java @@ -9,7 +9,7 @@ import xaero.map.region.LeveledRegion; import xaero.map.region.texture.RegionTexture; import xaeroplus.Globals; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import java.io.*; import java.util.zip.ZipOutputStream; @@ -21,7 +21,7 @@ public abstract class MixinLeveledRegion> { args = "class=java/io/DataOutputStream" )) public DataOutputStream replaceSaveCacheTexturesZipOutputStream(final OutputStream out) { - if (!XaeroPlusSettingRegistry.fastZipWrite.getValue()) return new DataOutputStream(out); + if (!Settings.REGISTRY.fastZipWrite.get()) return new DataOutputStream(out); Globals.zipFastByteBuffer.reset(); return new DataOutputStream(Globals.zipFastByteBuffer); } @@ -33,7 +33,7 @@ public DataOutputStream replaceSaveCacheTexturesZipOutputStream(final OutputStre public void writeSaveCacheTexturesZipOutputStream(final File tempFile, final int extraAttempts, final CallbackInfoReturnable cir, @Local(name = "zipOutput") ZipOutputStream zipOutputRef ) { - if (!XaeroPlusSettingRegistry.fastZipWrite.getValue()) return; + if (!Settings.REGISTRY.fastZipWrite.get()) return; try { Globals.zipFastByteBuffer.writeTo(zipOutputRef); Globals.zipFastByteBuffer.reset(); diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinMapPixel.java b/common/src/main/java/xaeroplus/mixin/client/MixinMapPixel.java index 990b58c6..bb8ba2c3 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinMapPixel.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinMapPixel.java @@ -19,7 +19,7 @@ import xaero.map.cache.BlockStateShortShapeCache; import xaero.map.region.*; import xaero.map.world.MapDimension; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import java.util.ArrayList; @Mixin(value = MapPixel.class, remap = false) @@ -60,11 +60,11 @@ public void getPixelColours( final BlockStateShortShapeCache blockStateShortShapeCache, final CallbackInfo ci ) { - if (XaeroPlusSettingRegistry.transparentObsidianRoofSetting.getValue()) { + if (Settings.REGISTRY.transparentObsidianRoofSetting.get()) { if (state.getBlock() == Blocks.OBSIDIAN || state.getBlock() == Blocks.CRYING_OBSIDIAN) { - result_dest[3] = (int) XaeroPlusSettingRegistry.transparentObsidianRoofDarkeningSetting.getValue(); + result_dest[3] = Settings.REGISTRY.transparentObsidianRoofDarkeningSetting.getAsInt(); } else if (state.getBlock() == Blocks.SNOW) { - result_dest[3] = (int) XaeroPlusSettingRegistry.transparentObsidianRoofSnowOpacitySetting.getValue(); + result_dest[3] = Settings.REGISTRY.transparentObsidianRoofSnowOpacitySetting.getAsInt(); } } } diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinMapProcessor.java b/common/src/main/java/xaeroplus/mixin/client/MixinMapProcessor.java index 0d90f5a6..aad83808 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinMapProcessor.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinMapProcessor.java @@ -25,7 +25,7 @@ import xaeroplus.XaeroPlus; import xaeroplus.event.XaeroWorldChangeEvent; import xaeroplus.feature.extensions.CustomMapProcessor; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import xaeroplus.util.ChunkUtils; import xaeroplus.util.DataFolderResolveUtil; @@ -157,7 +157,7 @@ public MapRegion createMapRegionInActualDimensionIfSignalled(String worldId, Str )) public MapDimension updateWorldSyncedGetActualDimension(final MapWorld mapWorld, final Operation original) { var world = this.world; - return XaeroPlusSettingRegistry.writesWhileDimSwitched.getValue() && world != null && mapWorld.isMultiplayer() + return Settings.REGISTRY.writesWhileDimSwitched.get() && world != null && mapWorld.isMultiplayer() ? mapWorld.getDimension(world.dimension()) : original.call(mapWorld); } diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinMapSaveLoad.java b/common/src/main/java/xaeroplus/mixin/client/MixinMapSaveLoad.java index 809dc6b5..c5410adc 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinMapSaveLoad.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinMapSaveLoad.java @@ -14,7 +14,7 @@ import xaero.map.region.MapRegion; import xaeroplus.Globals; import xaeroplus.XaeroPlus; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import java.io.DataOutputStream; import java.io.IOException; @@ -43,7 +43,7 @@ public void getOldFolder(final String oldUnfixedMainId, final String dim, final public DataOutputStream replaceSaveRegionZipOutputStream(final OutputStream out, @Local(name = "zipOut") final ZipOutputStream zipOut, @Share("zipOutShare") final LocalRef zipOutShare) { - if (!XaeroPlusSettingRegistry.fastZipWrite.getValue()) return new DataOutputStream(out); + if (!Settings.REGISTRY.fastZipWrite.get()) return new DataOutputStream(out); Globals.zipFastByteBuffer.reset(); zipOutShare.set(zipOut); return new DataOutputStream(Globals.zipFastByteBuffer); @@ -55,7 +55,7 @@ public DataOutputStream replaceSaveRegionZipOutputStream(final OutputStream out, )) public void saveRegionWriteZipOutputStream(final MapRegion region, final int extraAttempts, final CallbackInfoReturnable cir, @Local(name = "zipOut") final ZipOutputStream zipOut) throws IOException { - if (!XaeroPlusSettingRegistry.fastZipWrite.getValue()) return; + if (!Settings.REGISTRY.fastZipWrite.get()) return; Globals.zipFastByteBuffer.writeTo(zipOut); Globals.zipFastByteBuffer.reset(); } @@ -67,7 +67,7 @@ public void saveRegionWriteZipOutputStream(final MapRegion region, final int ext public void closeZipOutputStream(final MapRegion region, final int extraAttempts, final CallbackInfoReturnable cir, @Share("zipOutShare") final LocalRef zipOutShare ) throws IOException { - if (!XaeroPlusSettingRegistry.fastZipWrite.getValue()) return; + if (!Settings.REGISTRY.fastZipWrite.get()) return; zipOutShare.get().close(); } diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinMapTileChunk.java b/common/src/main/java/xaeroplus/mixin/client/MixinMapTileChunk.java index fe9e6dc1..0f930f56 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinMapTileChunk.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinMapTileChunk.java @@ -16,7 +16,7 @@ import xaero.map.world.MapDimension; import xaero.map.world.MapWorld; import xaeroplus.feature.extensions.SeenChunksTrackingMapTileChunk; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import java.io.DataInputStream; @@ -63,7 +63,7 @@ public void readCacheData( target = "Lxaero/map/world/MapWorld;getCurrentDimension()Lxaero/map/world/MapDimension;" )) public MapDimension useRegionDimensionInsteadOfMapWorld(final MapWorld mapWorld, final Operation original) { - if (XaeroPlusSettingRegistry.writesWhileDimSwitched.getValue() && mapWorld.isMultiplayer()) { + if (Settings.REGISTRY.writesWhileDimSwitched.get() && mapWorld.isMultiplayer()) { return getInRegion().getDim(); } else { return original.call(mapWorld); diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinMapWriter.java b/common/src/main/java/xaeroplus/mixin/client/MixinMapWriter.java index 03cbee87..df73c9e7 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinMapWriter.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinMapWriter.java @@ -38,7 +38,7 @@ import xaero.map.region.OverlayManager; import xaero.map.world.MapWorld; import xaeroplus.feature.extensions.CustomMapProcessor; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import xaeroplus.util.ChunkUtils; import java.util.concurrent.TimeUnit; @@ -73,7 +73,7 @@ public abstract class MixinMapWriter { @Inject(method = "loadPixel", at = @At("HEAD"), remap = false) public void setObsidianColumnLocalVar(final Level world, final Registry blockRegistry, final MapBlock pixel, final MapBlock currentPixel, final LevelChunk bchunk, final int insideX, final int insideZ, final int highY, final int lowY, final boolean cave, final boolean fullCave, final int mappedHeight, final boolean canReuseBiomeColours, final boolean ignoreHeightmaps, final Registry biomeRegistry, final boolean flowers, final int worldBottomY, final BlockPos.MutableBlockPos mutableBlockPos3, final CallbackInfo ci, @Share("columnRoofObsidian") LocalBooleanRef columnRoofObsidianRef) { - if (!XaeroPlusSettingRegistry.transparentObsidianRoofSetting.getValue()) return; + if (!Settings.REGISTRY.transparentObsidianRoofSetting.get()) return; columnRoofObsidianRef.set(false); } @@ -88,9 +88,9 @@ public void obsidianRoofHeadInject(final Level world, final Registry bloc @Local(name = "transparentSkipY") LocalIntRef transparentSkipYRef, @Share("columnRoofObsidian") LocalBooleanRef columnRoofObsidianRef ) { - if (!XaeroPlusSettingRegistry.transparentObsidianRoofSetting.getValue()) return; + if (!Settings.REGISTRY.transparentObsidianRoofSetting.get()) return; final Block b = stateRef.get().getBlock(); - final boolean blockHeightAboveYLimit = hRef.get() >= XaeroPlusSettingRegistry.transparentObsidianRoofYSetting.getValue(); + final boolean blockHeightAboveYLimit = hRef.get() >= Settings.REGISTRY.transparentObsidianRoofYSetting.get(); if (blockHeightAboveYLimit) { boolean shouldMakeTransparent = (b == Blocks.OBSIDIAN || b == Blocks.CRYING_OBSIDIAN); @@ -101,7 +101,7 @@ public void obsidianRoofHeadInject(final Level world, final Registry bloc shouldMakeTransparent = belowState.getBlock() == Blocks.OBSIDIAN || belowState.getBlock() == Blocks.CRYING_OBSIDIAN; } if (shouldMakeTransparent) { - if (XaeroPlusSettingRegistry.transparentObsidianRoofDarkeningSetting.getValue() == 0) { + if (Settings.REGISTRY.transparentObsidianRoofDarkeningSetting.get() == 0) { stateRef.set(Blocks.AIR.defaultBlockState()); transparentSkipYRef.set(transparentSkipYRef.get() - 1); } @@ -119,7 +119,7 @@ public void obsidianRoofHeadInject(final Level world, final Registry bloc ), remap = false) public boolean checkObsidianRoofColumn(final OverlayBuilder instance, final Operation original, @Share("columnRoofObsidian") final LocalBooleanRef columnRoofObsidianRef) { - if (!XaeroPlusSettingRegistry.transparentObsidianRoofSetting.getValue()) return original.call(instance); + if (!Settings.REGISTRY.transparentObsidianRoofSetting.get()) return original.call(instance); return original.call(instance) || columnRoofObsidianRef.get(); } @@ -133,8 +133,8 @@ public boolean obsidianRoofOverlayMod(final boolean original, @Local(name = "b") Block b, @Local(name = "h") int h ) { - if (XaeroPlusSettingRegistry.transparentObsidianRoofSetting.getValue() - && h > XaeroPlusSettingRegistry.transparentObsidianRoofYSetting.getValue()) { + if (Settings.REGISTRY.transparentObsidianRoofSetting.get() + && h > Settings.REGISTRY.transparentObsidianRoofYSetting.get()) { if (b == Blocks.OBSIDIAN || b == Blocks.CRYING_OBSIDIAN) { return true; } else if (b == Blocks.SNOW) { @@ -154,8 +154,8 @@ public boolean obsidianRoofOverlayMod(final boolean original, ), remap = true) public int getOpacityForObsidianRoof(BlockState instance, BlockGetter world, BlockPos pos, Operation original, @Local(name = "h") int h) { - if (XaeroPlusSettingRegistry.transparentObsidianRoofSetting.getValue() - && h > XaeroPlusSettingRegistry.transparentObsidianRoofYSetting.getValue()) { + if (Settings.REGISTRY.transparentObsidianRoofSetting.get() + && h > Settings.REGISTRY.transparentObsidianRoofYSetting.get()) { boolean shouldMakeTransparent = instance.getBlock() == Blocks.OBSIDIAN || instance.getBlock() == Blocks.CRYING_OBSIDIAN; if (instance.getBlock() == Blocks.SNOW) { this.mutableLocalPos.setY(h - 1); @@ -180,11 +180,11 @@ public int getOpacityForObsidianRoof(BlockState instance, BlockGetter world, Blo public void fastMapMaxTilesPerCycleSetting(final BiomeColorCalculator biomeColorCalculator, final OverlayManager overlayManager, final CallbackInfo ci, @Local(name = "tilesToUpdate") LocalLongRef tilesToUpdateRef, @Local(name = "sizeTiles") int sizeTiles) { - if (XaeroPlusSettingRegistry.fastMapSetting.getValue()) { + if (Settings.REGISTRY.fastMapSetting.get()) { this.writeFreeSinceLastWrite = Math.max(1L, this.writeFreeSinceLastWrite); if (this.mapProcessor.getCurrentCaveLayer() == Integer.MAX_VALUE) { tilesToUpdateRef.set((long) Math.min(sizeTiles, - XaeroPlusSettingRegistry.fastMapMaxTilesPerCycle.getValue())); + Settings.REGISTRY.fastMapMaxTilesPerCycle.get())); } } } @@ -195,7 +195,7 @@ public void fastMapMaxTilesPerCycleSetting(final BiomeColorCalculator biomeColor ordinal = 2 )) public long removeWriteTimeLimiterPerFrame(long original) { - if (XaeroPlusSettingRegistry.fastMapSetting.getValue()) { + if (Settings.REGISTRY.fastMapSetting.get()) { if (this.mapProcessor.getCurrentCaveLayer() == Integer.MAX_VALUE) { return 0; } @@ -231,12 +231,12 @@ public boolean fastMap(final MapWriter instance, int chunkX, int chunkZ, final Operation original) { - if (XaeroPlusSettingRegistry.fastMapSetting.getValue()) { + if (Settings.REGISTRY.fastMapSetting.get()) { if (this.mapProcessor.getCurrentCaveLayer() == Integer.MAX_VALUE) { final Long cacheable = ChunkUtils.chunkPosToLong(chunkX, chunkZ); final Long cacheValue = tileUpdateCache.getIfPresent(cacheable); if (nonNull(cacheValue)) { - if (cacheValue < System.currentTimeMillis() - (long) XaeroPlusSettingRegistry.fastMapWriterDelaySetting.getValue()) { + if (cacheValue < System.currentTimeMillis() - (long) Settings.REGISTRY.fastMapWriterDelaySetting.get()) { tileUpdateCache.put(cacheable, System.currentTimeMillis()); } else { return false; @@ -257,7 +257,7 @@ public void netherCaveFixInject(final Level world, final Registry blockRe @Local(index = 10, argsOnly = true) LocalBooleanRef caveRef, @Local(index = 11, argsOnly = true) LocalBooleanRef fullCaveRef ) { - if (XaeroPlusSettingRegistry.netherCaveFix.getValue()) { + if (Settings.REGISTRY.netherCaveFix.get()) { var nether = world.dimension() == NETHER; var shouldForceFullInNether = !cave && nether; caveRef.set(shouldForceFullInNether || cave); @@ -271,7 +271,7 @@ public void netherCaveFixInject(final Level world, final Registry blockRe remap = true) // $REMAP public ResourceKey removeCustomDimSwitchWriterPrevention(final MapWorld mapWorld, final Operation> original) { var world = mapProcessor.getWorld(); - return XaeroPlusSettingRegistry.writesWhileDimSwitched.getValue() && world != null && mapWorld.isMultiplayer() + return Settings.REGISTRY.writesWhileDimSwitched.get() && world != null && mapWorld.isMultiplayer() ? world.dimension() // makes if condition in injected code always true : original.call(mapWorld); } @@ -286,7 +286,7 @@ public ResourceKey removeCustomDimSwitchWriterPrevention(final MapWorld m @Inject(method = "onRender", at = @At("HEAD")) public void setCrossDimWriteSignals(final BiomeColorCalculator biomeColorCalculator, final OverlayManager overlayManager, final CallbackInfo ci) { - boolean signal = XaeroPlusSettingRegistry.writesWhileDimSwitched.getValue() + boolean signal = Settings.REGISTRY.writesWhileDimSwitched.get() && mapProcessor.getWorld() != null && mapProcessor.getMapWorld().isMultiplayer(); ((CustomMapProcessor) mapProcessor).xaeroPlus$getLeafRegionActualDimSignal().set(signal); @@ -304,7 +304,7 @@ public void resetSignals(final BiomeColorCalculator biomeColorCalculator, final target = "Lxaero/map/MapProcessor;getLeafMapRegion(IIIZ)Lxaero/map/region/MapRegion;" )) public MapRegion getActualMapRegionInOnRender(final MapProcessor mapProcessor, int caveLayer, int regX, int regZ, boolean create, final Operation original) { - if (XaeroPlusSettingRegistry.writesWhileDimSwitched.getValue() && mapProcessor.getMapWorld().isMultiplayer()) { + if (Settings.REGISTRY.writesWhileDimSwitched.get() && mapProcessor.getMapWorld().isMultiplayer()) { ((CustomMapProcessor) mapProcessor).xaeroPlus$getLeafRegionActualDimSignal().set(true); } try { diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinMinimapFBORenderer.java b/common/src/main/java/xaeroplus/mixin/client/MixinMinimapFBORenderer.java index 8f4ca030..7ebf3003 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinMinimapFBORenderer.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinMinimapFBORenderer.java @@ -37,7 +37,7 @@ import xaero.hud.minimap.module.MinimapSession; import xaeroplus.Globals; import xaeroplus.feature.extensions.CustomMinimapFBORenderer; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import xaeroplus.util.ColorHelper; @Mixin(value = MinimapFBORenderer.class, remap = false) @@ -121,7 +121,7 @@ public void modifyShaderMatrixStackTranslate(final PoseStack instance, final flo ), remap = true) public void modifyMMBackgroundFill(final GuiGraphics guiGraphics, final int x1, final int y1, final int x2, final int y2, final int color, @Share("scaledSize") LocalIntRef scaledSize) { - if (!XaeroPlusSettingRegistry.transparentMinimapBackground.getValue()) + if (!Settings.REGISTRY.transparentMinimapBackground.get()) guiGraphics.fill(-scaledSize.get(), -scaledSize.get(), scaledSize.get(), scaledSize.get(), ColorHelper.getColor(0, 0, 0, 255)); else guiGraphics.fill(-scaledSize.get(), -scaledSize.get(), scaledSize.get(), scaledSize.get(), ColorHelper.getColor(0, 0, 0, 0)); @@ -147,7 +147,7 @@ public void drawRenderDistanceSquare(final MinimapSession minimapSession, final @Local(name = "matrixStack") PoseStack matrixStack ) { final boolean isDimensionSwitched = Globals.getCurrentDimensionId() != Minecraft.getInstance().level.dimension(); - if (XaeroPlusSettingRegistry.showRenderDistanceSetting.getValue() && !isDimensionSwitched) { + if (Settings.REGISTRY.showRenderDistanceSetting.get() && !isDimensionSwitched) { double actualPlayerX = minimap.getEntityRadar().getEntityX(mc.player, partial); double actualPlayerZ = minimap.getEntityRadar().getEntityZ(mc.player, partial); int actualXFloored = OptimizedMath.myFloor(actualPlayerX); diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinMinimapModSettings.java b/common/src/main/java/xaeroplus/mixin/client/MixinMinimapModSettings.java index b270b941..8af55c1e 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinMinimapModSettings.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinMinimapModSettings.java @@ -1,7 +1,6 @@ package xaeroplus.mixin.client; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; -import com.llamalad7.mixinextras.sugar.Local; import net.minecraft.client.KeyMapping; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -15,15 +14,9 @@ import xaero.common.settings.ModSettings; import xaero.hud.minimap.Minimap; import xaeroplus.Globals; -import xaeroplus.settings.XaeroPlusModSettingsHooks; -import xaeroplus.settings.XaeroPlusSettingRegistry; -import xaeroplus.settings.XaeroPlusSettingsReflectionHax; +import xaeroplus.settings.SettingHooks; +import xaeroplus.settings.Settings; -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; - -import static xaeroplus.settings.XaeroPlusSettingsReflectionHax.ALL_MINIMAP_SETTINGS; @Mixin(value = ModSettings.class, remap = false) public class MixinMinimapModSettings { @@ -31,14 +24,8 @@ public class MixinMinimapModSettings { @Shadow public int caveMaps; @Shadow - private boolean lockNorth; - @Shadow - public boolean keepUnlockedWhenEnlarged; - @Shadow protected IXaeroMinimap modMain; - @Shadow private int minimapSize; - @Inject(method = "", at = @At(value = "RETURN")) private void init(CallbackInfo ci) { // don't show cave maps on minimap by default @@ -49,7 +36,7 @@ private void init(CallbackInfo ci) { value = "CONSTANT", args = "intValue=180")) public int allowNoNorthLockWithTransparentMM(final int original) { - if (XaeroPlusSettingRegistry.transparentMinimapBackground.getValue()) + if (Settings.REGISTRY.transparentMinimapBackground.get()) // will make the if expression always return false return Integer.MAX_VALUE; else return original; @@ -75,59 +62,47 @@ public void modifyMinimapSize(final CallbackInfoReturnable cir) { @Inject(method = "saveSettings", at = @At("RETURN")) public void saveSettings(final CallbackInfo ci) { - XaeroPlusModSettingsHooks.saveSettings(); - } - - @Inject(method = "loadSettings", at = @At(value = "INVOKE", target = "Lxaero/common/settings/ModSettings;saveSettings()V")) - public void loadSettings(final CallbackInfo ci, @Local(name = "mainConfigFile") Path mainConfigFile) throws IOException { - if (!mainConfigFile.toFile().exists()) { - XaeroPlusModSettingsHooks.loadSettings(null, ALL_MINIMAP_SETTINGS.get()); - } - } - - @Inject(method = "loadSettingsFile", at = @At("RETURN")) - public void loadSettingsFile(final File file, CallbackInfo ci) throws IOException { - XaeroPlusModSettingsHooks.loadSettings(file, ALL_MINIMAP_SETTINGS.get()); + SettingHooks.saveSettings(); } @Inject(method = "getClientBooleanValue", at = @At("HEAD"), cancellable = true) public void getClientBooleanValue(ModOptions o, CallbackInfoReturnable cir) { - XaeroPlusModSettingsHooks.getClientBooleanValue(o.getEnumString(), ALL_MINIMAP_SETTINGS.get(), cir); + SettingHooks.getClientBooleanValue(o.getEnumString(), cir); } @Inject(method = "setOptionValue", at = @At("HEAD")) public void setOptionValue(ModOptions o, Object value, final CallbackInfo ci) { - XaeroPlusModSettingsHooks.setOptionValue(o.getEnumString(), value, ALL_MINIMAP_SETTINGS.get()); + SettingHooks.setOptionValue(o.getEnumString(), value); } @Inject(method = "getOptionValue", at = @At("HEAD"), cancellable = true) public void getOptionValue(final ModOptions o, final CallbackInfoReturnable cir) { - XaeroPlusModSettingsHooks.getOptionValue(o.getEnumString(), cir, ALL_MINIMAP_SETTINGS.get()); + SettingHooks.getOptionValue(o.getEnumString(), cir); } @Inject(method = "setOptionDoubleValue", at = @At("HEAD")) public void setOptionFloatValue(ModOptions o, double f, CallbackInfo ci) { - XaeroPlusModSettingsHooks.setOptionDoubleValue(o.getEnumString(), f, ALL_MINIMAP_SETTINGS.get()); + SettingHooks.setOptionDoubleValue(o.getEnumString(), f); } @Inject(method = "getOptionDoubleValue", at = @At("HEAD"), cancellable = true) public void getOptionFloatValue(ModOptions o, CallbackInfoReturnable cir) { - XaeroPlusModSettingsHooks.getOptionDoubleValue(o.getEnumString(), cir, ALL_MINIMAP_SETTINGS.get()); + SettingHooks.getOptionDoubleValue(o.getEnumString(), cir); } @Inject(method = "getOptionValueName", at = @At("HEAD"), cancellable = true) public void getOptionValueName(ModOptions o, CallbackInfoReturnable cir) { - XaeroPlusModSettingsHooks.getOptionValueName(o.getEnumString(), cir, ALL_MINIMAP_SETTINGS.get()); + SettingHooks.getOptionValueName(o.getEnumString(), cir); } @Inject(method = "isKeyRepeat", at = @At("RETURN"), cancellable = true) public void isKeyRepeat(KeyMapping kb, CallbackInfoReturnable cir) { - cir.setReturnValue(cir.getReturnValue() && XaeroPlusSettingsReflectionHax.keybindingMapSupplier.get().get(kb) == null); + cir.setReturnValue(cir.getReturnValue() && Settings.REGISTRY.getKeybindingSetting(kb) == null); } @Inject(method = "getSliderOptionText", at = @At("HEAD"), cancellable = true) public void getSliderOptionText(final ModOptions o, final CallbackInfoReturnable cir) { - XaeroPlusModSettingsHooks.getSliderOptionText(o.getEnumString(), cir, ALL_MINIMAP_SETTINGS.get()); + SettingHooks.getSliderOptionText(o.getEnumString(), cir); } } diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinMinimapOption.java b/common/src/main/java/xaeroplus/mixin/client/MixinMinimapOption.java index 253c079c..191e9739 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinMinimapOption.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinMinimapOption.java @@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import xaero.common.settings.ModOptions; import xaero.common.settings.Option; -import xaeroplus.settings.XaeroPlusSettingsReflectionHax; +import xaeroplus.settings.Settings; import static xaeroplus.settings.XaeroPlusSetting.SETTING_PREFIX; @@ -25,10 +25,10 @@ public class MixinMinimapOption { @Inject(method = "", at = @At("RETURN")) public void constructorInject(final ModOptions option, final CallbackInfo ci) { if (option.getEnumString().startsWith(SETTING_PREFIX)) { - XaeroPlusSettingsReflectionHax.ALL_MINIMAP_SETTINGS.get().stream() - .filter(s -> s.getSettingName().equals(option.getEnumString())) - .findFirst() - .ifPresent(s -> caption = MutableComponent.create(new LiteralContents(SETTING_PREFIX)).append(Component.translatable(s.getSettingNameTranslationKey()))); + var xpSetting = Settings.REGISTRY.getSettingByName(option.getEnumString()); + if (xpSetting != null) { + caption = MutableComponent.create(new LiteralContents(SETTING_PREFIX)).append(Component.translatable(xpSetting.getSettingNameTranslationKey())); + } } } } diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinMinimapRenderer.java b/common/src/main/java/xaeroplus/mixin/client/MixinMinimapRenderer.java index 84796579..c340eca2 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinMinimapRenderer.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinMinimapRenderer.java @@ -24,7 +24,7 @@ import xaero.hud.minimap.module.MinimapSession; import xaeroplus.Globals; import xaeroplus.feature.extensions.CustomMinimapFBORenderer; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; @Mixin(value = MinimapRenderer.class, remap = false) public class MixinMinimapRenderer { @@ -49,8 +49,8 @@ public void renderMinimap( final CallbackInfo ci ) { if (this.minimap.usingFBO() && Globals.shouldResetFBO) { - Globals.minimapScaleMultiplier = (int) XaeroPlusSettingRegistry.minimapScaleMultiplierSetting.getValue(); - Globals.minimapSizeMultiplier = (int) XaeroPlusSettingRegistry.minimapSizeMultiplierSetting.getValue(); + Globals.minimapScaleMultiplier = Settings.REGISTRY.minimapScaleMultiplierSetting.getAsInt(); + Globals.minimapSizeMultiplier = Settings.REGISTRY.minimapSizeMultiplierSetting.getAsInt(); ((CustomMinimapFBORenderer) this.minimap.getMinimapFBORenderer()).reloadMapFrameBuffers(); Globals.shouldResetFBO = false; minimap.setToResetImage(true); @@ -209,7 +209,7 @@ public void redirectRenderMainEntityDot(final MinimapFBORenderer instance, final ModSettings settings, final MultiBufferSource.BufferSource renderTypeBuffers, final float minimapScale) { - if (XaeroPlusSettingRegistry.fixMainEntityDot.getValue()) { + if (Settings.REGISTRY.fixMainEntityDot.get()) { if (!(modMain.getSettings().mainEntityAs != 2 && !lockedNorth)) { return; } @@ -239,6 +239,6 @@ public void redirectRenderMainEntityDot(final MinimapFBORenderer instance, @ModifyVariable(method = "drawArrow", name = "offsetY", ordinal = 0, at = @At(value = "STORE")) public int modifyArrowOffsetY(final int offsetY) { - return XaeroPlusSettingRegistry.fixMainEntityDot.getValue() ? -10 : offsetY; + return Settings.REGISTRY.fixMainEntityDot.get() ? -10 : offsetY; } } diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinMinimapViewSettings.java b/common/src/main/java/xaeroplus/mixin/client/MixinMinimapViewSettings.java index 853895d6..c57ef7df 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinMinimapViewSettings.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinMinimapViewSettings.java @@ -11,7 +11,8 @@ import xaero.common.gui.GuiMinimapViewSettings; import xaero.common.gui.GuiSettings; import xaero.common.gui.ISettingEntry; -import xaeroplus.settings.XaeroPlusSettingsReflectionHax; +import xaeroplus.settings.SettingLocation; +import xaeroplus.settings.Settings; @Mixin(value = GuiMinimapViewSettings.class, remap = false) public abstract class MixinMinimapViewSettings extends GuiSettings { @@ -22,8 +23,7 @@ public MixinMinimapViewSettings(final IXaeroMinimap modMain, final Component tit @Inject(method = "", at = @At("RETURN")) public void init(final IXaeroMinimap modMain, final Screen backScreen, final Screen escScreen, final CallbackInfo ci) { - final ConfigSettingEntry[] configSettingEntries = XaeroPlusSettingsReflectionHax.getMinimapViewConfigSettingEntries() - .toArray(new ConfigSettingEntry[0]); + final ConfigSettingEntry[] configSettingEntries = Settings.REGISTRY.getMinimapConfigSettingEntries(SettingLocation.MINIMAP_VIEW); final int oldLen = this.entries.length; final int newLen = configSettingEntries.length; final int totalNewLen = oldLen + configSettingEntries.length; diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinMinimapWorldStateUpdater.java b/common/src/main/java/xaeroplus/mixin/client/MixinMinimapWorldStateUpdater.java index 36dac884..b6c8669a 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinMinimapWorldStateUpdater.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinMinimapWorldStateUpdater.java @@ -15,7 +15,7 @@ import xaero.hud.minimap.world.state.MinimapWorldState; import xaero.hud.minimap.world.state.MinimapWorldStateUpdater; import xaero.hud.path.XaeroPath; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import xaeroplus.util.ChunkUtils; import xaeroplus.util.DataFolderResolveUtil; @@ -36,7 +36,7 @@ public void preferOverworldWpSetCustomPathOnDimUpdate(final MinimapWorldState in @Local(name = "oldAutoWorldPath") XaeroPath oldAutoWorldPath, @Local(name = "potentialAutoWorldNode") String potentialAutoWorldNode) { original.call(instance, autoWorldPath); - if (XaeroPlusSettingRegistry.owAutoWaypointDimension.getValue()) { + if (Settings.REGISTRY.owAutoWaypointDimension.get()) { ResourceKey actualDimension = ChunkUtils.getActualDimension(); if (actualDimension == NETHER && currentDim != actualDimension) { XaeroPath overworldWpXaeroPath = session.getWorldState().getAutoRootContainerPath() diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinOverlay.java b/common/src/main/java/xaeroplus/mixin/client/MixinOverlay.java index 9603afbc..92916636 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinOverlay.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinOverlay.java @@ -6,7 +6,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import xaero.map.region.Overlay; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; @Mixin(value = Overlay.class, remap = false) public class MixinOverlay { @@ -14,7 +14,7 @@ public class MixinOverlay { @Inject(method = "increaseOpacity", at = @At("HEAD"), cancellable = true) public void increaseOpacity(final int toAdd, final CallbackInfo ci) { - if (XaeroPlusSettingRegistry.overlayOpacityFix.getValue()) { + if (Settings.REGISTRY.overlayOpacityFix.get()) { ci.cancel(); // fix byte overflow diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinPatreon.java b/common/src/main/java/xaeroplus/mixin/client/MixinPatreon.java index e4aa1661..98bbdb95 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinPatreon.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinPatreon.java @@ -5,13 +5,13 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import xaero.common.patreon.Patreon; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; @Mixin(value = Patreon.class, remap = false) public class MixinPatreon { @Inject(method = "checkPatreon(Lxaero/common/IXaeroMinimap;)V", at = @At("HEAD"), cancellable = true) private static void disableInternetAccessCheck(final CallbackInfo ci) { - if (XaeroPlusSettingRegistry.disableXaeroInternetAccess.getValue()) ci.cancel(); + if (Settings.REGISTRY.disableXaeroInternetAccess.get()) ci.cancel(); } } diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinRadarRenderProvider.java b/common/src/main/java/xaeroplus/mixin/client/MixinRadarRenderProvider.java index 058d2e26..706199bc 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinRadarRenderProvider.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinRadarRenderProvider.java @@ -15,7 +15,7 @@ import xaero.hud.HudSession; import xaeroplus.Globals; import xaeroplus.feature.extensions.IScreenRadarRenderContext; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import java.util.Objects; @@ -32,10 +32,10 @@ public void setupContextAndGetNextInject(final int location, final RadarRenderCo final Entity e = cir.getReturnValue(); if (e instanceof Player) { if (!Objects.equals(e, Minecraft.getInstance().player)) { - if (XaeroPlusSettingRegistry.alwaysRenderPlayerIconOnRadar.getValue()) { + if (Settings.REGISTRY.alwaysRenderPlayerIconOnRadar.get()) { context.icon = true; } - if (XaeroPlusSettingRegistry.alwaysRenderPlayerWithNameOnRadar.getValue()) { + if (Settings.REGISTRY.alwaysRenderPlayerWithNameOnRadar.get()) { context.name = true; } } diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinSupportXaeroMinimap.java b/common/src/main/java/xaeroplus/mixin/client/MixinSupportXaeroMinimap.java index 3ec50371..a6c7b7dd 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinSupportXaeroMinimap.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinSupportXaeroMinimap.java @@ -7,7 +7,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import xaero.map.mods.SupportXaeroMinimap; import xaero.map.mods.gui.Waypoint; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import java.util.ArrayList; @@ -34,7 +34,7 @@ public boolean waypointEqualityRedirect(final ArrayList waypoints, final Object @Inject(method = "getSubWorldNameToRender", at = @At("HEAD"), cancellable = true) public void getSubworldNameToRenderInject(final CallbackInfoReturnable cir) { - if (XaeroPlusSettingRegistry.owAutoWaypointDimension.getValue()) { + if (Settings.REGISTRY.owAutoWaypointDimension.get()) { // remove annoying string rendered in the middle of the worldmap cir.setReturnValue(null); } diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinSupportXaeroWorldmap.java b/common/src/main/java/xaeroplus/mixin/client/MixinSupportXaeroWorldmap.java index cd582732..fc587d6e 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinSupportXaeroWorldmap.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinSupportXaeroWorldmap.java @@ -24,7 +24,7 @@ import xaero.map.region.MapTileChunk; import xaeroplus.Globals; import xaeroplus.feature.render.MinimapBackgroundDrawHelper; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; @Mixin(value = SupportXaeroWorldmap.class, remap = false) public abstract class MixinSupportXaeroWorldmap { @@ -52,7 +52,7 @@ public void setupTransparentMMBgBuffer(final PoseStack matrixStack, final int mi @Share("bgTesselator") LocalRef bgTesselatorRef, @Share("bgBufferBuilder") LocalRef bgBufferBuilderRef ) { - if (XaeroPlusSettingRegistry.transparentMinimapBackground.getValue()) { + if (Settings.REGISTRY.transparentMinimapBackground.get()) { var bgTesselator = Tesselator.getInstance(); bgTesselatorRef.set(bgTesselator); var bgBufferBuilder = bgTesselator.getBuilder(); @@ -71,7 +71,7 @@ public void buildTransparentMMBg(final PoseStack matrixStack, final int minX, fi @Local(name = "drawZ") int drawZ, @Local(name = "chunk") MapTileChunk chunk ) { - if (XaeroPlusSettingRegistry.transparentMinimapBackground.getValue()) { + if (Settings.REGISTRY.transparentMinimapBackground.get()) { MinimapBackgroundDrawHelper.addMMBackgroundToBuffer(matrixStack.last().pose(), bgBufferBuilderRef.get(), drawX, @@ -91,7 +91,7 @@ public boolean hideSlimeChunksWhileDimSwitched(SupportXaeroWorldmap instance, Ma @Inject(method = "renderChunks", at = @At("RETURN"), remap = false) public void drawTransparentMMBackground(final PoseStack matrixStack, final int minX, final int maxX, final int minZ, final int maxZ, final int minViewX, final int maxViewX, final int minViewZ, final int maxViewZ, final MapProcessor mapProcessor, final int renderedCaveLayer, final boolean shouldRequestLoading, final boolean reloadEverything, final int globalReloadVersion, final int globalRegionCacheHashCode, final int globalCaveStart, final int globalCaveDepth, final boolean playerIsMoving, final boolean noCaveMaps, final boolean slimeChunks, final int chunkX, final int chunkZ, final int tileX, final int tileZ, final int insideX, final int insideZ, final Long seed, final MultiTextureRenderTypeRenderer mapWithLightRenderer, final MultiTextureRenderTypeRenderer mapNoLightRenderer, final MinimapRendererHelper helper, final VertexConsumer overlayBufferBuilder, final CallbackInfo ci, @Share("bgTesselator") LocalRef bgTesselatorRef) { - if (XaeroPlusSettingRegistry.transparentMinimapBackground.getValue()) bgTesselatorRef.get().end(); + if (Settings.REGISTRY.transparentMinimapBackground.get()) bgTesselatorRef.get().end(); } @Inject(method = "drawMinimap", at = @At(value = "RETURN"), remap = false) diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinWaypointReader.java b/common/src/main/java/xaeroplus/mixin/client/MixinWaypointReader.java index 34b5ceb5..fe4db25d 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinWaypointReader.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinWaypointReader.java @@ -10,7 +10,7 @@ import xaero.map.misc.Misc; import xaero.map.mods.gui.Waypoint; import xaero.map.mods.gui.WaypointReader; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import xaeroplus.util.BaritoneExecutor; import xaeroplus.util.BaritoneHelper; @@ -34,13 +34,13 @@ public void getRightClickOptionsReturn(final Waypoint element, final IRightClick public void onAction(Screen screen) { BaritoneExecutor.goal(goalX, goalZ); } - }.setNameFormatArgs(Misc.getKeyName(XaeroPlusSettingRegistry.worldMapBaritoneGoalHereKeybindSetting.getKeyBinding())), + }.setNameFormatArgs(Misc.getKeyName(Settings.REGISTRY.worldMapBaritoneGoalHereKeybindSetting.getKeyBinding())), new RightClickOption("gui.world_map.baritone_path_here", options.size(), target) { @Override public void onAction(Screen screen) { BaritoneExecutor.path(goalX, goalZ); } - }.setNameFormatArgs(Misc.getKeyName(XaeroPlusSettingRegistry.worldMapBaritonePathHereKeybindSetting.getKeyBinding())) + }.setNameFormatArgs(Misc.getKeyName(Settings.REGISTRY.worldMapBaritonePathHereKeybindSetting.getKeyBinding())) )); if (BaritoneHelper.isBaritoneElytraPresent()) { options.addAll(5, asList( @@ -49,12 +49,12 @@ public void onAction(Screen screen) { public void onAction(Screen screen) { BaritoneExecutor.elytra(goalX, goalZ); } - }.setNameFormatArgs(Misc.getKeyName(XaeroPlusSettingRegistry.worldMapBaritoneElytraHereKeybindSetting.getKeyBinding())) + }.setNameFormatArgs(Misc.getKeyName(Settings.REGISTRY.worldMapBaritoneElytraHereKeybindSetting.getKeyBinding())) )); } } - if (XaeroPlusSettingRegistry.disableWaypointSharing.getValue()) { + if (Settings.REGISTRY.disableWaypointSharing.get()) { cir.getReturnValue().removeIf(option -> ((AccessorRightClickOption) option).getName().equals("gui.xaero_right_click_waypoint_share")); } } diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinWaypointSharingHandler.java b/common/src/main/java/xaeroplus/mixin/client/MixinWaypointSharingHandler.java index 01c65b1a..7d848b05 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinWaypointSharingHandler.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinWaypointSharingHandler.java @@ -12,7 +12,7 @@ import xaero.common.minimap.waypoints.Waypoint; import xaero.common.minimap.waypoints.WaypointSharingHandler; import xaero.hud.minimap.world.MinimapWorld; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; @Mixin(value = WaypointSharingHandler.class, remap = false) public class MixinWaypointSharingHandler { @@ -24,7 +24,7 @@ public class MixinWaypointSharingHandler { cancellable = true, remap = true) // $REMAP public void shareWaypoint(final Screen parent, final Waypoint w, final MinimapWorld wWorld, final CallbackInfo ci) { - if (XaeroPlusSettingRegistry.disableWaypointSharing.getValue()) { + if (Settings.REGISTRY.disableWaypointSharing.get()) { ci.cancel(); } } @@ -43,7 +43,7 @@ public void shareWaypoint(final Screen parent, final Waypoint w, final MinimapWo remap = true) public void mutateWaypointSharingText(final boolean confirm, final CallbackInfo ci, @Local(name = "message") LocalRef containerIdRef) { - if (XaeroPlusSettingRegistry.plainWaypointSharing.getValue()) { + if (Settings.REGISTRY.plainWaypointSharing.get()) { containerIdRef.set(w.getName() + " [" + w.getX() + ", " + (w.isYIncluded() ? (w.getY() + ", ") : "") + w.getZ() + "]"); } } diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinWaypointsIngameRenderer.java b/common/src/main/java/xaeroplus/mixin/client/MixinWaypointsIngameRenderer.java index 3162fce5..cecc37b2 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinWaypointsIngameRenderer.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinWaypointsIngameRenderer.java @@ -37,7 +37,7 @@ import xaero.hud.minimap.BuiltInHudModules; import xaero.hud.minimap.module.MinimapSession; import xaeroplus.feature.extensions.CustomWaypointsIngameRenderer; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import xaeroplus.util.ChunkUtils; import xaeroplus.util.ColorHelper; @@ -89,7 +89,7 @@ public class MixinWaypointsIngameRenderer implements CustomWaypointsIngameRender )) public void preferOwWaypointsRemoveSubworldText(final MinimapSession session, final float partial, final MinimapProcessor minimap, final Matrix4f waypointsProjection, final Matrix4f worldModelView, final CallbackInfo ci, @Local(name = "subworldName") LocalRef subWorldNameRef) { - if (!XaeroPlusSettingRegistry.owAutoWaypointDimension.getValue()) return; + if (!Settings.REGISTRY.owAutoWaypointDimension.get()) return; if (subWorldNameRef.get() == null) return; ResourceKey actualDimension = ChunkUtils.getActualDimension(); ResourceKey currentWpWorldDim = session.getWorldManager().getCurrentWorld().getDimId(); @@ -117,8 +117,8 @@ public void renderWaypointBeacon(final Waypoint waypoint, final double dimDiv, f final Vec3 playerVec = mc.player.position(); Vec3 waypointVec = new Vec3(waypoint.getX(dimDiv), playerVec.y, waypoint.getZ(dimDiv)); final double xzDistance = playerVec.distanceTo(waypointVec); - if (xzDistance < (int) XaeroPlusSettingRegistry.waypointBeaconDistanceMin.getValue()) return; - final int farScale = (int) XaeroPlusSettingRegistry.waypointBeaconScaleMin.getValue(); + if (xzDistance < Settings.REGISTRY.waypointBeaconDistanceMin.getAsInt()) return; + final int farScale = Settings.REGISTRY.waypointBeaconScaleMin.getAsInt(); final double maxRenderDistance = Math.min(mc.options.renderDistance().get() << 4, farScale == 0 ? Integer.MAX_VALUE : farScale << 4); if (xzDistance > maxRenderDistance) { final Vec3 delta = waypointVec.subtract(playerVec).normalize(); @@ -154,7 +154,7 @@ public void renderWaypointBeacon(final Waypoint waypoint, final double dimDiv, f index = 9, remap = true) // $REMAP public String modifyDistanceText(final String text, @Local(argsOnly = true) Waypoint waypoint) { - if (!XaeroPlusSettingRegistry.waypointEta.getValue()) return text; + if (!Settings.REGISTRY.waypointEta.get()) return text; if (text.isBlank()) return text; var eta = getEtaSecondsToReachWaypoint(waypoint); if (eta <= 0) return text; diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinWorldDataReader.java b/common/src/main/java/xaeroplus/mixin/client/MixinWorldDataReader.java index 3f04f889..675a6986 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinWorldDataReader.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinWorldDataReader.java @@ -14,7 +14,7 @@ import xaero.map.file.worldsave.WorldDataReader; import xaero.map.region.MapTile; import xaero.map.region.MapTileChunk; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import static net.minecraft.world.level.Level.NETHER; @@ -69,7 +69,7 @@ public boolean redirectBuildTile(final WorldDataReader instance, boolean flowers, int worldBottomY, int worldTopY) { - if (XaeroPlusSettingRegistry.netherCaveFix.getValue()) { + if (Settings.REGISTRY.netherCaveFix.get()) { boolean cave = caveStart != Integer.MAX_VALUE; boolean nether = tileChunk.getInRegion().getDim().getDimId() == NETHER; int customCaveStart = caveStart; diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinWorldMapGuiSettings.java b/common/src/main/java/xaeroplus/mixin/client/MixinWorldMapGuiSettings.java index 3e6730ac..bb8c052c 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinWorldMapGuiSettings.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinWorldMapGuiSettings.java @@ -21,13 +21,10 @@ import xaero.map.misc.KeySortableByOther; import xaero.map.settings.ModOptions; import xaeroplus.XaeroPlus; -import xaeroplus.settings.XaeroPlusSetting; -import xaeroplus.settings.XaeroPlusSettingRegistry; -import xaeroplus.settings.XaeroPlusSettingsReflectionHax; +import xaeroplus.settings.Settings; import java.lang.reflect.Field; import java.util.ArrayList; -import java.util.Optional; @Mixin(value = GuiSettings.class, remap = false) public abstract class MixinWorldMapGuiSettings extends ScreenBase { @@ -49,7 +46,7 @@ protected MixinWorldMapGuiSettings(final Screen parent, final Screen escape, fin public void adjustEntriesPerPage(final CallbackInfo ci) { this.xaeroPlus$settingEntryWidth = 200; // default width this.entriesPerPage = 12; // fills height = 240 - if (XaeroPlusSettingRegistry.expandSettingEntries.getValue()) { + if (Settings.REGISTRY.expandSettingEntries.get()) { if (this.height > 350) { int extraRows = Math.min((height - 240) / 50, 6); this.entriesPerPage = 12 + (2 * extraRows); @@ -64,7 +61,7 @@ public void adjustEntriesPerPage(final CallbackInfo ci) { value = "RETURN" )) public void adjustForwardBackButtonPositionsForExtraRows(final CallbackInfo ci) { - if (!XaeroPlusSettingRegistry.expandSettingEntries.getValue()) return; + if (!Settings.REGISTRY.expandSettingEntries.get()) return; int extraRows = (this.entriesPerPage - 12) / 2; int yAdjust = (extraRows * 24); this.nextButton.setY(this.nextButton.getY() + yAdjust); @@ -88,11 +85,9 @@ public boolean settingListToRenderRedirect(final ArrayList instance, final Objec option.setAccessible(true); ModOptions modOptions = (ModOptions) option.get(settingEntry); String settingName = modOptions.getEnumString(); - Optional foundSetting = XaeroPlusSettingsReflectionHax.XAERO_PLUS_WORLDMAP_SETTINGS.stream() - .filter(s -> s.getSettingName().equals(settingName)) - .findFirst(); - if (foundSetting.isPresent()) { - if (!foundSetting.get().isVisible()) { + var xpSetting = Settings.REGISTRY.getSettingByName(settingName); + if (xpSetting != null) { + if (!xpSetting.isVisible()) { // skip adding setting return false; } @@ -122,7 +117,7 @@ public boolean settingListToRenderRedirect(final ArrayList instance, final Objec ) public AbstractWidget adjustSettingEntryWidth(final ISettingEntry instance, final int x, final int y, final int w, final boolean canEditIngameSettings, final Operation original, @Local(name = "i") int i) { - if (!XaeroPlusSettingRegistry.expandSettingEntries.getValue()) return original.call(instance, x, y, w, canEditIngameSettings); + if (!Settings.REGISTRY.expandSettingEntries.get()) return original.call(instance, x, y, w, canEditIngameSettings); int xOffset = ((i % 2 == 0) ? -1 : 1) * ((xaeroPlus$settingEntryWidth - 200) / 2); return original.call(instance, x + xOffset, y, xaeroPlus$settingEntryWidth, canEditIngameSettings); } diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinWorldMapInternet.java b/common/src/main/java/xaeroplus/mixin/client/MixinWorldMapInternet.java index c951fe06..18d0bc57 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinWorldMapInternet.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinWorldMapInternet.java @@ -5,13 +5,13 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import xaero.map.misc.Internet; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; @Mixin(value = Internet.class, remap = false) public class MixinWorldMapInternet { @Inject(method = "checkModVersion", at = @At("HEAD"), cancellable = true) private static void disableInternetAccessCheck(final CallbackInfo ci) { - if (XaeroPlusSettingRegistry.disableXaeroInternetAccess.getValue()) ci.cancel(); + if (Settings.REGISTRY.disableXaeroInternetAccess.get()) ci.cancel(); } } diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinWorldMapModSettings.java b/common/src/main/java/xaeroplus/mixin/client/MixinWorldMapModSettings.java index 790cba9a..684affa3 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinWorldMapModSettings.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinWorldMapModSettings.java @@ -1,6 +1,5 @@ package xaeroplus.mixin.client; -import com.llamalad7.mixinextras.sugar.Local; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -9,13 +8,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import xaero.map.settings.ModOptions; import xaero.map.settings.ModSettings; -import xaeroplus.settings.XaeroPlusModSettingsHooks; +import xaeroplus.settings.SettingHooks; -import java.io.File; import java.io.IOException; -import static xaeroplus.settings.XaeroPlusSettingsReflectionHax.ALL_WORLD_MAP_SETTINGS; - @Mixin(value = ModSettings.class, remap = false) public class MixinWorldMapModSettings { @@ -29,53 +25,41 @@ public void initInject(final CallbackInfo ci) { @Inject(method = "saveSettings", at = @At(value = "RETURN")) public void saveSettings(final CallbackInfo ci) throws IOException { - XaeroPlusModSettingsHooks.saveSettings(); - } - - @Inject(method = "loadSettings", at = @At(value = "INVOKE", target = "Lxaero/map/settings/ModSettings;saveSettings()V")) - public void loadSettings(final CallbackInfo ci, @Local File mainConfigFile) throws IOException { - if (!mainConfigFile.exists()) { - XaeroPlusModSettingsHooks.loadSettings(null, ALL_WORLD_MAP_SETTINGS.get()); - } - } - - @Inject(method = "loadSettingsFile", at = @At("RETURN")) - public void loadSettingsFile(final File file, CallbackInfo ci) throws IOException { - XaeroPlusModSettingsHooks.loadSettings(file, ALL_WORLD_MAP_SETTINGS.get()); + SettingHooks.saveSettings(); } @Inject(method = "getClientBooleanValue", at = @At("HEAD"), cancellable = true) public void getClientBooleanValue(ModOptions o, CallbackInfoReturnable cir) { - XaeroPlusModSettingsHooks.getClientBooleanValue(o.getEnumString(), ALL_WORLD_MAP_SETTINGS.get(), cir); + SettingHooks.getClientBooleanValue(o.getEnumString(), cir); } @Inject(method = "setOptionValue", at = @At("HEAD")) public void setOptionValue(ModOptions o, Object value, final CallbackInfo ci) { - XaeroPlusModSettingsHooks.setOptionValue(o.getEnumString(), value, ALL_WORLD_MAP_SETTINGS.get()); + SettingHooks.setOptionValue(o.getEnumString(), value); } @Inject(method = "getOptionValue", at = @At("HEAD"), cancellable = true) public void getOptionValue(final ModOptions o, final CallbackInfoReturnable cir) { - XaeroPlusModSettingsHooks.getOptionValue(o.getEnumString(), cir, ALL_WORLD_MAP_SETTINGS.get()); + SettingHooks.getOptionValue(o.getEnumString(), cir); } @Inject(method = "setOptionDoubleValue", at = @At("HEAD")) public void setOptionDoubleValue(ModOptions o, double f, CallbackInfo ci) { - XaeroPlusModSettingsHooks.setOptionDoubleValue(o.getEnumString(), f, ALL_WORLD_MAP_SETTINGS.get()); + SettingHooks.setOptionDoubleValue(o.getEnumString(), f); } @Inject(method = "getOptionDoubleValue", at = @At("HEAD"), cancellable = true) public void getOptionDoubleValue(ModOptions o, CallbackInfoReturnable cir) { - XaeroPlusModSettingsHooks.getOptionDoubleValue(o.getEnumString(), cir, ALL_WORLD_MAP_SETTINGS.get()); + SettingHooks.getOptionDoubleValue(o.getEnumString(), cir); } @Inject(method = "getOptionValueName", at = @At("HEAD"), cancellable = true) public void getOptionValueName(ModOptions o, CallbackInfoReturnable cir) { - XaeroPlusModSettingsHooks.getOptionValueName(o.getEnumString(), cir, ALL_WORLD_MAP_SETTINGS.get()); + SettingHooks.getOptionValueName(o.getEnumString(), cir); } @Inject(method = "getSliderOptionText", at = @At("HEAD"), cancellable = true) public void getSliderOptionText(final ModOptions o, final CallbackInfoReturnable cir) { - XaeroPlusModSettingsHooks.getSliderOptionText(o.getEnumString(), cir, ALL_WORLD_MAP_SETTINGS.get()); + SettingHooks.getSliderOptionText(o.getEnumString(), cir); } } diff --git a/common/src/main/java/xaeroplus/mixin/client/MixinWorldMapOption.java b/common/src/main/java/xaeroplus/mixin/client/MixinWorldMapOption.java index 6cb394f6..212f9d8b 100644 --- a/common/src/main/java/xaeroplus/mixin/client/MixinWorldMapOption.java +++ b/common/src/main/java/xaeroplus/mixin/client/MixinWorldMapOption.java @@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import xaero.map.settings.ModOptions; import xaero.map.settings.Option; -import xaeroplus.settings.XaeroPlusSettingsReflectionHax; +import xaeroplus.settings.Settings; import static xaeroplus.settings.XaeroPlusSetting.SETTING_PREFIX; @@ -25,10 +25,10 @@ public class MixinWorldMapOption { @Inject(method = "", at = @At("RETURN")) public void constructorInject(final ModOptions option, final CallbackInfo ci) { if (option.getEnumString().startsWith(SETTING_PREFIX)) { - XaeroPlusSettingsReflectionHax.ALL_WORLD_MAP_SETTINGS.get().stream() - .filter(s -> s.getSettingName().equals(option.getEnumString())) - .findFirst() - .ifPresent(s -> caption = MutableComponent.create(new LiteralContents(SETTING_PREFIX)).append(Component.translatable(s.getSettingNameTranslationKey()))); + var xpSetting = Settings.REGISTRY.getSettingByName(option.getEnumString()); + if (xpSetting != null) { + caption = MutableComponent.create(new LiteralContents(SETTING_PREFIX)).append(Component.translatable(xpSetting.getSettingNameTranslationKey())); + } } } } diff --git a/common/src/main/java/xaeroplus/mixin/client/mc/MixinGlStateManager.java b/common/src/main/java/xaeroplus/mixin/client/mc/MixinGlStateManager.java index 372f89d6..5146ddc9 100644 --- a/common/src/main/java/xaeroplus/mixin/client/mc/MixinGlStateManager.java +++ b/common/src/main/java/xaeroplus/mixin/client/mc/MixinGlStateManager.java @@ -6,13 +6,13 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import xaeroplus.module.impl.FpsLimiter; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; @Mixin(value = GlStateManager.class, remap = false) public class MixinGlStateManager { @Inject(method = "_glBindFramebuffer", at = @At("HEAD"), cancellable = true) private static void _glBindFramebuffer(int i, int j, CallbackInfo ci) { - if (!XaeroPlusSettingRegistry.minimapFpsLimiter.getValue()) return; + if (!Settings.REGISTRY.minimapFpsLimiter.get()) return; if (FpsLimiter.renderTargetOverwrite != null) ci.cancel(); } diff --git a/common/src/main/java/xaeroplus/mixin/client/mc/MixinMinecraftClient.java b/common/src/main/java/xaeroplus/mixin/client/mc/MixinMinecraftClient.java index 5cc5c365..35f97122 100644 --- a/common/src/main/java/xaeroplus/mixin/client/mc/MixinMinecraftClient.java +++ b/common/src/main/java/xaeroplus/mixin/client/mc/MixinMinecraftClient.java @@ -10,7 +10,7 @@ import xaeroplus.XaeroPlus; import xaeroplus.event.ClientTickEvent; import xaeroplus.module.impl.FpsLimiter; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; @Mixin(value = Minecraft.class) public class MixinMinecraftClient { @@ -26,7 +26,7 @@ public void tickReturn(final CallbackInfo ci) { @Inject(method = "getMainRenderTarget", at = @At("HEAD"), cancellable = true) public void getMainRenderTarget(CallbackInfoReturnable ci) { - if (!XaeroPlusSettingRegistry.minimapFpsLimiter.getValue()) return; + if (!Settings.REGISTRY.minimapFpsLimiter.get()) return; var renderTargetOverwrite = FpsLimiter.renderTargetOverwrite; if (renderTargetOverwrite != null) ci.setReturnValue(renderTargetOverwrite); } diff --git a/common/src/main/java/xaeroplus/mixin/client/mc/MixinWorldRenderer.java b/common/src/main/java/xaeroplus/mixin/client/mc/MixinWorldRenderer.java index 54a608ca..5255b762 100644 --- a/common/src/main/java/xaeroplus/mixin/client/mc/MixinWorldRenderer.java +++ b/common/src/main/java/xaeroplus/mixin/client/mc/MixinWorldRenderer.java @@ -17,7 +17,7 @@ import xaero.hud.minimap.module.MinimapSession; import xaeroplus.XaeroPlus; import xaeroplus.feature.extensions.CustomWaypointsIngameRenderer; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; @Mixin(value = LevelRenderer.class) public class MixinWorldRenderer { @@ -25,7 +25,7 @@ public class MixinWorldRenderer { private int errorCount = 0; @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;checkPoseStack(Lcom/mojang/blaze3d/vertex/PoseStack;)V", ordinal = 1, shift = At.Shift.AFTER)) public void renderBlockEntitiesInject(final PoseStack matrixStack, final float tickDelta, final long limitTime, final boolean renderBlockOutline, final Camera camera, final GameRenderer gameRenderer, final LightTexture lightmapTextureManager, final Matrix4f positionMatrix, final CallbackInfo ci) { - if (!XaeroPlusSettingRegistry.waypointBeacons.getValue()) return; + if (!Settings.REGISTRY.waypointBeacons.get()) return; HudMod hudMod = HudMod.INSTANCE; if (hudMod == null) return; Minimap minimap = hudMod.getMinimap(); diff --git a/common/src/main/java/xaeroplus/module/ModuleManager.java b/common/src/main/java/xaeroplus/module/ModuleManager.java index 5f4c4839..6eb29e92 100644 --- a/common/src/main/java/xaeroplus/module/ModuleManager.java +++ b/common/src/main/java/xaeroplus/module/ModuleManager.java @@ -9,23 +9,23 @@ public class ModuleManager { private static final Reference2ObjectMap, Module> modulesClassMap = new Reference2ObjectOpenHashMap<>(); - public static void init() { + static { asList( - new BaritoneGoalSync(), - new FpsLimiter(), - new Highways(), - new LiquidNewChunks(), - new OldChunks(), - new OldBiomes(), - new PaletteNewChunks(), - new Portals(), - new PortalSkipDetection(), - new WaystoneSync(), - new WorldTools() + new BaritoneGoalSync(), + new FpsLimiter(), + new Highways(), + new LiquidNewChunks(), + new OldChunks(), + new OldBiomes(), + new PaletteNewChunks(), + new Portals(), + new PortalSkipDetection(), + new WaystoneSync(), + new WorldTools() ).forEach(ModuleManager::addModule); } - private static void addModule(Module module) { + public static void addModule(Module module) { modulesClassMap.put(module.getClass(), module); } diff --git a/common/src/main/java/xaeroplus/module/impl/FpsLimiter.java b/common/src/main/java/xaeroplus/module/impl/FpsLimiter.java index 0251911b..e530cb90 100644 --- a/common/src/main/java/xaeroplus/module/impl/FpsLimiter.java +++ b/common/src/main/java/xaeroplus/module/impl/FpsLimiter.java @@ -6,7 +6,7 @@ import xaeroplus.event.MinimapRenderEvent; import xaeroplus.feature.render.buffered.BufferedComponent; import xaeroplus.module.Module; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import java.util.function.Supplier; @@ -15,7 +15,7 @@ public class FpsLimiter extends Module { // impact while minimap north is not locked // this must be initialized AFTER MC's screen is initialized private final Supplier minimapRenderInstanceSupplier = Suppliers.memoize( - () -> new BufferedComponent(() -> (int) XaeroPlusSettingRegistry.minimapFpsLimit.getValue())); + () -> new BufferedComponent(Settings.REGISTRY.minimapFpsLimit::getAsInt)); public static RenderTarget renderTargetOverwrite = null; @EventHandler diff --git a/common/src/main/java/xaeroplus/module/impl/Highways.java b/common/src/main/java/xaeroplus/module/impl/Highways.java index 74aeebe7..f2ba1187 100644 --- a/common/src/main/java/xaeroplus/module/impl/Highways.java +++ b/common/src/main/java/xaeroplus/module/impl/Highways.java @@ -8,7 +8,7 @@ import net.minecraft.world.level.Level; import xaeroplus.Globals; import xaeroplus.module.Module; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import xaeroplus.util.ChunkUtils; import xaeroplus.util.ColorHelper; @@ -128,10 +128,10 @@ public int getHighwayColor() { } public void setRgbColor(final int color) { - highwaysColor = ColorHelper.getColorWithAlpha(color, (int) XaeroPlusSettingRegistry.highwaysColorAlphaSetting.getValue()); + highwaysColor = ColorHelper.getColorWithAlpha(color, Settings.REGISTRY.highwaysColorAlphaSetting.getAsInt()); } - public void setAlpha(final float a) { + public void setAlpha(final double a) { highwaysColor = ColorHelper.getColorWithAlpha(highwaysColor, (int) a); } diff --git a/common/src/main/java/xaeroplus/module/impl/LiquidNewChunks.java b/common/src/main/java/xaeroplus/module/impl/LiquidNewChunks.java index 504e26e5..c029edc2 100644 --- a/common/src/main/java/xaeroplus/module/impl/LiquidNewChunks.java +++ b/common/src/main/java/xaeroplus/module/impl/LiquidNewChunks.java @@ -21,7 +21,7 @@ import xaeroplus.event.XaeroWorldChangeEvent; import xaeroplus.feature.render.highlights.SavableHighlightCacheInstance; import xaeroplus.module.Module; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import xaeroplus.util.ChunkScanner; import xaeroplus.util.ChunkUtils; import xaeroplus.util.ColorHelper; @@ -80,7 +80,7 @@ private void handleBlockUpdate(Level level, BlockPos pos, BlockState state) { if (newChunksCache.get().isHighlighted(chunkX, chunkZ, getActualDimension())) return; final int srcX = pos.getX(); final int srcY = pos.getY(); - if (XaeroPlusSettingRegistry.liquidNewChunksOnlyAboveY0Setting.getValue() && srcY <= 0) return; + if (Settings.REGISTRY.liquidNewChunksOnlyAboveY0Setting.get() && srcY <= 0) return; final int srcZ = pos.getZ(); MutableBlockPos bp = new MutableBlockPos(srcX, srcY, srcZ); for (int i = 0; i < searchDirs.length; i++) { @@ -134,7 +134,7 @@ public void onChunkData(final ChunkDataEvent event) { } } return false; - }, XaeroPlusSettingRegistry.liquidNewChunksOnlyAboveY0Setting.getValue() + }, Settings.REGISTRY.liquidNewChunksOnlyAboveY0Setting.get() ? Math.max(1, level.getMinBuildHeight()) : level.getMinBuildHeight()); } @@ -190,14 +190,14 @@ private int getInverseColor() { } public void setRgbColor(final int color) { - newChunksColor = ColorHelper.getColorWithAlpha(color, (int) XaeroPlusSettingRegistry.liquidNewChunksAlphaSetting.getValue()); + newChunksColor = ColorHelper.getColorWithAlpha(color, Settings.REGISTRY.liquidNewChunksAlphaSetting.getAsInt()); } public void setInverseRgbColor(final int color) { - inverseColor = ColorHelper.getColorWithAlpha(color, (int) XaeroPlusSettingRegistry.liquidNewChunksAlphaSetting.getValue()); + inverseColor = ColorHelper.getColorWithAlpha(color, Settings.REGISTRY.liquidNewChunksAlphaSetting.getAsInt()); } - public void setAlpha(final float a) { + public void setAlpha(final double a) { newChunksColor = ColorHelper.getColorWithAlpha(newChunksColor, (int) (a)); inverseColor = ColorHelper.getColorWithAlpha(inverseColor, (int) (a)); } diff --git a/common/src/main/java/xaeroplus/module/impl/OldBiomes.java b/common/src/main/java/xaeroplus/module/impl/OldBiomes.java index cf558f45..7d473402 100644 --- a/common/src/main/java/xaeroplus/module/impl/OldBiomes.java +++ b/common/src/main/java/xaeroplus/module/impl/OldBiomes.java @@ -19,7 +19,7 @@ import xaeroplus.event.ChunkDataEvent; import xaeroplus.feature.render.highlights.SavableHighlightCacheInstance; import xaeroplus.module.Module; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import xaeroplus.util.ChunkUtils; import xaeroplus.util.ColorHelper; @@ -151,11 +151,11 @@ public void setDiskCache(final boolean b) { oldBiomesCache.setDiskCache(b, isEnabled()); } - public void setAlpha(final float b) { + public void setAlpha(final double b) { oldBiomesColor = ColorHelper.getColorWithAlpha(oldBiomesColor, (int) b); } public void setRgbColor(final int color) { - oldBiomesColor = ColorHelper.getColorWithAlpha(color, (int) XaeroPlusSettingRegistry.oldBiomesAlphaSetting.getValue()); + oldBiomesColor = ColorHelper.getColorWithAlpha(color, Settings.REGISTRY.oldBiomesAlphaSetting.getAsInt()); } } diff --git a/common/src/main/java/xaeroplus/module/impl/OldChunks.java b/common/src/main/java/xaeroplus/module/impl/OldChunks.java index 33202851..8841bcf8 100644 --- a/common/src/main/java/xaeroplus/module/impl/OldChunks.java +++ b/common/src/main/java/xaeroplus/module/impl/OldChunks.java @@ -19,7 +19,7 @@ import xaeroplus.event.ChunkDataEvent; import xaeroplus.feature.render.highlights.SavableHighlightCacheInstance; import xaeroplus.module.Module; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import xaeroplus.util.ChunkScanner; import xaeroplus.util.ChunkUtils; import xaeroplus.util.ColorHelper; @@ -150,10 +150,10 @@ public int getOldChunksColor() { } public void setRgbColor(final int color) { - oldChunksColor = ColorHelper.getColorWithAlpha(color, (int) XaeroPlusSettingRegistry.oldChunksAlphaSetting.getValue()); + oldChunksColor = ColorHelper.getColorWithAlpha(color, Settings.REGISTRY.oldChunksAlphaSetting.getAsInt()); } - public void setAlpha(final float a) { + public void setAlpha(final double a) { oldChunksColor = ColorHelper.getColorWithAlpha(oldChunksColor, (int) (a)); } diff --git a/common/src/main/java/xaeroplus/module/impl/PaletteNewChunks.java b/common/src/main/java/xaeroplus/module/impl/PaletteNewChunks.java index 7dd31977..ebd70a07 100644 --- a/common/src/main/java/xaeroplus/module/impl/PaletteNewChunks.java +++ b/common/src/main/java/xaeroplus/module/impl/PaletteNewChunks.java @@ -17,7 +17,7 @@ import xaeroplus.event.ChunkDataEvent; import xaeroplus.feature.render.highlights.SavableHighlightCacheInstance; import xaeroplus.module.Module; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import xaeroplus.util.ChunkUtils; import xaeroplus.util.ColorHelper; @@ -167,10 +167,10 @@ public int getNewChunksColor() { } public void setRgbColor(final int color) { - newChunksColor = ColorHelper.getColorWithAlpha(color, (int) XaeroPlusSettingRegistry.paletteNewChunksAlphaSetting.getValue()); + newChunksColor = ColorHelper.getColorWithAlpha(color, Settings.REGISTRY.paletteNewChunksAlphaSetting.getAsInt()); } - public void setAlpha(final float a) { + public void setAlpha(final double a) { newChunksColor = ColorHelper.getColorWithAlpha(newChunksColor, (int) (a)); } diff --git a/common/src/main/java/xaeroplus/module/impl/PortalSkipDetection.java b/common/src/main/java/xaeroplus/module/impl/PortalSkipDetection.java index e349c78c..71e512a3 100644 --- a/common/src/main/java/xaeroplus/module/impl/PortalSkipDetection.java +++ b/common/src/main/java/xaeroplus/module/impl/PortalSkipDetection.java @@ -21,7 +21,7 @@ import xaeroplus.feature.render.highlights.ChunkHighlightLocalCache; import xaeroplus.module.Module; import xaeroplus.module.ModuleManager; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import xaeroplus.util.ChunkUtils; import xaeroplus.util.ColorHelper; @@ -184,14 +184,14 @@ private boolean isNewishChunk(final int chunkPosX, final int chunkPosZ, final Re } private boolean isNewChunk(final int chunkPosX, final int chunkPosZ, final ResourceKey currentlyViewedDimension) { - if (XaeroPlusSettingRegistry.paletteNewChunksSaveLoadToDisk.getValue() && newChunksModule != null) + if (Settings.REGISTRY.paletteNewChunksSaveLoadToDisk.get() && newChunksModule != null) return newChunksModule.isNewChunk(chunkPosX, chunkPosZ, currentlyViewedDimension); else return false; } private boolean isOldChunksInverse(final int chunkPosX, final int chunkPosZ, final ResourceKey currentlyViewedDimension) { - if (XaeroPlusSettingRegistry.oldChunksEnabledSetting.getValue() && oldChunksModule != null) + if (Settings.REGISTRY.oldChunksEnabledSetting.get() && oldChunksModule != null) return oldChunksModule.isOldChunkInverse(chunkPosX, chunkPosZ, currentlyViewedDimension); else return false; @@ -221,10 +221,10 @@ public int getPortalSkipChunksColor() { } public void setRgbColor(final int color) { - portalSkipChunksColor = ColorHelper.getColorWithAlpha(color, (int) XaeroPlusSettingRegistry.portalSkipDetectionAlphaSetting.getValue()); + portalSkipChunksColor = ColorHelper.getColorWithAlpha(color, Settings.REGISTRY.portalSkipDetectionAlphaSetting.getAsInt()); } - public void setAlpha(final float a) { + public void setAlpha(final double a) { portalSkipChunksColor = ColorHelper.getColorWithAlpha(portalSkipChunksColor, (int) a); } @@ -240,19 +240,19 @@ public boolean isPortalSkipChunk(final long chunkPos) { return cache.isHighlighted(chunkPos); } - public void setSearchDelayTicks(final float delay) { + public void setSearchDelayTicks(final double delay) { searchDelayTicks = (int) delay; } - public void setOldChunksInverse(final Boolean b) { + public void setOldChunksInverse(final boolean b) { this.oldChunksInverse = b; } - public void setNewChunks(final Boolean b) { + public void setNewChunks(final boolean b) { this.newChunks = b; } - public void setPortalRadius(final Float b) { - this.portalRadius = b.intValue(); + public void setPortalRadius(final double b) { + this.portalRadius = (int) b; } } diff --git a/common/src/main/java/xaeroplus/module/impl/Portals.java b/common/src/main/java/xaeroplus/module/impl/Portals.java index 75742159..6ddac1f1 100644 --- a/common/src/main/java/xaeroplus/module/impl/Portals.java +++ b/common/src/main/java/xaeroplus/module/impl/Portals.java @@ -22,7 +22,7 @@ import xaeroplus.event.ChunkDataEvent; import xaeroplus.feature.render.highlights.SavableHighlightCacheInstance; import xaeroplus.module.Module; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import xaeroplus.util.ChunkScanner; import xaeroplus.util.ChunkUtils; import xaeroplus.util.ColorHelper; @@ -154,10 +154,10 @@ public int getPortalsColor() { } public void setRgbColor(final int color) { - portalsColor = ColorHelper.getColorWithAlpha(color, (int) XaeroPlusSettingRegistry.portalsAlphaSetting.getValue()); + portalsColor = ColorHelper.getColorWithAlpha(color, Settings.REGISTRY.portalsAlphaSetting.getAsInt()); } - public void setAlpha(final float a) { + public void setAlpha(final double a) { portalsColor = ColorHelper.getColorWithAlpha(portalsColor, (int) (a)); } diff --git a/common/src/main/java/xaeroplus/module/impl/WorldTools.java b/common/src/main/java/xaeroplus/module/impl/WorldTools.java index 7f50267e..0c1c64b4 100644 --- a/common/src/main/java/xaeroplus/module/impl/WorldTools.java +++ b/common/src/main/java/xaeroplus/module/impl/WorldTools.java @@ -7,7 +7,7 @@ import org.waste.of.time.storage.cache.HotCache; import xaeroplus.Globals; import xaeroplus.module.Module; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import xaeroplus.util.ChunkUtils; import xaeroplus.util.ColorHelper; import xaeroplus.util.WorldToolsHelper; @@ -58,10 +58,10 @@ public int getWorldToolsColor() { } public void setRgbColor(final int color) { - worldToolsColor = ColorHelper.getColorWithAlpha(color, (int) XaeroPlusSettingRegistry.worldToolsAlphaSetting.getValue()); + worldToolsColor = ColorHelper.getColorWithAlpha(color, Settings.REGISTRY.worldToolsAlphaSetting.getAsInt()); } - public void setAlpha(final float alpha) { + public void setAlpha(final double alpha) { worldToolsColor = ColorHelper.getColorWithAlpha(worldToolsColor, (int) alpha); } } diff --git a/common/src/main/java/xaeroplus/settings/BooleanSetting.java b/common/src/main/java/xaeroplus/settings/BooleanSetting.java new file mode 100644 index 00000000..a00abdcc --- /dev/null +++ b/common/src/main/java/xaeroplus/settings/BooleanSetting.java @@ -0,0 +1,145 @@ +package xaeroplus.settings; + +import it.unimi.dsi.fastutil.booleans.BooleanConsumer; +import net.minecraft.client.KeyMapping; +import xaero.common.settings.ModOptions; +import xaero.map.gui.CursorBox; +import xaeroplus.XaeroPlus; +import xaeroplus.mixin.client.AccessorMinimapModOptions; +import xaeroplus.mixin.client.AccessorWorldMapModOptions; + +import java.util.function.BooleanSupplier; +import java.util.function.Consumer; + +import static java.util.Objects.nonNull; + +public class BooleanSetting extends XaeroPlusSetting { + + private boolean value; + private BooleanConsumer settingChangeConsumer; + + private BooleanSetting(final String settingName, + final String settingNameTranslationKey, + final String tooltipTranslationKey, + final KeyMapping keyBinding, + final boolean value, + final BooleanConsumer settingChangeConsumer, + final BooleanSupplier visibilitySupplier) { + super(settingName, settingNameTranslationKey, tooltipTranslationKey, keyBinding, visibilitySupplier); + this.value = value; + this.settingChangeConsumer = settingChangeConsumer; + } + + public static BooleanSetting create(String settingName, + String settingNameTranslationKey, + boolean defaultValue) { + return new BooleanSetting( + SETTING_PREFIX + settingName, + settingNameTranslationKey, + buildTooltipTranslationKey(settingNameTranslationKey), + new KeyMapping(settingNameTranslationKey, -1, "XaeroPlus"), + defaultValue, + null, null + ); + } + + public static BooleanSetting create(String settingName, + String settingNameTranslationKey, + boolean defaultValue, + BooleanConsumer settingChangeConsumer) { + return new BooleanSetting( + SETTING_PREFIX + settingName, + settingNameTranslationKey, + buildTooltipTranslationKey(settingNameTranslationKey), + new KeyMapping(settingNameTranslationKey, -1, "XaeroPlus"), defaultValue, + settingChangeConsumer, null + ); + } + + public static BooleanSetting create(String settingName, + String settingNameTranslationKey, + boolean defaultValue, + BooleanSupplier visibilitySupplier) { + return new BooleanSetting( + SETTING_PREFIX + settingName, + settingNameTranslationKey, + buildTooltipTranslationKey(settingNameTranslationKey), + new KeyMapping(settingNameTranslationKey, -1, "XaeroPlus"), defaultValue, + null, visibilitySupplier + ); + } + + public static BooleanSetting create(String settingName, + String settingNameTranslationKey, + boolean defaultValue, + BooleanConsumer settingChangeConsumer, + BooleanSupplier visibilitySupplier) { + return new BooleanSetting( + SETTING_PREFIX + settingName, + settingNameTranslationKey, + buildTooltipTranslationKey(settingNameTranslationKey), + new KeyMapping(settingNameTranslationKey, -1, "XaeroPlus"), defaultValue, + settingChangeConsumer, visibilitySupplier + ); + } + + @Override + public String getSerializedValue() { + return Boolean.toString(value); + } + + @Override + public void deserializeValue(String value) { + var v = Boolean.parseBoolean(value); + if (v != get()) setValue(v); + } + + @Override + public ModOptions toMinimapModOptions() { + return AccessorMinimapModOptions.createBooleanSetting( + getSettingName(), + new xaero.common.graphics.CursorBox(getTooltipTranslationKey()), + isIngameOnly()); + } + + @Override + public xaero.map.settings.ModOptions toWorldMapModOptions() { + return AccessorWorldMapModOptions.createBooleanSetting( + getSettingName(), + new CursorBox(getTooltipTranslationKey()), + isIngameOnly(), + isRequiresMinimap(), + false); + } + + public boolean get() { + return value; + } + + public void setValue(final boolean value) { + this.value = value; + if (nonNull(getSettingChangeConsumer())) { + try { + getSettingChangeConsumer().accept(value); + } catch (final Exception e) { + XaeroPlus.LOGGER.warn("Error applying setting change consumer for {}", getSettingName(), e); + } + } + } + + public Consumer getSettingChangeConsumer() { + return settingChangeConsumer; + } + + public void setSettingChangeConsumer(final BooleanConsumer settingChangeConsumer) { + this.settingChangeConsumer = settingChangeConsumer; + } + + @Override + public void init() { + if (nonNull(settingChangeConsumer)) { + settingChangeConsumer.accept(value); + } + } + +} diff --git a/common/src/main/java/xaeroplus/settings/DoubleSetting.java b/common/src/main/java/xaeroplus/settings/DoubleSetting.java new file mode 100644 index 00000000..221adfe3 --- /dev/null +++ b/common/src/main/java/xaeroplus/settings/DoubleSetting.java @@ -0,0 +1,168 @@ +package xaeroplus.settings; + +import net.minecraft.client.KeyMapping; +import xaero.common.settings.ModOptions; +import xaero.map.gui.CursorBox; +import xaeroplus.XaeroPlus; +import xaeroplus.mixin.client.AccessorMinimapModOptions; +import xaeroplus.mixin.client.AccessorWorldMapModOptions; + +import java.util.function.BooleanSupplier; +import java.util.function.DoubleConsumer; + +import static java.util.Objects.nonNull; + +public class DoubleSetting extends XaeroPlusSetting { + private final double valueMin; + private final double valueMax; + private final double valueStep; + private double value; + private DoubleConsumer settingChangeConsumer; + + private DoubleSetting(final String settingName, + final String settingNameTranslationKey, + final String tooltipTranslationKey, + final KeyMapping keyBinding, + final double valueMin, + final double valueMax, + final double valueStep, + final double defaultValue, + final DoubleConsumer settingChangeConsumer, + final BooleanSupplier visibilitySupplier) { + super(settingName, settingNameTranslationKey, tooltipTranslationKey, keyBinding, visibilitySupplier); + this.valueMin = valueMin; + this.valueMax = valueMax; + this.valueStep = valueStep; + this.value = defaultValue; + this.settingChangeConsumer = settingChangeConsumer; + } + + public static DoubleSetting create(String settingName, + String settingNameTranslationKey, + double valueMin, + double valueMax, + double valueStep, + double defaultValue) { + return new DoubleSetting( + SETTING_PREFIX + settingName, + settingNameTranslationKey, + buildTooltipTranslationKey(settingNameTranslationKey), + null, + valueMin, valueMax, valueStep, defaultValue, null, null + ); + } + + public static DoubleSetting create(String settingName, + String settingNameTranslationKey, + double valueMin, + double valueMax, + double valueStep, + double defaultValue, + DoubleConsumer changeConsumer) { + return new DoubleSetting( + SETTING_PREFIX + settingName, + settingNameTranslationKey, + buildTooltipTranslationKey(settingNameTranslationKey), + null, + valueMin, valueMax, valueStep, defaultValue, changeConsumer, null + ); + } + + public static DoubleSetting create(String settingName, + String settingNameTranslationKey, + double valueMin, + double valueMax, + double valueStep, + double defaultValue, + DoubleConsumer changeConsumer, + BooleanSupplier visibilitySupplier) { + return new DoubleSetting( + SETTING_PREFIX + settingName, + settingNameTranslationKey, + buildTooltipTranslationKey(settingNameTranslationKey), + null, + valueMin, valueMax, valueStep, defaultValue, changeConsumer, visibilitySupplier + ); + } + + @Override + public String getSerializedValue() { + return Double.toString(value); + } + + @Override + public void deserializeValue(String value) { + var f = Double.parseDouble(value); + if (f != get()) setValue(f); + } + + @Override + public ModOptions toMinimapModOptions() { + return AccessorMinimapModOptions.createDoubleSetting( + getSettingName(), + getValueMin(), + getValueMax(), + (float) getValueStep(), + new xaero.common.graphics.CursorBox(getTooltipTranslationKey()), + isIngameOnly() + ); + } + + @Override + public xaero.map.settings.ModOptions toWorldMapModOptions() { + return AccessorWorldMapModOptions.createDoubleSetting( + getSettingName(), + getValueMin(), + getValueMax(), + getValueStep(), + new CursorBox(getTooltipTranslationKey()), + isIngameOnly(), + isRequiresMinimap(), + false + ); + } + + public double getValueMin() { + return valueMin; + } + + public double getValueMax() { + return valueMax; + } + + public double getValueStep() { + return valueStep; + } + + public double get() { + return value; + } + + public int getAsInt() { + return (int) value; + } + + public void setValue(final double value) { + this.value = value; + if (nonNull(getSettingChangeConsumer())) { + try { + getSettingChangeConsumer().accept(value); + } catch (final Exception e) { + XaeroPlus.LOGGER.warn("Error applying setting change consumer for {}", getSettingName(), e); + } + } + } + + public DoubleConsumer getSettingChangeConsumer() { + return settingChangeConsumer; + } + + public void setSettingChangeConsumer(final DoubleConsumer settingChangeConsumer) { + this.settingChangeConsumer = settingChangeConsumer; + } + public void init() { + if (nonNull(settingChangeConsumer)) { + settingChangeConsumer.accept(value); + } + } +} diff --git a/common/src/main/java/xaeroplus/settings/EnumSetting.java b/common/src/main/java/xaeroplus/settings/EnumSetting.java new file mode 100644 index 00000000..092e2946 --- /dev/null +++ b/common/src/main/java/xaeroplus/settings/EnumSetting.java @@ -0,0 +1,169 @@ +package xaeroplus.settings; + +import net.minecraft.client.KeyMapping; +import org.apache.commons.lang3.ArrayUtils; +import xaero.common.settings.ModOptions; +import xaero.map.gui.CursorBox; +import xaeroplus.XaeroPlus; +import xaeroplus.mixin.client.AccessorMinimapModOptions; +import xaeroplus.mixin.client.AccessorWorldMapModOptions; + +import java.util.function.BooleanSupplier; +import java.util.function.Consumer; + +import static java.util.Objects.nonNull; + +public class EnumSetting> extends XaeroPlusSetting { + private final T[] enumValues; + private T value; + private Consumer settingChangeConsumer; + + private EnumSetting(final String settingName, + final String settingNameTranslationKey, + final String tooltipTranslationKey, + final KeyMapping keyBinding, + final T[] enumValues, + final T defaultValue, + final Consumer settingChangeConsumer, + final BooleanSupplier visibilitySupplier) { + super(settingName, settingNameTranslationKey, tooltipTranslationKey, keyBinding, visibilitySupplier); + this.enumValues = enumValues; + this.value = defaultValue; + this.settingChangeConsumer = settingChangeConsumer; + } + + public static > EnumSetting create( + String settingName, + String settingNameTranslationKey, + E[] values, + E defaultValue) { + return new EnumSetting<>( + SETTING_PREFIX + settingName, + settingNameTranslationKey, + buildTooltipTranslationKey(settingNameTranslationKey), + null, + values, defaultValue, null, null + ); + } + + public static > EnumSetting create( + String settingName, + String settingNameTranslationKey, + E[] values, + E defaultValue, + Consumer settingChangeConsumer) { + return new EnumSetting<>( + SETTING_PREFIX + settingName, + settingNameTranslationKey, + buildTooltipTranslationKey(settingNameTranslationKey), + null, + values, + defaultValue, + settingChangeConsumer, + null + ); + } + + public static > EnumSetting create( + String settingName, + String settingNameTranslationKey, + E[] values, + E defaultValue, + Consumer settingChangeConsumer, + BooleanSupplier visibilitySupplier) { + return new EnumSetting<>( + SETTING_PREFIX + settingName, + settingNameTranslationKey, + buildTooltipTranslationKey(settingNameTranslationKey), + null, + values, + defaultValue, + settingChangeConsumer, + visibilitySupplier + ); + } + + @Override + public String getSerializedValue() { + return Integer.toString(getValueIndex()); + } + + @Override + public void deserializeValue(String value) { + var index = Integer.parseInt(value); + if (index != getValueIndex()) setValueIndex(index); + } + + @Override + public ModOptions toMinimapModOptions() { + return AccessorMinimapModOptions.createEnumSetting( + getSettingName(), + 0, + getIndexMax(), + new xaero.common.graphics.CursorBox(getTooltipTranslationKey()), + isIngameOnly() + ); + } + + @Override + public xaero.map.settings.ModOptions toWorldMapModOptions() { + return AccessorWorldMapModOptions.createEnumSetting( + getSettingName(), + getIndexMax() + 1, + new CursorBox(getTooltipTranslationKey()), + isIngameOnly(), + isRequiresMinimap(), + false + ); + } + + public T get() { + return value; + } + + public void setValue(T newVal) { + this.value = newVal; + if (nonNull(getSettingChangeConsumer())) { + try { + getSettingChangeConsumer().accept(newVal); + } catch (final Exception e) { + XaeroPlus.LOGGER.error("Error applying setting change consumer for setting: {}, value: {}", getSettingName(), newVal, e); + } + + } + } + + public int getValueIndex() { + return ArrayUtils.indexOf(enumValues, get()); + } + + public void setValueIndex(final int index) { + try { + setValue(enumValues[index]); + } catch (final Exception e) { + XaeroPlus.LOGGER.error("Unable to set enum value setting for {}, index {}", getSettingName(), index, e); + } + } + + public int getIndexMax() { + return enumValues.length-1; + } + + public void setSettingChangeConsumer(final Consumer settingChangeConsumer) { + this.settingChangeConsumer = settingChangeConsumer; + } + + public Consumer getSettingChangeConsumer() { + return settingChangeConsumer; + } + + public T[] getEnumValues() { + return enumValues; + } + @Override + public void init() { + if (nonNull(settingChangeConsumer)) { + settingChangeConsumer.accept(value); + } + } +} diff --git a/common/src/main/java/xaeroplus/settings/SettingHooks.java b/common/src/main/java/xaeroplus/settings/SettingHooks.java new file mode 100644 index 00000000..198226a4 --- /dev/null +++ b/common/src/main/java/xaeroplus/settings/SettingHooks.java @@ -0,0 +1,122 @@ +package xaeroplus.settings; + +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import xaeroplus.XaeroPlus; + +import java.io.*; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; + +public class SettingHooks { + public static void saveSettings() { + try { + saveXPSettings(); + } catch (final Exception e) { + XaeroPlus.LOGGER.error("Failed saving settings", e); + } + } + + public static synchronized void saveXPSettings() throws IOException { + File tempFile = new File(XaeroPlus.configFile.getAbsolutePath() + ".tmp"); + if (tempFile.exists()) tempFile.delete(); + try (PrintWriter writer = new PrintWriter(new FileWriter(tempFile, true))) { + var allSettings = Settings.REGISTRY.getAllSettings(); + for (int i = 0; i < allSettings.size(); i++) { + final XaeroPlusSetting setting = allSettings.get(i); + writer.println(setting.getSettingName() + ":" + setting.getSerializedValue()); + } + } + Files.move(tempFile.toPath(), XaeroPlus.configFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + } + + public static synchronized void loadXPSettings() { + try { + if (!XaeroPlus.configFile.exists()) return; + loadXPSettingsFromFile(XaeroPlus.configFile); + } catch (final Throwable e) { + XaeroPlus.LOGGER.error("Error loading XaeroPlus settings", e); + } + } + + public static synchronized void loadXPSettingsFromFile(File file) throws IOException { + try(BufferedReader reader = new BufferedReader(new FileReader(file))) { + String s; + while ((s = reader.readLine()) != null) { + String[] args = s.split(":"); + if (args.length != 2) { + XaeroPlus.LOGGER.warn("Invalid setting line: {}", s); + continue; + } + var setting = Settings.REGISTRY.getSettingByName(args[0]); + if (setting == null) { + XaeroPlus.LOGGER.warn("Setting not found: {}", args[0]); + continue; + } + setting.deserializeValue(args[1]); + } + } + } + + public static void getClientBooleanValue(String enumString, CallbackInfoReturnable cir) { + var setting = Settings.REGISTRY.getSettingByName(enumString); + if (setting instanceof BooleanSetting booleanSetting) { + cir.setReturnValue(booleanSetting.get()); + } + } + + // boolean or enum... + public static void setOptionValue(String enumString, final Object value) { + var setting = Settings.REGISTRY.getSettingByName(enumString); + if (setting instanceof BooleanSetting booleanSetting && value instanceof Boolean) { + booleanSetting.setValue((Boolean) value); + } else if (setting instanceof EnumSetting enumSetting && value instanceof Integer) { + enumSetting.setValueIndex((Integer) value); + } + } + + // boolean or enum... + public static void getOptionValue(final String enumString, final CallbackInfoReturnable cir) { + var setting = Settings.REGISTRY.getSettingByName(enumString); + if (setting instanceof BooleanSetting booleanSetting) { + cir.setReturnValue(booleanSetting.get()); + } else if (setting instanceof EnumSetting enumSetting) { + cir.setReturnValue(enumSetting.getValueIndex()); + } + } + + public static void setOptionDoubleValue(String enumString, double f) { + var setting = Settings.REGISTRY.getSettingByName(enumString); + if (setting instanceof DoubleSetting doubleSetting) { + doubleSetting.setValue(f); + } + } + + public static void getOptionDoubleValue(String enumString, CallbackInfoReturnable cir) { + var setting = Settings.REGISTRY.getSettingByName(enumString); + if (setting instanceof DoubleSetting doubleSetting) { + cir.setReturnValue(doubleSetting.get()); + } + } + + public static void getOptionValueName(final String enumString, final CallbackInfoReturnable cir) { + var setting = Settings.REGISTRY.getSettingByName(enumString); + if (setting instanceof EnumSetting enumSetting) { + cir.setReturnValue(enumSetting.get() instanceof TranslatableSettingEnum + ? ((TranslatableSettingEnum) enumSetting.get()).getTranslatedName() + : enumSetting.get().toString()); + } + } + + public static void getSliderOptionText(final String enumString, final CallbackInfoReturnable cir) { + var setting = Settings.REGISTRY.getSettingByName(enumString); + if (setting == null) return; + var prefix = setting.getTranslatedName() + ": "; + if (setting instanceof DoubleSetting doubleSetting) { + cir.setReturnValue(prefix + String.format("%.2f", doubleSetting.get())); + } else if (setting instanceof EnumSetting enumSetting) { + cir.setReturnValue(prefix + (enumSetting.get() instanceof TranslatableSettingEnum + ? ((TranslatableSettingEnum) enumSetting.get()).getTranslatedName() + : enumSetting.get().toString())); + } + } +} diff --git a/common/src/main/java/xaeroplus/settings/SettingLocation.java b/common/src/main/java/xaeroplus/settings/SettingLocation.java new file mode 100644 index 00000000..9ef9720b --- /dev/null +++ b/common/src/main/java/xaeroplus/settings/SettingLocation.java @@ -0,0 +1,12 @@ +package xaeroplus.settings; + +public enum SettingLocation { + WORLD_MAP_MAIN, + CHUNK_HIGHLIGHTS, + MINIMAP_OVERLAYS, + MINIMAP_MAIN, + MINIMAP_VIEW, + KEYBINDS, + MINIMAP_ENTITY_RADAR, + MINIMAP_WAYPOINTS; +} diff --git a/common/src/main/java/xaeroplus/settings/SettingRegistry.java b/common/src/main/java/xaeroplus/settings/SettingRegistry.java new file mode 100644 index 00000000..cf37f57f --- /dev/null +++ b/common/src/main/java/xaeroplus/settings/SettingRegistry.java @@ -0,0 +1,82 @@ +package xaeroplus.settings; + +import net.minecraft.client.KeyMapping; + +import java.util.*; + +public abstract class SettingRegistry { + private final Map> settingLocationMap = new EnumMap<>(SettingLocation.class); + private final Map settingNameMap = new HashMap<>(); + private final Map keybindingMap = new HashMap<>(); + + public BooleanSetting register(BooleanSetting setting, SettingLocation settingLocation) { + register0(settingLocation, setting); + return setting; + } + + public DoubleSetting register(DoubleSetting setting, SettingLocation settingLocation) { + register0(settingLocation, setting); + return setting; + } + + public > EnumSetting register(EnumSetting setting, SettingLocation settingLocation) { + register0(settingLocation, setting); + return setting; + } + + private synchronized void register0(SettingLocation settingLocation, XaeroPlusSetting setting) { + if (settingNameMap.containsKey(setting.getSettingName())) { + throw new RuntimeException("Setting with name '" + setting.getSettingName() + "' already exists"); + } + var settingList = this.settingLocationMap.getOrDefault(settingLocation, new ArrayList<>()); + settingList.add(setting); + this.settingLocationMap.put(settingLocation, settingList); + this.settingNameMap.put(setting.getSettingName(), setting); + if (setting instanceof BooleanSetting booleanSetting) { + var kb = booleanSetting.getKeyBinding(); + if (kb != null) keybindingMap.put(kb, booleanSetting); + } + } + + public XaeroPlusSetting getSettingByName(String name) { + return settingNameMap.get(name); + } + + public List getKeybindings() { + return new ArrayList<>(keybindingMap.keySet()); + } + + public BooleanSetting getKeybindingSetting(KeyMapping keyMapping) { + return keybindingMap.get(keyMapping); + } + + public List getAllSettings() { + return new ArrayList<>(settingNameMap.values()); + } + + public synchronized xaero.common.gui.ConfigSettingEntry[] getMinimapConfigSettingEntries(SettingLocation settingLocation) { + var settingList = this.settingLocationMap.get(settingLocation); + if (settingList != null) { + xaero.common.gui.ConfigSettingEntry[] entries = new xaero.common.gui.ConfigSettingEntry[settingList.size()]; + for (int i = 0; i < settingList.size(); i++) { + final XaeroPlusSetting xaeroPlusSetting = settingList.get(i); + entries[i] = xaeroPlusSetting.toMinimapConfigSettingEntry(); + } + return entries; + } + return new xaero.common.gui.ConfigSettingEntry[0]; + } + + public synchronized xaero.map.gui.ConfigSettingEntry[] getWorldmapConfigSettingEntries(SettingLocation settingLocation) { + var settingList = this.settingLocationMap.get(settingLocation); + if (settingList != null) { + xaero.map.gui.ConfigSettingEntry[] entries = new xaero.map.gui.ConfigSettingEntry[settingList.size()]; + for (int i = 0; i < settingList.size(); i++) { + final XaeroPlusSetting xaeroPlusSetting = settingList.get(i); + entries[i] = xaeroPlusSetting.toWorldmapConfigSettingEntry(); + } + return entries; + } + return new xaero.map.gui.ConfigSettingEntry[0]; + } +} diff --git a/common/src/main/java/xaeroplus/settings/Settings.java b/common/src/main/java/xaeroplus/settings/Settings.java new file mode 100644 index 00000000..a323b922 --- /dev/null +++ b/common/src/main/java/xaeroplus/settings/Settings.java @@ -0,0 +1,709 @@ +package xaeroplus.settings; + +import net.minecraft.client.Minecraft; +import xaero.map.WorldMapSession; +import xaeroplus.Globals; +import xaeroplus.module.ModuleManager; +import xaeroplus.module.impl.*; +import xaeroplus.util.BaritoneHelper; +import xaeroplus.util.ColorHelper; +import xaeroplus.util.WaystonesHelper; +import xaeroplus.util.WorldToolsHelper; + +import java.io.ByteArrayOutputStream; + +import static net.minecraft.world.level.Level.*; + +public final class Settings extends SettingRegistry { + public static final Settings REGISTRY = new Settings(); + + private Settings() {} + + /** + * The order settings are defined here determines the order in the settings GUI's. + */ + public final BooleanSetting minimapFpsLimiter = register( + BooleanSetting.create( + "Minimap FPS Limiter", + "setting.minimap.fps_limiter", + false, + (b) -> ModuleManager.getModule(FpsLimiter.class).setEnabled(b)), + SettingLocation.MINIMAP_MAIN); + public final DoubleSetting minimapFpsLimit = register( + DoubleSetting.create( + "Minimap FPS Limit", + "setting.minimap.fps_limiter_limit", + 5, 120, 5, + 60), + SettingLocation.MINIMAP_MAIN); + public final BooleanSetting fastMapSetting = register( + BooleanSetting.create( + "Fast Mapping", + "setting.world_map.fast_mapping", + false), + SettingLocation.WORLD_MAP_MAIN); + public final DoubleSetting fastMapWriterDelaySetting = register( + DoubleSetting.create( + "Fast Mapping Delay", + "setting.world_map.fast_mapping_delay", + 10, 1000, 10, + 250), + SettingLocation.WORLD_MAP_MAIN); + public final DoubleSetting fastMapMaxTilesPerCycle = register( + DoubleSetting.create( + "Fast Mapping Rate Limit", + "setting.world_map.fast_mapping_rate_limit", + 10, 120, 10, + 25), + SettingLocation.WORLD_MAP_MAIN); + public final BooleanSetting fastZipWrite = register( + BooleanSetting.create( + "Fast Zip Writes", + "setting.world_map.fast_zip_writes", + true, + (b) -> { + if (!b) Globals.zipFastByteBuffer = new ByteArrayOutputStream(); // release any existing sized buffer to gc + }), + SettingLocation.WORLD_MAP_MAIN); + public final BooleanSetting writesWhileDimSwitched = register( + BooleanSetting.create( + "Region Writes While Dim Switched", + "setting.world_map.region_write_while_dimension_switched", + false), + SettingLocation.WORLD_MAP_MAIN); + public final BooleanSetting baritoneWaypointSyncSetting = register( + BooleanSetting.create( + "Baritone Goal Waypoint", + "setting.world_map.baritone_waypoint", + true, + (b) -> { + if (BaritoneHelper.isBaritonePresent()) ModuleManager.getModule(BaritoneGoalSync.class).setEnabled(b); + }, + BaritoneHelper::isBaritonePresent), + SettingLocation.WORLD_MAP_MAIN); + public final BooleanSetting waystonesWaypointSyncSetting = register( + BooleanSetting.create( + "Waystones Sync", + "setting.world_map.waystones_sync", + true, + (b) -> { + if (WaystonesHelper.isAnyWaystonesPresent()) ModuleManager.getModule(WaystoneSync.class).setEnabled(b); + }, + WaystonesHelper::isAnyWaystonesPresent), + SettingLocation.WORLD_MAP_MAIN); + public final EnumSetting waystoneColorSetting = register( + EnumSetting.create( + "Waystone Color", + "setting.world_map.waystone_color", + ColorHelper.WaystoneColor.values(), + ColorHelper.WaystoneColor.RANDOM, + (b) -> { + if (WaystonesHelper.isAnyWaystonesPresent()) ModuleManager.getModule(WaystoneSync.class).setColor(b); + }, + WaystonesHelper::isAnyWaystonesPresent), + SettingLocation.WORLD_MAP_MAIN); + public final BooleanSetting waystoneWaypointSetSetting = register( + BooleanSetting.create( + "Waystone Waypoint Set", + "setting.world_map.waystone_waypoint_set", + false, + (b) -> { + if (WaystonesHelper.isAnyWaystonesPresent()) ModuleManager.getModule(WaystoneSync.class).setWaypointSet(b); + }, + WaystonesHelper::isAnyWaystonesPresent), + SettingLocation.WORLD_MAP_MAIN); + public final EnumSetting waystoneWaypointVisibilityModeSetting = register( + EnumSetting.create( + "Waystone WP Visibility Type", + "setting.world_map.waystone_visibility_type", + WaystoneWpVisibilityType.values(), + WaystoneWpVisibilityType.LOCAL, + (mode) -> { + if (WaystonesHelper.isAnyWaystonesPresent()) ModuleManager.getModule(WaystoneSync.class).setVisibilityType(mode.ordinal()); + }, + WaystonesHelper::isAnyWaystonesPresent), + SettingLocation.WORLD_MAP_MAIN); + public enum WaystoneWpVisibilityType implements TranslatableSettingEnum { + // order here must mirror xaero's visibility enum + LOCAL("gui.xaeroplus.waystone_visibility_type.local"), + GLOBAL("gui.xaeroplus.waystone_visibility_type.global"), + WORLD_MAP_LOCAL("gui.xaeroplus.waystone_visibility_type.world_map_local"), + WORLD_MAP_GLOBAL("gui.xaeroplus.waystone_visibility_type.world_map_global"); + private final String translationKey; + WaystoneWpVisibilityType(final String translationKey) { + this.translationKey = translationKey; + } + @Override + public String getTranslationKey() { + return translationKey; + } + } + public final BooleanSetting persistMapDimensionSwitchSetting = register( + BooleanSetting.create( + "Persist Dim Switch", + "setting.world_map.persist_dimension_switch", + true), + SettingLocation.WORLD_MAP_MAIN); + public final BooleanSetting radarWhileDimensionSwitchedSetting = register( + BooleanSetting.create( + "Radar While Dim Switched", + "setting.world_map.radar_while_dimension_switched", + true), + SettingLocation.WORLD_MAP_MAIN); + static void markChunksDirtyInWriteDistance() { + Minecraft mc = Minecraft.getInstance(); + if (mc.level != null && mc.player != null) { + WorldMapSession session = WorldMapSession.getCurrentSession(); + if (session != null) { + session.getMapProcessor().getMapWriter().setDirtyInWriteDistance(mc.player, mc.level); + session.getMapProcessor().getMapWriter().requestCachedColoursClear(); + } + } + } + public final BooleanSetting transparentObsidianRoofSetting = register( + BooleanSetting.create( + "Transparent Obsidian Roof", + "setting.world_map.transparent_obsidian_roof", + false, + (v) -> markChunksDirtyInWriteDistance()), + SettingLocation.WORLD_MAP_MAIN); + public final DoubleSetting transparentObsidianRoofYSetting = register( + DoubleSetting.create( + "Roof Y Level", + "setting.world_map.transparent_obsidian_roof_y", + 0, 320, 1, + 250, + (v) -> markChunksDirtyInWriteDistance()), + SettingLocation.WORLD_MAP_MAIN); + public final DoubleSetting transparentObsidianRoofDarkeningSetting = register( + DoubleSetting.create( + "Roof Obsidian Opacity", + "setting.world_map.transparent_obsidian_roof_darkening", + 0, 255, 5, + 150, + (v) -> markChunksDirtyInWriteDistance()), + SettingLocation.WORLD_MAP_MAIN); + public final DoubleSetting transparentObsidianRoofSnowOpacitySetting = register( + DoubleSetting.create( + "Roof Snow Opacity", + "setting.world_map.transparent_obsidian_roof_snow_opacity", + 0, 255, 5, + 10, + (v) -> markChunksDirtyInWriteDistance()), + SettingLocation.WORLD_MAP_MAIN); + public final BooleanSetting overlayOpacityFix = register( + BooleanSetting.create( + "Overlay Opacity Fix", + "setting.world_map.overlay_opacity_fix", + true), + SettingLocation.WORLD_MAP_MAIN); + public final DoubleSetting worldMapMinZoomSetting = register( + DoubleSetting.create( + "Min WorldMap Zoom", + "setting.world_map.min_zoom", + 0, 0.625, 0.01, + 0.1), + SettingLocation.WORLD_MAP_MAIN); + public final BooleanSetting crossDimensionCursorCoordinates = register( + BooleanSetting.create( + "Cross Dim Cursor Coords", + "setting.world_map.cross_dimension_cursor_coordinates", + false), + SettingLocation.WORLD_MAP_MAIN); + public final BooleanSetting paletteNewChunksEnabledSetting = register( + BooleanSetting.create( + "Palette NewChunks", + "setting.world_map.palette_new_chunks_highlighting", + false, + (b) -> ModuleManager.getModule(PaletteNewChunks.class).setEnabled(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final BooleanSetting paletteNewChunksSaveLoadToDisk = register( + BooleanSetting.create( + "Save/Load Palette NewChunks to Disk", + "setting.world_map.palette_new_chunks_save_load_to_disk", + true, + (b) -> ModuleManager.getModule(PaletteNewChunks.class).setDiskCache(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final DoubleSetting paletteNewChunksAlphaSetting = register( + DoubleSetting.create( + "Palette NewChunks Opacity", + "setting.world_map.palette_new_chunks_opacity", + 0, 255, 10, + 100, + (b) -> ModuleManager.getModule(PaletteNewChunks.class).setAlpha(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final EnumSetting paletteNewChunksColorSetting = register( + EnumSetting.create( + "Palette NewChunks Color", + "setting.world_map.palette_new_chunks_color", + ColorHelper.HighlightColor.values(), + ColorHelper.HighlightColor.RED, + (b) -> ModuleManager.getModule(PaletteNewChunks.class).setRgbColor(b.getColor())), + SettingLocation.CHUNK_HIGHLIGHTS); + public final BooleanSetting paletteNewChunksRenderInverse = register( + BooleanSetting.create( + "Palette NewChunks Inverse", + "setting.world_map.palette_new_chunks_inverse", + false, + (b) -> ModuleManager.getModule(PaletteNewChunks.class).setInverse(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final BooleanSetting oldChunksEnabledSetting = register( + BooleanSetting.create( + "OldChunks Highlighting", + "setting.world_map.old_chunks_highlighting", + false, + (b) -> ModuleManager.getModule(OldChunks.class).setEnabled(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final BooleanSetting oldChunksInverse = register( + BooleanSetting.create( + "OldChunks Inverse", + "setting.world_map.old_chunks_inverse", + false, + (b) -> ModuleManager.getModule(OldChunks.class).setInverse(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final BooleanSetting oldChunksSaveLoadToDisk = register( + BooleanSetting.create( + "Save/Load OldChunks to Disk", + "setting.world_map.old_chunks_save_load_to_disk", + true, + (b) -> ModuleManager.getModule(OldChunks.class).setDiskCache(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final DoubleSetting oldChunksAlphaSetting = register( + DoubleSetting.create( + "Old Chunks Opacity", + "setting.world_map.old_chunks_opacity", + 0, 255, 10, + 100, + (b) -> ModuleManager.getModule(OldChunks.class).setAlpha(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final EnumSetting oldChunksColorSetting = register( + EnumSetting.create( + "Old Chunks Color", + "setting.world_map.old_chunks_color", + ColorHelper.HighlightColor.values(), + ColorHelper.HighlightColor.YELLOW, + (b) -> ModuleManager.getModule(OldChunks.class).setRgbColor(b.getColor())), + SettingLocation.CHUNK_HIGHLIGHTS); + public final BooleanSetting portalsEnabledSetting = register( + BooleanSetting.create( + "Portal Highlights", + "setting.world_map.portals", + false, + (b) -> ModuleManager.getModule(Portals.class).setEnabled(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final BooleanSetting portalsSaveLoadToDisk = register( + BooleanSetting.create( + "Save/Load Portals to Disk", + "setting.world_map.portals_save_load_to_disk", + true, + (b) -> ModuleManager.getModule(Portals.class).setDiskCache(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final DoubleSetting portalsAlphaSetting = register( + DoubleSetting.create( + "Portal Highlights Opacity", + "setting.world_map.portals_opacity", + 0, 255, 10, + 100, + (b) -> ModuleManager.getModule(Portals.class).setAlpha(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final EnumSetting portalsColorSetting = register( + EnumSetting.create( + "Portal Highlights Color", + "setting.world_map.portals_color", + ColorHelper.HighlightColor.values(), + ColorHelper.HighlightColor.MAGENTA, + (b) -> ModuleManager.getModule(Portals.class).setRgbColor(b.getColor())), + SettingLocation.CHUNK_HIGHLIGHTS); + public final BooleanSetting oldBiomesSetting = register( + BooleanSetting.create( + "Old Biomes", + "setting.world_map.old_biomes_enabled", + false, + (b) -> ModuleManager.getModule(OldBiomes.class).setEnabled(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final BooleanSetting oldBiomesSaveToDiskSetting = register( + BooleanSetting.create( + "Save/Load OldBiomes To Disk", + "setting.world_map.old_biomes_save_load_to_disk", + true, + (b) -> ModuleManager.getModule(OldBiomes.class).setDiskCache(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final DoubleSetting oldBiomesAlphaSetting = register( + DoubleSetting.create( + "OldBiomes Opacity", + "setting.world_map.old_biomes_opacity", + 0, 255, 10, + 100, + (b) -> ModuleManager.getModule(OldBiomes.class).setAlpha(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final EnumSetting oldBiomesColorSetting = register( + EnumSetting.create( + "OldBiomes Color", + "setting.world_map.old_biomes_color", + ColorHelper.HighlightColor.values(), + ColorHelper.HighlightColor.GREEN, + (b) -> ModuleManager.getModule(OldBiomes.class).setRgbColor(b.getColor())), + SettingLocation.CHUNK_HIGHLIGHTS); + public final BooleanSetting liquidNewChunksEnabledSetting = register( + BooleanSetting.create( + "NewChunks Highlighting", + "setting.world_map.new_chunks_highlighting", + false, + (b) -> ModuleManager.getModule(LiquidNewChunks.class).setEnabled(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final BooleanSetting liquidNewChunksSaveLoadToDisk = register( + BooleanSetting.create( + "Save/Load NewChunks to Disk", + "setting.world_map.new_chunks_save_load_to_disk", + true, + (b) -> ModuleManager.getModule(LiquidNewChunks.class).setDiskCache(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final DoubleSetting liquidNewChunksAlphaSetting = register( + DoubleSetting.create( + "New Chunks Opacity", + "setting.world_map.new_chunks_opacity", + 0, 255, 10, + 100, + (b) -> ModuleManager.getModule(LiquidNewChunks.class).setAlpha(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final EnumSetting liquidNewChunksColorSetting = register( + EnumSetting.create( + "New Chunks Color", + "setting.world_map.new_chunks_color", + ColorHelper.HighlightColor.values(), + ColorHelper.HighlightColor.RED, + (b) -> ModuleManager.getModule(LiquidNewChunks.class).setRgbColor(b.getColor())), + SettingLocation.CHUNK_HIGHLIGHTS); + public final BooleanSetting liquidNewChunksInverseHighlightsSetting = register( + BooleanSetting.create( + "New Chunks Render Inverse", + "setting.world_map.new_chunks_inverse_enabled", + false, + (b) -> ModuleManager.getModule(LiquidNewChunks.class).setInverseRenderEnabled(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final EnumSetting liquidNewChunksInverseColorSetting = register( + EnumSetting.create( + "New Chunks Inverse Color", + "setting.world_map.new_chunks_inverse_color", + ColorHelper.HighlightColor.values(), + ColorHelper.HighlightColor.GREEN, + (b) -> ModuleManager.getModule(LiquidNewChunks.class).setInverseRgbColor(b.getColor())), + SettingLocation.CHUNK_HIGHLIGHTS); + public final BooleanSetting liquidNewChunksOnlyAboveY0Setting = register( + BooleanSetting.create( + "Liquid NewChunks Only Y > 0", + "setting.world_map.new_chunks_only_above_y0", + false), + SettingLocation.CHUNK_HIGHLIGHTS); + public final BooleanSetting worldToolsEnabledSetting = register( + BooleanSetting.create( + "WorldTools Highlights", + "setting.world_map.world_tools", + true, + (b) -> ModuleManager.getModule(WorldTools.class).setEnabled(b), + WorldToolsHelper::isWorldToolsPresent), + SettingLocation.CHUNK_HIGHLIGHTS); + public DoubleSetting worldToolsAlphaSetting = register( + DoubleSetting.create( + "WorldTools Highlights Opacity", + "setting.world_map.world_tools_opacity", + 0, 255, 10, + 100, + (b) -> ModuleManager.getModule(WorldTools.class).setAlpha(b), + WorldToolsHelper::isWorldToolsPresent), + SettingLocation.CHUNK_HIGHLIGHTS); + public final EnumSetting worldToolsColorSetting = register( + EnumSetting.create( + "WorldTools Highlights Color", + "setting.world_map.world_tools_color", + ColorHelper.HighlightColor.values(), + ColorHelper.HighlightColor.GREEN, + (b) -> ModuleManager.getModule(WorldTools.class).setRgbColor(b.getColor()), + WorldToolsHelper::isWorldToolsPresent), + SettingLocation.CHUNK_HIGHLIGHTS); + public final BooleanSetting portalSkipDetectionEnabledSetting = register( + BooleanSetting.create( + "PortalSkip Detection", + "setting.world_map.portal_skip_detection", + false, + (b) -> ModuleManager.getModule(PortalSkipDetection.class).setEnabled(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final DoubleSetting portalSkipDetectionAlphaSetting = register( + DoubleSetting.create( + "PortalSkip Opacity", + "setting.world_map.portal_skip_opacity", + 0, 255, 10, + 100, + (b) -> ModuleManager.getModule(PortalSkipDetection.class).setAlpha(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final EnumSetting portalSkipDetectionColorSetting = register( + EnumSetting.create( + "PortalSkip Color", + "setting.world_map.portal_skip_color", + ColorHelper.HighlightColor.values(), + ColorHelper.HighlightColor.WHITE, + (b) -> ModuleManager.getModule(PortalSkipDetection.class).setRgbColor(b.getColor())), + SettingLocation.CHUNK_HIGHLIGHTS); + public final DoubleSetting portalSkipPortalRadius = register( + DoubleSetting.create( + "PortalSkip Portal Radius", + "setting.world_map.portal_skip_portal_radius", + 0, 32, 1, + 15, + (b) -> ModuleManager.getModule(PortalSkipDetection.class).setPortalRadius(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final DoubleSetting portalSkipDetectionSearchDelayTicksSetting = register( + DoubleSetting.create( + "PortalSkip Search Delay", + "setting.world_map.portal_skip_search_delay", + 0, 100, 1, + 10, + (b) -> ModuleManager.getModule(PortalSkipDetection.class).setSearchDelayTicks(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final BooleanSetting portalSkipNewChunksSetting = register( + BooleanSetting.create( + "PortalSkip NewChunks", + "setting.world_map.portal_skip_new_chunks", + true, + (b) -> ModuleManager.getModule(PortalSkipDetection.class).setNewChunks(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final BooleanSetting portalSkipOldChunkInverseSetting = register( + BooleanSetting.create( + "PortalSkip OldChunks Inverse", + "setting.world_map.portal_skip_old_chunks_inverse", + true, + (b) -> ModuleManager.getModule(PortalSkipDetection.class).setOldChunksInverse(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final BooleanSetting highwayHighlightsSetting = register( + BooleanSetting.create( + "2b2t Highways", + "setting.world_map.2b2t_highways_enabled", + false, + (b) -> ModuleManager.getModule(Highways.class).setEnabled(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final EnumSetting highwaysColorSetting = register( + EnumSetting.create( + "2b2t Highways Color", + "setting.world_map.2b2t_highways_color", + ColorHelper.HighlightColor.values(), + ColorHelper.HighlightColor.BLUE, + (b) -> ModuleManager.getModule(Highways.class).setRgbColor(b.getColor())), + SettingLocation.CHUNK_HIGHLIGHTS); + public final DoubleSetting highwaysColorAlphaSetting = register( + DoubleSetting.create( + "2b2t Highways Opacity", + "setting.world_map.2b2t_highways_opacity", + 0, 255, 10, + 100, + (b) -> ModuleManager.getModule(Highways.class).setAlpha(b)), + SettingLocation.CHUNK_HIGHLIGHTS); + public final BooleanSetting owAutoWaypointDimension = register( + BooleanSetting.create( + "Prefer Overworld Waypoints", + "setting.world_map.ow_auto_waypoint_dimension", + false), + SettingLocation.WORLD_MAP_MAIN); + public final BooleanSetting showWaypointDistances = register( + BooleanSetting.create( + "Show Waypoint Distances", + "setting.world_map.show_waypoint_distances", + true), + SettingLocation.WORLD_MAP_MAIN); + public final BooleanSetting showRenderDistanceSetting = register( + BooleanSetting.create( + "Show Render Distance", + "setting.world_map.show_render_distance", + false), + SettingLocation.MINIMAP_OVERLAYS); + public final BooleanSetting showRenderDistanceWorldMapSetting = register( + BooleanSetting.create( + "Show Render Distance WorldMap", + "setting.world_map.show_render_distance_world_map", + false), + SettingLocation.MINIMAP_OVERLAYS); + public final BooleanSetting nullOverworldDimensionFolder = register( + BooleanSetting.create( + "null OW Dim Dir", + "setting.world_map.null_overworld_dimension_folder", + true, + Globals::setNullOverworldDimFolderIfAble), + SettingLocation.WORLD_MAP_MAIN); + public final EnumSetting dataFolderResolutionMode = register( + EnumSetting.create( + "Data Dir Mode", + "setting.world_map.data_folder_resolution_mode", + DataFolderResolutionMode.values(), + DataFolderResolutionMode.IP, + Globals::setDataFolderResolutionModeIfAble), + SettingLocation.WORLD_MAP_MAIN); + + public enum DataFolderResolutionMode implements TranslatableSettingEnum { + IP("setting.world_map.data_folder_resolution_mode.ip"), + SERVER_NAME("setting.world_map.data_folder_resolution_mode.server_name"), + BASE_DOMAIN("setting.world_map.data_folder_resolution_mode.base_domain"); + + private final String translationKey; + + DataFolderResolutionMode(final String translationKey) { + this.translationKey = translationKey; + } + + @Override + public String getTranslationKey() { + return translationKey; + } + } + public final BooleanSetting transparentMinimapBackground = register( + BooleanSetting.create( + "Transparent Background", + "setting.minimap.transparent_background", + false), + SettingLocation.MINIMAP_VIEW); + public final DoubleSetting minimapScaleMultiplierSetting = register( + DoubleSetting.create( + "Minimap Scaling Factor", + "setting.minimap.minimap_scaling", + 1, 5, 1, + 1, + (b) -> Globals.shouldResetFBO = true), + SettingLocation.MINIMAP_VIEW); + public final DoubleSetting minimapSizeMultiplierSetting = register( + DoubleSetting.create( + "Minimap Size Multiplier", + "setting.minimap_size_multiplier", + 1, 4, 1, + 1, + (b) -> Globals.shouldResetFBO = true), + SettingLocation.MINIMAP_VIEW); + public final BooleanSetting switchToNetherSetting = register( + BooleanSetting.create( + "Switch to Nether", + "setting.keybinds.switch_to_nether", + false, + (b) -> Globals.switchToDimension(NETHER)), + SettingLocation.KEYBINDS); + public final BooleanSetting switchToOverworldSetting = register( + BooleanSetting.create( + "Switch to Overworld", + "setting.keybinds.switch_to_overworld", + false, + (b) -> Globals.switchToDimension(OVERWORLD)), + SettingLocation.KEYBINDS); + public final BooleanSetting switchToEndSetting = register( + BooleanSetting.create( + "Switch to End", + "setting.keybinds.switch_to_end", + false, + (b) -> Globals.switchToDimension(END)), + SettingLocation.KEYBINDS); + public final BooleanSetting worldMapBaritoneGoalHereKeybindSetting = register( + BooleanSetting.create( + "WorldMap Baritone Goal Here", + "setting.keybinds.world_map_baritone_goal_here", + false), + SettingLocation.KEYBINDS); + public final BooleanSetting worldMapBaritonePathHereKeybindSetting = register( + BooleanSetting.create( + "WorldMap Baritone Path Here", + "setting.keybinds.world_map_baritone_path_here", + false), + SettingLocation.KEYBINDS); + public final BooleanSetting worldMapBaritoneElytraHereKeybindSetting = register( + BooleanSetting.create( + "WorldMap Baritone Elytra Here", + "setting.keybinds.world_map_baritone_elytra_here", + false), + SettingLocation.KEYBINDS); + public final BooleanSetting netherCaveFix = register( + BooleanSetting.create( + "Nether Cave Fix", + "setting.world_map.nether_cave_fix", + true), + SettingLocation.WORLD_MAP_MAIN); + public final BooleanSetting alwaysRenderPlayerWithNameOnRadar = register( + BooleanSetting.create( + "Always Render Player Name", + "setting.minimap.always_render_player_name", + true), + SettingLocation.MINIMAP_ENTITY_RADAR); + public final BooleanSetting alwaysRenderPlayerIconOnRadar = register( + BooleanSetting.create( + "Always Render Player Icon", + "setting.minimap.always_render_player_icon", + true), + SettingLocation.MINIMAP_ENTITY_RADAR); + public final BooleanSetting fixMainEntityDot = register( + BooleanSetting.create( + "Fix Main Entity Dot", + "setting.minimap.fix_main_entity_dot", + true), + SettingLocation.MINIMAP_ENTITY_RADAR); + public final BooleanSetting waypointBeacons = register( + BooleanSetting.create( + "Waypoint Beacons", + "setting.waypoints.waypoint_beacons", + false), + SettingLocation.MINIMAP_WAYPOINTS); + public final DoubleSetting waypointBeaconScaleMin = register( + DoubleSetting.create( + "Waypoint Beacon Scale Min", + "setting.waypoints.waypoint_beacon_scale_min", + 0, 30, 1, + 0), + SettingLocation.MINIMAP_WAYPOINTS); + public final DoubleSetting waypointBeaconDistanceMin = register( + DoubleSetting.create( + "Waypoint Beacon Distance Min", + "setting.waypoints.waypoint_beacon_distance_min", + 0, 512, 8, + 0), + SettingLocation.MINIMAP_WAYPOINTS); + public final BooleanSetting waypointEta = register( + BooleanSetting.create( + "Waypoint ETA", + "setting.waypoints.waypoint_eta", + false), + SettingLocation.MINIMAP_WAYPOINTS); + public final BooleanSetting disableWaypointSharing = register( + BooleanSetting.create( + "Disable Waypoint Sharing", + "setting.world_map.disable_waypoint_sharing", + false), + SettingLocation.MINIMAP_WAYPOINTS); + public final BooleanSetting plainWaypointSharing = register( + BooleanSetting.create( + "Plain Waypoint Sharing", + "setting.world_map.plain_waypoint_sharing", + false), + SettingLocation.MINIMAP_WAYPOINTS); + public final BooleanSetting disableReceivingWaypoints = register( + BooleanSetting.create( + "Disable Receiving Waypoints", + "setting.world_map.disable_receiving_waypoints", + false), + SettingLocation.MINIMAP_WAYPOINTS); + public final BooleanSetting disableXaeroInternetAccess = register( + BooleanSetting.create( + "Disable Xaero Internet Access", + "setting.world_map.disable_internet", + false), + SettingLocation.WORLD_MAP_MAIN); + public final BooleanSetting expandSettingEntries = register( + BooleanSetting.create( + "Expanded Setting Entries", + "setting.world_map.expanded_settings", + false), + SettingLocation.WORLD_MAP_MAIN); + public final BooleanSetting sodiumSettingIntegration = register( + BooleanSetting.create( + "Sodium/Embeddium Setting Integration", + "setting.xaeroplus.sodium_embeddium_integration", + true), + SettingLocation.WORLD_MAP_MAIN); + public final BooleanSetting highlightShader = register( + BooleanSetting.create( + "Highlight Shader", + "setting.world_map.highlight_shader", + true), + SettingLocation.CHUNK_HIGHLIGHTS); +} diff --git a/common/src/main/java/xaeroplus/settings/XaeroPlusBooleanSetting.java b/common/src/main/java/xaeroplus/settings/XaeroPlusBooleanSetting.java deleted file mode 100644 index 8a0e349f..00000000 --- a/common/src/main/java/xaeroplus/settings/XaeroPlusBooleanSetting.java +++ /dev/null @@ -1,124 +0,0 @@ -package xaeroplus.settings; - -import it.unimi.dsi.fastutil.booleans.BooleanConsumer; -import net.minecraft.client.KeyMapping; -import xaeroplus.XaeroPlus; -import xaeroplus.settings.XaeroPlusSettingsReflectionHax.SettingLocation; - -import java.util.function.BooleanSupplier; -import java.util.function.Consumer; - -import static java.util.Objects.nonNull; - -public class XaeroPlusBooleanSetting extends XaeroPlusSetting { - - private boolean value; - private Consumer settingChangeConsumer; - - private XaeroPlusBooleanSetting(final String settingName, - final String settingNameTranslationKey, - final String tooltipTranslationKey, - final KeyMapping keyBinding, - final boolean value, - final BooleanConsumer settingChangeConsumer, - final BooleanSupplier visibilitySupplier) { - super(settingName, settingNameTranslationKey, tooltipTranslationKey, keyBinding, visibilitySupplier); - this.value = value; - this.settingChangeConsumer = settingChangeConsumer; - } - - public static XaeroPlusBooleanSetting create(String settingName, - String settingNameTranslationKey, - String tooltipTranslationKey, - boolean defaultValue, - final SettingLocation settingLocation) { - final XaeroPlusBooleanSetting setting = new XaeroPlusBooleanSetting( - SETTING_PREFIX + settingName, - settingNameTranslationKey, - tooltipTranslationKey, new KeyMapping(settingNameTranslationKey, -1, "XaeroPlus"), defaultValue, - null, null - ); - settingLocation.getSettingsList().add(setting); - return setting; - } - - public static XaeroPlusBooleanSetting create(String settingName, - String settingNameTranslationKey, - String tooltipTranslationKey, - boolean defaultValue, - BooleanConsumer settingChangeConsumer, - final SettingLocation settingLocation) { - final XaeroPlusBooleanSetting setting = new XaeroPlusBooleanSetting( - SETTING_PREFIX + settingName, - settingNameTranslationKey, - tooltipTranslationKey, new KeyMapping(settingNameTranslationKey, -1, "XaeroPlus"), defaultValue, - settingChangeConsumer, null - ); - settingLocation.getSettingsList().add(setting); - return setting; - } - - public static XaeroPlusBooleanSetting create(String settingName, - String settingNameTranslationKey, - String tooltipTranslationKey, - boolean defaultValue, - BooleanSupplier visibilitySupplier, - final SettingLocation settingLocation) { - final XaeroPlusBooleanSetting setting = new XaeroPlusBooleanSetting( - SETTING_PREFIX + settingName, - settingNameTranslationKey, - tooltipTranslationKey, new KeyMapping(settingNameTranslationKey, -1, "XaeroPlus"), defaultValue, - null, visibilitySupplier - ); - settingLocation.getSettingsList().add(setting); - return setting; - } - - public static XaeroPlusBooleanSetting create(String settingName, - String settingNameTranslationKey, - String tooltipTranslationKey, - boolean defaultValue, - BooleanConsumer settingChangeConsumer, - BooleanSupplier visibilitySupplier, - final SettingLocation settingLocation) { - final XaeroPlusBooleanSetting setting = new XaeroPlusBooleanSetting( - SETTING_PREFIX + settingName, - settingNameTranslationKey, - tooltipTranslationKey, new KeyMapping(settingNameTranslationKey, -1, "XaeroPlus"), defaultValue, - settingChangeConsumer, visibilitySupplier - ); - settingLocation.getSettingsList().add(setting); - return setting; - } - - public boolean getValue() { - return value; - } - - public void setValue(final boolean value) { - this.value = value; - if (nonNull(getSettingChangeConsumer())) { - try { - getSettingChangeConsumer().accept(value); - } catch (final Exception e) { - XaeroPlus.LOGGER.warn("Error applying setting change consumer for {}", getSettingName(), e); - } - } - } - - public Consumer getSettingChangeConsumer() { - return settingChangeConsumer; - } - - public void setSettingChangeConsumer(final Consumer settingChangeConsumer) { - this.settingChangeConsumer = settingChangeConsumer; - } - - @Override - public void init() { - if (nonNull(settingChangeConsumer)) { - settingChangeConsumer.accept(value); - } - } - -} diff --git a/common/src/main/java/xaeroplus/settings/XaeroPlusEnumSetting.java b/common/src/main/java/xaeroplus/settings/XaeroPlusEnumSetting.java deleted file mode 100644 index 95577d64..00000000 --- a/common/src/main/java/xaeroplus/settings/XaeroPlusEnumSetting.java +++ /dev/null @@ -1,142 +0,0 @@ -package xaeroplus.settings; - -import net.minecraft.client.KeyMapping; -import org.apache.commons.lang3.ArrayUtils; -import xaeroplus.XaeroPlus; -import xaeroplus.settings.XaeroPlusSettingsReflectionHax.SettingLocation; - -import java.util.function.BooleanSupplier; -import java.util.function.Consumer; - -import static java.util.Objects.nonNull; - -public class XaeroPlusEnumSetting> extends XaeroPlusSetting { - private final T[] enumValues; - private T value; - private Consumer settingChangeConsumer; - - private XaeroPlusEnumSetting(final String settingName, - final String settingNameTranslationKey, - final String tooltipTranslationKey, - final KeyMapping keyBinding, - final T[] enumValues, - final T defaultValue, - final Consumer settingChangeConsumer, - final BooleanSupplier visibilitySupplier) { - super(settingName, settingNameTranslationKey, tooltipTranslationKey, keyBinding, visibilitySupplier); - this.enumValues = enumValues; - this.value = defaultValue; - this.settingChangeConsumer = settingChangeConsumer; - } - - public static > XaeroPlusEnumSetting create(String settingName, - String settingNameTranslationKey, - String tooltipTranslationKey, - E[] values, - E defaultValue, - final SettingLocation settingLocation) { - final XaeroPlusEnumSetting setting = new XaeroPlusEnumSetting<>(SETTING_PREFIX + settingName, - settingNameTranslationKey, - tooltipTranslationKey, - null, - values, defaultValue, null, null - ); - settingLocation.getSettingsList().add(setting); - return setting; - } - - public static > XaeroPlusEnumSetting create( - String settingName, - String settingNameTranslationKey, - String tooltipTranslationKey, - E[] values, - E defaultValue, - Consumer settingChangeConsumer, - final SettingLocation settingLocation) { - final XaeroPlusEnumSetting setting = new XaeroPlusEnumSetting<>( - SETTING_PREFIX + settingName, - settingNameTranslationKey, - tooltipTranslationKey, - null, - values, - defaultValue, - settingChangeConsumer, - null - ); - settingLocation.getSettingsList().add(setting); - return setting; - } - - public static > XaeroPlusEnumSetting create( - String settingName, - String settingNameTranslationKey, - String tooltipTranslationKey, - E[] values, - E defaultValue, - Consumer settingChangeConsumer, - BooleanSupplier visibilitySupplier, - final SettingLocation settingLocation) { - final XaeroPlusEnumSetting setting = new XaeroPlusEnumSetting<>( - SETTING_PREFIX + settingName, - settingNameTranslationKey, - tooltipTranslationKey, - null, - values, - defaultValue, - settingChangeConsumer, - visibilitySupplier - ); - settingLocation.getSettingsList().add(setting); - return setting; - } - - public T getValue() { - return value; - } - - public void setValue(T newVal) { - this.value = newVal; - if (nonNull(getSettingChangeConsumer())) { - try { - getSettingChangeConsumer().accept(newVal); - } catch (final Exception e) { - XaeroPlus.LOGGER.error("Error applying setting change consumer for setting: {}, value: {}", getSettingName(), newVal, e); - } - - } - } - - public int getValueIndex() { - return ArrayUtils.indexOf(enumValues, getValue()); - } - - public void setValueIndex(final int index) { - try { - setValue(enumValues[index]); - } catch (final Exception e) { - XaeroPlus.LOGGER.error("Unable to set enum value setting for {}, index {}", getSettingName(), index, e); - } - } - - public int getIndexMax() { - return enumValues.length-1; - } - - public void setSettingChangeConsumer(final Consumer settingChangeConsumer) { - this.settingChangeConsumer = settingChangeConsumer; - } - - public Consumer getSettingChangeConsumer() { - return settingChangeConsumer; - } - - public T[] getEnumValues() { - return enumValues; - } - @Override - public void init() { - if (nonNull(settingChangeConsumer)) { - settingChangeConsumer.accept(value); - } - } -} diff --git a/common/src/main/java/xaeroplus/settings/XaeroPlusFloatSetting.java b/common/src/main/java/xaeroplus/settings/XaeroPlusFloatSetting.java deleted file mode 100644 index 9a6ab99a..00000000 --- a/common/src/main/java/xaeroplus/settings/XaeroPlusFloatSetting.java +++ /dev/null @@ -1,138 +0,0 @@ -package xaeroplus.settings; - -import it.unimi.dsi.fastutil.floats.FloatConsumer; -import net.minecraft.client.KeyMapping; -import xaeroplus.XaeroPlus; -import xaeroplus.settings.XaeroPlusSettingsReflectionHax.SettingLocation; - -import java.util.function.BooleanSupplier; -import java.util.function.Consumer; - -import static java.util.Objects.nonNull; - -public class XaeroPlusFloatSetting extends XaeroPlusSetting { - private final float valueMin; - private final float valueMax; - private final float valueStep; - - private float value; - private FloatConsumer settingChangeConsumer; - - private XaeroPlusFloatSetting(final String settingName, - final String settingNameTranslationKey, - final String tooltipTranslationKey, - final KeyMapping keyBinding, - final float valueMin, - final float valueMax, - final float valueStep, - final float defaultValue, - final FloatConsumer settingChangeConsumer, - final BooleanSupplier visibilitySupplier) { - super(settingName, settingNameTranslationKey, tooltipTranslationKey, keyBinding, visibilitySupplier); - this.valueMin = valueMin; - this.valueMax = valueMax; - this.valueStep = valueStep; - this.value = defaultValue; - this.settingChangeConsumer = settingChangeConsumer; - } - - public static XaeroPlusFloatSetting create(String settingName, - String settingNameTranslationKey, - String tooltipTranslationKey, - float valueMin, - float valueMax, - float valueStep, - float defaultValue, - SettingLocation settingLocation) { - final XaeroPlusFloatSetting setting = new XaeroPlusFloatSetting( - SETTING_PREFIX + settingName, - settingNameTranslationKey, - tooltipTranslationKey, - null, - valueMin, valueMax, valueStep, defaultValue, null, null - ); - settingLocation.getSettingsList().add(setting); - return setting; - } - - public static XaeroPlusFloatSetting create(String settingName, - String settingNameTranslationKey, - String tooltipTranslationKey, - float valueMin, - float valueMax, - float valueStep, - float defaultValue, - FloatConsumer changeConsumer, - SettingLocation settingLocation) { - final XaeroPlusFloatSetting setting = new XaeroPlusFloatSetting( - SETTING_PREFIX + settingName, - settingNameTranslationKey, - tooltipTranslationKey, - null, - valueMin, valueMax, valueStep, defaultValue, changeConsumer, null - ); - settingLocation.getSettingsList().add(setting); - return setting; - } - - public static XaeroPlusFloatSetting create(String settingName, - String settingNameTranslationKey, - String tooltipTranslationKey, - float valueMin, - float valueMax, - float valueStep, - float defaultValue, - FloatConsumer changeConsumer, - BooleanSupplier visibilitySupplier, - SettingLocation settingLocation) { - final XaeroPlusFloatSetting setting = new XaeroPlusFloatSetting( - SETTING_PREFIX + settingName, - settingNameTranslationKey, - tooltipTranslationKey, - null, - valueMin, valueMax, valueStep, defaultValue, changeConsumer, visibilitySupplier - ); - settingLocation.getSettingsList().add(setting); - return setting; - } - - public float getValueMin() { - return valueMin; - } - - public float getValueMax() { - return valueMax; - } - - public float getValueStep() { - return valueStep; - } - - public float getValue() { - return value; - } - - public void setValue(final float value) { - this.value = value; - if (nonNull(getSettingChangeConsumer())) { - try { - getSettingChangeConsumer().accept(value); - } catch (final Exception e) { - XaeroPlus.LOGGER.warn("Error applying setting change consumer for {}", getSettingName(), e); - } - } - } - - public Consumer getSettingChangeConsumer() { - return settingChangeConsumer; - } - - public void setSettingChangeConsumer(final FloatConsumer settingChangeConsumer) { - this.settingChangeConsumer = settingChangeConsumer; - } - public void init() { - if (nonNull(settingChangeConsumer)) { - settingChangeConsumer.accept(value); - } - } -} diff --git a/common/src/main/java/xaeroplus/settings/XaeroPlusModSettingsHooks.java b/common/src/main/java/xaeroplus/settings/XaeroPlusModSettingsHooks.java deleted file mode 100644 index 1a87008d..00000000 --- a/common/src/main/java/xaeroplus/settings/XaeroPlusModSettingsHooks.java +++ /dev/null @@ -1,196 +0,0 @@ -package xaeroplus.settings; - -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import xaeroplus.Globals; -import xaeroplus.XaeroPlus; - -import java.io.*; -import java.nio.file.Files; -import java.nio.file.StandardCopyOption; -import java.util.List; -import java.util.Optional; - -public class XaeroPlusModSettingsHooks { - private static int loadCount = 0; - - public static void saveSettings() { - try { - saveXPSettings(); - } catch (final Exception e) { - XaeroPlus.LOGGER.error("Failed saving settings", e); - } - } - - public static synchronized void saveXPSettings() throws IOException { - File tempFile = new File(XaeroPlus.configFile.getAbsolutePath() + ".tmp"); - if (tempFile.exists()) tempFile.delete(); - try (PrintWriter writer = new PrintWriter(new FileWriter(tempFile, true))) { - XaeroPlusSettingsReflectionHax.ALL_SETTINGS.get().forEach(k -> { - writer.println(k.getSettingName() + ":" + - ((k instanceof XaeroPlusBooleanSetting) - ? ((XaeroPlusBooleanSetting) k).getValue() - : (k instanceof XaeroPlusFloatSetting) - ? ((XaeroPlusFloatSetting) k).getValue() - : (k instanceof XaeroPlusEnumSetting) - ? ((XaeroPlusEnumSetting) k).getValueIndex() - : "")); - }); - } - Files.move(tempFile.toPath(), XaeroPlus.configFile.toPath(), StandardCopyOption.REPLACE_EXISTING); - } - - public static void loadSettings(@Nullable File file, List settings) throws IOException { - loadCount++; - // load from XP config file - if (loadCount == 1) loadXPSettings(); - // load legacy XP settings from xaero config files - if (file != null) loadXPSettingsFromFile(file, settings); - // 1 for minimap, 1 for worldmap - // the reason we need to track load count is on Fabric, WorldMap or Minimap mods could load first - // but we have legacy settings that are stored in their config files - // xaero mods save their settings immediately after loading - // which would overwrite our legacy settings - if (loadCount == 2) Globals.onAllSettingsLoaded(); - } - - public static synchronized void loadXPSettings() { - try { - if (!XaeroPlus.configFile.exists()) return; - loadXPSettingsFromFile(XaeroPlus.configFile, XaeroPlusSettingsReflectionHax.ALL_SETTINGS.get()); - } catch (final Throwable e) { - XaeroPlus.LOGGER.error("Error loading XaeroPlus settings", e); - } - } - - public static synchronized void loadXPSettingsFromFile(File file, List settings) throws IOException { - try(BufferedReader reader = new BufferedReader(new FileReader(file))) { - String s; - while ((s = reader.readLine()) != null) { - String[] args = s.split(":"); - Optional settingOptional = settings.stream() - .filter(setting -> setting.getSettingName().equalsIgnoreCase(args[0])) - .findFirst(); - if (settingOptional.isPresent()) { - final XaeroPlusSetting setting = settingOptional.get(); - if (setting instanceof XaeroPlusBooleanSetting set) { - var value = Boolean.parseBoolean(args[1]); - if (value != set.getValue()) set.setValue(value); - set.setValue(Boolean.parseBoolean(args[1])); - } else if (setting instanceof XaeroPlusFloatSetting set) { - var value = Float.parseFloat(args[1]); - if (value != set.getValue()) set.setValue(value); - } else if (setting instanceof XaeroPlusEnumSetting set) { - var value = (int) Float.parseFloat(args[1]); - if (set.getValueIndex() != value) set.setValueIndex(value); - } - } - } - } - } - - - public static void getClientBooleanValue(String enumString, List settings, CallbackInfoReturnable cir) { - Optional settingOptional = settings.stream() - .filter(xaeroPlusSetting -> xaeroPlusSetting.getSettingName().equals(enumString) && xaeroPlusSetting instanceof XaeroPlusBooleanSetting) - .map(xaeroPlusSetting -> (XaeroPlusBooleanSetting) xaeroPlusSetting) - .findFirst(); - if (settingOptional.isPresent()) { - cir.setReturnValue(settingOptional.get().getValue()); - cir.cancel(); - } - } - - // boolean or enum... - public static void setOptionValue(String enumString, final Object value, List settings) { - Optional foundSetting = settings.stream() - .filter(xaeroPlusSetting -> xaeroPlusSetting.getSettingName().equals(enumString)) - .findFirst(); - foundSetting - .filter(xaeroPlusSetting -> xaeroPlusSetting instanceof XaeroPlusBooleanSetting && value instanceof Boolean) - .map(xaeroPlusSetting -> (XaeroPlusBooleanSetting) xaeroPlusSetting) - .ifPresent(xaeroPlusBooleanSetting -> { - xaeroPlusBooleanSetting.setValue((Boolean) value); - }); - foundSetting - .filter(xaeroPlusSetting -> xaeroPlusSetting instanceof XaeroPlusEnumSetting && value instanceof Integer && (Integer) value <= ((XaeroPlusEnumSetting) xaeroPlusSetting).getIndexMax() && (Integer) value >= 0) - .map(xaeroPlusSetting -> (XaeroPlusEnumSetting) xaeroPlusSetting) - .ifPresent(xaeroPlusEnumSetting -> { - xaeroPlusEnumSetting.setValueIndex((Integer) value); - }); - } - - // boolean or enum... - public static void getOptionValue(final String enumString, final CallbackInfoReturnable cir, final List settings) { - Optional foundSetting = settings.stream() - .filter(xaeroPlusSetting -> xaeroPlusSetting.getSettingName().equals(enumString)) - .findFirst(); - foundSetting - .filter(xaeroPlusSetting -> xaeroPlusSetting instanceof XaeroPlusBooleanSetting) - .map(xaeroPlusSetting -> (XaeroPlusBooleanSetting) xaeroPlusSetting) - .ifPresent(xaeroPlusBooleanSetting -> { - cir.setReturnValue(xaeroPlusBooleanSetting.getValue()); - }); - foundSetting - .filter(xaeroPlusSetting -> xaeroPlusSetting instanceof XaeroPlusEnumSetting) - .map(xaeroPlusSetting -> (XaeroPlusEnumSetting) xaeroPlusSetting) - .ifPresent(xaeroPlusEnumSetting -> { - cir.setReturnValue(xaeroPlusEnumSetting.getValueIndex()); - }); - } - - public static void setOptionDoubleValue(String enumString, double f, List settings) { - Optional foundSetting = settings.stream() - .filter(xaeroPlusSetting -> xaeroPlusSetting.getSettingName().equals(enumString)) - .findFirst(); - foundSetting - .filter(xaeroPlusSetting -> xaeroPlusSetting instanceof XaeroPlusFloatSetting) - .map(xaeroPlusSetting -> (XaeroPlusFloatSetting) xaeroPlusSetting) - .ifPresent(xaeroPlusSetting -> xaeroPlusSetting.setValue((float) f)); - } - - public static void getOptionDoubleValue(String enumString, CallbackInfoReturnable cir, List settings) { - Optional settingOptional = settings.stream() - .filter(xaeroPlusSetting -> xaeroPlusSetting.getSettingName().equals(enumString)) - .findFirst(); - settingOptional - .filter(xaeroPlusSetting -> xaeroPlusSetting instanceof XaeroPlusFloatSetting) - .map(xaeroPlusSetting -> (XaeroPlusFloatSetting) xaeroPlusSetting) - .ifPresent(xaeroPlusSetting -> { - cir.setReturnValue((double) xaeroPlusSetting.getValue()); - cir.cancel(); - }); - } - - public static void getOptionValueName(final String enumString, final CallbackInfoReturnable cir, final List settings) { - Optional settingOptional = settings.stream() - .filter(xaeroPlusSetting -> xaeroPlusSetting.getSettingName().equals(enumString)) - .findFirst(); - settingOptional - .filter(xaeroPlusSetting -> xaeroPlusSetting instanceof XaeroPlusEnumSetting) - .map(xaeroPlusSetting -> (XaeroPlusEnumSetting) xaeroPlusSetting) - .ifPresent(xaeroPlusEnumSetting -> { - cir.setReturnValue(xaeroPlusEnumSetting.getValue() instanceof TranslatableSettingEnum - ? ((TranslatableSettingEnum) xaeroPlusEnumSetting.getValue()).getTranslatedName() - : xaeroPlusEnumSetting.getValue().toString()); - }); - } - - public static void getSliderOptionText(final String enumString, final CallbackInfoReturnable cir, final List settings) { - settings.stream() - .filter(xaeroPlusSetting -> xaeroPlusSetting.getSettingName().equals(enumString)) - .findFirst() - .ifPresent(xaeroPlusSetting -> { - String s = xaeroPlusSetting.getTranslatedName() + ": "; - if (xaeroPlusSetting instanceof XaeroPlusFloatSetting) { - s += String.format("%.2f", ((XaeroPlusFloatSetting) xaeroPlusSetting).getValue()); - } else if (xaeroPlusSetting instanceof XaeroPlusEnumSetting) { - XaeroPlusEnumSetting xaeroPlusEnumSetting = (XaeroPlusEnumSetting) xaeroPlusSetting; - s += xaeroPlusEnumSetting.getValue() instanceof TranslatableSettingEnum - ? ((TranslatableSettingEnum) xaeroPlusEnumSetting.getValue()).getTranslatedName() - : xaeroPlusEnumSetting.getValue().toString(); - } - cir.setReturnValue(s); - }); - } -} diff --git a/common/src/main/java/xaeroplus/settings/XaeroPlusSetting.java b/common/src/main/java/xaeroplus/settings/XaeroPlusSetting.java index 4c19bf6b..6f69d3ad 100644 --- a/common/src/main/java/xaeroplus/settings/XaeroPlusSetting.java +++ b/common/src/main/java/xaeroplus/settings/XaeroPlusSetting.java @@ -29,9 +29,16 @@ public XaeroPlusSetting(String settingName, this.visibilitySupplier = visibilitySupplier; } - protected static String defaultValueStr(final String settingName, final Object defaultVal) { - return settingName + " \n Default: " + defaultVal + " \n "; - } + // Called after setting is loaded from file for the first time + public abstract void init(); + + public abstract String getSerializedValue(); + + public abstract void deserializeValue(String value); + + public abstract xaero.common.settings.ModOptions toMinimapModOptions(); + + public abstract xaero.map.settings.ModOptions toWorldMapModOptions(); public String getSettingName() { return settingName; @@ -49,18 +56,26 @@ public String getTooltipTranslationKey() { return tooltipTranslationKey; } + public static String buildTooltipTranslationKey(String baseKey) { + return baseKey + ".tooltip"; + } + public boolean isIngameOnly() { return ingameOnly; } + public boolean isRequiresMinimap() { return requiresMinimap; } + public KeyMapping getKeyBinding() { return keyBinding; } + public void setKeyBinding(KeyMapping keyBinding) { this.keyBinding = keyBinding; } + public boolean isVisible() { if (visibilitySupplier != null) { return visibilitySupplier.getAsBoolean(); @@ -68,5 +83,12 @@ public boolean isVisible() { return true; } } - public abstract void init(); + + public xaero.common.gui.ConfigSettingEntry toMinimapConfigSettingEntry() { + return new xaero.common.gui.ConfigSettingEntry(toMinimapModOptions()); + } + + public xaero.map.gui.ConfigSettingEntry toWorldmapConfigSettingEntry() { + return new xaero.map.gui.ConfigSettingEntry(toWorldMapModOptions()); + } } diff --git a/common/src/main/java/xaeroplus/settings/XaeroPlusSettingRegistry.java b/common/src/main/java/xaeroplus/settings/XaeroPlusSettingRegistry.java deleted file mode 100644 index 1fe32edc..00000000 --- a/common/src/main/java/xaeroplus/settings/XaeroPlusSettingRegistry.java +++ /dev/null @@ -1,700 +0,0 @@ -package xaeroplus.settings; - -import xaeroplus.Globals; -import xaeroplus.module.ModuleManager; -import xaeroplus.module.impl.*; -import xaeroplus.settings.XaeroPlusSettingsReflectionHax.SettingLocation; -import xaeroplus.util.BaritoneHelper; -import xaeroplus.util.ColorHelper; -import xaeroplus.util.ColorHelper.WaystoneColor; -import xaeroplus.util.WaystonesHelper; -import xaeroplus.util.WorldToolsHelper; - -import java.io.ByteArrayOutputStream; - -import static net.minecraft.world.level.Level.*; -import static xaeroplus.settings.XaeroPlusSettingsReflectionHax.markChunksDirtyInWriteDistance; - -/** - * Registry for XaeroPlus-specific settings - */ -public final class XaeroPlusSettingRegistry { - /** - * The order settings are defined here determines the order in the settings GUI's. - */ - public static final XaeroPlusBooleanSetting minimapFpsLimiter = XaeroPlusBooleanSetting.create( - "Minimap FPS Limiter", - "setting.minimap.fps_limiter", - "setting.minimap.fps_limiter.tooltip", - false, - (b) -> ModuleManager.getModule(FpsLimiter.class).setEnabled(b), - SettingLocation.MINIMAP_MAIN); - public static final XaeroPlusFloatSetting minimapFpsLimit = XaeroPlusFloatSetting.create( - "Minimap FPS Limit", - "setting.minimap.fps_limiter_limit", - "setting.minimap.fps_limiter_limit.tooltip", - 5f, 120f, 5f, - 60f, - SettingLocation.MINIMAP_MAIN); - public static final XaeroPlusBooleanSetting fastMapSetting = XaeroPlusBooleanSetting.create( - "Fast Mapping", - "setting.world_map.fast_mapping", - "setting.world_map.fast_mapping.tooltip", - false, - SettingLocation.WORLD_MAP_MAIN); - public static final XaeroPlusFloatSetting fastMapWriterDelaySetting = XaeroPlusFloatSetting.create( - "Fast Mapping Delay", - "setting.world_map.fast_mapping_delay", - "setting.world_map.fast_mapping_delay.tooltip", - 10, 1000, 10, - 250, - SettingLocation.WORLD_MAP_MAIN); - public static final XaeroPlusFloatSetting fastMapMaxTilesPerCycle = XaeroPlusFloatSetting.create( - "Fast Mapping Rate Limit", - "setting.world_map.fast_mapping_rate_limit", - "setting.world_map.fast_mapping_rate_limit.tooltip", - 10, 120, 10, - 25, - SettingLocation.WORLD_MAP_MAIN); - public static final XaeroPlusBooleanSetting fastZipWrite = XaeroPlusBooleanSetting.create( - "Fast Zip Writes", - "setting.world_map.fast_zip_writes", - "setting.world_map.fast_zip_writes.tooltip", - true, - (b) -> { - if (!b) Globals.zipFastByteBuffer = new ByteArrayOutputStream(); // release any existing sized buffer to gc - }, - SettingLocation.WORLD_MAP_MAIN); - public static final XaeroPlusBooleanSetting writesWhileDimSwitched = XaeroPlusBooleanSetting.create( - "Region Writes While Dim Switched", - "setting.world_map.region_write_while_dimension_switched", - "setting.world_map.region_write_while_dimension_switched.tooltip", - false, - SettingLocation.WORLD_MAP_MAIN); - public static final XaeroPlusBooleanSetting baritoneWaypointSyncSetting = XaeroPlusBooleanSetting.create( - "Baritone Goal Waypoint", - "setting.world_map.baritone_waypoint", - "setting.world_map.baritone_waypoint.tooltip", - true, - (b) -> { - if (BaritoneHelper.isBaritonePresent()) ModuleManager.getModule(BaritoneGoalSync.class).setEnabled(b); - }, - BaritoneHelper::isBaritonePresent, - SettingLocation.WORLD_MAP_MAIN); - public static final XaeroPlusBooleanSetting waystonesWaypointSyncSetting = XaeroPlusBooleanSetting.create( - "Waystones Sync", - "setting.world_map.waystones_sync", - "setting.world_map.waystones_sync.tooltip", - true, - (b) -> { - if (WaystonesHelper.isAnyWaystonesPresent()) ModuleManager.getModule(WaystoneSync.class).setEnabled(b); - }, - WaystonesHelper::isAnyWaystonesPresent, - SettingLocation.WORLD_MAP_MAIN); - public static final XaeroPlusEnumSetting waystoneColorSetting = XaeroPlusEnumSetting.create( - "Waystone Color", - "setting.world_map.waystone_color", - "setting.world_map.waystone_color.tooltip", - WaystoneColor.values(), - WaystoneColor.RANDOM, - (b) -> { - if (WaystonesHelper.isAnyWaystonesPresent()) ModuleManager.getModule(WaystoneSync.class).setColor(b); - }, - WaystonesHelper::isAnyWaystonesPresent, - SettingLocation.WORLD_MAP_MAIN); - public static final XaeroPlusBooleanSetting waystoneWaypointSetSetting = XaeroPlusBooleanSetting.create( - "Waystone Waypoint Set", - "setting.world_map.waystone_waypoint_set", - "setting.world_map.waystone_waypoint_set.tooltip", - false, - (b) -> { - if (WaystonesHelper.isAnyWaystonesPresent()) ModuleManager.getModule(WaystoneSync.class).setWaypointSet(b); - }, - WaystonesHelper::isAnyWaystonesPresent, - SettingLocation.WORLD_MAP_MAIN); - public static final XaeroPlusEnumSetting waystoneWaypointVisibilityModeSetting = XaeroPlusEnumSetting.create( - "Waystone WP Visibility Type", - "setting.world_map.waystone_visibility_type", - "setting.world_map.waystone_visibility_type.tooltip", - WaystoneWpVisibilityType.values(), - WaystoneWpVisibilityType.LOCAL, - (mode) -> { - if (WaystonesHelper.isAnyWaystonesPresent()) ModuleManager.getModule(WaystoneSync.class).setVisibilityType(mode.ordinal()); - }, - WaystonesHelper::isAnyWaystonesPresent, - SettingLocation.WORLD_MAP_MAIN); - public enum WaystoneWpVisibilityType implements TranslatableSettingEnum { - // order here must mirror xaero's visibility enum - LOCAL("gui.xaeroplus.waystone_visibility_type.local"), - GLOBAL("gui.xaeroplus.waystone_visibility_type.global"), - WORLD_MAP_LOCAL("gui.xaeroplus.waystone_visibility_type.world_map_local"), - WORLD_MAP_GLOBAL("gui.xaeroplus.waystone_visibility_type.world_map_global"); - private final String translationKey; - WaystoneWpVisibilityType(final String translationKey) { - this.translationKey = translationKey; - } - @Override - public String getTranslationKey() { - return translationKey; - } - } - public static final XaeroPlusBooleanSetting persistMapDimensionSwitchSetting = XaeroPlusBooleanSetting.create( - "Persist Dim Switch", - "setting.world_map.persist_dimension_switch", - "setting.world_map.persist_dimension_switch.tooltip", - true, - SettingLocation.WORLD_MAP_MAIN); - public static final XaeroPlusBooleanSetting radarWhileDimensionSwitchedSetting = XaeroPlusBooleanSetting.create( - "Radar While Dim Switched", - "setting.world_map.radar_while_dimension_switched", - "setting.world_map.radar_while_dimension_switched.tooltip", - true, - SettingLocation.WORLD_MAP_MAIN); - public static final XaeroPlusBooleanSetting transparentObsidianRoofSetting = XaeroPlusBooleanSetting.create( - "Transparent Obsidian Roof", - "setting.world_map.transparent_obsidian_roof", - "setting.world_map.transparent_obsidian_roof.tooltip", - false, - (v) -> markChunksDirtyInWriteDistance(), - SettingLocation.WORLD_MAP_MAIN); - public static final XaeroPlusFloatSetting transparentObsidianRoofYSetting = XaeroPlusFloatSetting.create( - "Roof Y Level", - "setting.world_map.transparent_obsidian_roof_y", - "Sets the starting Y level of the roof", - 0, 320, 1, - 250, - (v) -> markChunksDirtyInWriteDistance(), - SettingLocation.WORLD_MAP_MAIN); - public static final XaeroPlusFloatSetting transparentObsidianRoofDarkeningSetting = XaeroPlusFloatSetting.create( - "Roof Obsidian Opacity", - "setting.world_map.transparent_obsidian_roof_darkening", - "setting.world_map.transparent_obsidian_roof_darkening.tooltip", - 0, 255, 5, - 150, - (v) -> markChunksDirtyInWriteDistance(), - SettingLocation.WORLD_MAP_MAIN); - public static final XaeroPlusFloatSetting transparentObsidianRoofSnowOpacitySetting = XaeroPlusFloatSetting.create( - "Roof Snow Opacity", - "setting.world_map.transparent_obsidian_roof_snow_opacity", - "setting.world_map.transparent_obsidian_roof_snow_opacity.tooltip", - 0, 255, 5, - 10, - (v) -> markChunksDirtyInWriteDistance(), - SettingLocation.WORLD_MAP_MAIN); - public static final XaeroPlusBooleanSetting overlayOpacityFix = XaeroPlusBooleanSetting.create( - "Overlay Opacity Fix", - "setting.world_map.overlay_opacity_fix", - "setting.world_map.overlay_opacity_fix.tooltip", - true, - SettingLocation.WORLD_MAP_MAIN); - public static final XaeroPlusFloatSetting worldMapMinZoomSetting = XaeroPlusFloatSetting.create( - "Min WorldMap Zoom", - "setting.world_map.min_zoom", - "setting.world_map.min_zoom.tooltip", - 0, 0.625f, 0.01f, - 0.1f, - SettingLocation.WORLD_MAP_MAIN); - public static final XaeroPlusBooleanSetting crossDimensionCursorCoordinates = XaeroPlusBooleanSetting.create( - "Cross Dim Cursor Coords", - "setting.world_map.cross_dimension_cursor_coordinates", - "setting.world_map.cross_dimension_cursor_coordinates.tooltip", - false, - SettingLocation.WORLD_MAP_MAIN); - public static final XaeroPlusBooleanSetting paletteNewChunksEnabledSetting = XaeroPlusBooleanSetting.create( - "Palette NewChunks", - "setting.world_map.palette_new_chunks_highlighting", - "setting.world_map.palette_new_chunks_highlighting.tooltip", - false, - (b) -> ModuleManager.getModule(PaletteNewChunks.class).setEnabled(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusBooleanSetting paletteNewChunksSaveLoadToDisk = XaeroPlusBooleanSetting.create( - "Save/Load Palette NewChunks to Disk", - "setting.world_map.palette_new_chunks_save_load_to_disk", - "setting.world_map.palette_new_chunks_save_load_to_disk.tooltip", - true, - (b) -> ModuleManager.getModule(PaletteNewChunks.class).setDiskCache(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusFloatSetting paletteNewChunksAlphaSetting = XaeroPlusFloatSetting.create( - "Palette NewChunks Opacity", - "setting.world_map.palette_new_chunks_opacity", - "setting.world_map.palette_new_chunks_opacity.tooltip", - 0f, 255f, 10f, - 100, - (b) -> ModuleManager.getModule(PaletteNewChunks.class).setAlpha(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusEnumSetting paletteNewChunksColorSetting = XaeroPlusEnumSetting.create( - "Palette NewChunks Color", - "setting.world_map.palette_new_chunks_color", - "setting.world_map.palette_new_chunks_color.tooltip", - ColorHelper.HighlightColor.values(), - ColorHelper.HighlightColor.RED, - (b) -> ModuleManager.getModule(PaletteNewChunks.class).setRgbColor(b.getColor()), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusBooleanSetting paletteNewChunksRenderInverse = XaeroPlusBooleanSetting.create( - "Palette NewChunks Inverse", - "setting.world_map.palette_new_chunks_inverse", - "setting.world_map.palette_new_chunks_inverse.tooltip", - false, - (b) -> ModuleManager.getModule(PaletteNewChunks.class).setInverse(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusBooleanSetting oldChunksEnabledSetting = XaeroPlusBooleanSetting.create( - "OldChunks Highlighting", - "setting.world_map.old_chunks_highlighting", - "setting.world_map.old_chunks_highlighting.tooltip", - false, - (b) -> ModuleManager.getModule(OldChunks.class).setEnabled(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusBooleanSetting oldChunksInverse = XaeroPlusBooleanSetting.create( - "OldChunks Inverse", - "setting.world_map.old_chunks_inverse", - "setting.world_map.old_chunks_inverse.tooltip", - false, - (b) -> ModuleManager.getModule(OldChunks.class).setInverse(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusBooleanSetting oldChunksSaveLoadToDisk = XaeroPlusBooleanSetting.create( - "Save/Load OldChunks to Disk", - "setting.world_map.old_chunks_save_load_to_disk", - "setting.world_map.old_chunks_save_load_to_disk.tooltip", - true, - (b) -> ModuleManager.getModule(OldChunks.class).setDiskCache(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusFloatSetting oldChunksAlphaSetting = XaeroPlusFloatSetting.create( - "Old Chunks Opacity", - "setting.world_map.old_chunks_opacity", - "setting.world_map.old_chunks_opacity.tooltip", - 0f, 255f, 10f, - 100, - (b) -> ModuleManager.getModule(OldChunks.class).setAlpha(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusEnumSetting oldChunksColorSetting = XaeroPlusEnumSetting.create( - "Old Chunks Color", - "setting.world_map.old_chunks_color", - "setting.world_map.old_chunks_color.tooltip", - ColorHelper.HighlightColor.values(), - ColorHelper.HighlightColor.YELLOW, - (b) -> ModuleManager.getModule(OldChunks.class).setRgbColor(b.getColor()), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusBooleanSetting portalsEnabledSetting = XaeroPlusBooleanSetting.create( - "Portal Highlights", - "setting.world_map.portals", - "setting.world_map.portals.tooltip", - false, - (b) -> ModuleManager.getModule(Portals.class).setEnabled(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusBooleanSetting portalsSaveLoadToDisk = XaeroPlusBooleanSetting.create( - "Save/Load Portals to Disk", - "setting.world_map.portals_save_load_to_disk", - "setting.world_map.portals_save_load_to_disk.tooltip", - true, - (b) -> ModuleManager.getModule(Portals.class).setDiskCache(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusFloatSetting portalsAlphaSetting = XaeroPlusFloatSetting.create( - "Portal Highlights Opacity", - "setting.world_map.portals_opacity", - "setting.world_map.portals_opacity.tooltip", - 0f, 255f, 10f, - 100, - (b) -> ModuleManager.getModule(Portals.class).setAlpha(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusEnumSetting portalsColorSetting = XaeroPlusEnumSetting.create( - "Portal Highlights Color", - "setting.world_map.portals_color", - "setting.world_map.portals_color.tooltip", - ColorHelper.HighlightColor.values(), - ColorHelper.HighlightColor.MAGENTA, - (b) -> ModuleManager.getModule(Portals.class).setRgbColor(b.getColor()), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusBooleanSetting oldBiomesSetting = XaeroPlusBooleanSetting.create( - "Old Biomes", - "setting.world_map.old_biomes_enabled", - "setting.world_map.old_biomes_enabled.tooltip", - false, - (b) -> ModuleManager.getModule(OldBiomes.class).setEnabled(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusBooleanSetting oldBiomesSaveToDiskSetting = XaeroPlusBooleanSetting.create( - "Save/Load OldBiomes To Disk", - "setting.world_map.old_biomes_save_load_to_disk", - "setting.world_map.old_biomes_save_load_to_disk.tooltip", - true, - (b) -> ModuleManager.getModule(OldBiomes.class).setDiskCache(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusFloatSetting oldBiomesAlphaSetting = XaeroPlusFloatSetting.create( - "OldBiomes Opacity", - "setting.world_map.old_biomes_opacity", - "setting.world_map.old_biomes_opacity.tooltip", - 0f, 255f, 10f, - 100, - (b) -> ModuleManager.getModule(OldBiomes.class).setAlpha(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusEnumSetting oldBiomesColorSetting = XaeroPlusEnumSetting.create( - "OldBiomes Color", - "setting.world_map.old_biomes_color", - "setting.world_map.old_biomes_color.tooltip", - ColorHelper.HighlightColor.values(), - ColorHelper.HighlightColor.GREEN, - (b) -> ModuleManager.getModule(OldBiomes.class).setRgbColor(b.getColor()), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusBooleanSetting liquidNewChunksEnabledSetting = XaeroPlusBooleanSetting.create( - "NewChunks Highlighting", - "setting.world_map.new_chunks_highlighting", - "setting.world_map.new_chunks_highlighting.tooltip", - false, - (b) -> ModuleManager.getModule(LiquidNewChunks.class).setEnabled(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusBooleanSetting liquidNewChunksSaveLoadToDisk = XaeroPlusBooleanSetting.create( - "Save/Load NewChunks to Disk", - "setting.world_map.new_chunks_save_load_to_disk", - "setting.world_map.new_chunks_save_load_to_disk.tooltip", - true, - (b) -> ModuleManager.getModule(LiquidNewChunks.class).setDiskCache(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusFloatSetting liquidNewChunksAlphaSetting = XaeroPlusFloatSetting.create( - "New Chunks Opacity", - "setting.world_map.new_chunks_opacity", - "setting.world_map.new_chunks_opacity.tooltip", - 0f, 255f, 10f, - 100, - (b) -> ModuleManager.getModule(LiquidNewChunks.class).setAlpha(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusEnumSetting liquidNewChunksColorSetting = XaeroPlusEnumSetting.create( - "New Chunks Color", - "setting.world_map.new_chunks_color", - "setting.world_map.new_chunks_color.tooltip", - ColorHelper.HighlightColor.values(), - ColorHelper.HighlightColor.RED, - (b) -> ModuleManager.getModule(LiquidNewChunks.class).setRgbColor(b.getColor()), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusBooleanSetting liquidNewChunksInverseHighlightsSetting = XaeroPlusBooleanSetting.create( - "New Chunks Render Inverse", - "setting.world_map.new_chunks_inverse_enabled", - "setting.world_map.new_chunks_inverse_enabled.tooltip", - false, - (b) -> ModuleManager.getModule(LiquidNewChunks.class).setInverseRenderEnabled(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusEnumSetting liquidNewChunksInverseColorSetting = XaeroPlusEnumSetting.create( - "New Chunks Inverse Color", - "setting.world_map.new_chunks_inverse_color", - "setting.world_map.new_chunks_inverse_color.tooltip", - ColorHelper.HighlightColor.values(), - ColorHelper.HighlightColor.GREEN, - (b) -> ModuleManager.getModule(LiquidNewChunks.class).setInverseRgbColor(b.getColor()), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusBooleanSetting liquidNewChunksOnlyAboveY0Setting = XaeroPlusBooleanSetting.create( - "Liquid NewChunks Only Y > 0", - "setting.world_map.new_chunks_only_above_y0", - "setting.world_map.new_chunks_only_above_y0.tooltip", - false, - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusBooleanSetting worldToolsEnabledSetting = XaeroPlusBooleanSetting.create( - "WorldTools Highlights", - "setting.world_map.world_tools", - "setting.world_map.world_tools.tooltip", - true, - (b) -> ModuleManager.getModule(WorldTools.class).setEnabled(b), - WorldToolsHelper::isWorldToolsPresent, - SettingLocation.CHUNK_HIGHLIGHTS); - public static XaeroPlusFloatSetting worldToolsAlphaSetting = XaeroPlusFloatSetting.create( - "WorldTools Highlights Opacity", - "setting.world_map.world_tools_opacity", - "setting.world_map.world_tools_opacity.tooltip", - 0f, 255f, 10f, - 100, - (b) -> ModuleManager.getModule(WorldTools.class).setAlpha(b), - WorldToolsHelper::isWorldToolsPresent, - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusEnumSetting worldToolsColorSetting = XaeroPlusEnumSetting.create( - "WorldTools Highlights Color", - "setting.world_map.world_tools_color", - "setting.world_map.world_tools_color.tooltip", - ColorHelper.HighlightColor.values(), - ColorHelper.HighlightColor.GREEN, - (b) -> ModuleManager.getModule(WorldTools.class).setRgbColor(b.getColor()), - WorldToolsHelper::isWorldToolsPresent, - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusBooleanSetting portalSkipDetectionEnabledSetting = XaeroPlusBooleanSetting.create( - "PortalSkip Detection", - "setting.world_map.portal_skip_detection", - "setting.world_map.portal_skip_detection.tooltip", - false, - (b) -> ModuleManager.getModule(PortalSkipDetection.class).setEnabled(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusFloatSetting portalSkipDetectionAlphaSetting = XaeroPlusFloatSetting.create( - "PortalSkip Opacity", - "setting.world_map.portal_skip_opacity", - "setting.world_map.portal_skip_opacity.tooltip", - 0f, 255f, 10f, - 100, - (b) -> ModuleManager.getModule(PortalSkipDetection.class).setAlpha(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusEnumSetting portalSkipDetectionColorSetting = XaeroPlusEnumSetting.create( - "PortalSkip Color", - "setting.world_map.portal_skip_color", - "setting.world_map.portal_skip_color.tooltip", - ColorHelper.HighlightColor.values(), - ColorHelper.HighlightColor.WHITE, - (b) -> ModuleManager.getModule(PortalSkipDetection.class).setRgbColor(b.getColor()), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusFloatSetting portalSkipPortalRadius = XaeroPlusFloatSetting.create( - "PortalSkip Portal Radius", - "setting.world_map.portal_skip_portal_radius", - "setting.world_map.portal_skip_portal_radius.tooltip", - 0, 32, 1, - 15, - (b) -> ModuleManager.getModule(PortalSkipDetection.class).setPortalRadius(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusFloatSetting portalSkipDetectionSearchDelayTicksSetting = XaeroPlusFloatSetting.create( - "PortalSkip Search Delay", - "setting.world_map.portal_skip_search_delay", - "setting.world_map.portal_skip_search_delay.tooltip", - 0, 100, 1, - 10, - (b) -> ModuleManager.getModule(PortalSkipDetection.class).setSearchDelayTicks(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusBooleanSetting portalSkipNewChunksSetting = XaeroPlusBooleanSetting.create( - "PortalSkip NewChunks", - "setting.world_map.portal_skip_new_chunks", - "setting.world_map.portal_skip_new_chunks.tooltip", - true, - (b) -> ModuleManager.getModule(PortalSkipDetection.class).setNewChunks(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusBooleanSetting portalSkipOldChunkInverseSetting = XaeroPlusBooleanSetting.create( - "PortalSkip OldChunks Inverse", - "setting.world_map.portal_skip_old_chunks_inverse", - "setting.world_map.portal_skip_old_chunks_inverse.tooltip", - true, - (b) -> ModuleManager.getModule(PortalSkipDetection.class).setOldChunksInverse(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusBooleanSetting highwayHighlightsSetting = XaeroPlusBooleanSetting.create( - "2b2t Highways", - "setting.world_map.2b2t_highways_enabled", - "setting.world_map.2b2t_highways_enabled.tooltip", - false, - (b) -> ModuleManager.getModule(Highways.class).setEnabled(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusEnumSetting highwaysColorSetting = XaeroPlusEnumSetting.create( - "2b2t Highways Color", - "setting.world_map.2b2t_highways_color", - "setting.world_map.2b2t_highways_color.tooltip", - ColorHelper.HighlightColor.values(), - ColorHelper.HighlightColor.BLUE, - (b) -> ModuleManager.getModule(Highways.class).setRgbColor(b.getColor()), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusFloatSetting highwaysColorAlphaSetting = XaeroPlusFloatSetting.create( - "2b2t Highways Opacity", - "setting.world_map.2b2t_highways_opacity", - "setting.world_map.2b2t_highways_opacity.tooltip", - 0f, 255f, 10f, - 100, - (b) -> ModuleManager.getModule(Highways.class).setAlpha(b), - SettingLocation.CHUNK_HIGHLIGHTS); - public static final XaeroPlusBooleanSetting owAutoWaypointDimension = XaeroPlusBooleanSetting.create( - "Prefer Overworld Waypoints", - "setting.world_map.ow_auto_waypoint_dimension", - "setting.world_map.ow_auto_waypoint_dimension.tooltip", - false, - SettingLocation.WORLD_MAP_MAIN); - public static final XaeroPlusBooleanSetting showWaypointDistances = XaeroPlusBooleanSetting.create( - "Show Waypoint Distances", - "setting.world_map.show_waypoint_distances", - "setting.world_map.show_waypoint_distances.tooltip", - true, - SettingLocation.WORLD_MAP_MAIN); - public static final XaeroPlusBooleanSetting showRenderDistanceSetting = XaeroPlusBooleanSetting.create( - "Show Render Distance", - "setting.world_map.show_render_distance", - "setting.world_map.show_render_distance.tooltip", - false, - SettingLocation.MINIMAP_OVERLAYS); - public static final XaeroPlusBooleanSetting showRenderDistanceWorldMapSetting = XaeroPlusBooleanSetting.create( - "Show Render Distance WorldMap", - "setting.world_map.show_render_distance_world_map", - "setting.world_map.show_render_distance_world_map.tooltip", - false, - SettingLocation.MINIMAP_OVERLAYS); - public static final XaeroPlusBooleanSetting nullOverworldDimensionFolder = XaeroPlusBooleanSetting.create( - "null OW Dim Dir", - "setting.world_map.null_overworld_dimension_folder", - "setting.world_map.null_overworld_dimension_folder.tooltip", - true, - Globals::setNullOverworldDimFolderIfAble, - SettingLocation.WORLD_MAP_MAIN); - public static final XaeroPlusEnumSetting dataFolderResolutionMode = XaeroPlusEnumSetting.create( - "Data Dir Mode", - "setting.world_map.data_folder_resolution_mode", - "setting.world_map.data_folder_resolution_mode.tooltip", - DataFolderResolutionMode.values(), - DataFolderResolutionMode.IP, - Globals::setDataFolderResolutionModeIfAble, - SettingLocation.WORLD_MAP_MAIN); - - public enum DataFolderResolutionMode implements TranslatableSettingEnum { - IP("setting.world_map.data_folder_resolution_mode.ip"), - SERVER_NAME("setting.world_map.data_folder_resolution_mode.server_name"), - BASE_DOMAIN("setting.world_map.data_folder_resolution_mode.base_domain"); - - private final String translationKey; - - DataFolderResolutionMode(final String translationKey) { - this.translationKey = translationKey; - } - - @Override - public String getTranslationKey() { - return translationKey; - } - } - - public static final XaeroPlusBooleanSetting transparentMinimapBackground = XaeroPlusBooleanSetting.create( - "Transparent Background", - "setting.minimap.transparent_background", - "setting.minimap.transparent_background.tooltip", - false, - SettingLocation.MINIMAP_VIEW); - public static final XaeroPlusFloatSetting minimapScaleMultiplierSetting = XaeroPlusFloatSetting.create( - "Minimap Scaling Factor", - "setting.minimap.minimap_scaling", - "setting.minimap.minimap_scaling.tooltip", - 1f, 5f, 1f, - 1f, - (b) -> Globals.shouldResetFBO = true, - SettingLocation.MINIMAP_VIEW); - public static final XaeroPlusFloatSetting minimapSizeMultiplierSetting = XaeroPlusFloatSetting.create( - "Minimap Size Multiplier", - "setting.minimap_size_multiplier", - "setting.minimap_size_multiplier.tooltip", - 1f, 4f, 1f, - 1f, - (b) -> Globals.shouldResetFBO = true, - SettingLocation.MINIMAP_VIEW); - public static final XaeroPlusBooleanSetting switchToNetherSetting = XaeroPlusBooleanSetting.create( - "Switch to Nether", - "setting.keybinds.switch_to_nether", - "setting.keybinds.switch_to_nether.tooltip", - false, - (b) -> Globals.switchToDimension(NETHER), - SettingLocation.KEYBINDS); - public static final XaeroPlusBooleanSetting switchToOverworldSetting = XaeroPlusBooleanSetting.create( - "Switch to Overworld", - "setting.keybinds.switch_to_overworld", - "setting.keybinds.switch_to_overworld.tooltip", - false, - (b) -> Globals.switchToDimension(OVERWORLD), - SettingLocation.KEYBINDS); - public static final XaeroPlusBooleanSetting switchToEndSetting = XaeroPlusBooleanSetting.create( - "Switch to End", - "setting.keybinds.switch_to_end", - "setting.keybinds.switch_to_end.tooltip", - false, - (b) -> Globals.switchToDimension(END), - SettingLocation.KEYBINDS); - public static final XaeroPlusBooleanSetting worldMapBaritoneGoalHereKeybindSetting = XaeroPlusBooleanSetting.create( - "WorldMap Baritone Goal Here", - "setting.keybinds.world_map_baritone_goal_here", - "setting.keybinds.world_map_baritone_goal_here.tooltip", - false, - SettingLocation.KEYBINDS); - public static final XaeroPlusBooleanSetting worldMapBaritonePathHereKeybindSetting = XaeroPlusBooleanSetting.create( - "WorldMap Baritone Path Here", - "setting.keybinds.world_map_baritone_path_here", - "setting.keybinds.world_map_baritone_path_here.tooltip", - false, - SettingLocation.KEYBINDS); - public static final XaeroPlusBooleanSetting worldMapBaritoneElytraHereKeybindSetting = XaeroPlusBooleanSetting.create( - "WorldMap Baritone Elytra Here", - "setting.keybinds.world_map_baritone_elytra_here", - "setting.keybinds.world_map_baritone_elytra_here.tooltip", - false, - SettingLocation.KEYBINDS); - public static final XaeroPlusBooleanSetting netherCaveFix = XaeroPlusBooleanSetting.create( - "Nether Cave Fix", - "setting.world_map.nether_cave_fix", - "setting.world_map.nether_cave_fix.tooltip", - true, - SettingLocation.WORLD_MAP_MAIN); - public static final XaeroPlusBooleanSetting alwaysRenderPlayerWithNameOnRadar = XaeroPlusBooleanSetting.create( - "Always Render Player Name", - "setting.minimap.always_render_player_name", - "setting.minimap.always_render_player_name.tooltip", - true, - SettingLocation.MINIMAP_ENTITY_RADAR); - public static final XaeroPlusBooleanSetting alwaysRenderPlayerIconOnRadar = XaeroPlusBooleanSetting.create( - "Always Render Player Icon", - "setting.minimap.always_render_player_icon", - "setting.minimap.always_render_player_icon.tooltip", - true, - SettingLocation.MINIMAP_ENTITY_RADAR); - public static final XaeroPlusBooleanSetting fixMainEntityDot = XaeroPlusBooleanSetting.create( - "Fix Main Entity Dot", - "setting.minimap.fix_main_entity_dot", - "setting.minimap.fix_main_entity_dot.tooltip", - true, - SettingLocation.MINIMAP_ENTITY_RADAR); - public static final XaeroPlusBooleanSetting waypointBeacons = XaeroPlusBooleanSetting.create( - "Waypoint Beacons", - "setting.waypoints.waypoint_beacons", - "setting.waypoints.waypoint_beacons.tooltip", - false, - SettingLocation.MINIMAP_WAYPOINTS); - public static final XaeroPlusFloatSetting waypointBeaconScaleMin = XaeroPlusFloatSetting.create( - "Waypoint Beacon Scale Min", - "setting.waypoints.waypoint_beacon_scale_min", - "setting.waypoints.waypoint_beacon_scale_min.tooltip", - 0f, 30f, 1f, - 0f, - SettingLocation.MINIMAP_WAYPOINTS); - public static final XaeroPlusFloatSetting waypointBeaconDistanceMin = XaeroPlusFloatSetting.create( - "Waypoint Beacon Distance Min", - "setting.waypoints.waypoint_beacon_distance_min", - "setting.waypoints.waypoint_beacon_distance_min.tooltip", - 0f, 512f, 8f, - 0f, - SettingLocation.MINIMAP_WAYPOINTS); - public static final XaeroPlusBooleanSetting waypointEta = XaeroPlusBooleanSetting.create( - "Waypoint ETA", - "setting.waypoints.waypoint_eta", - "setting.waypoints.waypoint_eta.tooltip", - false, - SettingLocation.MINIMAP_WAYPOINTS); - public static final XaeroPlusBooleanSetting disableWaypointSharing = XaeroPlusBooleanSetting.create( - "Disable Waypoint Sharing", - "setting.world_map.disable_waypoint_sharing", - "setting.world_map.disable_waypoint_sharing.tooltip", - false, - SettingLocation.MINIMAP_WAYPOINTS); - public static final XaeroPlusBooleanSetting plainWaypointSharing = XaeroPlusBooleanSetting.create( - "Plain Waypoint Sharing", - "setting.world_map.plain_waypoint_sharing", - "setting.world_map.plain_waypoint_sharing.tooltip", - false, - SettingLocation.MINIMAP_WAYPOINTS); - public static final XaeroPlusBooleanSetting disableReceivingWaypoints = XaeroPlusBooleanSetting.create( - "Disable Receiving Waypoints", - "setting.world_map.disable_receiving_waypoints", - "setting.world_map.disable_receiving_waypoints.tooltip", - false, - SettingLocation.MINIMAP_WAYPOINTS); - public static final XaeroPlusBooleanSetting disableXaeroInternetAccess = XaeroPlusBooleanSetting.create( - "Disable Xaero Internet Access", - "setting.world_map.disable_internet", - "setting.world_map.disable_internet.tooltip", - false, - SettingLocation.WORLD_MAP_MAIN); - public static final XaeroPlusBooleanSetting expandSettingEntries = XaeroPlusBooleanSetting.create( - "Expanded Setting Entries", - "setting.world_map.expanded_settings", - "setting.world_map.expanded_settings.tooltip", - false, - SettingLocation.WORLD_MAP_MAIN); - public static final XaeroPlusBooleanSetting sodiumSettingIntegration = XaeroPlusBooleanSetting.create( - "Sodium/Embeddium Setting Integration", - "setting.xaeroplus.sodium_embeddium_integration", - "setting.xaeroplus.sodium_embeddium_integration.tooltip", - true, - SettingLocation.WORLD_MAP_MAIN); - public static final XaeroPlusBooleanSetting highlightShader = XaeroPlusBooleanSetting.create( - "Highlight Shader", - "setting.world_map.highlight_shader", - "setting.world_map.highlight_shader.tooltip", - true, - SettingLocation.CHUNK_HIGHLIGHTS); -} diff --git a/common/src/main/java/xaeroplus/settings/XaeroPlusSettingsReflectionHax.java b/common/src/main/java/xaeroplus/settings/XaeroPlusSettingsReflectionHax.java deleted file mode 100644 index 083d157d..00000000 --- a/common/src/main/java/xaeroplus/settings/XaeroPlusSettingsReflectionHax.java +++ /dev/null @@ -1,251 +0,0 @@ -package xaeroplus.settings; - -import com.google.common.base.Suppliers; -import net.minecraft.client.KeyMapping; -import net.minecraft.client.Minecraft; -import xaero.map.WorldMapSession; -import xaero.map.gui.CursorBox; -import xaero.map.settings.ModOptions; -import xaeroplus.mixin.client.AccessorMinimapModOptions; -import xaeroplus.mixin.client.AccessorWorldMapModOptions; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.function.Supplier; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -// yucky reflection and utils so our settings can be in xaero's gui's -public class XaeroPlusSettingsReflectionHax { - public static final List XAERO_PLUS_WORLDMAP_SETTINGS = new ArrayList<>(); - public static final List XAERO_PLUS_CHUNK_HIGHLIGHT_SETTINGS = new ArrayList<>(); - public static final List XAERO_PLUS_MINIMAP_OVERLAY_SETTINGS = new ArrayList<>(); - public static final List XAERO_PLUS_MINIMAP_ENTITY_RADAR_SETTINGS = new ArrayList<>(); - public static final List XAERO_PLUS_MINIMAP_MAIN_SETTINGS = new ArrayList<>(); - public static final List XAERO_PLUS_MINIMAP_VIEW_SETTINGS = new ArrayList<>(); - public static final List XAERO_PLUS_MINIMAP_WAYPOINT_SETTINGS = new ArrayList<>(); - public static final Supplier> ALL_MINIMAP_SETTINGS = Suppliers.memoize(() -> - Stream.of(XAERO_PLUS_MINIMAP_OVERLAY_SETTINGS.stream(), - XAERO_PLUS_MINIMAP_MAIN_SETTINGS.stream(), - XAERO_PLUS_MINIMAP_VIEW_SETTINGS.stream(), - XAERO_PLUS_MINIMAP_ENTITY_RADAR_SETTINGS.stream(), - XAERO_PLUS_MINIMAP_WAYPOINT_SETTINGS.stream()) - .flatMap(x -> x) - .collect(Collectors.toList())); - public static final Supplier> ALL_WORLD_MAP_SETTINGS = Suppliers.memoize(() -> - Stream.of(XAERO_PLUS_WORLDMAP_SETTINGS.stream(), - XAERO_PLUS_CHUNK_HIGHLIGHT_SETTINGS.stream()) - .flatMap(x -> x) - .collect(Collectors.toList())); - public static final List XAERO_PLUS_KEYBIND_SETTINGS = new ArrayList<>(); - public static final Supplier> ALL_SETTINGS = Suppliers.memoize(() -> - Stream.of(XAERO_PLUS_WORLDMAP_SETTINGS.stream(), - XAERO_PLUS_CHUNK_HIGHLIGHT_SETTINGS.stream(), - XAERO_PLUS_MINIMAP_OVERLAY_SETTINGS.stream(), - XAERO_PLUS_MINIMAP_ENTITY_RADAR_SETTINGS.stream(), - XAERO_PLUS_MINIMAP_MAIN_SETTINGS.stream(), - XAERO_PLUS_MINIMAP_VIEW_SETTINGS.stream(), - XAERO_PLUS_KEYBIND_SETTINGS.stream(), - XAERO_PLUS_MINIMAP_WAYPOINT_SETTINGS.stream()) - .flatMap(x -> x) - .collect(Collectors.toList())); - - public enum SettingLocation { - WORLD_MAP_MAIN(XAERO_PLUS_WORLDMAP_SETTINGS), - CHUNK_HIGHLIGHTS(XAERO_PLUS_CHUNK_HIGHLIGHT_SETTINGS), - MINIMAP_OVERLAYS(XAERO_PLUS_MINIMAP_OVERLAY_SETTINGS), - MINIMAP_MAIN(XAERO_PLUS_MINIMAP_MAIN_SETTINGS), - MINIMAP_VIEW(XAERO_PLUS_MINIMAP_VIEW_SETTINGS), - KEYBINDS(XAERO_PLUS_KEYBIND_SETTINGS), - MINIMAP_ENTITY_RADAR(XAERO_PLUS_MINIMAP_ENTITY_RADAR_SETTINGS), - MINIMAP_WAYPOINTS(XAERO_PLUS_MINIMAP_WAYPOINT_SETTINGS); - - private final List settingsList; - - SettingLocation(final List settingsList) { - this.settingsList = settingsList; - } - - public List getSettingsList() { - return settingsList; - } - } - - private static final Supplier> memoizingKeybindsList = Suppliers.memoize(() -> - Stream.of(XAERO_PLUS_WORLDMAP_SETTINGS.stream(), - XAERO_PLUS_CHUNK_HIGHLIGHT_SETTINGS.stream(), - XAERO_PLUS_MINIMAP_OVERLAY_SETTINGS.stream(), - XAERO_PLUS_MINIMAP_ENTITY_RADAR_SETTINGS.stream(), - XAERO_PLUS_MINIMAP_MAIN_SETTINGS.stream(), - XAERO_PLUS_MINIMAP_VIEW_SETTINGS.stream(), - XAERO_PLUS_KEYBIND_SETTINGS.stream(), - XAERO_PLUS_MINIMAP_WAYPOINT_SETTINGS.stream()) - .flatMap(x -> x) - .filter(setting -> setting instanceof XaeroPlusBooleanSetting) - .map(setting -> (XaeroPlusBooleanSetting) setting) - .filter(setting -> setting.getKeyBinding() != null) - .collect(Collectors.toList())); - private static List WORLDMAP_MOD_OPTIONS_LIST = null; - private static List CHUNK_HIGHLIGHTS_MOD_OPTIONS_LIST = null; - private static List MINIMAP_OVERLAY_MOD_OPTIONS_LIST = null; - private static List MINIMAP_MAIN_MOD_OPTIONS_LIST = null; - private static List MINIMAP_ENTITY_RADAR_MOD_OPTIONS_LIST = null; - private static List MINIMAP_WAYPOINTS_MOD_OPTIONS_LIST = null; - private static List MINIMAP_VIEW_MOD_OPTIONS_LIST = null; - - private static List constructXaeroPlusMinimapModOptions(final List settings) { - return settings.stream().map(XaeroPlusSettingsReflectionHax::buildMinimapModOptions).collect(Collectors.toList()); - } - - private static List constructXaeroPlusWorldMapModOptions(final List settings) { - return settings.stream().map(XaeroPlusSettingsReflectionHax::buildWorldMapModOptions).collect(Collectors.toList()); - } - - public static List getWorldMapConfigSettingEntries() { - if (WORLDMAP_MOD_OPTIONS_LIST == null) { - WORLDMAP_MOD_OPTIONS_LIST = constructXaeroPlusWorldMapModOptions(XAERO_PLUS_WORLDMAP_SETTINGS); - } - return WORLDMAP_MOD_OPTIONS_LIST.stream() - .map(xaero.map.gui.ConfigSettingEntry::new) - .collect(Collectors.toList()); - } - - public static List getChunkHighlightConfigSettingEntries() { - if (CHUNK_HIGHLIGHTS_MOD_OPTIONS_LIST == null) { - CHUNK_HIGHLIGHTS_MOD_OPTIONS_LIST = constructXaeroPlusWorldMapModOptions(XAERO_PLUS_CHUNK_HIGHLIGHT_SETTINGS); - } - return CHUNK_HIGHLIGHTS_MOD_OPTIONS_LIST.stream() - .map(xaero.map.gui.ConfigSettingEntry::new) - .collect(Collectors.toList()); - } - - public static List getMinimapOverlayConfigSettingEntries() { - if (MINIMAP_OVERLAY_MOD_OPTIONS_LIST == null) { - MINIMAP_OVERLAY_MOD_OPTIONS_LIST = constructXaeroPlusMinimapModOptions(XAERO_PLUS_MINIMAP_OVERLAY_SETTINGS); - } - return MINIMAP_OVERLAY_MOD_OPTIONS_LIST.stream() - .map(xaero.common.gui.ConfigSettingEntry::new) - .collect(Collectors.toList()); - } - - public static List getMinimapEntityRadarSettingEntries() { - if (MINIMAP_ENTITY_RADAR_MOD_OPTIONS_LIST == null) { - MINIMAP_ENTITY_RADAR_MOD_OPTIONS_LIST = constructXaeroPlusMinimapModOptions(XAERO_PLUS_MINIMAP_ENTITY_RADAR_SETTINGS); - } - return MINIMAP_ENTITY_RADAR_MOD_OPTIONS_LIST.stream() - .map(xaero.common.gui.ConfigSettingEntry::new) - .collect(Collectors.toList()); - } - - public static List getMinimapMainConfigSettingEntries() { - if (MINIMAP_MAIN_MOD_OPTIONS_LIST == null) { - MINIMAP_MAIN_MOD_OPTIONS_LIST = constructXaeroPlusMinimapModOptions(XAERO_PLUS_MINIMAP_MAIN_SETTINGS); - } - return MINIMAP_MAIN_MOD_OPTIONS_LIST.stream() - .map(xaero.common.gui.ConfigSettingEntry::new) - .collect(Collectors.toList()); - } - - public static List getMinimapWaypointConfigSettingEntries() { - if (MINIMAP_WAYPOINTS_MOD_OPTIONS_LIST == null) { - MINIMAP_WAYPOINTS_MOD_OPTIONS_LIST = constructXaeroPlusMinimapModOptions(XAERO_PLUS_MINIMAP_WAYPOINT_SETTINGS); - } - return MINIMAP_WAYPOINTS_MOD_OPTIONS_LIST.stream() - .map(xaero.common.gui.ConfigSettingEntry::new) - .collect(Collectors.toList()); - } - - public static List getMinimapViewConfigSettingEntries() { - if (MINIMAP_VIEW_MOD_OPTIONS_LIST == null) { - MINIMAP_VIEW_MOD_OPTIONS_LIST = constructXaeroPlusMinimapModOptions(XAERO_PLUS_MINIMAP_VIEW_SETTINGS); - } - return MINIMAP_VIEW_MOD_OPTIONS_LIST.stream() - .map(xaero.common.gui.ConfigSettingEntry::new) - .collect(Collectors.toList()); - } - - private static xaero.map.settings.ModOptions buildWorldMapModOptions(final XaeroPlusSetting xaeroPlusSetting) { - try { - if (xaeroPlusSetting instanceof XaeroPlusBooleanSetting) { - return AccessorWorldMapModOptions.createBooleanSetting( - xaeroPlusSetting.getSettingName(), - new CursorBox(xaeroPlusSetting.getTooltipTranslationKey()), - xaeroPlusSetting.isIngameOnly(), - xaeroPlusSetting.isRequiresMinimap(), - false); - } else if (xaeroPlusSetting instanceof XaeroPlusFloatSetting) { - return AccessorWorldMapModOptions.createDoubleSetting( - xaeroPlusSetting.getSettingName(), - ((XaeroPlusFloatSetting) xaeroPlusSetting).getValueMin(), - ((XaeroPlusFloatSetting) xaeroPlusSetting).getValueMax(), - ((XaeroPlusFloatSetting) xaeroPlusSetting).getValueStep(), - new CursorBox(xaeroPlusSetting.getTooltipTranslationKey()), - xaeroPlusSetting.isIngameOnly(), - xaeroPlusSetting.isRequiresMinimap(), - false - ); - } else if (xaeroPlusSetting instanceof XaeroPlusEnumSetting) { - return AccessorWorldMapModOptions.createEnumSetting( - xaeroPlusSetting.getSettingName(), - ((XaeroPlusEnumSetting) xaeroPlusSetting).getIndexMax() + 1, - new CursorBox(xaeroPlusSetting.getTooltipTranslationKey()), - xaeroPlusSetting.isIngameOnly(), - xaeroPlusSetting.isRequiresMinimap(), - false - ); - } - throw new RuntimeException("Unknown XaeroPlusSetting type: " + xaeroPlusSetting.getClass().getName()); - } catch (final Throwable e) { - throw new RuntimeException(e); - } - } - - private static xaero.common.settings.ModOptions buildMinimapModOptions(final XaeroPlusSetting xaeroPlusSetting) { - try { - if (xaeroPlusSetting instanceof XaeroPlusBooleanSetting) { - return AccessorMinimapModOptions.createBooleanSetting( - xaeroPlusSetting.getSettingName(), - new xaero.common.graphics.CursorBox(xaeroPlusSetting.getTooltipTranslationKey()), - xaeroPlusSetting.isIngameOnly()); - } else if (xaeroPlusSetting instanceof XaeroPlusFloatSetting) { - return AccessorMinimapModOptions.createDoubleSetting( - xaeroPlusSetting.getSettingName(), - ((XaeroPlusFloatSetting) xaeroPlusSetting).getValueMin(), - ((XaeroPlusFloatSetting) xaeroPlusSetting).getValueMax(), - ((XaeroPlusFloatSetting) xaeroPlusSetting).getValueStep(), - new xaero.common.graphics.CursorBox(xaeroPlusSetting.getTooltipTranslationKey()), - xaeroPlusSetting.isIngameOnly() - ); - } else if (xaeroPlusSetting instanceof XaeroPlusEnumSetting) { - return AccessorMinimapModOptions.createEnumSetting( - xaeroPlusSetting.getSettingName(), - 0, - ((XaeroPlusEnumSetting) xaeroPlusSetting).getIndexMax(), - new xaero.common.graphics.CursorBox(xaeroPlusSetting.getTooltipTranslationKey()), - xaeroPlusSetting.isIngameOnly() - ); - } - throw new RuntimeException("Unknown XaeroPlusSetting type: " + xaeroPlusSetting.getClass().getName()); - } catch (final Throwable e) { - throw new RuntimeException(e); - } - } - - static void markChunksDirtyInWriteDistance() { - Minecraft mc = Minecraft.getInstance(); - if (mc.level != null && mc.player != null) { - WorldMapSession session = WorldMapSession.getCurrentSession(); - if (session != null) { - session.getMapProcessor().getMapWriter().setDirtyInWriteDistance(mc.player, mc.level); - session.getMapProcessor().getMapWriter().requestCachedColoursClear(); - } - } - } - - public static Supplier> keybindingMapSupplier = Suppliers.memoize(() -> - memoizingKeybindsList.get().stream().collect(Collectors.toMap(XaeroPlusSetting::getKeyBinding, s -> s))); - - public static Supplier> keybindsSupplier = Suppliers.memoize(() -> new ArrayList<>( - keybindingMapSupplier.get().keySet())); -} diff --git a/common/src/main/java/xaeroplus/util/DataFolderResolveUtil.java b/common/src/main/java/xaeroplus/util/DataFolderResolveUtil.java index 2444e7ac..4c6b36b2 100644 --- a/common/src/main/java/xaeroplus/util/DataFolderResolveUtil.java +++ b/common/src/main/java/xaeroplus/util/DataFolderResolveUtil.java @@ -13,7 +13,7 @@ import xaero.map.file.MapSaveLoad; import xaeroplus.Globals; import xaeroplus.XaeroPlus; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import java.nio.file.Path; @@ -22,8 +22,8 @@ public class DataFolderResolveUtil { public static void resolveDataFolder(final ClientPacketListener connection, final CallbackInfoReturnable cir) { - final XaeroPlusSettingRegistry.DataFolderResolutionMode dataFolderResolutionMode = Globals.dataFolderResolutionMode; - if (dataFolderResolutionMode == XaeroPlusSettingRegistry.DataFolderResolutionMode.SERVER_NAME) { + final Settings.DataFolderResolutionMode dataFolderResolutionMode = Globals.dataFolderResolutionMode; + if (dataFolderResolutionMode == Settings.DataFolderResolutionMode.SERVER_NAME) { if (nonNull(connection.getServerData())) { String serverName = connection.getServerData().name; if (!serverName.isEmpty()) { @@ -38,7 +38,7 @@ public static void resolveDataFolder(final ClientPacketListener connection, fina if (!Minecraft.getInstance().hasSingleplayerServer()) { XaeroPlus.LOGGER.error("Unable to resolve valid MC Server Name. Falling back to default Xaero data folder resolution"); } - } else if (dataFolderResolutionMode == XaeroPlusSettingRegistry.DataFolderResolutionMode.BASE_DOMAIN) { + } else if (dataFolderResolutionMode == Settings.DataFolderResolutionMode.BASE_DOMAIN) { if (nonNull(connection.getServerData())) { // use the base domain name, e.g connect.2b2t.org -> 2b2t.org String id; diff --git a/fabric/src/main/java/xaeroplus/fabric/XaeroPlusFabric.java b/fabric/src/main/java/xaeroplus/fabric/XaeroPlusFabric.java index 50dc2b32..b4f1cb1e 100644 --- a/fabric/src/main/java/xaeroplus/fabric/XaeroPlusFabric.java +++ b/fabric/src/main/java/xaeroplus/fabric/XaeroPlusFabric.java @@ -7,23 +7,17 @@ import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.fabricmc.fabric.api.resource.ResourceManagerHelper; import net.fabricmc.loader.api.Version; -import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.server.packs.PackType; -import xaeroplus.Globals; import xaeroplus.XaeroPlus; import xaeroplus.fabric.util.FabricWaystonesHelperInit; import xaeroplus.fabric.util.XPShaderResourceReloadListener; import xaeroplus.fabric.util.compat.IncompatibleMinimapWarningScreen; import xaeroplus.fabric.util.compat.XaeroPlusMinimapCompatibilityChecker; -import xaeroplus.module.ModuleManager; -import xaeroplus.settings.XaeroPlusSettingRegistry; -import xaeroplus.settings.XaeroPlusSettingsReflectionHax; +import xaeroplus.settings.Settings; import xaeroplus.util.DataFolderResolveUtil; import xaeroplus.util.XaeroPlusGameTest; -import java.util.List; - import static xaeroplus.fabric.util.compat.XaeroPlusMinimapCompatibilityChecker.versionCheckResult; public class XaeroPlusFabric implements ClientModInitializer { @@ -36,11 +30,8 @@ public static void initialize() { versionCheckResult.anyPresentMinimapVersion().map(Version::getFriendlyString).orElse("None!")); return; } - ModuleManager.init(); - boolean a = Globals.shouldResetFBO; // force static instances to init - XaeroPlusSettingRegistry.fastMapSetting.getValue(); // force static instances to init - List keybinds = XaeroPlusSettingsReflectionHax.keybindsSupplier.get(); - keybinds.forEach(KeyBindingHelper::registerKeyBinding); + XaeroPlus.initializeSettings(); + Settings.REGISTRY.getKeybindings().forEach(KeyBindingHelper::registerKeyBinding); FabricWaystonesHelperInit.doInit(); if (System.getenv("XP_CI_TEST") != null) Minecraft.getInstance().execute(XaeroPlusGameTest::applyMixinsTest); diff --git a/fabric/src/main/java/xaeroplus/fabric/mixin/client/MixinSodium6OptionsGUI.java b/fabric/src/main/java/xaeroplus/fabric/mixin/client/MixinSodium6OptionsGUI.java index 0adfbdf8..b8d456cc 100644 --- a/fabric/src/main/java/xaeroplus/fabric/mixin/client/MixinSodium6OptionsGUI.java +++ b/fabric/src/main/java/xaeroplus/fabric/mixin/client/MixinSodium6OptionsGUI.java @@ -19,7 +19,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import xaeroplus.fabric.XaeroPlusSodium6OptionStorage; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import java.util.List; @@ -35,7 +35,7 @@ public class MixinSodium6OptionsGUI { value = "RETURN" )) public void injectXPSettings(final Screen prevScreen, final CallbackInfo ci) { - if (!XaeroPlusSettingRegistry.sodiumSettingIntegration.getValue()) return; + if (!Settings.REGISTRY.sodiumSettingIntegration.get()) return; pages.add(new OptionPage(Component.literal("XaeroPlus"), ImmutableList.of( OptionGroup.createBuilder() .add(OptionImpl.createBuilder(Boolean.TYPE, XaeroPlusSodium6OptionStorage.INSTANCE) @@ -43,8 +43,8 @@ public void injectXPSettings(final Screen prevScreen, final CallbackInfo ci) { .setTooltip(Component.translatable("setting.minimap.fps_limiter.tooltip")) .setControl(TickBoxControl::new) .setBinding(new GenericBinding<>( - (config, value) -> XaeroPlusSettingRegistry.minimapFpsLimiter.setValue(value), - config -> XaeroPlusSettingRegistry.minimapFpsLimiter.getValue() + (config, value) -> Settings.REGISTRY.minimapFpsLimiter.setValue(value), + config -> Settings.REGISTRY.minimapFpsLimiter.get() )) .build()) .add(OptionImpl.createBuilder(int.class, XaeroPlusSodium6OptionStorage.INSTANCE) @@ -52,13 +52,13 @@ public void injectXPSettings(final Screen prevScreen, final CallbackInfo ci) { .setTooltip(Component.translatable("setting.minimap.fps_limiter_limit.tooltip")) .setControl(option -> new SliderControl( option, - (int) XaeroPlusSettingRegistry.minimapFpsLimit.getValueMin(), - (int) XaeroPlusSettingRegistry.minimapFpsLimit.getValueMax(), - (int) XaeroPlusSettingRegistry.minimapFpsLimit.getValueStep(), + (int) Settings.REGISTRY.minimapFpsLimit.getValueMin(), + (int) Settings.REGISTRY.minimapFpsLimit.getValueMax(), + (int) Settings.REGISTRY.minimapFpsLimit.getValueStep(), ControlValueFormatter.number())) .setBinding(new GenericBinding<>( - (config, value) -> XaeroPlusSettingRegistry.minimapFpsLimit.setValue((float) value), - config -> (int) XaeroPlusSettingRegistry.minimapFpsLimit.getValue() + (config, value) -> Settings.REGISTRY.minimapFpsLimit.setValue(value), + config -> Settings.REGISTRY.minimapFpsLimit.getAsInt() )) .build()) .add(OptionImpl.createBuilder(int.class, XaeroPlusSodium6OptionStorage.INSTANCE) @@ -66,13 +66,13 @@ public void injectXPSettings(final Screen prevScreen, final CallbackInfo ci) { .setTooltip(Component.translatable("setting.minimap.minimap_scaling.tooltip")) .setControl(option -> new SliderControl( option, - (int) XaeroPlusSettingRegistry.minimapScaleMultiplierSetting.getValueMin(), - (int) XaeroPlusSettingRegistry.minimapScaleMultiplierSetting.getValueMax(), - (int) XaeroPlusSettingRegistry.minimapScaleMultiplierSetting.getValueStep(), + (int) Settings.REGISTRY.minimapScaleMultiplierSetting.getValueMin(), + (int) Settings.REGISTRY.minimapScaleMultiplierSetting.getValueMax(), + (int) Settings.REGISTRY.minimapScaleMultiplierSetting.getValueStep(), ControlValueFormatter.number())) .setBinding(new GenericBinding<>( - (config, value) -> XaeroPlusSettingRegistry.minimapScaleMultiplierSetting.setValue((float) value), - config -> (int) XaeroPlusSettingRegistry.minimapScaleMultiplierSetting.getValue() + (config, value) -> Settings.REGISTRY.minimapScaleMultiplierSetting.setValue(value), + config -> Settings.REGISTRY.minimapScaleMultiplierSetting.getAsInt() )) .build()) .build() diff --git a/fabric/src/main/java/xaeroplus/fabric/mixin/client/MixinSodiumOptionsGUI.java b/fabric/src/main/java/xaeroplus/fabric/mixin/client/MixinSodiumOptionsGUI.java index 464d4453..085de68b 100644 --- a/fabric/src/main/java/xaeroplus/fabric/mixin/client/MixinSodiumOptionsGUI.java +++ b/fabric/src/main/java/xaeroplus/fabric/mixin/client/MixinSodiumOptionsGUI.java @@ -19,7 +19,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import xaeroplus.fabric.XaeroPlusSodiumOptionStorage; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import java.util.List; @@ -35,7 +35,7 @@ public class MixinSodiumOptionsGUI { value = "RETURN" )) public void injectXPSettings(final Screen prevScreen, final CallbackInfo ci) { - if (!XaeroPlusSettingRegistry.sodiumSettingIntegration.getValue()) return; + if (!Settings.REGISTRY.sodiumSettingIntegration.get()) return; pages.add(new OptionPage(Component.literal("XaeroPlus"), ImmutableList.of( OptionGroup.createBuilder() .add(OptionImpl.createBuilder(Boolean.TYPE, XaeroPlusSodiumOptionStorage.INSTANCE) @@ -43,8 +43,8 @@ public void injectXPSettings(final Screen prevScreen, final CallbackInfo ci) { .setTooltip(Component.translatable("setting.minimap.fps_limiter.tooltip")) .setControl(TickBoxControl::new) .setBinding(new GenericBinding<>( - (config, value) -> XaeroPlusSettingRegistry.minimapFpsLimiter.setValue(value), - config -> XaeroPlusSettingRegistry.minimapFpsLimiter.getValue() + (config, value) -> Settings.REGISTRY.minimapFpsLimiter.setValue(value), + config -> Settings.REGISTRY.minimapFpsLimiter.get() )) .build()) .add(OptionImpl.createBuilder(int.class, XaeroPlusSodiumOptionStorage.INSTANCE) @@ -52,13 +52,13 @@ public void injectXPSettings(final Screen prevScreen, final CallbackInfo ci) { .setTooltip(Component.translatable("setting.minimap.fps_limiter_limit.tooltip")) .setControl(option -> new SliderControl( option, - (int) XaeroPlusSettingRegistry.minimapFpsLimit.getValueMin(), - (int) XaeroPlusSettingRegistry.minimapFpsLimit.getValueMax(), - (int) XaeroPlusSettingRegistry.minimapFpsLimit.getValueStep(), + (int) Settings.REGISTRY.minimapFpsLimit.getValueMin(), + (int) Settings.REGISTRY.minimapFpsLimit.getValueMax(), + (int) Settings.REGISTRY.minimapFpsLimit.getValueStep(), ControlValueFormatter.number())) .setBinding(new GenericBinding<>( - (config, value) -> XaeroPlusSettingRegistry.minimapFpsLimit.setValue((float) value), - config -> (int) XaeroPlusSettingRegistry.minimapFpsLimit.getValue() + (config, value) -> Settings.REGISTRY.minimapFpsLimit.setValue(value), + config -> Settings.REGISTRY.minimapFpsLimit.getAsInt() )) .build()) .add(OptionImpl.createBuilder(int.class, XaeroPlusSodiumOptionStorage.INSTANCE) @@ -66,13 +66,13 @@ public void injectXPSettings(final Screen prevScreen, final CallbackInfo ci) { .setTooltip(Component.translatable("setting.minimap.minimap_scaling.tooltip")) .setControl(option -> new SliderControl( option, - (int) XaeroPlusSettingRegistry.minimapScaleMultiplierSetting.getValueMin(), - (int) XaeroPlusSettingRegistry.minimapScaleMultiplierSetting.getValueMax(), - (int) XaeroPlusSettingRegistry.minimapScaleMultiplierSetting.getValueStep(), + (int) Settings.REGISTRY.minimapScaleMultiplierSetting.getValueMin(), + (int) Settings.REGISTRY.minimapScaleMultiplierSetting.getValueMax(), + (int) Settings.REGISTRY.minimapScaleMultiplierSetting.getValueStep(), ControlValueFormatter.number())) .setBinding(new GenericBinding<>( - (config, value) -> XaeroPlusSettingRegistry.minimapScaleMultiplierSetting.setValue((float) value), - config -> (int) XaeroPlusSettingRegistry.minimapScaleMultiplierSetting.getValue() + (config, value) -> Settings.REGISTRY.minimapScaleMultiplierSetting.setValue(value), + config -> Settings.REGISTRY.minimapScaleMultiplierSetting.getAsInt() )) .build()) .build() diff --git a/forge/src/main/java/xaeroplus/forge/XaeroPlusEmbeddiumOptionsInit.java b/forge/src/main/java/xaeroplus/forge/XaeroPlusEmbeddiumOptionsInit.java index 023bf1af..4922103a 100644 --- a/forge/src/main/java/xaeroplus/forge/XaeroPlusEmbeddiumOptionsInit.java +++ b/forge/src/main/java/xaeroplus/forge/XaeroPlusEmbeddiumOptionsInit.java @@ -11,11 +11,11 @@ import net.minecraft.network.chat.Component; import org.embeddedt.embeddium.api.OptionGUIConstructionEvent; import org.embeddedt.embeddium.client.gui.options.OptionIdentifier; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; public class XaeroPlusEmbeddiumOptionsInit { public static void onEmbeddiumOptionGUIConstructionEvent(OptionGUIConstructionEvent event) { - if (!XaeroPlusSettingRegistry.sodiumSettingIntegration.getValue()) return; + if (!Settings.REGISTRY.sodiumSettingIntegration.get()) return; event.addPage(new OptionPage(OptionIdentifier.create("xaeroplus", "options"), Component.literal("XaeroPlus"), ImmutableList.of( OptionGroup.createBuilder() .add(OptionImpl.createBuilder(Boolean.TYPE, XaeroPlusEmbeddiumOptionStorage.INSTANCE) @@ -23,8 +23,8 @@ public static void onEmbeddiumOptionGUIConstructionEvent(OptionGUIConstructionEv .setTooltip(Component.translatable("setting.minimap.fps_limiter.tooltip")) .setControl(TickBoxControl::new) .setBinding(new GenericBinding<>( - (config, value) -> XaeroPlusSettingRegistry.minimapFpsLimiter.setValue(value), - config -> XaeroPlusSettingRegistry.minimapFpsLimiter.getValue() + (config, value) -> Settings.REGISTRY.minimapFpsLimiter.setValue(value), + config -> Settings.REGISTRY.minimapFpsLimiter.get() )) .build()) .add(OptionImpl.createBuilder(int.class, XaeroPlusEmbeddiumOptionStorage.INSTANCE) @@ -32,13 +32,13 @@ public static void onEmbeddiumOptionGUIConstructionEvent(OptionGUIConstructionEv .setTooltip(Component.translatable("setting.minimap.fps_limiter_limit.tooltip")) .setControl(option -> new SliderControl( option, - (int) XaeroPlusSettingRegistry.minimapFpsLimit.getValueMin(), - (int) XaeroPlusSettingRegistry.minimapFpsLimit.getValueMax(), - (int) XaeroPlusSettingRegistry.minimapFpsLimit.getValueStep(), + (int) Settings.REGISTRY.minimapFpsLimit.getValueMin(), + (int) Settings.REGISTRY.minimapFpsLimit.getValueMax(), + (int) Settings.REGISTRY.minimapFpsLimit.getValueStep(), ControlValueFormatter.number())) .setBinding(new GenericBinding<>( - (config, value) -> XaeroPlusSettingRegistry.minimapFpsLimit.setValue((float) value), - config -> (int) XaeroPlusSettingRegistry.minimapFpsLimit.getValue() + (config, value) -> Settings.REGISTRY.minimapFpsLimit.setValue(value), + config -> Settings.REGISTRY.minimapFpsLimit.getAsInt() )) .build()) .add(OptionImpl.createBuilder(int.class, XaeroPlusEmbeddiumOptionStorage.INSTANCE) @@ -46,13 +46,13 @@ public static void onEmbeddiumOptionGUIConstructionEvent(OptionGUIConstructionEv .setTooltip(Component.translatable("setting.minimap.minimap_scaling.tooltip")) .setControl(option -> new SliderControl( option, - (int) XaeroPlusSettingRegistry.minimapScaleMultiplierSetting.getValueMin(), - (int) XaeroPlusSettingRegistry.minimapScaleMultiplierSetting.getValueMax(), - (int) XaeroPlusSettingRegistry.minimapScaleMultiplierSetting.getValueStep(), + (int) Settings.REGISTRY.minimapScaleMultiplierSetting.getValueMin(), + (int) Settings.REGISTRY.minimapScaleMultiplierSetting.getValueMax(), + (int) Settings.REGISTRY.minimapScaleMultiplierSetting.getValueStep(), ControlValueFormatter.number())) .setBinding(new GenericBinding<>( - (config, value) -> XaeroPlusSettingRegistry.minimapScaleMultiplierSetting.setValue((float) value), - config -> (int) XaeroPlusSettingRegistry.minimapScaleMultiplierSetting.getValue() + (config, value) -> Settings.REGISTRY.minimapScaleMultiplierSetting.setValue(value), + config -> Settings.REGISTRY.minimapScaleMultiplierSetting.getAsInt() )) .build()) .build() diff --git a/forge/src/main/java/xaeroplus/forge/XaeroPlusForge.java b/forge/src/main/java/xaeroplus/forge/XaeroPlusForge.java index ad5c197c..38387c5c 100644 --- a/forge/src/main/java/xaeroplus/forge/XaeroPlusForge.java +++ b/forge/src/main/java/xaeroplus/forge/XaeroPlusForge.java @@ -2,7 +2,6 @@ import com.github.benmanes.caffeine.cache.RemovalCause; import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.commands.CommandSourceStack; import net.minecraftforge.api.distmarker.Dist; @@ -17,17 +16,12 @@ import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import xaero.map.gui.GuiWorldMapSettings; -import xaeroplus.Globals; import xaeroplus.XaeroPlus; import xaeroplus.feature.extensions.GuiXaeroPlusWorldMapSettings; -import xaeroplus.module.ModuleManager; -import xaeroplus.settings.XaeroPlusSettingRegistry; -import xaeroplus.settings.XaeroPlusSettingsReflectionHax; +import xaeroplus.settings.Settings; import xaeroplus.util.DataFolderResolveUtil; import xaeroplus.util.XaeroPlusGameTest; -import java.util.List; - import static net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext.get; @Mod(value = "xaeroplus") @@ -36,21 +30,19 @@ public class XaeroPlusForge { public XaeroPlusForge() { IEventBus modEventBus = get().getModEventBus(); - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> { - return () -> { - modEventBus.addListener(this::onInitialize); - modEventBus.addListener(this::onRegisterKeyMappingsEvent); - modEventBus.addListener(this::onRegisterClientResourceReloadListeners); - FORGE_EVENT_BUS.addListener(this::onRegisterClientCommandsEvent); - FORGE_EVENT_BUS.register(modEventBus); - if (EmbeddiumHelper.isEmbeddiumPresent()) - FORGE_EVENT_BUS.addListener(XaeroPlusEmbeddiumOptionsInit::onEmbeddiumOptionGUIConstructionEvent); - RemovalCause explicit = RemovalCause.EXPLICIT; // force class load to stop forge shitting itself at runtime?? - ModLoadingContext.get().registerExtensionPoint( - ConfigScreenHandler.ConfigScreenFactory.class, - () -> new ConfigScreenHandler.ConfigScreenFactory((mc, screen) -> new GuiXaeroPlusWorldMapSettings(new GuiWorldMapSettings(screen), screen)) - ); - }; + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { + modEventBus.addListener(this::onInitialize); + modEventBus.addListener(this::onRegisterKeyMappingsEvent); + modEventBus.addListener(this::onRegisterClientResourceReloadListeners); + FORGE_EVENT_BUS.addListener(this::onRegisterClientCommandsEvent); + FORGE_EVENT_BUS.register(modEventBus); + if (EmbeddiumHelper.isEmbeddiumPresent()) + FORGE_EVENT_BUS.addListener(XaeroPlusEmbeddiumOptionsInit::onEmbeddiumOptionGUIConstructionEvent); + RemovalCause explicit = RemovalCause.EXPLICIT; // force class load to stop forge shitting itself at runtime?? + ModLoadingContext.get().registerExtensionPoint( + ConfigScreenHandler.ConfigScreenFactory.class, + () -> new ConfigScreenHandler.ConfigScreenFactory((mc, screen) -> new GuiXaeroPlusWorldMapSettings(new GuiWorldMapSettings(screen), screen)) + ); }); } @@ -60,11 +52,8 @@ public void onInitialize(FMLClientSetupEvent event) { public void onRegisterKeyMappingsEvent(final RegisterKeyMappingsEvent event) { if (XaeroPlus.initialized.compareAndSet(false, true)) { - ModuleManager.init(); - boolean a = Globals.shouldResetFBO; // force static instances to init - XaeroPlusSettingRegistry.fastMapSetting.getValue(); // force static instances to init - List keybinds = XaeroPlusSettingsReflectionHax.keybindsSupplier.get(); - keybinds.forEach(event::register); + XaeroPlus.initializeSettings(); + Settings.REGISTRY.getKeybindings().forEach(event::register); if (System.getenv("XP_CI_TEST") != null) Minecraft.getInstance().execute(XaeroPlusGameTest::applyMixinsTest); } diff --git a/forge/src/main/java/xaeroplus/forge/mixin/client/MixinSodium6OptionsGUI.java b/forge/src/main/java/xaeroplus/forge/mixin/client/MixinSodium6OptionsGUI.java index b5d3452d..44a1cbf7 100644 --- a/forge/src/main/java/xaeroplus/forge/mixin/client/MixinSodium6OptionsGUI.java +++ b/forge/src/main/java/xaeroplus/forge/mixin/client/MixinSodium6OptionsGUI.java @@ -19,7 +19,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import xaeroplus.forge.XaeroPlusSodium6OptionStorage; -import xaeroplus.settings.XaeroPlusSettingRegistry; +import xaeroplus.settings.Settings; import java.util.List; @@ -35,7 +35,7 @@ public class MixinSodium6OptionsGUI { value = "RETURN" )) public void injectXPSettings(final Screen prevScreen, final CallbackInfo ci) { - if (!XaeroPlusSettingRegistry.sodiumSettingIntegration.getValue()) return; + if (!Settings.REGISTRY.sodiumSettingIntegration.get()) return; pages.add(new OptionPage(Component.literal("XaeroPlus"), ImmutableList.of( OptionGroup.createBuilder() .add(OptionImpl.createBuilder(Boolean.TYPE, XaeroPlusSodium6OptionStorage.INSTANCE) @@ -43,8 +43,8 @@ public void injectXPSettings(final Screen prevScreen, final CallbackInfo ci) { .setTooltip(Component.translatable("setting.minimap.fps_limiter.tooltip")) .setControl(TickBoxControl::new) .setBinding(new GenericBinding<>( - (config, value) -> XaeroPlusSettingRegistry.minimapFpsLimiter.setValue(value), - config -> XaeroPlusSettingRegistry.minimapFpsLimiter.getValue() + (config, value) -> Settings.REGISTRY.minimapFpsLimiter.setValue(value), + config -> Settings.REGISTRY.minimapFpsLimiter.get() )) .build()) .add(OptionImpl.createBuilder(int.class, XaeroPlusSodium6OptionStorage.INSTANCE) @@ -52,13 +52,13 @@ public void injectXPSettings(final Screen prevScreen, final CallbackInfo ci) { .setTooltip(Component.translatable("setting.minimap.fps_limiter_limit.tooltip")) .setControl(option -> new SliderControl( option, - (int) XaeroPlusSettingRegistry.minimapFpsLimit.getValueMin(), - (int) XaeroPlusSettingRegistry.minimapFpsLimit.getValueMax(), - (int) XaeroPlusSettingRegistry.minimapFpsLimit.getValueStep(), + (int) Settings.REGISTRY.minimapFpsLimit.getValueMin(), + (int) Settings.REGISTRY.minimapFpsLimit.getValueMax(), + (int) Settings.REGISTRY.minimapFpsLimit.getValueStep(), ControlValueFormatter.number())) .setBinding(new GenericBinding<>( - (config, value) -> XaeroPlusSettingRegistry.minimapFpsLimit.setValue((float) value), - config -> (int) XaeroPlusSettingRegistry.minimapFpsLimit.getValue() + (config, value) -> Settings.REGISTRY.minimapFpsLimit.setValue((float) value), + config -> Settings.REGISTRY.minimapFpsLimit.getAsInt() )) .build()) .add(OptionImpl.createBuilder(int.class, XaeroPlusSodium6OptionStorage.INSTANCE) @@ -66,13 +66,13 @@ public void injectXPSettings(final Screen prevScreen, final CallbackInfo ci) { .setTooltip(Component.translatable("setting.minimap.minimap_scaling.tooltip")) .setControl(option -> new SliderControl( option, - (int) XaeroPlusSettingRegistry.minimapScaleMultiplierSetting.getValueMin(), - (int) XaeroPlusSettingRegistry.minimapScaleMultiplierSetting.getValueMax(), - (int) XaeroPlusSettingRegistry.minimapScaleMultiplierSetting.getValueStep(), + (int) Settings.REGISTRY.minimapScaleMultiplierSetting.getValueMin(), + (int) Settings.REGISTRY.minimapScaleMultiplierSetting.getValueMax(), + (int) Settings.REGISTRY.minimapScaleMultiplierSetting.getValueStep(), ControlValueFormatter.number())) .setBinding(new GenericBinding<>( - (config, value) -> XaeroPlusSettingRegistry.minimapScaleMultiplierSetting.setValue((float) value), - config -> (int) XaeroPlusSettingRegistry.minimapScaleMultiplierSetting.getValue() + (config, value) -> Settings.REGISTRY.minimapScaleMultiplierSetting.setValue((float) value), + config -> Settings.REGISTRY.minimapScaleMultiplierSetting.getAsInt() )) .build()) .build()