Skip to content

Commit

Permalink
fix: CobbleGen ignored filter
Browse files Browse the repository at this point in the history
  • Loading branch information
null2264 committed Sep 3, 2023
1 parent 4b8de9e commit 0e64f07
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ private String randomizeBlockId(Block key, String dim, Integer yLevel) {
getOutput().getOrDefault("*", List.of())
);

if (blockIds.isEmpty()) return null;

if (blockIds.size() == 1) return blockIds.get(0).id;

ArrayList<WeightedBlock> filteredBlockIds = new ArrayList<>();
AtomicReference<Double> totalWeight = new AtomicReference<>(0.0);

Expand All @@ -53,13 +49,16 @@ private String randomizeBlockId(Block key, String dim, Integer yLevel) {
}
}

if (filteredBlockIds.isEmpty()) return null;

if (filteredBlockIds.size() == 1) return filteredBlockIds.get(0).id;

int idx = 0;
for (double r = Math.random() * totalWeight.get(); idx < filteredBlockIds.size() - 1; ++idx) {
r -= filteredBlockIds.get(idx).weight;
if (r <= 0.0) break;
}

if (filteredBlockIds.isEmpty()) return null;
return filteredBlockIds.get(idx).id;
}

Expand Down

0 comments on commit 0e64f07

Please sign in to comment.