From 81b8fb02aeb019efe3d9052f8f5c5051eb045e31 Mon Sep 17 00:00:00 2001 From: Julian Krings Date: Sun, 22 Jun 2025 16:31:12 +0200 Subject: [PATCH] replace rarity calculation due to it breaking at more than two values --- .../com/volmit/iris/engine/object/IRare.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/core/src/main/java/com/volmit/iris/engine/object/IRare.java b/core/src/main/java/com/volmit/iris/engine/object/IRare.java index 56f4da4d4..f010046d4 100644 --- a/core/src/main/java/com/volmit/iris/engine/object/IRare.java +++ b/core/src/main/java/com/volmit/iris/engine/object/IRare.java @@ -69,6 +69,32 @@ public interface IRare { 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 pickLegacy(List possibilities, double noiseValue) { + if (possibilities.isEmpty()) { + return null; + } + if (possibilities.size() == 1) { return possibilities.get(0); }