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
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)

View File

@ -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() {