From 54c3c28788437c229fc15cfe13370abad60a9d10 Mon Sep 17 00:00:00 2001 From: wietse Date: Sun, 2 Aug 2026 15:12:13 +0200 Subject: [PATCH] Fix random rock texture selection --- .../toniarts/openkeeper/view/map/MapViewController.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/toniarts/openkeeper/view/map/MapViewController.java b/src/main/java/toniarts/openkeeper/view/map/MapViewController.java index a1ac19893..0cb67db0b 100644 --- a/src/main/java/toniarts/openkeeper/view/map/MapViewController.java +++ b/src/main/java/toniarts/openkeeper/view/map/MapViewController.java @@ -397,7 +397,10 @@ public void visit(Spatial spatial) { // The principle is bit wrong, the random texture is tied to the tile, and not material etc. // But it is probably just the tops of few tiles, so... - int tex = tile.getRandomTextureIndex(); + // ROCK TOP.kmf contains 2 texture alternatives while Rock declares 3 textureFrames + // in Terrain.kwd. Wrap the third weighted slot to the default texture instead of + // trying to load the nonexistent T_Rock_Top2T_Rock_top2_2.j3m material. + int tex = Math.floorMod(tile.getRandomTextureIndex(), textures.size()); if (tex != 0) { // 0 is the default anyway Geometry g = (Geometry) spatial; Material m = g.getMaterial(); @@ -413,7 +416,6 @@ public void visit(Spatial spatial) { g.setMaterial(newMaterial); } catch (Exception e) { - // FIXME: Rock top fails, we may have a problem in the material naming logger.log(Level.WARNING, "Failed to load a random texture to terrain id " + tile.getTerrainId() + ", texture index " + tex + "!", e); } }