From 3ba2c17c6a8fb6390d5ad91bfabea5038d9db5ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20F?= Date: Wed, 1 Jul 2020 21:15:18 +0100 Subject: [PATCH] Add support to hives with variable capacity --- .../java/com/tomff/beesplus/gui/BeeHiveInfo.java | 13 +++---------- .../tomff/beesplus/gui/HoneyLevelIndicators.java | 15 ++++++++++----- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/tomff/beesplus/gui/BeeHiveInfo.java b/src/main/java/com/tomff/beesplus/gui/BeeHiveInfo.java index be0d3a1..dcf915e 100644 --- a/src/main/java/com/tomff/beesplus/gui/BeeHiveInfo.java +++ b/src/main/java/com/tomff/beesplus/gui/BeeHiveInfo.java @@ -52,14 +52,6 @@ public class BeeHiveInfo extends Gui { } } - private int getBeehivePopulation(Beehive beehive) { - return beehive.getEntityCount(); - } - - private int getBeehiveMaxPopulation(Beehive beehive) { - return beehive.getMaxEntities(); - } - @Override public void buildIcons() { org.bukkit.block.data.type.Beehive beehiveData = (org.bukkit.block.data.type.Beehive) beehive.getBlockData(); @@ -78,7 +70,7 @@ public class BeeHiveInfo extends Gui { ItemStack beeCapacity = new ItemBuilder(Material.BEE_NEST) .setName(Localization.get(Localization.BEEHIVE_INFO_GUI_BEE_CAPACITY)) - .setLore(Localization.get(Localization.BEEHIVE_INFO_GUI_BEE_CAPACITY_DESC, getBeehivePopulation(beehive), getBeehiveMaxPopulation(beehive)), + .setLore(Localization.get(Localization.BEEHIVE_INFO_GUI_BEE_CAPACITY_DESC, beehive.getEntityCount(), beehive.getMaxEntities()), isSedated) .build(); @@ -100,7 +92,8 @@ public class BeeHiveInfo extends Gui { Icon flowerIcon = new Icon(flower, null); setIcon(flowerIcon, 37); - HoneyLevelIndicators honeyLevelIndicator = HoneyLevelIndicators.getFromLevel(beehiveData.getHoneyLevel()); + HoneyLevelIndicators honeyLevelIndicator = HoneyLevelIndicators.getFromLevel(beehiveData.getHoneyLevel(), + beehiveData.getMaximumHoneyLevel()); setHoneyLevelSlots(honeyLevelIndicator); ItemStack filler = new ItemBuilder(Material.WHITE_STAINED_GLASS_PANE) diff --git a/src/main/java/com/tomff/beesplus/gui/HoneyLevelIndicators.java b/src/main/java/com/tomff/beesplus/gui/HoneyLevelIndicators.java index a221d48..43eca14 100644 --- a/src/main/java/com/tomff/beesplus/gui/HoneyLevelIndicators.java +++ b/src/main/java/com/tomff/beesplus/gui/HoneyLevelIndicators.java @@ -28,11 +28,16 @@ public enum HoneyLevelIndicators { this.slots = slots; } - public static HoneyLevelIndicators getFromLevel(int level) { - return Arrays.stream(values()) - .filter((levelIndicator) -> levelIndicator.level == level) - .findFirst() - .orElse(VERY_HIGH); + public static HoneyLevelIndicators getFromLevel(int currentHoneyLvl, int maxHoneyLvl) { + float ratio = (float) currentHoneyLvl / (float) maxHoneyLvl; + + if (ratio == 0) return EMPTY; + if (ratio <= 0.25) return LOW; + if (ratio <= 0.50) return MEDIUM; + if (ratio <= 0.75) return HIGH; + if (ratio <= 1) return VERY_HIGH; + + return EMPTY; } public int getLevel() {