From 3542c1a62bd3591144aaae6fcfa9689d3e3376e6 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 4 Jul 2021 19:13:36 +0200 Subject: [PATCH] Fixed natural loot generated items going above hard cap --- .../support/obtaining/LootPopulator.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java index 5780d22e..e91d1bb4 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java @@ -88,6 +88,8 @@ public class LootPopulator extends BlockPopulator { multiplier /= plugin.getConfigYml().getDouble("loot.reduce-probability.factor"); } + int cap = 0; + for (EcoEnchant enchantment : enchantments) { if (enchantment == null || enchantment.getRarity() == null) { continue; @@ -145,6 +147,16 @@ public class LootPopulator extends BlockPopulator { if (plugin.getConfigYml().getBool("loot.reduce-probability.enabled")) { multiplier /= plugin.getConfigYml().getDouble("loot.reduce-probability.factor"); } + + if (!enchantment.hasFlag("hard-cap-ignore")) { + cap++; + } + + if (plugin.getConfigYml().getBool("anvil.hard-cap.enabled")) { + if (cap >= plugin.getConfigYml().getInt("anvil.hard-cap.cap")) { + break; + } + } } if (item.getItemMeta() instanceof EnchantmentStorageMeta meta) {