From 190f8e3c62f4ecb205ec24cfab0a9cff8e44c3c9 Mon Sep 17 00:00:00 2001 From: Timo Ley Date: Tue, 17 Jan 2023 09:25:09 +0100 Subject: [PATCH] feat: option to enable farlands --- build.gradle | 2 +- src/main/java/dev/tilera/cwg/Config.java | 2 + .../mixins/MixinNoiseGeneratorOctaves.java | 63 +++++++++++++++++++ src/main/resources/cwg.mixins.json | 4 +- 4 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 src/main/java/dev/tilera/cwg/mixins/MixinNoiseGeneratorOctaves.java diff --git a/build.gradle b/build.gradle index d7e4aa9..14e6e59 100644 --- a/build.gradle +++ b/build.gradle @@ -24,7 +24,7 @@ apply from: './gradle/scripts/mixins.gradle' sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 -version = "1.4.0" +version = "1.5.0" group= "dev.tilera.modding" archivesBaseName = "cwg" diff --git a/src/main/java/dev/tilera/cwg/Config.java b/src/main/java/dev/tilera/cwg/Config.java index 90bef30..d29e139 100644 --- a/src/main/java/dev/tilera/cwg/Config.java +++ b/src/main/java/dev/tilera/cwg/Config.java @@ -15,6 +15,7 @@ public class Config { public static boolean disableNewFlowers = false; public static boolean classicExtremeHills = false; public static boolean disableHeightTemperature = false; + public static boolean enableFarlands = false; public static void initConfig() { conf = new Configuration(new File(Loader.instance().getConfigDir(), "ClassicWorldgen.cfg")); @@ -26,6 +27,7 @@ public class Config { classicExtremeHills = conf.getBoolean("classicExtremeHills", "tweaks", classicExtremeHills, "generate 1.6 extreme hills instead of 1.7"); disableHeightTemperature = conf.getBoolean("disableHeightTemperature", "tweaks", disableHeightTemperature, "disable snow on mountains"); changeWorldTypeCommand = conf.getBoolean("changeTypeCommand", "commands", changeWorldTypeCommand, "enable command to change the WorldType"); + enableFarlands = conf.getBoolean("enableFarlands", "tweaks", enableFarlands, "reenable the Farlands!"); conf.save(); } diff --git a/src/main/java/dev/tilera/cwg/mixins/MixinNoiseGeneratorOctaves.java b/src/main/java/dev/tilera/cwg/mixins/MixinNoiseGeneratorOctaves.java new file mode 100644 index 0000000..34df8f3 --- /dev/null +++ b/src/main/java/dev/tilera/cwg/mixins/MixinNoiseGeneratorOctaves.java @@ -0,0 +1,63 @@ +package dev.tilera.cwg.mixins; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +import dev.tilera.cwg.Config; +import net.minecraft.util.MathHelper; +import net.minecraft.world.gen.NoiseGenerator; +import net.minecraft.world.gen.NoiseGeneratorImproved; +import net.minecraft.world.gen.NoiseGeneratorOctaves; + +@Mixin(NoiseGeneratorOctaves.class) +public abstract class MixinNoiseGeneratorOctaves extends NoiseGenerator { + + @Shadow + private NoiseGeneratorImproved[] generatorCollection; + @Shadow + private int octaves; + + /** + * @author tilera + * @reason farlands + */ + @Overwrite + public double[] generateNoiseOctaves(double[] p_76304_1_, int p_76304_2_, int p_76304_3_, int p_76304_4_, int p_76304_5_, int p_76304_6_, int p_76304_7_, double p_76304_8_, double p_76304_10_, double p_76304_12_) { + if (p_76304_1_ == null) + { + p_76304_1_ = new double[p_76304_5_ * p_76304_6_ * p_76304_7_]; + } + else + { + for (int k1 = 0; k1 < p_76304_1_.length; ++k1) + { + p_76304_1_[k1] = 0.0D; + } + } + + double d6 = 1.0D; + + for (int l1 = 0; l1 < this.octaves; ++l1) + { + double d3 = (double)p_76304_2_ * d6 * p_76304_8_; + double d4 = (double)p_76304_3_ * d6 * p_76304_10_; + double d5 = (double)p_76304_4_ * d6 * p_76304_12_; + long i2 = MathHelper.floor_double_long(d3); + long j2 = MathHelper.floor_double_long(d5); + d3 -= (double)i2; + d5 -= (double)j2; + if (!Config.enableFarlands) { + i2 %= 16777216L; + j2 %= 16777216L; + } + d3 += (double)i2; + d5 += (double)j2; + this.generatorCollection[l1].populateNoiseArray(p_76304_1_, d3, d4, d5, p_76304_5_, p_76304_6_, p_76304_7_, p_76304_8_ * d6, p_76304_10_ * d6, p_76304_12_ * d6, d6); + d6 /= 2.0D; + } + + return p_76304_1_; + } + +} diff --git a/src/main/resources/cwg.mixins.json b/src/main/resources/cwg.mixins.json index bd42d91..57ae14e 100644 --- a/src/main/resources/cwg.mixins.json +++ b/src/main/resources/cwg.mixins.json @@ -9,7 +9,9 @@ "MixinBiomeGenHills", "MixinBiomeGenPlains", "MixinBiomeGenSwamp", - "MixinGenDoublePlant"], + "MixinGenDoublePlant", + "MixinNoiseGeneratorOctaves" + ], "injectors": { "defaultRequire": 1 }