From 6f0f8efeba706435f6de905db1c3ced0f665a230 Mon Sep 17 00:00:00 2001 From: dags- Date: Sun, 10 May 2020 00:48:32 +0100 Subject: [PATCH] - only apply custom redwood trees to minecraft biomes - added options to use other mods' generators for nether/end - added options to change bedrock material, depth, and variance --- TerraForgedMod/build.gradle | 10 +-- .../java/com/terraforged/mod/TerraWorld.java | 75 +++++++++++-------- .../biome/provider/AbstractBiomeProvider.java | 20 +++-- .../mod/biome/provider/BiomeProvider.java | 10 +-- .../mod/chunk/TerraChunkGenerator.java | 3 +- .../mod/decorator/base/BedrockDecorator.java | 34 ++++++++- .../com/terraforged/mod/gui/ScrollPane.java | 10 +++ .../terraforged/mod/gui/SettingsScreen.java | 11 ++- .../mod/gui/element/TerraTextInput.java | 56 ++++++++++++++ .../element/{Toggle.java => TerraToggle.java} | 6 +- .../mod/gui/page/DimensionsPage.java | 68 +++++++++++++++++ .../com/terraforged/mod/gui/page/Page.java | 13 +++- .../mod/settings/DimesionSettings.java | 74 ++++++++++++++++++ .../mod/settings/SettingsHelper.java | 12 ++- .../mod/settings/TerraSettings.java | 2 + .../terraforged/features/trees/redwood.json | 3 + gradle.properties | 4 +- 17 files changed, 348 insertions(+), 63 deletions(-) create mode 100644 TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraTextInput.java rename TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/{Toggle.java => TerraToggle.java} (95%) create mode 100644 TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/DimensionsPage.java create mode 100644 TerraForgedMod/src/main/java/com/terraforged/mod/settings/DimesionSettings.java diff --git a/TerraForgedMod/build.gradle b/TerraForgedMod/build.gradle index 923c40d..b165533 100644 --- a/TerraForgedMod/build.gradle +++ b/TerraForgedMod/build.gradle @@ -24,9 +24,9 @@ repositories { dependencies { minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}" compile project(":Noise2D") - compile (project(":TerraForgedCore")) { transitive false } - compile (project(":FeatureManager")) { transitive false } - compile (project(":TerraForgedAPI")) { transitive false } + compile(project(":TerraForgedCore")) { transitive false } + compile(project(":FeatureManager")) { transitive false } + compile(project(":TerraForgedAPI")) { transitive false } } minecraft { @@ -58,7 +58,7 @@ minecraft { } task collectClasses(type: Copy) { - configurations.collectMany { it.allDependencies }.findAll{ it instanceof ProjectDependency }.each { + configurations.collectMany { it.allDependencies }.findAll { it instanceof ProjectDependency }.each { ProjectDependency project = (ProjectDependency) it from("$project.dependencyProject.buildDir/classes/java/main") } @@ -66,7 +66,7 @@ task collectClasses(type: Copy) { } task collectResources(type: Copy) { - configurations.collectMany { it.allDependencies }.findAll{ it instanceof ProjectDependency }.each { + configurations.collectMany { it.allDependencies }.findAll { it instanceof ProjectDependency }.each { ProjectDependency project = (ProjectDependency) it from("$project.dependencyProject.buildDir/resources/main") } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/TerraWorld.java b/TerraForgedMod/src/main/java/com/terraforged/mod/TerraWorld.java index 260e032..0c7d479 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/TerraWorld.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/TerraWorld.java @@ -33,6 +33,7 @@ import com.terraforged.mod.chunk.TerraContext; import com.terraforged.mod.chunk.TerraGenSettings; import com.terraforged.mod.chunk.test.TestChunkGenerator; import com.terraforged.mod.gui.SettingsScreen; +import com.terraforged.mod.settings.DimesionSettings; import com.terraforged.mod.settings.SettingsHelper; import com.terraforged.mod.settings.TerraSettings; import com.terraforged.mod.util.Environment; @@ -46,6 +47,7 @@ import net.minecraft.world.biome.provider.OverworldBiomeProviderSettings; import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.gen.ChunkGenerator; import net.minecraft.world.gen.OverworldGenSettings; +import net.minecraft.world.storage.WorldInfo; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -66,6 +68,44 @@ public class TerraWorld extends WorldType { TerraWorld.types.add(this); } + @Override + public ChunkGenerator createChunkGenerator(World world) { + if (world.getDimension().getType() == DimensionType.OVERWORLD) { + WorldInfo info = world.getWorldInfo(); + int version = SettingsHelper.getVersion(info); + TerraSettings settings = SettingsHelper.getSettings(info); + SettingsHelper.syncSettings(world.getWorldInfo(), settings, version); + settings.dimensions.dimensionGenerators.apply(world.getWorldInfo()); + + Terrains terrains = Terrains.create(settings); + + OverworldGenSettings genSettings = new TerraGenSettings(settings.structures); + OverworldBiomeProviderSettings biomeSettings = new OverworldBiomeProviderSettings(world.getWorldInfo()); + biomeSettings.setGeneratorSettings(genSettings); + world.getWorldInfo().setGeneratorOptions(NBTHelper.serializeCompact(settings)); + + TerraContext context = new TerraContext(world, terrains, settings); + BiomeProvider biomeProvider = new BiomeProvider(context); + + Log.debug("Creating Terra {} generator", world.getDimension().getType().getRegistryName()); + return factory.create(context, biomeProvider, genSettings); + } + + if (world.getDimension().getType() == DimensionType.THE_NETHER) { + WorldType type = DimesionSettings.getWorldType(world.getWorldInfo(), DimensionType.THE_NETHER); + Log.debug("Creating {} {} generator", type.getName(), world.getDimension().getType().getRegistryName()); + return type.createChunkGenerator(world); + } + + if (world.getDimension().getType() == DimensionType.THE_END) { + WorldType type = DimesionSettings.getWorldType(world.getWorldInfo(), DimensionType.THE_END); + Log.debug("Creating {} {} generator", type.getName(), world.getDimension().getType().getRegistryName()); + return type.createChunkGenerator(world); + } + + return super.createChunkGenerator(world); + } + @Override public double getHorizon(World world) { return 0; @@ -76,41 +116,12 @@ public class TerraWorld extends WorldType { return 260.0F; } - @Override - public ChunkGenerator createChunkGenerator(World world) { - if (world.getDimension().getType() != DimensionType.OVERWORLD) { - return world.getDimension().createChunkGenerator(); - } - - Log.debug("Creating {} generator", world.getDimension().getType()); - - int version = SettingsHelper.getVersion(world.getWorldInfo()); - TerraSettings settings = SettingsHelper.getSettings(world); - SettingsHelper.syncSettings(world.getWorldInfo(), settings, version); - - Terrains terrains = Terrains.create(settings); - - OverworldGenSettings genSettings = new TerraGenSettings(settings.structures); - OverworldBiomeProviderSettings biomeSettings = new OverworldBiomeProviderSettings(world.getWorldInfo()); - biomeSettings.setGeneratorSettings(genSettings); - world.getWorldInfo().setGeneratorOptions(NBTHelper.serializeCompact(settings)); - - TerraContext context = new TerraContext(world, terrains, settings); - BiomeProvider biomeProvider = new BiomeProvider(context); - - return getGeneratorFactory().create(context, biomeProvider, genSettings); - } - @Override @OnlyIn(Dist.CLIENT) public void onCustomizeButton(Minecraft mc, CreateWorldScreen gui) { mc.displayGuiScreen(new SettingsScreen(gui)); } - public ChunkGeneratorFactory getGeneratorFactory() { - return factory; - } - public static void init() { Log.info("Registered world type"); new TerraWorld("terraforged", TerraChunkGenerator::new); @@ -120,9 +131,13 @@ public class TerraWorld extends WorldType { } } + public static boolean isTerraType(WorldType type) { + return types.contains(type); + } + public static boolean isTerraWorld(IWorld world) { if (world instanceof World) { - return types.contains(((World) world).getWorldType()); + return isTerraType(((World) world).getWorldType()); } return false; } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/AbstractBiomeProvider.java b/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/AbstractBiomeProvider.java index 19aea74..99cb204 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/AbstractBiomeProvider.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/AbstractBiomeProvider.java @@ -25,21 +25,24 @@ package com.terraforged.mod.biome.provider; -import com.google.common.collect.ImmutableSet; import net.minecraft.util.math.BlockPos; import net.minecraft.world.biome.Biome; -import net.minecraft.world.biome.Biomes; +import net.minecraftforge.common.BiomeDictionary; +import net.minecraftforge.registries.ForgeRegistries; import java.util.List; import java.util.Random; import java.util.Set; +import java.util.stream.Collectors; public abstract class AbstractBiomeProvider extends net.minecraft.world.biome.provider.BiomeProvider { - protected static final Set defaultBiomes = ImmutableSet.of(Biomes.OCEAN, Biomes.PLAINS, Biomes.DESERT, Biomes.MOUNTAINS, Biomes.FOREST, Biomes.TAIGA, Biomes.SWAMP, Biomes.RIVER, Biomes.FROZEN_OCEAN, Biomes.FROZEN_RIVER, Biomes.SNOWY_TUNDRA, Biomes.SNOWY_MOUNTAINS, Biomes.MUSHROOM_FIELDS, Biomes.MUSHROOM_FIELD_SHORE, Biomes.BEACH, Biomes.DESERT_HILLS, Biomes.WOODED_HILLS, Biomes.TAIGA_HILLS, Biomes.MOUNTAIN_EDGE, Biomes.JUNGLE, Biomes.JUNGLE_HILLS, Biomes.JUNGLE_EDGE, Biomes.DEEP_OCEAN, Biomes.STONE_SHORE, Biomes.SNOWY_BEACH, Biomes.BIRCH_FOREST, Biomes.BIRCH_FOREST_HILLS, Biomes.DARK_FOREST, Biomes.SNOWY_TAIGA, Biomes.SNOWY_TAIGA_HILLS, Biomes.GIANT_TREE_TAIGA, Biomes.GIANT_TREE_TAIGA_HILLS, Biomes.WOODED_MOUNTAINS, Biomes.SAVANNA, Biomes.SAVANNA_PLATEAU, Biomes.BADLANDS, Biomes.WOODED_BADLANDS_PLATEAU, Biomes.BADLANDS_PLATEAU, Biomes.WARM_OCEAN, Biomes.LUKEWARM_OCEAN, Biomes.COLD_OCEAN, Biomes.DEEP_WARM_OCEAN, Biomes.DEEP_LUKEWARM_OCEAN, Biomes.DEEP_COLD_OCEAN, Biomes.DEEP_FROZEN_OCEAN, Biomes.SUNFLOWER_PLAINS, Biomes.DESERT_LAKES, Biomes.GRAVELLY_MOUNTAINS, Biomes.FLOWER_FOREST, Biomes.TAIGA_MOUNTAINS, Biomes.SWAMP_HILLS, Biomes.ICE_SPIKES, Biomes.MODIFIED_JUNGLE, Biomes.MODIFIED_JUNGLE_EDGE, Biomes.TALL_BIRCH_FOREST, Biomes.TALL_BIRCH_HILLS, Biomes.DARK_FOREST_HILLS, Biomes.SNOWY_TAIGA_MOUNTAINS, Biomes.GIANT_SPRUCE_TAIGA, Biomes.GIANT_SPRUCE_TAIGA_HILLS, Biomes.MODIFIED_GRAVELLY_MOUNTAINS, Biomes.SHATTERED_SAVANNA, Biomes.SHATTERED_SAVANNA_PLATEAU, Biomes.ERODED_BADLANDS, Biomes.MODIFIED_WOODED_BADLANDS_PLATEAU, Biomes.MODIFIED_BADLANDS_PLATEAU); - public AbstractBiomeProvider() { - super(defaultBiomes); + super(getOverworldBiomes()); + } + + public Set getAvailableBiomes() { + return super.field_226837_c_; } @Override @@ -55,4 +58,11 @@ public abstract class AbstractBiomeProvider extends net.minecraft.world.biome.pr public abstract Set getBiomesInSquare(int x, int y, int z, int size); public abstract BlockPos findBiomePosition(int centerX, int centerY, int centerZ, int range, List biomes, Random random); + + private static Set getOverworldBiomes() { + return ForgeRegistries.BIOMES.getValues().stream() + .map(biome -> biome.delegate.get()) + .filter(biome -> BiomeDictionary.getTypes(biome).contains(BiomeDictionary.Type.OVERWORLD)) + .collect(Collectors.toSet()); + } } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/BiomeProvider.java b/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/BiomeProvider.java index 0d46c2e..5e7bc4f 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/BiomeProvider.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/BiomeProvider.java @@ -139,10 +139,10 @@ public class BiomeProvider extends AbstractBiomeProvider { } @Override - public boolean hasStructure(Structure structureIn) { - return this.hasStructureCache.computeIfAbsent(structureIn, (p_205006_1_) -> { - for (Biome biome : defaultBiomes) { - if (biome.hasStructure(p_205006_1_)) { + public boolean hasStructure(Structure structure) { + return this.hasStructureCache.computeIfAbsent(structure, (name) -> { + for (Biome biome : getAvailableBiomes()) { + if (biome.hasStructure(name)) { return true; } } @@ -153,7 +153,7 @@ public class BiomeProvider extends AbstractBiomeProvider { @Override public Set getSurfaceBlocks() { if (this.topBlocksCache.isEmpty()) { - for (Biome biome : defaultBiomes) { + for (Biome biome : getAvailableBiomes()) { this.topBlocksCache.add(biome.getSurfaceBuilderConfig().getTop()); } } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/TerraChunkGenerator.java b/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/TerraChunkGenerator.java index 9210d43..45465db 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/TerraChunkGenerator.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/TerraChunkGenerator.java @@ -368,12 +368,13 @@ public class TerraChunkGenerator extends ObfHelperChunkGenerator implements return option.mouseReleased(x, y, button); } + @Override + public boolean keyPressed(int i, int j, int k) { + return option.keyPressed(i, j, k); + } + + @Override + public boolean charTyped(char c, int code) { + return option.charTyped(c, code); + } + @Override public void render(int index, int top, int left, int width, int height, int mouseX, int mouseY, boolean wut, float partialTicks) { int optionWidth = Math.min(396, width); diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/SettingsScreen.java b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/SettingsScreen.java index 6364996..cae2e4b 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/SettingsScreen.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/SettingsScreen.java @@ -28,6 +28,7 @@ package com.terraforged.mod.gui; import com.terraforged.mod.gui.element.TerraButton; import com.terraforged.mod.gui.element.TerraLabel; import com.terraforged.mod.gui.page.ClimatePage; +import com.terraforged.mod.gui.page.DimensionsPage; import com.terraforged.mod.gui.page.FeaturePage; import com.terraforged.mod.gui.page.FilterPage; import com.terraforged.mod.gui.page.GeneratorPage; @@ -70,7 +71,8 @@ public class SettingsScreen extends OverlayScreen { new RiverPage(settings, preview), new FilterPage(settings, preview), new FeaturePage(settings), - new StructurePage(settings) + new StructurePage(settings), + new DimensionsPage(settings), }; } @@ -249,6 +251,13 @@ public class SettingsScreen extends OverlayScreen { return a || b || c; } + @Override + public boolean charTyped(char c, int code) { + boolean a = pages[pageIndex].action(pane -> pane.charTyped(c, code)); + boolean b = preview.action(pane -> pane.charTyped(c, code)); + return a || b || super.charTyped(c, code); + } + @Override public void onClose() { for (Page page : pages) { diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraTextInput.java b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraTextInput.java new file mode 100644 index 0000000..42c5d3e --- /dev/null +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraTextInput.java @@ -0,0 +1,56 @@ +package com.terraforged.mod.gui.element; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.widget.TextFieldWidget; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.StringNBT; + +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Predicate; + +public class TerraTextInput extends TextFieldWidget implements Element, Consumer { + + private final CompoundNBT value; + private final List tooltip; + private Predicate validator = s -> true; + private Consumer callback = t -> {}; + + public TerraTextInput(String name, CompoundNBT value) { + super(Minecraft.getInstance().fontRenderer, 0, 0, 100, 20, name); + this.value = value; + this.tooltip = Element.readTooltip(value); + setText(value.getString("value")); + setResponder(this); + } + + public void setColorValidator(Predicate validator) { + this.validator = validator; + } + + @Override + public boolean keyPressed(int i, int j, int k) { + return super.keyPressed(i, j, k); + } + + @Override + public boolean charTyped(char c, int code) { + return super.charTyped(c, code); + } + + @Override + public List getTooltip() { + return tooltip; + } + + @Override + public void accept(String text) { + value.put("value", StringNBT.valueOf(text)); + callback.accept(this); + if (validator.test(text)) { + setTextColor(14737632); + } else { + setTextColor(0xffff3f30); + } + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/Toggle.java b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraToggle.java similarity index 95% rename from TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/Toggle.java rename to TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraToggle.java index e32fbf1..27946e9 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/Toggle.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraToggle.java @@ -32,7 +32,7 @@ import net.minecraftforge.common.util.Constants; import java.util.List; -public class Toggle extends TerraButton { +public class TerraToggle extends TerraButton { private final String prefix; private final CompoundNBT value; @@ -42,7 +42,7 @@ public class Toggle extends TerraButton { private int index; private Runnable callback = () -> {}; - public Toggle(String prefix, CompoundNBT value) { + public TerraToggle(String prefix, CompoundNBT value) { super(value.getString("value")); this.value = value; this.prefix = prefix; @@ -58,7 +58,7 @@ public class Toggle extends TerraButton { setMessage(prefix + value.getString("value")); } - public Toggle callback(Runnable runnable) { + public TerraToggle callback(Runnable runnable) { this.callback = runnable; return this; } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/DimensionsPage.java b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/DimensionsPage.java new file mode 100644 index 0000000..0fece56 --- /dev/null +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/DimensionsPage.java @@ -0,0 +1,68 @@ +package com.terraforged.mod.gui.page; + +import com.terraforged.mod.TerraWorld; +import com.terraforged.mod.gui.OverlayScreen; +import com.terraforged.mod.gui.element.TerraTextInput; +import com.terraforged.mod.settings.TerraSettings; +import com.terraforged.mod.util.nbt.NBTHelper; +import net.minecraft.client.gui.widget.Widget; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.ListNBT; +import net.minecraft.nbt.StringNBT; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.WorldType; +import net.minecraftforge.registries.ForgeRegistries; + +public class DimensionsPage extends BasePage { + + private final TerraSettings settings; + private final CompoundNBT dimensionSettings; + + public DimensionsPage(TerraSettings settings) { + this.settings = settings; + this.dimensionSettings = NBTHelper.serialize(settings.dimensions); + + CompoundNBT generators = dimensionSettings.getCompound("dimensionGenerators").getCompound("value"); + for (String name : generators.keySet()) { + CompoundNBT setting = generators.getCompound(name); + setting.put("#options", getWorldTypes()); + } + } + + @Override + public String getTitle() { + return "Dimension Settings"; + } + + @Override + public void save() { + NBTHelper.deserialize(dimensionSettings, settings.dimensions); + } + + @Override + public void init(OverlayScreen parent) { + Column left = getColumn(0); + addElements(left.left, left.top, left, dimensionSettings, true, left.scrollPane::addButton, this::update); + } + + @Override + public void onAddWidget(Widget widget) { + if (widget instanceof TerraTextInput) { + TerraTextInput input = (TerraTextInput) widget; + input.setColorValidator(string -> ForgeRegistries.BLOCKS.containsKey(new ResourceLocation(string))); + } + } + + private static ListNBT getWorldTypes() { + ListNBT options = new ListNBT(); + for (WorldType type : WorldType.WORLD_TYPES) { + if (type == null || (type.getId() >= 1 && type.getId() <= 6) || type.getId() == 8) { + continue; + } + if (!TerraWorld.isTerraType(type)) { + options.add(StringNBT.valueOf(type.getName())); + } + } + return options; + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/Page.java b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/Page.java index f806fad..824a562 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/Page.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/Page.java @@ -28,10 +28,10 @@ package com.terraforged.mod.gui.page; import com.terraforged.mod.gui.OverlayRenderer; import com.terraforged.mod.gui.OverlayScreen; import com.terraforged.mod.gui.ScrollPane; -import com.terraforged.mod.gui.element.TerraButton; import com.terraforged.mod.gui.element.TerraLabel; import com.terraforged.mod.gui.element.TerraSlider; -import com.terraforged.mod.gui.element.Toggle; +import com.terraforged.mod.gui.element.TerraTextInput; +import com.terraforged.mod.gui.element.TerraToggle; import com.terraforged.mod.util.nbt.NBTHelper; import net.minecraft.client.gui.IGuiEventListener; import net.minecraft.client.gui.screen.Screen; @@ -144,6 +144,7 @@ public abstract class Page implements IGuiEventListener, OverlayRenderer { button.x = x; button.y = top.getAndAdd(SLIDER_HEIGHT + SLIDER_PAD); consumer.accept(button); + onAddWidget(button); } else if (deep) { INBT child = value.get("value"); if (child == null || child.getId() != Constants.NBT.TAG_COMPOUND) { @@ -170,14 +171,18 @@ public abstract class Page implements IGuiEventListener, OverlayRenderer { } else if (type == Constants.NBT.TAG_FLOAT) { return new TerraSlider.Float(name + ": ", value).callback(callback); } else if (type == Constants.NBT.TAG_STRING && value.contains("#options")) { - return new Toggle(name + ": ", value).callback(callback); + return new TerraToggle(name + ": ", value).callback(callback); } else if (type == Constants.NBT.TAG_STRING) { - return new TerraButton(name); + return new TerraTextInput(name, value); } else { return null; } } + public void onAddWidget(Widget widget) { + + } + public static class Column { public final int left; diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/settings/DimesionSettings.java b/TerraForgedMod/src/main/java/com/terraforged/mod/settings/DimesionSettings.java new file mode 100644 index 0000000..7290350 --- /dev/null +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/settings/DimesionSettings.java @@ -0,0 +1,74 @@ +package com.terraforged.mod.settings; + +import com.terraforged.core.util.serialization.annotation.Comment; +import com.terraforged.core.util.serialization.annotation.Range; +import com.terraforged.core.util.serialization.annotation.Serializable; +import com.terraforged.mod.TerraWorld; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.StringNBT; +import net.minecraft.world.WorldType; +import net.minecraft.world.dimension.DimensionType; +import net.minecraft.world.storage.WorldInfo; +import org.jline.utils.Log; + +@Serializable +public class DimesionSettings { + + public BaseDecorator baseLayer = new BaseDecorator(); + + public DimensionGenerators dimensionGenerators = new DimensionGenerators(); + + @Serializable + public static class BaseDecorator { + + @Comment("Controls the material that should be used in the world's base layer") + public String material = "minecraft:bedrock"; + + @Range(min = 0, max = 10) + @Comment("Controls the minimum height of the world's base layer") + public int minDepth = 1; + + @Range(min = 0, max = 10) + @Comment("Controls the amount of height randomness of the world's base layer") + public int variance = 4; + } + + @Serializable + public static class DimensionGenerators { + + @Comment("Select the nether generator") + public String nether = "default"; + + @Comment("Select the end generator") + public String end = "default"; + + public void apply(WorldInfo info) { + set(info, DimensionType.THE_NETHER, nether); + set(info, DimensionType.THE_END, end); + } + } + + public static WorldType getWorldType(WorldInfo info, DimensionType type) { + String generator = info.getDimensionData(type).getString("TerraDelegateGenerator"); + return getWorldType(generator); + } + + private static void set(WorldInfo info, DimensionType type, String value) { + CompoundNBT data = info.getDimensionData(type); + data.put("TerraDelegateGenerator", StringNBT.valueOf(getWorldType(value).getName())); + info.setDimensionData(type, data); + } + + private static WorldType getWorldType(String name) { + WorldType type = WorldType.byName(name); + if (type == null) { + Log.warn("WorldType {} does not exist. Reverting to default", name); + return WorldType.DEFAULT; + } + if (TerraWorld.isTerraType(type)) { + Log.warn("Cannot set TerraForged as world type for {}", name); + return WorldType.DEFAULT; + } + return type; + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/settings/SettingsHelper.java b/TerraForgedMod/src/main/java/com/terraforged/mod/settings/SettingsHelper.java index 56014ef..9b5e0c8 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/settings/SettingsHelper.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/settings/SettingsHelper.java @@ -8,7 +8,7 @@ import com.terraforged.mod.Log; import com.terraforged.mod.TerraWorld; import com.terraforged.mod.util.nbt.NBTHelper; import net.minecraft.nbt.CompoundNBT; -import net.minecraft.world.IWorld; +import net.minecraft.world.World; import net.minecraft.world.storage.WorldInfo; import java.io.BufferedReader; @@ -72,9 +72,13 @@ public class SettingsHelper { NBTHelper.deserialize(options, dest); } - public static TerraSettings getSettings(IWorld world) { + public static TerraSettings getSettings(World world) { + return getSettings(world.getWorldInfo()); + } + + public static TerraSettings getSettings(WorldInfo info) { TerraSettings settings = new TerraSettings(); - if (world.getWorldInfo().getGeneratorOptions().isEmpty()) { + if (info.getGeneratorOptions().isEmpty()) { if (SETTINGS_FILE.exists()) { try (Reader reader = new BufferedReader(new FileReader(SETTINGS_FILE))) { Log.info("Loading generator settings from json"); @@ -87,7 +91,7 @@ public class SettingsHelper { } } else { Log.info("Loading generator settings from level.dat"); - NBTHelper.deserialize(world.getWorldInfo().getGeneratorOptions(), settings); + NBTHelper.deserialize(info.getGeneratorOptions(), settings); } return settings; } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/settings/TerraSettings.java b/TerraForgedMod/src/main/java/com/terraforged/mod/settings/TerraSettings.java index dee2fbb..e880506 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/settings/TerraSettings.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/settings/TerraSettings.java @@ -36,4 +36,6 @@ public class TerraSettings extends Settings { public FeatureSettings features = new FeatureSettings(); public StructureSettings structures = new StructureSettings(); + + public DimesionSettings dimensions = new DimesionSettings(); } diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/redwood.json b/TerraForgedMod/src/main/resources/data/terraforged/features/trees/redwood.json index 69f0998..e9fb356 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/redwood.json +++ b/TerraForgedMod/src/main/resources/data/terraforged/features/trees/redwood.json @@ -1,4 +1,7 @@ { + "biomes": [ + "minecraft:*" + ], "match": [ [ "minecraft:mega_spruce_tree" diff --git a/gradle.properties b/gradle.properties index a141690..01967c6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ -mod_version=0.0.13 +mod_version=0.0.14 mc_version=1.15.2 -forge_version=31.1.1 +forge_version=31.1.77 mcp_channel=snapshot mcp_version=20200225-1.15.1 org.gradle.jvmargs=-Xmx4G