From ec607a41ed4938287af9c5d4944b0b10ce482231 Mon Sep 17 00:00:00 2001 From: danyadev Date: Thu, 24 Sep 2026 18:49:17 +0300 Subject: [PATCH] remove theoretical item submap support and fix memory leak on resource reload --- .../team/chisel/ctmlib/TextureSubmap.java | 40 ++++--------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/src/main/java/team/chisel/ctmlib/TextureSubmap.java b/src/main/java/team/chisel/ctmlib/TextureSubmap.java index 5b90d422..f6740ed5 100644 --- a/src/main/java/team/chisel/ctmlib/TextureSubmap.java +++ b/src/main/java/team/chisel/ctmlib/TextureSubmap.java @@ -116,10 +116,12 @@ public class TextureSubmap implements IIcon, ISubmap { */ @SubscribeEvent public final void onTextureStitchPre(TextureStitchEvent.Pre event) { + if (event.map.getTextureType() != 0) return; TextureSubmapSprite.clearSourceCache(); for (TextureSubmap ts : submaps) { ts.registerSubIcons(event.map); } + submaps.clear(); } @SubscribeEvent @@ -135,17 +137,6 @@ public class TextureSubmap implements IIcon, ISubmap { return; } - // Texture maps rebuild their registered icon list on reload. Ignore stale TextureSubmap instances left over - // from an earlier stitch (and submaps belonging to a different atlas). - if (textureMap.getTextureExtry(baseIcon.getIconName()) != baseIcon) { - return; - } - - int textureType = textureMap.getTextureType(); - if (textureType != 0 && textureType != 1) { - return; - } - ResourceLocation sourceIcon = new ResourceLocation(baseIcon.getIconName()); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { @@ -153,14 +144,7 @@ public class TextureSubmap implements IIcon, ISubmap { TextureAtlasSprite registered = textureMap.getTextureExtry(name); if (!(registered instanceof TextureSubmapSprite)) { - TextureSubmapSprite sprite = new TextureSubmapSprite( - name, - sourceIcon, - textureType, - width, - height, - x, - y); + TextureSubmapSprite sprite = new TextureSubmapSprite(name, sourceIcon, width, height, x, y); if (textureMap.setTextureEntry(name, sprite)) { registered = sprite; } else { @@ -194,17 +178,15 @@ public class TextureSubmap implements IIcon, ISubmap { private static final Map sourceCache = new ConcurrentHashMap<>(); private final ResourceLocation sourceIcon; - private final int textureType; private final int columns; private final int rows; private final int cellX; private final int cellY; - private TextureSubmapSprite(String name, ResourceLocation sourceIcon, int textureType, int columns, int rows, - int cellX, int cellY) { + private TextureSubmapSprite(String name, ResourceLocation sourceIcon, int columns, int rows, int cellX, + int cellY) { super(name); this.sourceIcon = sourceIcon; - this.textureType = textureType; this.columns = columns; this.rows = rows; this.cellX = cellX; @@ -264,15 +246,9 @@ public class TextureSubmap implements IIcon, ISubmap { } private ResourceLocation getSourceResource() { - String path; - if (textureType == 0) { - path = "textures/blocks/"; - } else if (textureType == 1) { - path = "textures/items/"; - } else { - throw new IllegalStateException("Unsupported texture map type " + textureType); - } - return new ResourceLocation(sourceIcon.getResourceDomain(), path + sourceIcon.getResourcePath() + ".png"); + return new ResourceLocation( + sourceIcon.getResourceDomain(), + "textures/blocks/" + sourceIcon.getResourcePath() + ".png"); } private BufferedImage extractSubImage(BufferedImage source, boolean animated) {