9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-19 15:09:18 +00:00

replace rarity calculation due to it breaking at more than two values

This commit is contained in:
Julian Krings
2025-06-22 16:31:12 +02:00
committed by Julian Krings
parent 77842489e5
commit 81b8fb02ae

View File

@@ -69,6 +69,32 @@ public interface IRare {
return null; return null;
} }
if (possibilities.size() == 1) {
return possibilities.getFirst();
}
double total = 0;
for (T i : possibilities) {
total += 1d / i.getRarity();
}
double threshold = total * noiseValue;
double buffer = 0;
for (T i : possibilities) {
buffer += 1d / i.getRarity();
if (buffer >= threshold) {
return i;
}
}
return possibilities.getLast();
}
static <T extends IRare> T pickLegacy(List<T> possibilities, double noiseValue) {
if (possibilities.isEmpty()) {
return null;
}
if (possibilities.size() == 1) { if (possibilities.size() == 1) {
return possibilities.get(0); return possibilities.get(0);
} }