mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-18 10:32:30 +00:00
Trees are now backed with a registry, custom trees can override Vanilla ones.
This commit is contained in:
parent
0e3577063e
commit
57cefea2f3
@ -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<String, AbstractBiomeConfig> abstractBiomes;
|
||||
private final Map<String, BiomeConfig> biomes;
|
||||
private final Map<String, BiomeGridConfig> grids;
|
||||
private final Map<String, TreeConfig> trees;
|
||||
private final TreeRegistry treeRegistry = new TreeRegistry();
|
||||
private final Set<StructureConfig> 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<String, TreeConfig> trees = ConfigLoader.load(new File(file, "trees").toPath(), this, TreeConfig.class);
|
||||
|
||||
for(Map.Entry<String, TreeConfig> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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")));
|
||||
|
36
src/main/java/com/dfsek/terra/tree/TreeRegistry.java
Normal file
36
src/main/java/com/dfsek/terra/tree/TreeRegistry.java
Normal file
@ -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<String, Tree> 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);
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -43,7 +43,7 @@ flora:
|
||||
trees:
|
||||
density: 75
|
||||
items:
|
||||
SPRUCE_CUSTOM:
|
||||
SPRUCE:
|
||||
weight: 1
|
||||
y:
|
||||
min: 58
|
||||
|
@ -36,7 +36,7 @@ flora:
|
||||
trees:
|
||||
density: 75
|
||||
items:
|
||||
SPRUCE_CUSTOM:
|
||||
SPRUCE:
|
||||
weight: 1
|
||||
y:
|
||||
min: 58
|
||||
|
@ -22,7 +22,7 @@ snow:
|
||||
max: 255
|
||||
chance: 100
|
||||
trees:
|
||||
density: 200
|
||||
density: 60
|
||||
items:
|
||||
SPRUCE:
|
||||
weight: 1
|
||||
|
@ -22,7 +22,7 @@ snow:
|
||||
max: 255
|
||||
chance: 100
|
||||
trees:
|
||||
density: 200
|
||||
density: 60
|
||||
items:
|
||||
SPRUCE:
|
||||
weight: 1
|
||||
|
@ -22,7 +22,7 @@ snow:
|
||||
max: 255
|
||||
chance: 100
|
||||
trees:
|
||||
density: 200
|
||||
density: 60
|
||||
items:
|
||||
SPRUCE:
|
||||
weight: 1
|
||||
|
@ -6,7 +6,7 @@ files:
|
||||
spruce5: 1
|
||||
spruce6: 1
|
||||
spruce7: 1
|
||||
id: SPRUCE_CUSTOM
|
||||
id: SPRUCE
|
||||
y-offset: 0
|
||||
spawnable:
|
||||
- "minecraft:grass_block"
|
||||
|
Loading…
x
Reference in New Issue
Block a user