mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-02-12 13:01:26 +01:00
!Added IDs to WorldGenTemplates
This commit is contained in:
parent
503857569e
commit
e529ab7139
@ -10,6 +10,7 @@ import org.bukkit.block.Biome;
|
|||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
public class WorldGenTemplate {
|
public class WorldGenTemplate {
|
||||||
|
private final String id;
|
||||||
private final double chunkChance;
|
private final double chunkChance;
|
||||||
private final int minDepth, maxDepth, veinSize, veinCount;
|
private final int minDepth, maxDepth, veinSize, veinCount;
|
||||||
|
|
||||||
@ -21,6 +22,7 @@ public class WorldGenTemplate {
|
|||||||
public WorldGenTemplate(ConfigurationSection config) {
|
public WorldGenTemplate(ConfigurationSection config) {
|
||||||
Validate.notNull(config, "Could not read gen template 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(" ", "_"))));
|
config.getStringList("replace").forEach(str -> replaceable.add(Material.valueOf(str.toUpperCase().replace("-", "_").replace(" ", "_"))));
|
||||||
|
|
||||||
for (String world : config.getStringList("worlds"))
|
for (String world : config.getStringList("worlds"))
|
||||||
@ -43,6 +45,10 @@ public class WorldGenTemplate {
|
|||||||
veinCount = config.getInt("vein-count");
|
veinCount = config.getInt("vein-count");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
public double getChunkChance() {
|
public double getChunkChance() {
|
||||||
return chunkChance;
|
return chunkChance;
|
||||||
}
|
}
|
||||||
|
@ -57,30 +57,28 @@ public class WorldGenManager implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void a(ChunkLoadEvent event) {
|
public void a(ChunkLoadEvent event) {
|
||||||
if (!event.isNewChunk())
|
if (event.isNewChunk())
|
||||||
return;
|
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 (template.canGenerate(generatePoint)) {
|
||||||
if (random.nextDouble() < template.getChunkChance())
|
Block modify = event.getWorld().getBlockAt(generatePoint);
|
||||||
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)) {
|
for (int j = 0; j < template.getVeinSize(); j++) {
|
||||||
Block modify = event.getWorld().getBlockAt(generatePoint);
|
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++) {
|
BlockFace nextFace = faces[random.nextInt(faces.length)];
|
||||||
if (template.canReplace(modify.getType())) {
|
modify = modify.getRelative(nextFace);
|
||||||
modify.setType(block.getState().getType(), false);
|
|
||||||
modify.setBlockData(block.getState().getBlockData(), false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockFace nextFace = faces[random.nextInt(faces.length)];
|
|
||||||
modify = modify.getRelative(nextFace);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reload() {
|
public void reload() {
|
||||||
@ -89,10 +87,10 @@ public class WorldGenManager implements Listener {
|
|||||||
FileConfiguration config = new ConfigFile("gen-templates").getConfig();
|
FileConfiguration config = new ConfigFile("gen-templates").getConfig();
|
||||||
for (String key : config.getKeys(false))
|
for (String key : config.getKeys(false))
|
||||||
try {
|
try {
|
||||||
templates.put(key, new WorldGenTemplate(config.getConfigurationSection(key)));
|
WorldGenTemplate template = new WorldGenTemplate(config.getConfigurationSection(key));
|
||||||
|
templates.put(template.getId(), template);
|
||||||
} catch (IllegalArgumentException exception) {
|
} catch (IllegalArgumentException exception) {
|
||||||
MMOItems.plugin.getLogger().log(Level.WARNING, "An error occured when loading gen template '" + key + "': " + exception.getMessage());
|
MMOItems.plugin.getLogger().log(Level.WARNING, "An error occured when loading gen template '" + key + "': " + exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user