From 73a9d124152dc60032677d9df22be3095446c297 Mon Sep 17 00:00:00 2001 From: Maik Marschner Date: Fri, 28 Jul 2023 22:40:04 +0200 Subject: [PATCH] Fix biome palette errors when loading worlds generated with WorldPainter. --- .../se/llbit/chunky/world/biome/ArrayBiomePalette.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/chunky/src/java/se/llbit/chunky/world/biome/ArrayBiomePalette.java b/chunky/src/java/se/llbit/chunky/world/biome/ArrayBiomePalette.java index e34aa0eb28..174be38bae 100644 --- a/chunky/src/java/se/llbit/chunky/world/biome/ArrayBiomePalette.java +++ b/chunky/src/java/se/llbit/chunky/world/biome/ArrayBiomePalette.java @@ -24,8 +24,10 @@ public ArrayBiomePalette(@NotNull List palette) { @Override public Biome get(int id) { - assert id >= 0 && id < palette.size() : "id " + id + " out of bounds for palette"; - + if (id < 0 || id >= palette.size()) { + // this should not happen but is very common with WorldPainter generated worlds + return Biomes.biomesPrePalette[1]; + } return this.palette.get(id); } @@ -34,12 +36,12 @@ public int put(@NotNull Biome biome) { assert biome != null; for (int i = 0, len = this.palette.size(); i <= len; i++) { - if(i == palette.size()) { //biome must not be in palette, so add it + if (i == palette.size()) { //biome must not be in palette, so add it this.palette.add(biome); return i; } - if(this.palette.get(i) == biome) { //found biome in palette, return it + if (this.palette.get(i) == biome) { //found biome in palette, return it return i; } }