diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/material/WGTags.java b/TerraForgedAPI/src/main/java/com/terraforged/api/material/WGTags.java index e968e40..f2c741a 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/material/WGTags.java +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/material/WGTags.java @@ -25,11 +25,15 @@ package com.terraforged.api.material; +import com.terraforged.api.material.state.StateTagPredicate; import net.minecraft.block.Block; +import net.minecraft.block.BlockState; import net.minecraft.tags.BlockTags; import net.minecraft.tags.Tag; import net.minecraft.util.ResourceLocation; +import java.util.function.Predicate; + public class WGTags { public static final Tag STONE = tag("wg_stone"); @@ -45,4 +49,8 @@ public class WGTags { private static Tag tag(String name) { return new BlockTags.Wrapper(new ResourceLocation("forge", name)); } + + public static Predicate stone() { + return new StateTagPredicate(STONE); + } } diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/material/state/StateTagPredicate.java b/TerraForgedAPI/src/main/java/com/terraforged/api/material/state/StateTagPredicate.java new file mode 100644 index 0000000..87f0d5f --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/material/state/StateTagPredicate.java @@ -0,0 +1,21 @@ +package com.terraforged.api.material.state; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.tags.Tag; + +import java.util.function.Predicate; + +public class StateTagPredicate implements Predicate { + + private final Tag tag; + + public StateTagPredicate(Tag tag) { + this.tag = tag; + } + + @Override + public boolean test(BlockState state) { + return tag.contains(state.getBlock()); + } +} 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/TerraForgedMod.java b/TerraForgedMod/src/main/java/com/terraforged/mod/TerraForgedMod.java index 7898c6d..83f36db 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/TerraForgedMod.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/TerraForgedMod.java @@ -37,6 +37,7 @@ import com.terraforged.mod.util.DataPackFinder; import com.terraforged.mod.util.Environment; import net.minecraft.world.biome.Biomes; import net.minecraft.world.gen.feature.Feature; +import net.minecraft.world.gen.feature.OreFeatureConfig; import net.minecraft.world.gen.placement.Placement; import net.minecraftforge.common.BiomeDictionary; import net.minecraftforge.event.RegistryEvent; @@ -62,11 +63,14 @@ public class TerraForgedMod { TerraWorld.init(); SaplingManager.init(); TerraCommand.init(); - SettingsHelper.moveSettings(); + SettingsHelper.initSettings(); // temp fix BiomeDictionary.addTypes(Biomes.BAMBOO_JUNGLE, BiomeDictionary.Type.OVERWORLD); BiomeDictionary.addTypes(Biomes.BAMBOO_JUNGLE_HILLS, BiomeDictionary.Type.OVERWORLD); + + // allows ores to replace any world-gen stone type + OreFeatureConfig.FillerBlockType.create("WG_STONE", "wg_stone", WGTags.stone()); } @SubscribeEvent 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/gui/preview/Preview.java b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/Preview.java index 0ccac71..226d03d 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/Preview.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/Preview.java @@ -35,6 +35,7 @@ import com.terraforged.core.util.concurrent.ThreadPool; import com.terraforged.core.util.concurrent.cache.CacheEntry; import com.terraforged.core.world.GeneratorContext; import com.terraforged.core.world.WorldGeneratorFactory; +import com.terraforged.core.world.heightmap.Levels; import com.terraforged.core.world.terrain.Terrain; import com.terraforged.core.world.terrain.Terrains; import com.terraforged.mod.util.nbt.NBTHelper; @@ -53,9 +54,9 @@ import java.util.Random; public class Preview extends Button { private static final int FACTOR = 4; - public static final int WIDTH = 256;//Size.chunkToBlock(1 << FACTOR); + public static final int WIDTH = 256; private static final int SLICE_HEIGHT = 64; - public static final int HEIGHT = WIDTH + SLICE_HEIGHT;//Size.chunkToBlock(1 << FACTOR); + public static final int HEIGHT = WIDTH + SLICE_HEIGHT; private static final float[] LEGEND_SCALES = {1, 0.9F, 0.75F, 0.6F}; private final int offsetX; @@ -64,15 +65,15 @@ public class Preview extends Button { private final PreviewSettings previewSettings = new PreviewSettings(); private final DynamicTexture texture = new DynamicTexture(new NativeImage(WIDTH, HEIGHT, true)); + private final String[] values = {"", "", ""}; + private final String[] labels = {"Area: ", "Terrain: ", "Biome: "}; + private int seed; private long lastUpdate = 0L; private Settings settings = new Settings(); private CacheEntry task = null; private Region region = null; - private String[] labels = {"Area: ", "Terrain: ", "Biome: "}; - private String[] values = {"", "", ""}; - public Preview(int seed) { super(0, 0, 0, 0, "", b -> {}); this.seed = seed == -1 ? random.nextInt() : seed; @@ -109,6 +110,7 @@ public class Preview extends Button { RenderSystem.disableRescaleNormal(); updateLegend(mx, my); + renderLegend(labels, values, x, y + width, 10, 0xFFFFFF); } @@ -130,6 +132,8 @@ public class Preview extends Button { try { region = task.get(); render(region); + } catch (Throwable t) { + t.printStackTrace(); } finally { task = null; } @@ -143,8 +147,7 @@ public class Preview extends Button { } RenderMode renderer = previewSettings.mode; - Terrains terrains = Terrains.create(settings); - GeneratorContext context = new GeneratorContext(terrains, settings); + Levels levels = new Levels(settings.generator); int stroke = 2; int width = region.getBlockSize().size; @@ -164,8 +167,7 @@ public class Preview extends Button { if (x < stroke || z < stroke || x >= width - stroke || z >= width - stroke) { image.setPixelRGBA(x, z, Color.BLACK.getRGB()); } else { - Color color = renderer.color(cell, context); - image.setPixelRGBA(x, z, RenderMode.rgba(color)); + image.setPixelRGBA(x, z, renderer.getColor(cell, levels)); } if (z == half) { @@ -203,19 +205,21 @@ public class Preview extends Button { .size(FACTOR, 0) .build(); - return renderer.queue(offsetX, offsetZ, 101 - previewSettings.zoom, true); + return renderer.queue(offsetX, offsetZ, 101 - previewSettings.zoom, false); } private void updateLegend(int mx ,int my) { if (region != null) { + int left = this.x; + int top = this.y; + float size = this.width; int zoom = (101 - previewSettings.zoom); int width = Math.max(1, region.getBlockSize().size * zoom); int height = Math.max(1, region.getBlockSize().size * zoom); values[0] = width + "x" + height; - - if (mx >= this.x && mx <= this.x + this.width && my >= this.y && my <= this.y + this.height) { - float fx = (mx - this.x) / (float) this.width; - float fz = (my - this.y) / (float) this.height; + if (mx >= left && mx <= left + size && my >= top && my <= top + size) { + float fx = (mx - left) / size; + float fz = (my - top) / size; int ix = NoiseUtil.round(fx * region.getBlockSize().size); int iz = NoiseUtil.round(fz * region.getBlockSize().size); Cell cell = region.getCell(ix, iz); diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/PreviewPage.java b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/PreviewPage.java index eea35af..97bd7be 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/PreviewPage.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/PreviewPage.java @@ -92,7 +92,7 @@ public class PreviewPage extends BasePage { update(); } - protected void update() { + public void update() { preview.update(settings, previewerSettings); } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/RenderMode.java b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/RenderMode.java index 7f00eca..0442131 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/RenderMode.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/RenderMode.java @@ -26,7 +26,6 @@ package com.terraforged.mod.gui.preview; import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.GeneratorContext; import com.terraforged.core.world.heightmap.Levels; import com.terraforged.core.world.terrain.Terrain; import me.dags.noise.util.NoiseUtil; @@ -34,50 +33,77 @@ import me.dags.noise.util.NoiseUtil; import java.awt.*; public enum RenderMode { - BIOME_TYPE, - TEMPERATURE, - MOISTURE, - BIOME_SHAPE, + BIOME_TYPE { + @Override + public int getColor(Cell cell, float scale, float bias) { + Color color = cell.biomeType.getColor(); + float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), new float[3]); + return rgba(hsb[0], hsb[1], (hsb[2] * scale) + bias); + } + }, + TEMPERATURE { + @Override + public int getColor(Cell cell, float scale, float bias) { + float saturation = 0.7F; + float brightness = 0.8F; + return rgba(step(1 - cell.temperature, 8) * 0.65F, saturation, brightness); + } + }, + MOISTURE { + @Override + public int getColor(Cell cell, float scale, float bias) { + float saturation = 0.7F; + float brightness = 0.8F; + return rgba(step(cell.moisture, 8) * 0.65F, saturation, brightness); + } + }, + BIOME_SHAPE { + @Override + public int getColor(Cell cell, float scale, float bias) { + float saturation = 0.7F; + float brightness = 0.8F; + return rgba(cell.biome, saturation, brightness); + } + }, + TERRAIN_TYPE { + @Override + public int getColor(Cell cell, float scale, float bias) { + float saturation = 0.7F; + float brightness = 0.8F; + return rgba(cell.region, saturation, brightness); + } + }, ; - public Color color(Cell cell, GeneratorContext context) { - float baseHeight = Levels.getSeaLevel(context.settings.generator); + public int getColor(Cell cell, Levels levels) { + float baseHeight = levels.water; if (cell.value < baseHeight) { - return new Color(40, 140, 200); + return rgba(40, 140, 200); } - float bands = 10F; float alpha = 0.2F; float elevation = (cell.value - baseHeight) / (1F - baseHeight); - int band = NoiseUtil.round(elevation * bands); float scale = 1F - alpha; float bias = alpha * (band / bands); - - float saturation = 0.7F; - float brightness = 0.8F; - - switch (this) { - case BIOME_SHAPE: - return Color.getHSBColor(cell.biome, saturation, brightness); - case BIOME_TYPE: - Color color = cell.biomeType.getColor(); - float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), new float[3]); - return Color.getHSBColor(hsb[0], hsb[1], (hsb[2] * scale) + bias); - case MOISTURE: - return Color.getHSBColor(step(cell.moisture, 8) * 0.65F, saturation, brightness); - case TEMPERATURE: - return Color.getHSBColor(step(1 - cell.temperature, 8) * 0.65F, saturation, brightness); - default: - return Color.black; - } + return getColor(cell, scale, bias); } + public abstract int getColor(Cell cell, float scale, float bias); + private static float step(float value, int steps) { return ((float) NoiseUtil.round(value * steps)) / steps; } - public static int rgba(Color color) { - return color.getRed() + (color.getGreen() << 8) + (color.getBlue() << 16) + (255 << 24); + public static int rgba(float h, float s, float b) { + int argb = Color.HSBtoRGB(h, s, b); + int red = (argb >> 16) & 0xFF; + int green = (argb >> 8) & 0xFF; + int blue = argb & 0xFF; + return rgba(red, green, blue); + } + + public static int rgba(int r, int g, int b) { + return r + (g << 8) + (b << 16) + (255 << 24); } } 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..86af287 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/settings/SettingsHelper.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/settings/SettingsHelper.java @@ -8,8 +8,9 @@ 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.storage.WorldInfo; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -72,9 +73,9 @@ public class SettingsHelper { NBTHelper.deserialize(options, dest); } - public static TerraSettings getSettings(IWorld world) { + 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 +88,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; } @@ -99,7 +100,7 @@ public class SettingsHelper { info.setGeneratorOptions(options); } - public static void moveSettings() { + public static void initSettings() { if (SETTINGS_FILE.exists()) { return; } @@ -116,6 +117,12 @@ public class SettingsHelper { e.printStackTrace(); } } + } else { + DistExecutor.runWhenOn(Dist.DEDICATED_SERVER, () -> () -> exportDefaults(new TerraSettings())); } } + + private static void initServerSettings() { + DistExecutor.runWhenOn(Dist.DEDICATED_SERVER, () -> () -> exportDefaults(new TerraSettings())); + } } 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/biomes.txt b/TerraForgedMod/src/main/resources/biomes.txt index b1b2021..c4bcb1b 100644 --- a/TerraForgedMod/src/main/resources/biomes.txt +++ b/TerraForgedMod/src/main/resources/biomes.txt @@ -1,13 +1,13 @@ -#TerraForged BiomeType Hex Colors (do not include hash/pound character) +#BiomeType Hex Colors (do not include hash/pound character) #Fri Jan 10 23:15:10 GMT 2020 -ALPINE=4b7835 -TAIGA=4b7835 -TEMPERATE_RAINFOREST=3c602b -TUNDRA=f7fafc -TROPICAL_RAINFOREST=4aa73a -SAVANNA=389a38 -GRASSLAND=429545 -TEMPERATE_FOREST=456938 -STEPPE=c3aa61 -DESERT=e5d98f -COLD_STEPPE=a7a374 \ No newline at end of file +ALPINE=eff2ed +TAIGA=4d733b +TEMPERATE_RAINFOREST=528c35 +TUNDRA=d7dbc8 +TROPICAL_RAINFOREST=347d3f +SAVANNA=88ad3e +GRASSLAND=4bb34f +TEMPERATE_FOREST=5d9948 +STEPPE=e0cb89 +DESERT=e6db9c +COLD_STEPPE=c2bb84 \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/ores/coal.json b/TerraForgedMod/src/main/resources/data/terraforged/features/ores/coal.json index dd5634a..2b9c419 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/ores/coal.json +++ b/TerraForgedMod/src/main/resources/data/terraforged/features/ores/coal.json @@ -12,7 +12,7 @@ "name": "minecraft:ore", "config": { "size": 16, - "target": "natural_stone", + "target": "wg_stone", "state": { "Name": "minecraft:coal_ore" } diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/ores/diamond.json b/TerraForgedMod/src/main/resources/data/terraforged/features/ores/diamond.json index f90d61c..a79e19d 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/ores/diamond.json +++ b/TerraForgedMod/src/main/resources/data/terraforged/features/ores/diamond.json @@ -12,7 +12,7 @@ "name": "minecraft:ore", "config": { "size": 8, - "target": "natural_stone", + "target": "wg_stone", "state": { "Name": "minecraft:diamond_ore" } diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/ores/gold.json b/TerraForgedMod/src/main/resources/data/terraforged/features/ores/gold.json index f6c8243..1d4c22e 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/ores/gold.json +++ b/TerraForgedMod/src/main/resources/data/terraforged/features/ores/gold.json @@ -12,7 +12,7 @@ "name": "minecraft:ore", "config": { "size": 9, - "target": "natural_stone", + "target": "wg_stone", "state": { "Name": "minecraft:gold_ore" } diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/ores/gold_extra.json b/TerraForgedMod/src/main/resources/data/terraforged/features/ores/gold_extra.json index fbc6bbf..3643095 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/ores/gold_extra.json +++ b/TerraForgedMod/src/main/resources/data/terraforged/features/ores/gold_extra.json @@ -19,7 +19,7 @@ "name": "minecraft:ore", "config": { "size": 9, - "target": "natural_stone", + "target": "wg_stone", "state": { "Name": "minecraft:gold_ore" } diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/ores/iron.json b/TerraForgedMod/src/main/resources/data/terraforged/features/ores/iron.json index 2d91914..392a79d 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/ores/iron.json +++ b/TerraForgedMod/src/main/resources/data/terraforged/features/ores/iron.json @@ -12,7 +12,7 @@ "name": "minecraft:ore", "config": { "size": 9, - "target": "natural_stone", + "target": "wg_stone", "state": { "Name": "minecraft:iron_ore" } diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/ores/lapis.json b/TerraForgedMod/src/main/resources/data/terraforged/features/ores/lapis.json index 5d19183..c9cc27f 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/ores/lapis.json +++ b/TerraForgedMod/src/main/resources/data/terraforged/features/ores/lapis.json @@ -12,7 +12,7 @@ "name": "minecraft:ore", "config": { "size": 7, - "target": "natural_stone", + "target": "wg_stone", "state": { "Name": "minecraft:lapis_ore" } diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/ores/redstone.json b/TerraForgedMod/src/main/resources/data/terraforged/features/ores/redstone.json index 8fd9093..2c31840 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/ores/redstone.json +++ b/TerraForgedMod/src/main/resources/data/terraforged/features/ores/redstone.json @@ -12,7 +12,7 @@ "name": "minecraft:ore", "config": { "size": 8, - "target": "natural_stone", + "target": "wg_stone", "state": { "Name": "minecraft:redstone_ore", "Properties": { 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