v3.4.2
This commit is contained in:
parent
11f0b489a5
commit
f153b00c7b
@ -72,8 +72,12 @@ public class EnchantPopulator {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Tier getTierByChance() {
|
public Tier getTierByChance() {
|
||||||
if (this.getEnchants().keySet().isEmpty()) return null;
|
Map<Tier, Double> map = this.getEnchants().keySet().stream()
|
||||||
return ExcellentEnchantsAPI.getTierManager().getTierByChance(this.getObtainType());
|
.filter(tier -> tier.getChance(this.getObtainType()) > 0D)
|
||||||
|
.collect(Collectors.toMap(k -> k, v -> v.getChance(this.getObtainType()), (o, n) -> n, HashMap::new));
|
||||||
|
if (map.isEmpty()) return null;
|
||||||
|
|
||||||
|
return Rnd.getByWeight(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -11,6 +11,7 @@ import su.nightexpress.excellentenchants.enchantment.type.ObtainType;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class TierManager extends AbstractManager<ExcellentEnchants> {
|
public class TierManager extends AbstractManager<ExcellentEnchants> {
|
||||||
|
|
||||||
@ -90,9 +91,11 @@ public class TierManager extends AbstractManager<ExcellentEnchants> {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Tier getTierByChance(@NotNull ObtainType obtainType) {
|
public Tier getTierByChance(@NotNull ObtainType obtainType) {
|
||||||
Map<Tier, Double> map = new HashMap<>();
|
Map<Tier, Double> map = this.getTiers().stream()
|
||||||
this.getTiers().forEach(tier -> map.put(tier, tier.getChance(obtainType)));
|
.filter(tier -> tier.getChance(obtainType) > 0D)
|
||||||
map.values().removeIf(chance -> chance <= 0D);
|
.collect(Collectors.toMap(k -> k, v -> v.getChance(obtainType), (o, n) -> n, HashMap::new));
|
||||||
|
if (map.isEmpty()) return null;
|
||||||
|
|
||||||
return Rnd.getByWeight(map);
|
return Rnd.getByWeight(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user