Add support to hives with variable capacity

This commit is contained in:
Tomás F 2020-07-01 21:15:18 +01:00
parent c73fcba252
commit 3ba2c17c6a
2 changed files with 13 additions and 15 deletions

View File

@ -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 @Override
public void buildIcons() { public void buildIcons() {
org.bukkit.block.data.type.Beehive beehiveData = (org.bukkit.block.data.type.Beehive) beehive.getBlockData(); 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) ItemStack beeCapacity = new ItemBuilder(Material.BEE_NEST)
.setName(Localization.get(Localization.BEEHIVE_INFO_GUI_BEE_CAPACITY)) .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) isSedated)
.build(); .build();
@ -100,7 +92,8 @@ public class BeeHiveInfo extends Gui {
Icon flowerIcon = new Icon(flower, null); Icon flowerIcon = new Icon(flower, null);
setIcon(flowerIcon, 37); setIcon(flowerIcon, 37);
HoneyLevelIndicators honeyLevelIndicator = HoneyLevelIndicators.getFromLevel(beehiveData.getHoneyLevel()); HoneyLevelIndicators honeyLevelIndicator = HoneyLevelIndicators.getFromLevel(beehiveData.getHoneyLevel(),
beehiveData.getMaximumHoneyLevel());
setHoneyLevelSlots(honeyLevelIndicator); setHoneyLevelSlots(honeyLevelIndicator);
ItemStack filler = new ItemBuilder(Material.WHITE_STAINED_GLASS_PANE) ItemStack filler = new ItemBuilder(Material.WHITE_STAINED_GLASS_PANE)

View File

@ -28,11 +28,16 @@ public enum HoneyLevelIndicators {
this.slots = slots; this.slots = slots;
} }
public static HoneyLevelIndicators getFromLevel(int level) { public static HoneyLevelIndicators getFromLevel(int currentHoneyLvl, int maxHoneyLvl) {
return Arrays.stream(values()) float ratio = (float) currentHoneyLvl / (float) maxHoneyLvl;
.filter((levelIndicator) -> levelIndicator.level == level)
.findFirst() if (ratio == 0) return EMPTY;
.orElse(VERY_HIGH); 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() { public int getLevel() {