From 9786d819b0674112c74aa27d2ef0b0d9834014e5 Mon Sep 17 00:00:00 2001 From: dags- Date: Sun, 10 May 2020 10:30:03 +0100 Subject: [PATCH] - added wg_stone predicate for ores - generate the settings json on dedicated servers if one doesn't exist --- .../com/terraforged/api/material/WGTags.java | 8 +++++++ .../api/material/state/StateTagPredicate.java | 21 +++++++++++++++++++ .../com/terraforged/mod/TerraForgedMod.java | 6 +++++- .../mod/settings/SettingsHelper.java | 15 +++++++------ .../data/terraforged/features/ores/coal.json | 2 +- .../terraforged/features/ores/diamond.json | 2 +- .../data/terraforged/features/ores/gold.json | 2 +- .../terraforged/features/ores/gold_extra.json | 2 +- .../data/terraforged/features/ores/iron.json | 2 +- .../data/terraforged/features/ores/lapis.json | 2 +- .../terraforged/features/ores/redstone.json | 2 +- 11 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/material/state/StateTagPredicate.java 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/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/settings/SettingsHelper.java b/TerraForgedMod/src/main/java/com/terraforged/mod/settings/SettingsHelper.java index 9b5e0c8..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.World; 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,10 +73,6 @@ public class SettingsHelper { NBTHelper.deserialize(options, dest); } - public static TerraSettings getSettings(World world) { - return getSettings(world.getWorldInfo()); - } - public static TerraSettings getSettings(WorldInfo info) { TerraSettings settings = new TerraSettings(); if (info.getGeneratorOptions().isEmpty()) { @@ -103,7 +100,7 @@ public class SettingsHelper { info.setGeneratorOptions(options); } - public static void moveSettings() { + public static void initSettings() { if (SETTINGS_FILE.exists()) { return; } @@ -120,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/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": {