Skip to content

Commit 14a89f9

Browse files
committed
Backport CTM mixin from 1.21
Related: #487
1 parent 8307564 commit 14a89f9

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

forge/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ dependencies {
5555
modCompileOnly("me.shedaniel:RoughlyEnoughItems-forge:${rei_version}") { transitive false }
5656
modCompileOnly("dev.latvian.mods:kubejs-forge:${kubejs_version}")
5757
//modRuntimeOnly("curse.maven:ferritecore-429235:4441949")
58-
modCompileOnly("team.chisel.ctm:CTM:${ctm_version}")
58+
modCompileOnly("curse.maven:ctm-267602:${ctm_version}")
5959

6060
modCompileOnly("curse.maven:supermartijncore-454372:4455391")
6161
modCompileOnly("vazkii.patchouli:Patchouli:1.19.2-77")
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.embeddedt.modernfix.forge.mixin.perf.dynamic_resources.ctm;
2+
3+
import net.minecraft.client.resources.model.BakedModel;
4+
import net.minecraft.client.resources.model.ModelBakery;
5+
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.gen.Accessor;
8+
9+
import java.util.Map;
10+
11+
@Mixin(ModelBakery.class)
12+
@ClientOnlyMixin
13+
public interface CTMModelBakeryAccessor {
14+
@Accessor("bakedCache")
15+
Map<ModelBakery.BakedCacheKey, BakedModel> mfix$getBakedCache();
16+
}

forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/ctm/TextureMetadataHandlerMixin.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
2121
import team.chisel.ctm.CTM;
2222
import team.chisel.ctm.api.model.IModelCTM;
23-
import team.chisel.ctm.client.mixin.ModelBakerImplAccessor;
2423
import team.chisel.ctm.client.model.AbstractCTMBakedModel;
2524
import team.chisel.ctm.client.model.ModelCTM;
2625
import team.chisel.ctm.client.texture.IMetadataSectionCTM;
@@ -39,7 +38,7 @@ public abstract class TextureMetadataHandlerMixin implements ModernFixClientInte
3938

4039
@Shadow(remap = false) @Nonnull protected abstract BakedModel wrap(UnbakedModel model, BakedModel object) throws IOException;
4140

42-
@Shadow(remap = false) @Final public static Multimap<ResourceLocation, Material> TEXTURES_SCRAPED;
41+
@Shadow(remap = false) @Final private Multimap<ResourceLocation, Material> scrapedTextures;
4342

4443
@Inject(method = "<init>", at = @At("RETURN"))
4544
private void subscribeDynamic(CallbackInfo ci) {
@@ -70,7 +69,7 @@ public BakedModel onBakedModelLoad(ResourceLocation rl, UnbakedModel rootModel,
7069
continue;
7170
}
7271

73-
Collection<Material> textures = Sets.newHashSet(TEXTURES_SCRAPED.get(dep));
72+
Collection<Material> textures = Sets.newHashSet(scrapedTextures.get(dep));
7473
Collection<ResourceLocation> newDependencies = model.getDependencies();
7574
for (Material tex : textures) {
7675
IMetadataSectionCTM meta = null;
@@ -108,10 +107,12 @@ private void handleInit(ResourceLocation key, BakedModel wrappedModel, ModelBake
108107
IModelCTM var10 = baked.getModel();
109108
if (var10 instanceof ModelCTM ctmModel) {
110109
if (!ctmModel.isInitialized()) {
110+
// Clear the baked cache as upstream CTM does
111+
((CTMModelBakeryAccessor)bakery).mfix$getBakedCache().clear();
111112
Function<Material, TextureAtlasSprite> spriteGetter = (m) -> {
112113
return Minecraft.getInstance().getModelManager().getAtlas(m.atlasLocation()).getSprite(m.texture());
113114
};
114-
ModelBakery.ModelBakerImpl baker = ModelBakerImplAccessor.createImpl(bakery, ($, m) -> {
115+
ModelBakery.ModelBakerImpl baker = bakery.new ModelBakerImpl(($, m) -> {
115116
return spriteGetter.apply(m);
116117
}, key);
117118
// bypass bakedCache so that dependent models get re-baked and thus retrieve their sprites again

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ parchment_version=2023.07.09
1212
refined_storage_version=4392788
1313
jei_version=15.8.0.11
1414
rei_version=11.0.597
15-
ctm_version=1.20.1-1.1.8+4
15+
ctm_version=5983309
1616
kubejs_version=1902.6.0-build.142
1717
rhino_version=1902.2.2-build.268
1818
supported_minecraft_versions=1.20.1

0 commit comments

Comments
 (0)