From aeb31a97655a36fd94d227c8a7cc85e931b704eb Mon Sep 17 00:00:00 2001 From: KnightMiner Date: Fri, 3 May 2024 19:28:20 -0400 Subject: [PATCH] Fix improper handling of frames in mantle item layer Frames may be repeated, so the index both is not a valid index into the sprite and getting the index from the frame data may have duplicates. Use the unique frames stream instead to guarantee unique valid frame indexes. --- .../mantle/client/model/util/MantleItemLayerModel.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/slimeknights/mantle/client/model/util/MantleItemLayerModel.java b/src/main/java/slimeknights/mantle/client/model/util/MantleItemLayerModel.java index cd753de6..28fe0973 100644 --- a/src/main/java/slimeknights/mantle/client/model/util/MantleItemLayerModel.java +++ b/src/main/java/slimeknights/mantle/client/model/util/MantleItemLayerModel.java @@ -43,6 +43,7 @@ import java.util.Collections; import java.util.EnumMap; import java.util.List; +import java.util.PrimitiveIterator.OfInt; import java.util.Set; import java.util.function.Function; @@ -162,7 +163,10 @@ public static ImmutableList getQuadsForSprite(int color, int tint, Te FaceData faceData = new FaceData(uMax, vMax); boolean translucent = false; - for(int f = 0; f < sprite.getFrameCount(); f++) { + OfInt frames = sprite.getUniqueFrames().iterator(); + boolean hasFrames = frames.hasNext(); + while (frames.hasNext()) { + int f = frames.nextInt(); boolean ptu; boolean[] ptv = new boolean[uMax]; Arrays.fill(ptv, true); @@ -309,7 +313,7 @@ else if (building) { // 3. only use the first frame // of these, 2 would give the most accurate result. However, its also the hardest to calculate // of the remaining methods, 3 is both more accurate and easier to calculate than 1, so I opted for that approach - if (sprite.getFrameCount() > 0) { + if (hasFrames) { for(int v = 0; v < vMax; v++) { for(int u = 0; u < uMax; u++) { int alpha = sprite.getPixelRGBA(0, u, vMax - v - 1) >> 24 & 0xFF;