Made custom block WorldGen go BRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR

This commit is contained in:
Ashijin 2020-09-03 01:25:18 -06:00
parent b998972e38
commit ab06070851
2 changed files with 31 additions and 24 deletions

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.Indyuce</groupId>
<artifactId>MMOItems</artifactId>
<version>6.1.0</version>
<version>6.1.0-SNAPSHOT</version>
<name>MMOItems</name>
<description>A great item solution for your RPG server.</description>

View File

@ -64,28 +64,34 @@ public class WorldGenManager implements Listener {
@EventHandler
public void a(ChunkLoadEvent event) {
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();
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);
}
BlockFace nextFace = faces[random.nextInt(faces.length)];
modify = modify.getRelative(nextFace);
}
}
}
});
if(event.isNewChunk()) {
Bukkit.getScheduler().runTaskAsynchronously(MMOItems.plugin, () -> {
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 = generatePoint.getWorld().getBlockAt(generatePoint);
for(int j = 0; j < template.getVeinSize(); j++) {
if(template.canReplace(modify.getType())) {
final Block fModify = modify;
Bukkit.getScheduler().runTask(MMOItems.plugin, () -> {
fModify.setType(block.getState().getType(), false);
fModify.setBlockData(block.getState().getBlockData(), false);
});
}
BlockFace nextFace = faces[random.nextInt(faces.length)];
modify = modify.getRelative(nextFace);
}
}
}
});
});
}
}
public void reload() {
@ -93,12 +99,13 @@ public class WorldGenManager implements Listener {
templates.clear();
FileConfiguration config = new ConfigFile("gen-templates").getConfig();
for (String key : config.getKeys(false))
for(String key : config.getKeys(false)) {
try {
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());
}
}
}
}