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); }