From 559260761fbb4fc879eb07506b43c2f02df7297a Mon Sep 17 00:00:00 2001 From: coderbot Date: Fri, 5 Mar 2021 17:10:30 -0800 Subject: [PATCH] Fully support shader dimension overrides (Fixes #90) --- src/main/java/net/coderbot/iris/Iris.java | 34 +++++++++++++++++-- .../coderbot/iris/shaderpack/ShaderPack.java | 20 +++++++++-- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/coderbot/iris/Iris.java b/src/main/java/net/coderbot/iris/Iris.java index 6f5ece4c80..67f9800e05 100644 --- a/src/main/java/net/coderbot/iris/Iris.java +++ b/src/main/java/net/coderbot/iris/Iris.java @@ -13,9 +13,12 @@ import com.mojang.blaze3d.platform.GlStateManager; import net.coderbot.iris.config.IrisConfig; import net.coderbot.iris.pipeline.ShaderPipeline; -import net.coderbot.iris.postprocess.CompositeRenderer; -import net.coderbot.iris.rendertarget.RenderTargets; +import net.coderbot.iris.shaderpack.DimensionId; import net.coderbot.iris.shaderpack.ShaderPack; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.util.registry.Registry; +import net.minecraft.util.registry.RegistryKey; +import net.minecraft.world.dimension.DimensionType; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -255,9 +258,34 @@ private static void destroyEverything() { } } + private static DimensionId lastDimension = DimensionId.OVERWORLD; + public static ShaderPipeline getPipeline() { + ClientWorld world = MinecraftClient.getInstance().world; + + if (world != null) { + DimensionId currentDimension = DimensionId.OVERWORLD; + + DimensionType current = world.getDimension(); + Registry dimensionTypes = world.getRegistryManager().getDimensionTypes(); + RegistryKey id = dimensionTypes.getKey(current).orElseThrow(RuntimeException::new); + + if (id.equals(DimensionType.THE_END_REGISTRY_KEY)) { + currentDimension = DimensionId.END; + } else if (id.equals(DimensionType.THE_NETHER_REGISTRY_KEY)) { + currentDimension = DimensionId.NETHER; + } + + if (currentDimension != lastDimension) { + Iris.logger.info("Reloading shaderpack on dimension change (" + lastDimension + " -> " + currentDimension + ")"); + + lastDimension = currentDimension; + pipeline = null; + } + } + if (pipeline == null) { - pipeline = new ShaderPipeline(Objects.requireNonNull(currentPack).getProgramSet()); + pipeline = new ShaderPipeline(Objects.requireNonNull(currentPack).getProgramSet(lastDimension)); } return pipeline; diff --git a/src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java b/src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java index 4f14a96199..1683774b28 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java +++ b/src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java @@ -62,8 +62,24 @@ private static Optional loadProperties(Path shaderPath, String name) return Optional.of(properties); } - public ProgramSet getProgramSet() { - return ProgramSet.merged(base, nether); + public ProgramSet getProgramSet(DimensionId dimension) { + ProgramSet overrides; + + switch (dimension) { + case OVERWORLD: + overrides = overworld; + break; + case NETHER: + overrides = nether; + break; + case END: + overrides = end; + break; + default: + throw new IllegalArgumentException("Unknown dimension " + dimension); + } + + return ProgramSet.merged(base, overrides); } public IdMap getIdMap() {