From 55c39659af42cfebfd54141b162c81faa4e394c7 Mon Sep 17 00:00:00 2001 From: Timo Ley Date: Sun, 3 Nov 2024 13:36:39 +0100 Subject: [PATCH] feat: option system changes --- .../cwg/classic/ChunkProviderClassic.java | 19 +++++++++++++------ .../cwg/classic/WorldChunkManagerClassic.java | 3 +-- .../dev/tilera/cwg/hooks/ICavegenHook.java | 6 ++++++ .../tilera/cwg/hooks/SwissCavegenHook.java | 1 - .../tilera/cwg/options/OptionProvider.java | 5 ++--- .../SingleBiomeChunkManagerFactory.java | 7 ++++++- .../vanilla/VanillaChunkManagerFactory.java | 7 ++++++- src/main/resources/META-INF/cwg_at.cfg | 1 + 8 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/main/java/dev/tilera/cwg/classic/ChunkProviderClassic.java b/src/main/java/dev/tilera/cwg/classic/ChunkProviderClassic.java index 508ec89..81a0c86 100644 --- a/src/main/java/dev/tilera/cwg/classic/ChunkProviderClassic.java +++ b/src/main/java/dev/tilera/cwg/classic/ChunkProviderClassic.java @@ -1,6 +1,8 @@ package dev.tilera.cwg.classic; -import dev.tilera.cwg.api.CwgGlobals; +import dev.tilera.cwg.api.hooks.IHookProvider; +import dev.tilera.cwg.api.options.IGeneratorOptionProvider; +import dev.tilera.cwg.hooks.ICavegenHook; import net.minecraft.block.BlockFalling; import net.minecraft.init.Blocks; import net.minecraft.world.SpawnerAnimals; @@ -17,8 +19,13 @@ import net.minecraftforge.event.terraingen.PopulateChunkEvent.Populate.EventType public class ChunkProviderClassic extends ChunkProviderGenerate { - public ChunkProviderClassic(World world, long seed, boolean features) { + private IGeneratorOptionProvider options; + + public ChunkProviderClassic(World world, long seed, boolean features, IGeneratorOptionProvider options) { super(world, seed, features); + this.options = options; + ICavegenHook hook = options.getValue("cwg:cavegen_hook", IHookProvider.class).getHook(ICavegenHook.class); + hook.setCavegen(this); } @Override @@ -33,7 +40,7 @@ public class ChunkProviderClassic extends ChunkProviderGenerate { this.rand.setSeed((long)p_73153_2_ * i1 + (long)p_73153_3_ * j1 ^ this.worldObj.getSeed()); boolean flag = false; - if (CwgGlobals.getOptionProvider(worldObj).getBoolean("cwg:generator.classic:enableModdedWorldgen")) { + if (options.getBoolean("cwg:generator.classic:enableModdedWorldgen")) { MinecraftForge.EVENT_BUS.post(new PopulateChunkEvent.Pre(p_73153_1_, worldObj, rand, p_73153_2_, p_73153_3_, flag)); } @@ -70,7 +77,7 @@ public class ChunkProviderClassic extends ChunkProviderGenerate { } } - boolean doGen = !CwgGlobals.getOptionProvider(worldObj).getBoolean("cwg:generator.classic:enableModdedWorldgen") || TerrainGen.populate(p_73153_1_, worldObj, rand, p_73153_2_, p_73153_3_, flag, EventType.DUNGEON); + boolean doGen = !options.getBoolean("cwg:generator.classic:enableModdedWorldgen") || TerrainGen.populate(p_73153_1_, worldObj, rand, p_73153_2_, p_73153_3_, flag, EventType.DUNGEON); for (k1 = 0; doGen && k1 < 8; ++k1) { l1 = k + this.rand.nextInt(16) + 8; @@ -106,7 +113,7 @@ public class ChunkProviderClassic extends ChunkProviderGenerate { } } - if (CwgGlobals.getOptionProvider(worldObj).getBoolean("cwg:generator.classic:enableModdedWorldgen")) { + if (options.getBoolean("cwg:generator.classic:enableModdedWorldgen")) { MinecraftForge.EVENT_BUS.post(new PopulateChunkEvent.Post(p_73153_1_, worldObj, rand, p_73153_2_, p_73153_3_, flag)); } @@ -114,7 +121,7 @@ public class ChunkProviderClassic extends ChunkProviderGenerate { } public boolean hasDesertLakes() { - return CwgGlobals.getOptionProvider(worldObj).getBoolean("cwg:classic_extreme_hills"); + return options.getBoolean("cwg:classic_extreme_hills"); } } diff --git a/src/main/java/dev/tilera/cwg/classic/WorldChunkManagerClassic.java b/src/main/java/dev/tilera/cwg/classic/WorldChunkManagerClassic.java index 00f0571..8644e61 100644 --- a/src/main/java/dev/tilera/cwg/classic/WorldChunkManagerClassic.java +++ b/src/main/java/dev/tilera/cwg/classic/WorldChunkManagerClassic.java @@ -2,7 +2,6 @@ package dev.tilera.cwg.classic; import dev.tilera.cwg.api.generator.AbstractChunkManager; import dev.tilera.cwg.api.options.IGeneratorOptionProvider; -import dev.tilera.cwg.api.options.IOption; import dev.tilera.cwg.genlayer.GenLayerAddIslandClassic; import dev.tilera.cwg.genlayer.GenLayerAddSnowClassic; import dev.tilera.cwg.genlayer.GenLayerBiomeClassic; @@ -93,7 +92,7 @@ public class WorldChunkManagerClassic extends AbstractChunkManager{ @Override public IChunkProvider getGenerator(World world) { - return new ChunkProviderClassic(world, world.getSeed(), world.getWorldInfo().isMapFeaturesEnabled()); + return new ChunkProviderClassic(world, world.getSeed(), world.getWorldInfo().isMapFeaturesEnabled(), provider); } @Override diff --git a/src/main/java/dev/tilera/cwg/hooks/ICavegenHook.java b/src/main/java/dev/tilera/cwg/hooks/ICavegenHook.java index 0d3448f..d0dd268 100644 --- a/src/main/java/dev/tilera/cwg/hooks/ICavegenHook.java +++ b/src/main/java/dev/tilera/cwg/hooks/ICavegenHook.java @@ -1,6 +1,7 @@ package dev.tilera.cwg.hooks; import dev.tilera.cwg.api.hooks.IHookProvider; +import net.minecraft.world.gen.ChunkProviderGenerate; import net.minecraft.world.gen.MapGenBase; public interface ICavegenHook extends IHookProvider { @@ -9,4 +10,9 @@ public interface ICavegenHook extends IHookProvider { MapGenBase createRavineGenerator(); + default void setCavegen(ChunkProviderGenerate generator) { + generator.caveGenerator = createCaveGenerator(); + generator.ravineGenerator = createRavineGenerator(); + } + } diff --git a/src/main/java/dev/tilera/cwg/hooks/SwissCavegenHook.java b/src/main/java/dev/tilera/cwg/hooks/SwissCavegenHook.java index 30032b2..ea82832 100644 --- a/src/main/java/dev/tilera/cwg/hooks/SwissCavegenHook.java +++ b/src/main/java/dev/tilera/cwg/hooks/SwissCavegenHook.java @@ -8,7 +8,6 @@ public class SwissCavegenHook implements ICavegenHook { @Override public MapGenBase createCaveGenerator() { - System.out.println("ALECALECALEC"); return new MapGenCavesSwiss(); } diff --git a/src/main/java/dev/tilera/cwg/options/OptionProvider.java b/src/main/java/dev/tilera/cwg/options/OptionProvider.java index 560c683..1121b40 100644 --- a/src/main/java/dev/tilera/cwg/options/OptionProvider.java +++ b/src/main/java/dev/tilera/cwg/options/OptionProvider.java @@ -4,14 +4,13 @@ import java.util.HashMap; import java.util.Map; import dev.tilera.cwg.api.options.IGeneratorOptionProvider; -import dev.tilera.cwg.api.options.IGeneratorOptionRegistry; public class OptionProvider implements IGeneratorOptionProvider { - private IGeneratorOptionRegistry registry; + private IGeneratorOptionProvider registry; private Map storage = new HashMap<>(); - public OptionProvider(IGeneratorOptionRegistry registry) { + public OptionProvider(IGeneratorOptionProvider registry) { this.registry = registry; } diff --git a/src/main/java/dev/tilera/cwg/vanilla/SingleBiomeChunkManagerFactory.java b/src/main/java/dev/tilera/cwg/vanilla/SingleBiomeChunkManagerFactory.java index a8b70b3..bb06c58 100644 --- a/src/main/java/dev/tilera/cwg/vanilla/SingleBiomeChunkManagerFactory.java +++ b/src/main/java/dev/tilera/cwg/vanilla/SingleBiomeChunkManagerFactory.java @@ -3,8 +3,10 @@ package dev.tilera.cwg.vanilla; import dev.tilera.cwg.DelegateChunkManager; import dev.tilera.cwg.api.generator.AbstractChunkManager; import dev.tilera.cwg.api.generator.IChunkManagerFactory; +import dev.tilera.cwg.api.hooks.IHookProvider; import dev.tilera.cwg.api.options.IGeneratorOptionProvider; import dev.tilera.cwg.api.options.IOption; +import dev.tilera.cwg.hooks.ICavegenHook; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.world.biome.WorldChunkManagerHell; @@ -15,9 +17,12 @@ public class SingleBiomeChunkManagerFactory implements IChunkManagerFactory { @Override public AbstractChunkManager createChunkManager(IGeneratorOptionProvider options, World world) { int biomeID = options.getInt("cwg:generator.singleBiome:biomeID"); + ICavegenHook hook = options.getValue("cwg:cavegen_hook", IHookProvider.class).getHook(ICavegenHook.class); + ChunkProviderGenerate generator = new ChunkProviderGenerate(world, world.getSeed(), world.getWorldInfo().isMapFeaturesEnabled()); + hook.setCavegen(generator); return new DelegateChunkManager( options, - new ChunkProviderGenerate(world, world.getSeed(), world.getWorldInfo().isMapFeaturesEnabled()), + generator, new WorldChunkManagerHell(BiomeGenBase.getBiome(biomeID), 1.0f) ); } diff --git a/src/main/java/dev/tilera/cwg/vanilla/VanillaChunkManagerFactory.java b/src/main/java/dev/tilera/cwg/vanilla/VanillaChunkManagerFactory.java index 9fe58e9..3331155 100644 --- a/src/main/java/dev/tilera/cwg/vanilla/VanillaChunkManagerFactory.java +++ b/src/main/java/dev/tilera/cwg/vanilla/VanillaChunkManagerFactory.java @@ -3,8 +3,10 @@ package dev.tilera.cwg.vanilla; import dev.tilera.cwg.DelegateChunkManager; import dev.tilera.cwg.api.generator.AbstractChunkManager; import dev.tilera.cwg.api.generator.IChunkManagerFactory; +import dev.tilera.cwg.api.hooks.IHookProvider; import dev.tilera.cwg.api.options.IGeneratorOptionProvider; import dev.tilera.cwg.api.options.IOption; +import dev.tilera.cwg.hooks.ICavegenHook; import net.minecraft.world.World; import net.minecraft.world.biome.WorldChunkManager; import net.minecraft.world.gen.ChunkProviderGenerate; @@ -13,9 +15,12 @@ public class VanillaChunkManagerFactory implements IChunkManagerFactory { @Override public AbstractChunkManager createChunkManager(IGeneratorOptionProvider options, World world) { + ICavegenHook hook = options.getValue("cwg:cavegen_hook", IHookProvider.class).getHook(ICavegenHook.class); + ChunkProviderGenerate generator = new ChunkProviderGenerate(world, world.getSeed(), world.getWorldInfo().isMapFeaturesEnabled()); + hook.setCavegen(generator); return new DelegateChunkManager( options, - new ChunkProviderGenerate(world, world.getSeed(), world.getWorldInfo().isMapFeaturesEnabled()), + generator, new WorldChunkManager(world) ); } diff --git a/src/main/resources/META-INF/cwg_at.cfg b/src/main/resources/META-INF/cwg_at.cfg index 1c3dba7..13ae69c 100644 --- a/src/main/resources/META-INF/cwg_at.cfg +++ b/src/main/resources/META-INF/cwg_at.cfg @@ -7,5 +7,6 @@ public net.minecraft.world.gen.ChunkProviderGenerate field_73223_w # mineshaftGe public net.minecraft.world.gen.ChunkProviderGenerate field_73225_u # strongholdGenerator public net.minecraft.world.gen.ChunkProviderGenerate field_73233_x # scatteredFeatureGenerator public net.minecraft.world.gen.ChunkProviderGenerate field_73226_t # caveGenerator +public net.minecraft.world.gen.ChunkProviderGenerate field_73232_y # ravineGenerator public net.minecraft.world.gen.NoiseGeneratorOctaves field_76306_b # octaves public net.minecraft.world.gen.NoiseGeneratorOctaves field_76307_a # generatorCollection \ No newline at end of file