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;
|
package com.dfsek.terra.config.base;
|
||||||
|
|
||||||
|
import com.dfsek.terra.Debug;
|
||||||
import com.dfsek.terra.Terra;
|
import com.dfsek.terra.Terra;
|
||||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||||
import com.dfsek.terra.carving.UserDefinedCarver;
|
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.biome.BiomeConfig;
|
||||||
import com.dfsek.terra.config.genconfig.structure.StructureConfig;
|
import com.dfsek.terra.config.genconfig.structure.StructureConfig;
|
||||||
import com.dfsek.terra.config.lang.LangUtil;
|
import com.dfsek.terra.config.lang.LangUtil;
|
||||||
|
import com.dfsek.terra.tree.TreeRegistry;
|
||||||
import com.dfsek.terra.util.StructureTypeEnum;
|
import com.dfsek.terra.util.StructureTypeEnum;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
@ -67,7 +69,7 @@ public class ConfigPack extends YamlConfiguration {
|
|||||||
private final Map<String, AbstractBiomeConfig> abstractBiomes;
|
private final Map<String, AbstractBiomeConfig> abstractBiomes;
|
||||||
private final Map<String, BiomeConfig> biomes;
|
private final Map<String, BiomeConfig> biomes;
|
||||||
private final Map<String, BiomeGridConfig> grids;
|
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 Set<StructureConfig> allStructures = new HashSet<>();
|
||||||
private final File dataFolder;
|
private final File dataFolder;
|
||||||
private final String id;
|
private final String id;
|
||||||
@ -90,7 +92,12 @@ public class ConfigPack extends YamlConfiguration {
|
|||||||
|
|
||||||
structures = ConfigLoader.load(new File(file, "structures").toPath(), this, StructureConfig.class);
|
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);
|
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);
|
return flora.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TreeConfig getTree(String id) {
|
public TreeRegistry getTreeRegistry() {
|
||||||
return trees.get(id);
|
return treeRegistry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import org.bukkit.configuration.InvalidConfigurationException;
|
|||||||
import org.polydev.gaea.math.ProbabilityCollection;
|
import org.polydev.gaea.math.ProbabilityCollection;
|
||||||
import org.polydev.gaea.math.Range;
|
import org.polydev.gaea.math.Range;
|
||||||
import org.polydev.gaea.tree.Tree;
|
import org.polydev.gaea.tree.Tree;
|
||||||
import org.polydev.gaea.tree.TreeType;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -32,14 +31,10 @@ public class BiomeTreeConfig extends TerraConfigSection {
|
|||||||
Map<?, ?> y = ((ConfigurationSection) val.get("y")).getValues(false);
|
Map<?, ?> y = ((ConfigurationSection) val.get("y")).getValues(false);
|
||||||
Tree tree;
|
Tree tree;
|
||||||
try {
|
try {
|
||||||
tree = TreeType.valueOf(e.getKey());
|
tree = Objects.requireNonNull(parent.getConfig().getTreeRegistry().get(e.getKey()));
|
||||||
} catch(IllegalArgumentException ex) {
|
|
||||||
try {
|
|
||||||
tree = Objects.requireNonNull(parent.getConfig().getTree(e.getKey()));
|
|
||||||
} catch(NullPointerException ex2) {
|
} catch(NullPointerException ex2) {
|
||||||
throw new ConfigException("Invalid tree type: \"" + e.getKey() + "\"", parent.getID());
|
throw new ConfigException("Invalid tree type: \"" + e.getKey() + "\"", parent.getID());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
trees.add(tree, (Integer) val.get("weight"));
|
trees.add(tree, (Integer) val.get("weight"));
|
||||||
treeHeights.put(tree, new Range((Integer) y.get("min"), (Integer) y.get("max")));
|
treeHeights.put(tree, new Range((Integer) y.get("min"), (Integer) y.get("max")));
|
||||||
} catch(ClassCastException ex) {
|
} catch(ClassCastException ex) {
|
||||||
|
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
|
min-height: 0
|
||||||
max-height: 16
|
max-height: 16
|
||||||
|
|
||||||
trees:
|
|
||||||
chance: 15
|
|
||||||
density: 1
|
|
||||||
items:
|
|
||||||
SPRUCE:
|
|
||||||
weight: 1
|
|
||||||
y:
|
|
||||||
min: 58
|
|
||||||
max: 72
|
|
||||||
|
|
||||||
flora:
|
flora:
|
||||||
chance: 60
|
chance: 60
|
||||||
attempts: 2
|
attempts: 2
|
||||||
|
@ -66,16 +66,6 @@ ores:
|
|||||||
min-height: 0
|
min-height: 0
|
||||||
max-height: 16
|
max-height: 16
|
||||||
|
|
||||||
trees:
|
|
||||||
chance: 15
|
|
||||||
density: 1
|
|
||||||
items:
|
|
||||||
SPRUCE:
|
|
||||||
weight: 1
|
|
||||||
y:
|
|
||||||
min: 58
|
|
||||||
max: 72
|
|
||||||
|
|
||||||
flora:
|
flora:
|
||||||
chance: 60
|
chance: 60
|
||||||
attempts: 2
|
attempts: 2
|
||||||
|
@ -66,16 +66,6 @@ ores:
|
|||||||
min-height: 0
|
min-height: 0
|
||||||
max-height: 16
|
max-height: 16
|
||||||
|
|
||||||
trees:
|
|
||||||
chance: 15
|
|
||||||
density: 1
|
|
||||||
items:
|
|
||||||
SPRUCE:
|
|
||||||
weight: 1
|
|
||||||
y:
|
|
||||||
min: 58
|
|
||||||
max: 72
|
|
||||||
|
|
||||||
flora:
|
flora:
|
||||||
chance: 60
|
chance: 60
|
||||||
attempts: 2
|
attempts: 2
|
||||||
|
@ -43,7 +43,7 @@ flora:
|
|||||||
trees:
|
trees:
|
||||||
density: 75
|
density: 75
|
||||||
items:
|
items:
|
||||||
SPRUCE_CUSTOM:
|
SPRUCE:
|
||||||
weight: 1
|
weight: 1
|
||||||
y:
|
y:
|
||||||
min: 58
|
min: 58
|
||||||
|
@ -36,7 +36,7 @@ flora:
|
|||||||
trees:
|
trees:
|
||||||
density: 75
|
density: 75
|
||||||
items:
|
items:
|
||||||
SPRUCE_CUSTOM:
|
SPRUCE:
|
||||||
weight: 1
|
weight: 1
|
||||||
y:
|
y:
|
||||||
min: 58
|
min: 58
|
||||||
|
@ -22,7 +22,7 @@ snow:
|
|||||||
max: 255
|
max: 255
|
||||||
chance: 100
|
chance: 100
|
||||||
trees:
|
trees:
|
||||||
density: 200
|
density: 60
|
||||||
items:
|
items:
|
||||||
SPRUCE:
|
SPRUCE:
|
||||||
weight: 1
|
weight: 1
|
||||||
|
@ -22,7 +22,7 @@ snow:
|
|||||||
max: 255
|
max: 255
|
||||||
chance: 100
|
chance: 100
|
||||||
trees:
|
trees:
|
||||||
density: 200
|
density: 60
|
||||||
items:
|
items:
|
||||||
SPRUCE:
|
SPRUCE:
|
||||||
weight: 1
|
weight: 1
|
||||||
|
@ -22,7 +22,7 @@ snow:
|
|||||||
max: 255
|
max: 255
|
||||||
chance: 100
|
chance: 100
|
||||||
trees:
|
trees:
|
||||||
density: 200
|
density: 60
|
||||||
items:
|
items:
|
||||||
SPRUCE:
|
SPRUCE:
|
||||||
weight: 1
|
weight: 1
|
||||||
|
@ -6,7 +6,7 @@ files:
|
|||||||
spruce5: 1
|
spruce5: 1
|
||||||
spruce6: 1
|
spruce6: 1
|
||||||
spruce7: 1
|
spruce7: 1
|
||||||
id: SPRUCE_CUSTOM
|
id: SPRUCE
|
||||||
y-offset: 0
|
y-offset: 0
|
||||||
spawnable:
|
spawnable:
|
||||||
- "minecraft:grass_block"
|
- "minecraft:grass_block"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user