diff --git a/src/main/java/com/dfsek/terra/config/base/ConfigPack.java b/src/main/java/com/dfsek/terra/config/base/ConfigPack.java index c57fad859..2c762f712 100644 --- a/src/main/java/com/dfsek/terra/config/base/ConfigPack.java +++ b/src/main/java/com/dfsek/terra/config/base/ConfigPack.java @@ -1,5 +1,6 @@ package com.dfsek.terra.config.base; +import com.dfsek.terra.Debug; import com.dfsek.terra.Terra; import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.carving.UserDefinedCarver; @@ -16,6 +17,7 @@ import com.dfsek.terra.config.genconfig.biome.AbstractBiomeConfig; import com.dfsek.terra.config.genconfig.biome.BiomeConfig; import com.dfsek.terra.config.genconfig.structure.StructureConfig; import com.dfsek.terra.config.lang.LangUtil; +import com.dfsek.terra.tree.TreeRegistry; import com.dfsek.terra.util.StructureTypeEnum; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.InvalidConfigurationException; @@ -67,7 +69,7 @@ public class ConfigPack extends YamlConfiguration { private final Map abstractBiomes; private final Map biomes; private final Map grids; - private final Map trees; + private final TreeRegistry treeRegistry = new TreeRegistry(); private final Set allStructures = new HashSet<>(); private final File dataFolder; private final String id; @@ -90,7 +92,12 @@ public class ConfigPack extends YamlConfiguration { structures = ConfigLoader.load(new File(file, "structures").toPath(), this, StructureConfig.class); - trees = ConfigLoader.load(new File(file, "trees").toPath(), this, TreeConfig.class); + Map trees = ConfigLoader.load(new File(file, "trees").toPath(), this, TreeConfig.class); + + for(Map.Entry entry : trees.entrySet()) { + if(treeRegistry.add(entry.getKey(), entry.getValue())) + Debug.info("Overriding Vanilla tree: " + entry.getKey()); + } abstractBiomes = ConfigLoader.load(new File(file, "abstract" + File.separator + "biomes").toPath(), this, AbstractBiomeConfig.class); @@ -278,7 +285,7 @@ public class ConfigPack extends YamlConfiguration { return flora.get(id); } - public TreeConfig getTree(String id) { - return trees.get(id); + public TreeRegistry getTreeRegistry() { + return treeRegistry; } } diff --git a/src/main/java/com/dfsek/terra/config/genconfig/biome/BiomeTreeConfig.java b/src/main/java/com/dfsek/terra/config/genconfig/biome/BiomeTreeConfig.java index b9d8c7139..a74a40693 100644 --- a/src/main/java/com/dfsek/terra/config/genconfig/biome/BiomeTreeConfig.java +++ b/src/main/java/com/dfsek/terra/config/genconfig/biome/BiomeTreeConfig.java @@ -8,7 +8,6 @@ import org.bukkit.configuration.InvalidConfigurationException; import org.polydev.gaea.math.ProbabilityCollection; import org.polydev.gaea.math.Range; import org.polydev.gaea.tree.Tree; -import org.polydev.gaea.tree.TreeType; import java.util.HashMap; import java.util.Map; @@ -32,13 +31,9 @@ public class BiomeTreeConfig extends TerraConfigSection { Map y = ((ConfigurationSection) val.get("y")).getValues(false); Tree tree; try { - tree = TreeType.valueOf(e.getKey()); - } catch(IllegalArgumentException ex) { - try { - tree = Objects.requireNonNull(parent.getConfig().getTree(e.getKey())); - } catch(NullPointerException ex2) { - throw new ConfigException("Invalid tree type: \"" + e.getKey() + "\"", parent.getID()); - } + tree = Objects.requireNonNull(parent.getConfig().getTreeRegistry().get(e.getKey())); + } catch(NullPointerException ex2) { + throw new ConfigException("Invalid tree type: \"" + e.getKey() + "\"", parent.getID()); } trees.add(tree, (Integer) val.get("weight")); treeHeights.put(tree, new Range((Integer) y.get("min"), (Integer) y.get("max"))); diff --git a/src/main/java/com/dfsek/terra/tree/TreeRegistry.java b/src/main/java/com/dfsek/terra/tree/TreeRegistry.java new file mode 100644 index 000000000..9fe3d71dd --- /dev/null +++ b/src/main/java/com/dfsek/terra/tree/TreeRegistry.java @@ -0,0 +1,36 @@ +package com.dfsek.terra.tree; + +import org.polydev.gaea.tree.Tree; +import org.polydev.gaea.tree.TreeType; + +import java.util.HashMap; +import java.util.Map; + +public class TreeRegistry { + private final Map trees = new HashMap<>(); + + public TreeRegistry() { + for(TreeType t : TreeType.values()) trees.put(t.toString(), t); // Populate registry with default trees. + } + + /** + * Add a tree to the registry with a name. + * + * @param name Name of the tree. + * @param value Tree to add + * @return True if tree was overwritten. + */ + public boolean add(String name, Tree value) { + boolean exists = trees.containsKey(name); + trees.put(name, value); + return exists; + } + + public boolean contains(String name) { + return trees.containsKey(name); + } + + public Tree get(String id) { + return trees.get(id); + } +} diff --git a/src/main/resources/default-config/abstract/biomes/mountain/mountains_pretty.yml b/src/main/resources/default-config/abstract/biomes/mountain/mountains_pretty.yml index 0db3425de..7804b2f8b 100644 --- a/src/main/resources/default-config/abstract/biomes/mountain/mountains_pretty.yml +++ b/src/main/resources/default-config/abstract/biomes/mountain/mountains_pretty.yml @@ -66,16 +66,6 @@ ores: min-height: 0 max-height: 16 -trees: - chance: 15 - density: 1 - items: - SPRUCE: - weight: 1 - y: - min: 58 - max: 72 - flora: chance: 60 attempts: 2 diff --git a/src/main/resources/default-config/abstract/biomes/mountain/mountains_pretty_border_0.yml b/src/main/resources/default-config/abstract/biomes/mountain/mountains_pretty_border_0.yml index 24f769460..f1d67c27a 100644 --- a/src/main/resources/default-config/abstract/biomes/mountain/mountains_pretty_border_0.yml +++ b/src/main/resources/default-config/abstract/biomes/mountain/mountains_pretty_border_0.yml @@ -66,16 +66,6 @@ ores: min-height: 0 max-height: 16 -trees: - chance: 15 - density: 1 - items: - SPRUCE: - weight: 1 - y: - min: 58 - max: 72 - flora: chance: 60 attempts: 2 diff --git a/src/main/resources/default-config/abstract/biomes/mountain/mountains_pretty_border_1.yml b/src/main/resources/default-config/abstract/biomes/mountain/mountains_pretty_border_1.yml index d463b5a16..0ad6d73ee 100644 --- a/src/main/resources/default-config/abstract/biomes/mountain/mountains_pretty_border_1.yml +++ b/src/main/resources/default-config/abstract/biomes/mountain/mountains_pretty_border_1.yml @@ -66,16 +66,6 @@ ores: min-height: 0 max-height: 16 -trees: - chance: 15 - density: 1 - items: - SPRUCE: - weight: 1 - y: - min: 58 - max: 72 - flora: chance: 60 attempts: 2 diff --git a/src/main/resources/default-config/biomes/forest/snowy_taiga.yml b/src/main/resources/default-config/biomes/forest/snowy_taiga.yml index 7d6164ea3..dc6635901 100644 --- a/src/main/resources/default-config/biomes/forest/snowy_taiga.yml +++ b/src/main/resources/default-config/biomes/forest/snowy_taiga.yml @@ -43,7 +43,7 @@ flora: trees: density: 75 items: - SPRUCE_CUSTOM: + SPRUCE: weight: 1 y: min: 58 diff --git a/src/main/resources/default-config/biomes/forest/taiga.yml b/src/main/resources/default-config/biomes/forest/taiga.yml index 22f9c91d5..6aac7adfe 100644 --- a/src/main/resources/default-config/biomes/forest/taiga.yml +++ b/src/main/resources/default-config/biomes/forest/taiga.yml @@ -36,7 +36,7 @@ flora: trees: density: 75 items: - SPRUCE_CUSTOM: + SPRUCE: weight: 1 y: min: 58 diff --git a/src/main/resources/default-config/biomes/mountain/mountains_stone.yml b/src/main/resources/default-config/biomes/mountain/mountains_stone.yml index 990d33129..ddd1d3525 100644 --- a/src/main/resources/default-config/biomes/mountain/mountains_stone.yml +++ b/src/main/resources/default-config/biomes/mountain/mountains_stone.yml @@ -22,7 +22,7 @@ snow: max: 255 chance: 100 trees: - density: 200 + density: 60 items: SPRUCE: weight: 1 diff --git a/src/main/resources/default-config/biomes/mountain/mountains_stone_border_0.yml b/src/main/resources/default-config/biomes/mountain/mountains_stone_border_0.yml index f50551b3e..ace29f0cc 100644 --- a/src/main/resources/default-config/biomes/mountain/mountains_stone_border_0.yml +++ b/src/main/resources/default-config/biomes/mountain/mountains_stone_border_0.yml @@ -22,7 +22,7 @@ snow: max: 255 chance: 100 trees: - density: 200 + density: 60 items: SPRUCE: weight: 1 diff --git a/src/main/resources/default-config/biomes/mountain/mountains_stone_border_1.yml b/src/main/resources/default-config/biomes/mountain/mountains_stone_border_1.yml index 44502269e..537750dbf 100644 --- a/src/main/resources/default-config/biomes/mountain/mountains_stone_border_1.yml +++ b/src/main/resources/default-config/biomes/mountain/mountains_stone_border_1.yml @@ -22,7 +22,7 @@ snow: max: 255 chance: 100 trees: - density: 200 + density: 60 items: SPRUCE: weight: 1 diff --git a/src/main/resources/default-config/trees/trees/spruce.yml b/src/main/resources/default-config/trees/trees/spruce.yml index e5ab346aa..a8c7baae4 100644 --- a/src/main/resources/default-config/trees/trees/spruce.yml +++ b/src/main/resources/default-config/trees/trees/spruce.yml @@ -6,7 +6,7 @@ files: spruce5: 1 spruce6: 1 spruce7: 1 -id: SPRUCE_CUSTOM +id: SPRUCE y-offset: 0 spawnable: - "minecraft:grass_block"