fix: re-resolve microblock icons after texture stitch

loadIcons runs in TextureStitchEvent.Post and could cache icons before
other mods finished theirs in the same event (Chisel CTMLib -v4 submaps),
leaving microblocks with missing or previous-stitch textures.

loadIcons now marks icons stale; the first icont() read after a stitch
rebuilds them once. Icons set through icont_$eq are kept. Addon materials
reading icont() get the fix without API changes.

Fixes GTNH issue 27183 without relying on handler priority (upstream #63).
This commit is contained in:
Algent committed 2026-10-14 16:37:20 +02:00
1 parent ac2cd5017c
commit 255b817c92
4 files changed
+81 -2

No files matched your search

@@ -31,6 +31,10 @@ public class BlockMicroMaterial implements IMicroMaterial {
@SideOnly(Side.CLIENT)
private MultiIconTransformation icont;
/** Set by {@link #loadIcons()} so the next {@link #icont()} read re-resolves the block's icons. */
@SideOnly(Side.CLIENT)
private volatile boolean iconsStale;
public BlockMicroMaterial(Block block, int meta) {
this.block = block;
this.meta = meta;
@@ -111,23 +115,40 @@ public class BlockMicroMaterial implements IMicroMaterial {
return blockKey;
}
/**
* Returns the side icons. The first read after a texture stitch rebuilds them from the block: {@link #loadIcons()}
* runs inside {@code TextureStitchEvent.Post}, possibly before another mod's Post handler finishes its own icons
* (Chisel's CTMLib submaps create their sub-icons there), and the cached copy would otherwise keep missing or
* previous-stitch icons until the next stitch.
*/
public MultiIconTransformation icont() {
if (iconsStale) {
icont = buildIcons();
iconsStale = false;
}
return icont;
}
/** Explicitly assigned icons are kept as-is and are not re-resolved on the next {@link #icont()} read. */
public void icont_$eq(MultiIconTransformation icont) {
this.icont = icont;
iconsStale = false;
}
@Override
@SideOnly(Side.CLIENT)
public void loadIcons() {
icont_$eq(buildIcons());
iconsStale = true;
}
private MultiIconTransformation buildIcons() {
Block currentBlock = Block.getBlockFromName(blockKey());
IIcon[] icons = new IIcon[6];
for (int side = 0; side < icons.length; side++) {
icons[side] = codechicken$microblock$BlockMicroMaterial$$safeIcon$1(currentBlock, side);
}
icont_$eq(new MultiIconTransformation(icons));
return new MultiIconTransformation(icons);
}
public final IIcon codechicken$microblock$BlockMicroMaterial$$safeIcon$1(Block block, int side) {