From 353838db419063c43a5845599b1c19339b651bab Mon Sep 17 00:00:00 2001 From: James Seibel Date: Tue, 23 Dec 2025 12:22:00 -0600 Subject: [PATCH] add experimental option to ignore rendering dimensions by name --- .../distanthorizons/core/Initializer.java | 4 + .../core/api/internal/SharedApi.java | 8 ++ .../distanthorizons/core/config/Config.java | 16 +++ .../IgnoredDimensionCsvHandler.java | 125 ++++++++++++++++++ .../assets/distanthorizons/lang/en_us.json | 4 + 5 files changed, 157 insertions(+) create mode 100644 core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/IgnoredDimensionCsvHandler.java diff --git a/core/src/main/java/com/seibel/distanthorizons/core/Initializer.java b/core/src/main/java/com/seibel/distanthorizons/core/Initializer.java index 94b2fcfba..d063c5055 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/Initializer.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/Initializer.java @@ -20,7 +20,9 @@ package com.seibel.distanthorizons.core; import com.github.luben.zstd.ZstdOutputStream; +import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeRenderEvent; import com.seibel.distanthorizons.core.config.Config; +import com.seibel.distanthorizons.core.config.eventHandlers.IgnoredDimensionCsvHandler; import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector; import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; import com.seibel.distanthorizons.core.render.renderer.generic.GenericRenderObjectFactory; @@ -171,6 +173,8 @@ public class Initializer } } + DhApi.events.bind(DhApiBeforeRenderEvent.class, IgnoredDimensionCsvHandler.INSTANCE); + } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java b/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java index 8b0485823..2a8d16ef7 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java @@ -25,6 +25,7 @@ import com.seibel.distanthorizons.core.Initializer; import com.seibel.distanthorizons.core.api.internal.chunkUpdating.ChunkUpdateData; import com.seibel.distanthorizons.core.api.internal.chunkUpdating.ChunkUpdateQueueManager; import com.seibel.distanthorizons.core.config.Config; +import com.seibel.distanthorizons.core.config.eventHandlers.IgnoredDimensionCsvHandler; import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector; import com.seibel.distanthorizons.core.generation.DhLightingEngine; import com.seibel.distanthorizons.core.level.DhClientLevel; @@ -239,6 +240,13 @@ public class SharedApi } } + // ignore chunk updates for non-rendered levels + String dimName = dhLevel.getLevelWrapper().getDimensionName(); + if (IgnoredDimensionCsvHandler.INSTANCE.dimensionNameShouldBeIgnored(dimName)) + { + return; + } + // shouldn't normally happen, but just in case if (CHUNK_UPDATE_QUEUE_MANAGER.contains(chunkWrapper.getChunkPos())) { diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java b/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java index 6cf20210a..59f38df55 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java @@ -849,6 +849,20 @@ public class Config .addListener(WorldCurvatureConfigEventHandler.INSTANCE) .build(); + public static ConfigEntry ignoredDimensionCsv = new ConfigEntry.Builder() + .set("") + .comment("" + + "A comma separated list of dimension resource locations where DH won't render. \n" + + "\n" + + "Example: \"minecraft:the_nether,minecraft:the_end\"\n" + + "\n" + + "Note:\n" + + "Some DH settings will be disabled and/or changed to improve \n" + + "visuals when DH rendering is disabled. \n" + + "") + .addListener(IgnoredDimensionCsvHandler.INSTANCE) + .build(); + } } @@ -1848,6 +1862,8 @@ public class Config ThreadPresetConfigEventHandler.INSTANCE.setUiOnlyConfigValues(); RenderQualityPresetConfigEventHandler.INSTANCE.setUiOnlyConfigValues(); QuickRenderToggleConfigEventHandler.INSTANCE.setUiOnlyConfigValues(); + + IgnoredDimensionCsvHandler.INSTANCE.onConfigValueSet(); } catch (Exception e) { diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/IgnoredDimensionCsvHandler.java b/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/IgnoredDimensionCsvHandler.java new file mode 100644 index 000000000..d79b05b41 --- /dev/null +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/IgnoredDimensionCsvHandler.java @@ -0,0 +1,125 @@ +/* + * This file is part of the Distant Horizons mod + * licensed under the GNU LGPL v3 License. + * + * Copyright (C) 2020 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.seibel.distanthorizons.core.config.eventHandlers; + +import com.seibel.distanthorizons.api.enums.config.EDhApiMcRenderingFadeMode; +import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeRenderEvent; +import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiCancelableEventParam; +import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam; +import com.seibel.distanthorizons.core.config.Config; +import com.seibel.distanthorizons.core.config.listeners.IConfigListener; +import com.seibel.distanthorizons.core.logging.DhLogger; +import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; +import com.seibel.distanthorizons.coreapi.util.StringUtil; + +public class IgnoredDimensionCsvHandler extends DhApiBeforeRenderEvent implements IConfigListener +{ + private static final DhLogger LOGGER = new DhLoggerBuilder().build(); + + public static IgnoredDimensionCsvHandler INSTANCE = new IgnoredDimensionCsvHandler(); + + private String[] dimensionNames = null; + + + + //=============// + // constructor // + //=============// + + /** private since we only ever need one handler at a time */ + private IgnoredDimensionCsvHandler() { } + + + + //=================// + // config handling // + //=================// + + @Override + public void onConfigValueSet() + { + String ignoredDimensionCsvString = Config.Client.Advanced.Graphics.Experimental.ignoredDimensionCsv.get(); + if (ignoredDimensionCsvString == null + || ignoredDimensionCsvString.isEmpty()) + { + LOGGER.info("Dimension ignoring disabled, DH will render all dimensions."); + this.dimensionNames = null; + } + else + { + try + { + this.dimensionNames = ignoredDimensionCsvString.split(","); + LOGGER.info("DH set to ignore dimensions: ["+ StringUtil.join(", ", this.dimensionNames)+"]."); + } + catch (Exception e) + { + LOGGER.error("Failed to separate ignored dimensions from CSV string, error: ["+e.getMessage()+"].", e); + this.dimensionNames = null; + } + } + + } + + + + //===================// + // external handling // + //===================// + + @Override + public void beforeRender(DhApiCancelableEventParam event) + { + String dimName = event.value.clientLevelWrapper.getDimensionName(); + if (IgnoredDimensionCsvHandler.INSTANCE.dimensionNameShouldBeIgnored(dimName)) + { + event.cancelEvent(); + Config.Client.Advanced.Graphics.Fog.enableVanillaFog.setApiValue(true); + Config.Client.Advanced.Graphics.Quality.vanillaFadeMode.setApiValue(EDhApiMcRenderingFadeMode.NONE); + } + else + { + Config.Client.Advanced.Graphics.Fog.enableVanillaFog.setApiValue(null); + Config.Client.Advanced.Graphics.Quality.vanillaFadeMode.setApiValue(null); + } + } + + public boolean dimensionNameShouldBeIgnored(String dimName) + { + if (this.dimensionNames == null + || this.dimensionNames.length == 0) + { + return false; + } + + for (int i = 0; i < this.dimensionNames.length; i++) + { + String dimNameToIgnore = this.dimensionNames[i]; + if (dimName.equalsIgnoreCase(dimNameToIgnore)) + { + return true; + } + } + + return false; + } + + +} diff --git a/core/src/main/resources/assets/distanthorizons/lang/en_us.json b/core/src/main/resources/assets/distanthorizons/lang/en_us.json index 9f8f91626..4dd543aa9 100644 --- a/core/src/main/resources/assets/distanthorizons/lang/en_us.json +++ b/core/src/main/resources/assets/distanthorizons/lang/en_us.json @@ -403,6 +403,10 @@ "Earth Curve Ratio", "distanthorizons.config.client.advanced.graphics.experimental.earthCurveRatio.@tooltip": "A value of 1 is equivalent to the curvature of Earth in real life. \nThe minimum accepted value is 50 and the maximum value is 5000. \nEverything between 1 and 49 will be rounded up to 50.", + "distanthorizons.config.client.advanced.graphics.experimental.ignoredDimensionCsv": + "Ignored Dimension CSV", + "distanthorizons.config.client.advanced.graphics.experimental.ignoredDimensionCsv.@tooltip": + "A comma separated list of dimension resource locations where DH won't render. Example: \"minecraft:the_nether,minecraft:the_end\" \n\nNote: \nSome DH settings will be disabled and/or changed to improve \nvisuals when DH rendering is disabled.",