From b998972e38d010f9742e01e00c01192e532fd1d0 Mon Sep 17 00:00:00 2001 From: Ashijin Date: Thu, 3 Sep 2020 01:18:58 -0600 Subject: [PATCH] Added bordering and not-bordering options to worldgen templates --- .../mmoitems/api/block/WorldGenTemplate.java | 92 +++++++++++++++++-- 1 file changed, 82 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/Indyuce/mmoitems/api/block/WorldGenTemplate.java b/src/main/java/net/Indyuce/mmoitems/api/block/WorldGenTemplate.java index 6bd9d0fa..82aa59f0 100644 --- a/src/main/java/net/Indyuce/mmoitems/api/block/WorldGenTemplate.java +++ b/src/main/java/net/Indyuce/mmoitems/api/block/WorldGenTemplate.java @@ -7,6 +7,7 @@ import org.apache.commons.lang.Validate; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Biome; +import org.bukkit.block.BlockFace; import org.bukkit.configuration.ConfigurationSection; public class WorldGenTemplate { @@ -15,6 +16,8 @@ public class WorldGenTemplate { private final int minDepth, maxDepth, veinSize, veinCount; private final List replaceable = new ArrayList<>(); + private final List bordering = new ArrayList<>(); + private final List notBordering = new ArrayList<>(); private final List worldWhitelist = new ArrayList<>(), worldBlacklist = new ArrayList<>(); private final List biomeWhitelist = new ArrayList<>(), biomeBlacklist = new ArrayList<>(); private final boolean slimeChunk; @@ -24,13 +27,15 @@ public class WorldGenTemplate { 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")) + config.getStringList("bordering").forEach(str -> bordering.add(Material.valueOf(str.toUpperCase().replace("-", "_").replace(" ", "_")))); + config.getStringList("not-bordering").forEach(str -> notBordering.add(Material.valueOf(str.toUpperCase().replace("-", "_").replace(" ", "_")))); + + for (String world : config.getStringList("worlds")) { (world.startsWith("!") ? worldBlacklist : worldWhitelist).add(world.toLowerCase().replace("_", "-")); - - for (String biome : config.getStringList("biomes")) + } + for (String biome : config.getStringList("biomes")) { (biome.startsWith("!") ? biomeBlacklist : biomeWhitelist).add(biome.toUpperCase().replace("-", "_").replace(" ", "_")); - + } chunkChance = config.getDouble("chunk-chance"); slimeChunk = config.getBoolean("slime-chunk", false); @@ -82,15 +87,30 @@ public class WorldGenTemplate { // check biome list Biome biome = pos.getWorld().getBiome(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()); - if (!biomeWhitelist.isEmpty() && !biomeWhitelist.contains(biome.name())) + if (!biomeWhitelist.isEmpty() && !biomeWhitelist.contains(biome.name())) { return false; - if (!biomeBlacklist.isEmpty() && biomeBlacklist.contains(biome.name())) + } + if (!biomeBlacklist.isEmpty() && biomeBlacklist.contains(biome.name())) { return false; - + } + // check extra options - if (slimeChunk && !pos.getChunk().isSlimeChunk()) + if (slimeChunk && !pos.getChunk().isSlimeChunk()) { return false; - + } + + if(!bordering.isEmpty()) { + if(!checkIfBorderingBlocks(pos)) { + return false; + } + } + + if(!notBordering.isEmpty()) { + if(!checkIfNotBorderingBlocks(pos)) { + return false; + } + } + // can generate if no restrictions applied return true; } @@ -98,4 +118,56 @@ public class WorldGenTemplate { public boolean canReplace(Material type) { return replaceable.isEmpty() || replaceable.contains(type); } + + public boolean canBorder(Material type) { + return bordering.isEmpty() || bordering.contains(type); + } + + public boolean checkIfBorderingBlocks(Location pos) { + if(!canBorder(pos.getBlock().getRelative(BlockFace.NORTH).getType())) { + return false; + } + if(!canBorder(pos.getBlock().getRelative(BlockFace.EAST).getType())) { + return false; + } + if(!canBorder(pos.getBlock().getRelative(BlockFace.SOUTH).getType())) { + return false; + } + if(!canBorder(pos.getBlock().getRelative(BlockFace.WEST).getType())) { + return false; + } + if(!canBorder(pos.getBlock().getRelative(BlockFace.UP).getType())) { + return false; + } + if(!canBorder(pos.getBlock().getRelative(BlockFace.DOWN).getType())) { + return false; + } + return true; + } + + public boolean canNotBorder(Material type) { + return !notBordering.isEmpty() && notBordering.contains(type); + } + + public boolean checkIfNotBorderingBlocks(Location pos) { + if(canNotBorder(pos.getBlock().getRelative(BlockFace.NORTH).getType())) { + return false; + } + if(canNotBorder(pos.getBlock().getRelative(BlockFace.EAST).getType())) { + return false; + } + if(canNotBorder(pos.getBlock().getRelative(BlockFace.SOUTH).getType())) { + return false; + } + if(canNotBorder(pos.getBlock().getRelative(BlockFace.WEST).getType())) { + return false; + } + if(canNotBorder(pos.getBlock().getRelative(BlockFace.UP).getType())) { + return false; + } + if(canNotBorder(pos.getBlock().getRelative(BlockFace.DOWN).getType())) { + return false; + } + return true; + } }