9
0
mirror of https://github.com/Auxilor/EcoMobs.git synced 2025-12-22 16:39:25 +00:00

Improved drops for multiple identical items

This commit is contained in:
Auxilor
2021-09-12 16:57:14 +01:00
parent 2795fa8220
commit 30e0ed02a4
2 changed files with 30 additions and 25 deletions

View File

@@ -9,6 +9,7 @@ import com.willfp.eco.core.items.builder.ItemBuilder;
import com.willfp.eco.core.items.builder.ItemStackBuilder;
import com.willfp.eco.core.recipe.Recipes;
import com.willfp.eco.core.tuples.Pair;
import com.willfp.eco.util.NumberUtils;
import com.willfp.eco.util.StringUtils;
import com.willfp.ecobosses.bosses.effects.Effect;
import com.willfp.ecobosses.bosses.effects.Effects;
@@ -142,8 +143,7 @@ public class EcoBoss extends PluginDependent<EcoPlugin> {
/**
* The drops.
*/
@Getter
private final Map<ItemStack, Double> drops;
private final List<String> drops;
/**
* The exp to drop.
@@ -335,23 +335,8 @@ public class EcoBoss extends PluginDependent<EcoPlugin> {
this.spawnTotemDisabledWorldNames = this.getConfig().getStrings("spawn-totem.world-blacklist").stream().map(String::toLowerCase).collect(Collectors.toList());
// Rewards
this.drops = new HashMap<>();
for (String string : this.getConfig().getStrings("rewards.drops")) {
YamlConfiguration tempConfig = new YamlConfiguration();
double chance = 100;
if (string.contains("::")) {
String[] split = string.split("::");
chance = Double.parseDouble(split[0]);
string = split[1];
}
ItemStack itemStack = Items.lookup(string).getItem();
if (itemStack.getType() == Material.AIR) {
Bukkit.getLogger().warning(this.getName() + " has an invalid drop configured! (" + string + ")");
continue;
}
this.drops.put(itemStack, chance);
}
this.drops = new ArrayList<>();
drops.addAll(this.getConfig().getStrings("rewards.drops", false));
this.experienceOptions = new ExperienceOptions(
this.getConfig().getInt("rewards.xp.minimum"),
@@ -588,6 +573,31 @@ public class EcoBoss extends PluginDependent<EcoPlugin> {
return true;
}
public List<ItemStack> generateDrops() {
List<ItemStack> drops = new ArrayList<>();
for (String dropName : this.drops) {
double chance = 100;
if (dropName.contains("::")) {
String[] split = dropName.split("::");
chance = Double.parseDouble(split[0]);
dropName = split[1];
}
ItemStack itemStack = Items.lookup(dropName).getItem();
if (itemStack.getType() == Material.AIR) {
Bukkit.getLogger().warning(this.getName() + " has an invalid drop configured! (" + dropName + ")");
continue;
}
if (NumberUtils.randFloat(0, 100) <= chance) {
drops.add(itemStack);
}
}
return drops;
}
/**
* Create effect tickers for Living Boss.
*

View File

@@ -131,12 +131,7 @@ public class DeathListeners extends PluginDependent<EcoPlugin> implements Listen
}
}
List<ItemStack> drops = new ArrayList<>();
for (Map.Entry<ItemStack, Double> entry : boss.getDrops().entrySet()) {
if (NumberUtils.randFloat(0, 100) < entry.getValue()) {
drops.add(entry.getKey().clone());
}
}
List<ItemStack> drops = boss.generateDrops();
for (Entity nearby : entity.getNearbyEntities(boss.getNearbyRadius(), boss.getNearbyRadius(), boss.getNearbyRadius())) {
if (nearby instanceof Player) {