diff --git a/src/main/java/net/coderbot/iris/Iris.java b/src/main/java/net/coderbot/iris/Iris.java index f00715f25b..460bd9739d 100644 --- a/src/main/java/net/coderbot/iris/Iris.java +++ b/src/main/java/net/coderbot/iris/Iris.java @@ -13,6 +13,7 @@ import net.coderbot.iris.pipeline.WorldRenderingPipeline; import net.coderbot.iris.pipeline.newshader.NewWorldRenderingPipeline; import net.coderbot.iris.shaderpack.DimensionId; +import net.coderbot.iris.shaderpack.IrisDefines; import net.coderbot.iris.shaderpack.OptionalBoolean; import net.coderbot.iris.shaderpack.ProgramSet; import net.coderbot.iris.shaderpack.ShaderPack; @@ -32,7 +33,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.network.chat.TranslatableComponent; -import net.minecraft.world.level.dimension.DimensionType; import org.jetbrains.annotations.NotNull; import org.lwjgl.glfw.GLFW; diff --git a/src/main/java/net/coderbot/iris/gl/shader/StandardMacros.java b/src/main/java/net/coderbot/iris/gl/shader/StandardMacros.java index a5376ff82f..b59a9e66ad 100644 --- a/src/main/java/net/coderbot/iris/gl/shader/StandardMacros.java +++ b/src/main/java/net/coderbot/iris/gl/shader/StandardMacros.java @@ -37,7 +37,7 @@ private static void define(List defines, String key, String value) { defines.add(new StringPair(key, value)); } - public static Iterable createStandardEnvironmentDefines() { + public static ImmutableList createStandardEnvironmentDefines() { ArrayList standardDefines = new ArrayList<>(); define(standardDefines, "MC_VERSION", getMcVersion()); diff --git a/src/main/java/net/coderbot/iris/shaderpack/IrisDefines.java b/src/main/java/net/coderbot/iris/shaderpack/IrisDefines.java new file mode 100644 index 0000000000..d99ead8f3d --- /dev/null +++ b/src/main/java/net/coderbot/iris/shaderpack/IrisDefines.java @@ -0,0 +1,41 @@ +package net.coderbot.iris.shaderpack; + +import com.google.common.collect.ImmutableList; +import net.coderbot.iris.Iris; +import net.coderbot.iris.gl.shader.StandardMacros; +import net.coderbot.iris.uniforms.BiomeParameters; +import net.minecraft.world.level.biome.Biome; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.regex.Pattern; + +public class IrisDefines { + private static final Pattern SEMVER_PATTERN = Pattern.compile("(?\\d+)\\.(?\\d+)\\.*(?\\d*)(.*)"); + + private static void define(List defines, String key) { + defines.add(new StringPair(key, "")); + } + + private static void define(List defines, String key, String value) { + defines.add(new StringPair(key, value)); + } + + public static ImmutableList createIrisReplacements() { + ArrayList s = new ArrayList<>(StandardMacros.createStandardEnvironmentDefines()); + define(s, "PPT_NONE", "0"); + define(s, "PPT_RAIN", "1"); + define(s, "PPT_SNOW", "2"); + define(s, "BIOME_SWAMP_HILLS", "-1"); + + BiomeParameters.getBiomeMap().forEach((biome, id) -> define(s, "BIOME_" + biome.location().getPath().toUpperCase(Locale.ROOT), String.valueOf(id))); + + Biome.BiomeCategory[] categories = Biome.BiomeCategory.values(); + for (int i = 0; i < categories.length; i++) { + define(s, "CAT_" + categories[i].getName().toUpperCase(Locale.ROOT), String.valueOf(i)); + } + + return ImmutableList.copyOf(s); + } +} diff --git a/src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java b/src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java index 85f544389e..7f829c3cf1 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java +++ b/src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java @@ -47,17 +47,7 @@ import java.nio.file.Files; import java.nio.file.NoSuchFileException; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collections; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Properties; -import java.util.Set; +import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -163,9 +153,10 @@ public ShaderPack(Path root, Map changedConfigs, Iterable replacements = IrisDefines.createIrisReplacements(); Iterable finalEnvironmentDefines = environmentDefines; this.shaderProperties = loadProperties(root, "shaders.properties") - .map(source -> new ShaderProperties(source, shaderPackOptions, finalEnvironmentDefines)) + .map(source -> new ShaderProperties(source, shaderPackOptions, finalEnvironmentDefines, replacements)) .orElseGet(ShaderProperties::empty); activeFeatures = new HashSet<>(); @@ -250,7 +241,8 @@ public ShaderPack(Path root, Map changedConfigs, Iterable finalEnvironmentDefines1 = environmentDefines; + ArrayList finalEnvironmentDefines1 = new ArrayList<>((Collection) finalEnvironmentDefines); + finalEnvironmentDefines1.addAll(IrisDefines.createIrisReplacements()); this.sourceProvider = (path) -> { String pathString = path.getPathString(); // Removes the first "/" in the path if present, and the file diff --git a/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java b/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java index 31e12f2657..32bb6eddf8 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java +++ b/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java @@ -111,7 +111,11 @@ private ShaderProperties() { } // TODO: Is there a better solution than having ShaderPack pass a root path to ShaderProperties to be able to read textures? - public ShaderProperties(String contents, ShaderPackOptions shaderPackOptions, Iterable environmentDefines) { + public ShaderProperties(String contents, ShaderPackOptions shaderPackOptions, Iterable environmentDefines, Iterable replacements) { + for (StringPair pair : replacements) { + contents = contents.replace(pair.getKey(), pair.getValue()); + } + String preprocessedContents = PropertiesPreprocessor.preprocessSource(contents, shaderPackOptions, environmentDefines); Properties preprocessed = new OrderBackedProperties(); diff --git a/src/main/java/net/coderbot/iris/uniforms/BiomeParameters.java b/src/main/java/net/coderbot/iris/uniforms/BiomeParameters.java index fd1e3d7891..bbbe0c60f0 100644 --- a/src/main/java/net/coderbot/iris/uniforms/BiomeParameters.java +++ b/src/main/java/net/coderbot/iris/uniforms/BiomeParameters.java @@ -26,7 +26,6 @@ public static Object2IntMap> getBiomeMap() { } public static void addBiomeUniforms(UniformHolder uniforms) { - uniforms .uniform1i(PER_TICK, "biome", playerI(player -> biomeMap.getInt(player.level.getBiome(player.blockPosition()).unwrapKey().orElse(null)))) @@ -45,33 +44,7 @@ public static void addBiomeUniforms(UniformHolder uniforms) { .uniform1f(PER_TICK, "rainfall", playerF(player -> (player.level.getBiome(player.blockPosition()).value()).getDownfall())) .uniform1f(PER_TICK, "temperature", playerF(player -> - player.level.getBiome(player.blockPosition()).value().getBaseTemperature())) - - - .uniform1i(ONCE, "PPT_NONE", () -> 0) - .uniform1i(ONCE, "PPT_RAIN", () -> 1) - .uniform1i(ONCE, "PPT_SNOW", () -> 2) - // Temporary fix for Sildur's Vibrant - .uniform1i(ONCE, "BIOME_SWAMP_HILLS", () -> -1); - - - - - addBiomes(uniforms); - addCategories(uniforms); - - } - - private static void addBiomes(UniformHolder uniforms) { - biomeMap.forEach((biome, id) -> uniforms.uniform1i(ONCE, "BIOME_" + biome.location().getPath().toUpperCase(Locale.ROOT), () -> id)); - } - - public static void addCategories(UniformHolder uniforms) { - Biome.BiomeCategory[] categories = Biome.BiomeCategory.values(); - for (int i = 0; i < categories.length; i++) { - int finalI = i; - uniforms.uniform1i(ONCE, "CAT_" + categories[i].getName().toUpperCase(Locale.ROOT), () -> finalI); - } + player.level.getBiome(player.blockPosition()).value().getBaseTemperature())); } static IntSupplier playerI(ToIntFunction function) {