!Added IDs to WorldGenTemplates

This commit is contained in:
Indyuce 2020-04-29 20:29:30 +02:00
parent 503857569e
commit e529ab7139
2 changed files with 24 additions and 20 deletions

View File

@ -10,6 +10,7 @@ import org.bukkit.block.Biome;
import org.bukkit.configuration.ConfigurationSection;
public class WorldGenTemplate {
private final String id;
private final double chunkChance;
private final int minDepth, maxDepth, veinSize, veinCount;
@ -21,6 +22,7 @@ public class WorldGenTemplate {
public WorldGenTemplate(ConfigurationSection config) {
Validate.notNull(config, "Could not read gen template config");
id = config.getName().toLowerCase().replace(" ", "-").replace("_", "-");
config.getStringList("replace").forEach(str -> replaceable.add(Material.valueOf(str.toUpperCase().replace("-", "_").replace(" ", "_"))));
for (String world : config.getStringList("worlds"))
@ -43,6 +45,10 @@ public class WorldGenTemplate {
veinCount = config.getInt("vein-count");
}
public String getId() {
return id;
}
public double getChunkChance() {
return chunkChance;
}

View File

@ -57,30 +57,28 @@ public class WorldGenManager implements Listener {
@EventHandler
public void a(ChunkLoadEvent event) {
if (!event.isNewChunk())
return;
if (event.isNewChunk())
assigned.forEach((block, template) -> {
if (random.nextDouble() < template.getChunkChance())
for (int i = 0; i < template.getVeinCount(); i++) {
int y = random.nextInt(template.getMaxDepth() - template.getMinDepth() + 1) + template.getMinDepth();
Location generatePoint = event.getChunk().getBlock(random.nextInt(16), y, random.nextInt(16)).getLocation();
assigned.forEach((block, template) -> {
if (random.nextDouble() < template.getChunkChance())
for (int i = 0; i < template.getVeinCount(); i++) {
int y = random.nextInt(template.getMaxDepth() - template.getMinDepth() + 1) + template.getMinDepth();
Location generatePoint = event.getChunk().getBlock(random.nextInt(16), y, random.nextInt(16)).getLocation();
if (template.canGenerate(generatePoint)) {
Block modify = event.getWorld().getBlockAt(generatePoint);
if (template.canGenerate(generatePoint)) {
Block modify = event.getWorld().getBlockAt(generatePoint);
for (int j = 0; j < template.getVeinSize(); j++) {
if (template.canReplace(modify.getType())) {
modify.setType(block.getState().getType(), false);
modify.setBlockData(block.getState().getBlockData(), false);
}
for (int j = 0; j < template.getVeinSize(); j++) {
if (template.canReplace(modify.getType())) {
modify.setType(block.getState().getType(), false);
modify.setBlockData(block.getState().getBlockData(), false);
BlockFace nextFace = faces[random.nextInt(faces.length)];
modify = modify.getRelative(nextFace);
}
BlockFace nextFace = faces[random.nextInt(faces.length)];
modify = modify.getRelative(nextFace);
}
}
}
});
});
}
public void reload() {
@ -89,10 +87,10 @@ public class WorldGenManager implements Listener {
FileConfiguration config = new ConfigFile("gen-templates").getConfig();
for (String key : config.getKeys(false))
try {
templates.put(key, new WorldGenTemplate(config.getConfigurationSection(key)));
WorldGenTemplate template = new WorldGenTemplate(config.getConfigurationSection(key));
templates.put(template.getId(), template);
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "An error occured when loading gen template '" + key + "': " + exception.getMessage());
}
}
}