From 38eeb4743105d4acd3fb835ec6f27bc0892d95aa Mon Sep 17 00:00:00 2001 From: tastybento Date: Mon, 6 Jul 2020 16:26:08 -0700 Subject: [PATCH] Fix for 1.16.1 nether biomes https://github.com/BentoBoxWorld/Greenhouses/issues/51 --- .../managers/GreenhouseManager.java | 36 ++++++------------- .../greenhouses/managers/RecipeManager.java | 32 ++++++++++++----- src/main/resources/biomes.yml | 2 +- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/main/java/world/bentobox/greenhouses/managers/GreenhouseManager.java b/src/main/java/world/bentobox/greenhouses/managers/GreenhouseManager.java index 8490465..365a235 100644 --- a/src/main/java/world/bentobox/greenhouses/managers/GreenhouseManager.java +++ b/src/main/java/world/bentobox/greenhouses/managers/GreenhouseManager.java @@ -5,10 +5,6 @@ import java.util.List; import java.util.Set; import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Particle; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -129,24 +125,11 @@ public class GreenhouseManager implements Listener { handler.deleteObject(g); map.removeGreenhouse(g); addon.log("Returning biome to original state: " + g.getOriginalBiome().toString()); - for (int x = (int)g.getBoundingBox().getMinX(); x<= (int)g.getBoundingBox().getMaxX(); x++) { - for (int z = (int)g.getBoundingBox().getMinZ(); z<= (int)g.getBoundingBox().getMaxZ(); z++) { - // Set back to the original biome - g.getLocation().getWorld().setBiome(x, z, g.getOriginalBiome()); - if (g.getOriginalBiome().equals(Biome.NETHER) || g.getOriginalBiome().equals(Biome.DESERT) - || g.getOriginalBiome().equals(Biome.DESERT_HILLS)) { - for (int y = g.getFloorHeight(); y< g.getCeilingHeight(); y++) { - Block b = g.getLocation().getWorld().getBlockAt(x, y, z); - // Remove any water - if (b.getType().equals(Material.WATER) || b.getType().equals(Material.BLUE_ICE) - || b.getType().equals(Material.FROSTED_ICE) - || b.getType().equals(Material.ICE) || b.getType().equals(Material.PACKED_ICE) - || b.getType().equals(Material.SNOW) || b.getType().equals(Material.SNOW_BLOCK)) { - // Evaporate it - b.setType(Material.AIR); - b.getWorld().spawnParticle(Particle.SMOKE_LARGE, b.getLocation(), 5); - } - } + for (int x = (int)g.getBoundingBox().getMinX(); x<= (int)g.getBoundingBox().getMaxX(); x+=4) { + for (int z = (int)g.getBoundingBox().getMinZ(); z<= (int)g.getBoundingBox().getMaxZ(); z+=4) { + for (int y = (int)g.getBoundingBox().getMinY(); y<= (int)g.getBoundingBox().getMaxY(); y+=4) { + // Set back to the original biome + g.getLocation().getWorld().setBiome(x, y, z, g.getOriginalBiome()); } } } @@ -194,12 +177,13 @@ public class GreenhouseManager implements Listener { } private void activateGreenhouse(Greenhouse gh) { - for (int x = (int)gh.getBoundingBox().getMinX(); x < gh.getBoundingBox().getMaxX(); x++) { - for (int z = (int)gh.getBoundingBox().getMinZ(); z < gh.getBoundingBox().getMaxZ(); z++) { - gh.getWorld().setBiome(x, z, gh.getBiomeRecipe().getBiome()); + for (int x = (int)gh.getBoundingBox().getMinX(); x < gh.getBoundingBox().getMaxX(); x+=4) { + for (int z = (int)gh.getBoundingBox().getMinZ(); z < gh.getBoundingBox().getMaxZ(); z+=4) { + for (int y = (int)gh.getBoundingBox().getMinY(); y < gh.getBoundingBox().getMaxY(); y+=4) { + gh.getWorld().setBiome(x, y, z, gh.getBiomeRecipe().getBiome()); + } } } - } /** diff --git a/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java b/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java index 3edc878..13c7104 100644 --- a/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java +++ b/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java @@ -2,10 +2,12 @@ package world.bentobox.greenhouses.managers; import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; import java.util.Optional; +import java.util.stream.Collectors; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -15,6 +17,8 @@ import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.EntityType; +import com.google.common.base.Enums; + import world.bentobox.bentobox.util.Util; import world.bentobox.greenhouses.Greenhouses; import world.bentobox.greenhouses.greenhouse.BiomeRecipe; @@ -77,14 +81,8 @@ public class RecipeManager { private void processEntries(String biomeType, ConfigurationSection biomeSection) { try { ConfigurationSection biomeRecipeConfig = biomeSection.getConfigurationSection(biomeType); - Biome thisBiome; - if (biomeRecipeConfig.contains("biome")) { - // Try and get the biome via the biome setting - thisBiome = Biome.valueOf(biomeRecipeConfig.getString("biome").toUpperCase()); - } else { - // Old style, where type was the biome name - thisBiome = Biome.valueOf(biomeType); - } + Biome thisBiome = loadBiome(biomeType, biomeRecipeConfig); + if (thisBiome == null) return; int priority = biomeRecipeConfig.getInt("priority", 0); // Create the biome recipe @@ -120,6 +118,24 @@ public class RecipeManager { } + private Biome loadBiome(String biomeType, ConfigurationSection biomeRecipeConfig) { + if (!biomeRecipeConfig.contains("biome")) { + addon.logError("No biome defined in the biome reciepe " + biomeType + ". Skipping..."); + return null; + } + String name = biomeRecipeConfig.getString("biome").toUpperCase(); + if (Enums.getIfPresent(Biome.class, name).isPresent()) { + return Biome.valueOf(name); + } + // Special case for nether + if (name.equals("NETHER") || name.equals("NETHER_WASTES")) { + return Enums.getIfPresent(Biome.class, "NETHER").or(Enums.getIfPresent(Biome.class, "NETHER_WASTES").or(Biome.PLAINS)); + } + addon.logError("Biome " + name + " is invalid! Use one of these..."); + addon.logError(Arrays.stream(Biome.values()).map(Biome::name).collect(Collectors.joining(","))); + return null; + } + private BiomeRecipe getBiomeRecipe(ConfigurationSection biomeRecipeConfig, String biomeType, Biome thisBiome, int priority) { BiomeRecipe b = new BiomeRecipe(addon, thisBiome, priority); // Set the name diff --git a/src/main/resources/biomes.yml b/src/main/resources/biomes.yml index 8b8dba0..637517b 100644 --- a/src/main/resources/biomes.yml +++ b/src/main/resources/biomes.yml @@ -116,7 +116,7 @@ biomes: TALL_GRASS: 20:GRASS_BLOCK NETHER: friendlyname: "&cNether" - biome: NETHER + biome: NETHER_WASTES icon: LAVA_BUCKET priority: 5 contents: