33import com .google .common .collect .Multimap ;
44import com .google .common .collect .Sets ;
55import com .mojang .datafixers .util .Pair ;
6+ import net .minecraft .client .Minecraft ;
7+ import net .minecraft .client .renderer .texture .TextureAtlasSprite ;
68import net .minecraft .client .resources .model .*;
79import net .minecraft .resources .ResourceLocation ;
810import org .embeddedt .modernfix .ModernFixClient ;
911import org .embeddedt .modernfix .annotation .ClientOnlyMixin ;
1012import org .embeddedt .modernfix .annotation .RequiresMod ;
1113import org .embeddedt .modernfix .api .entrypoint .ModernFixClientIntegration ;
14+ import org .embeddedt .modernfix .neoforge .dynresources .IModelBakerImpl ;
1215import org .spongepowered .asm .mixin .Final ;
1316import org .spongepowered .asm .mixin .Mixin ;
1417import org .spongepowered .asm .mixin .Shadow ;
1518import org .spongepowered .asm .mixin .injection .At ;
1619import org .spongepowered .asm .mixin .injection .Inject ;
1720import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
1821import team .chisel .ctm .CTM ;
22+ import team .chisel .ctm .api .model .IModelCTM ;
23+ import team .chisel .ctm .client .model .AbstractCTMBakedModel ;
24+ import team .chisel .ctm .client .model .ModelCTM ;
1925import team .chisel .ctm .client .texture .IMetadataSectionCTM ;
2026import team .chisel .ctm .client .util .ResourceUtil ;
2127import team .chisel .ctm .client .util .TextureMetadataHandler ;
2228
2329import javax .annotation .Nonnull ;
2430import java .io .IOException ;
2531import java .util .*;
32+ import java .util .function .Function ;
2633
2734@ Mixin (TextureMetadataHandler .class )
2835@ RequiresMod ("ctm" )
@@ -31,22 +38,21 @@ public abstract class TextureMetadataHandlerMixin implements ModernFixClientInte
3138
3239 @ Shadow (remap = false ) @ Nonnull protected abstract BakedModel wrap (UnbakedModel model , BakedModel object ) throws IOException ;
3340
34- @ Shadow ( remap = false ) @ Final public static Multimap <ResourceLocation , Material > TEXTURES_SCRAPED ;
41+ @ Shadow @ Final private Multimap <ResourceLocation , Material > scrapedTextures ;
3542
3643 @ Inject (method = "<init>" , at = @ At ("RETURN" ))
3744 private void subscribeDynamic (CallbackInfo ci ) {
3845 ModernFixClient .CLIENT_INTEGRATIONS .add (this );
3946 }
4047
41- @ Inject (method = { "onModelBake(Lnet/minecraftforge/ client/event/ModelEvent$ModifyBakingResult;)V" , "onModelBake(Lnet/minecraftforge /client/event/ModelEvent$BakingCompleted;)V" }, at = @ At ("HEAD" ), cancellable = true , remap = false )
48+ @ Inject (method = { "onModelBake(Lnet/neoforged/neoforge/ client/event/ModelEvent$ModifyBakingResult;)V" , "onModelBake(Lnet/neoforged/neoforge /client/event/ModelEvent$BakingCompleted;)V" }, at = @ At ("HEAD" ), cancellable = true , remap = false )
4249 private void noIteration (CallbackInfo ci ) {
4350 ci .cancel ();
4451 }
4552
4653 @ Override
4754 public BakedModel onBakedModelLoad (ResourceLocation rl , UnbakedModel rootModel , BakedModel baked , ModelState state , ModelBakery bakery ) {
48- if (true ) throw new UnsupportedOperationException ("not ported yet" );
49- if (rl instanceof ModelResourceLocation && false /* !(baked instanceof AbstractCTMBakedModel) && !baked.isCustomRenderer() */ ) {
55+ if (rl instanceof ModelResourceLocation && !(baked instanceof AbstractCTMBakedModel ) && !baked .isCustomRenderer ()) {
5056 Deque <ResourceLocation > dependencies = new ArrayDeque <>();
5157 Set <ResourceLocation > seenModels = new HashSet <>();
5258 dependencies .push (rl );
@@ -63,7 +69,7 @@ public BakedModel onBakedModelLoad(ResourceLocation rl, UnbakedModel rootModel,
6369 continue ;
6470 }
6571
66- Collection <Material > textures = Sets .newHashSet (TEXTURES_SCRAPED .get (dep ));
72+ Collection <Material > textures = Sets .newHashSet (scrapedTextures .get (dep ));
6773 Collection <ResourceLocation > newDependencies = model .getDependencies ();
6874 for (Material tex : textures ) {
6975 IMetadataSectionCTM meta = null ;
@@ -97,24 +103,21 @@ public BakedModel onBakedModelLoad(ResourceLocation rl, UnbakedModel rootModel,
97103 }
98104
99105 private void handleInit (ResourceLocation key , BakedModel wrappedModel , ModelBakery bakery ) {
100- if (true ) throw new UnsupportedOperationException ("not ported yet" );
101- /*
102106 if (wrappedModel instanceof AbstractCTMBakedModel baked ) {
103107 IModelCTM var10 = baked .getModel ();
104108 if (var10 instanceof ModelCTM ctmModel ) {
105109 if (!ctmModel .isInitialized ()) {
106110 Function <Material , TextureAtlasSprite > spriteGetter = (m ) -> {
107111 return Minecraft .getInstance ().getModelManager ().getAtlas (m .atlasLocation ()).getSprite (m .texture ());
108112 };
109- ModelBakery.ModelBakerImpl baker = ModelBakerImplAccessor.createImpl( bakery, ($ , m) -> {
110- return spriteGetter.apply(m );
113+ ModelBakery .ModelBakerImpl baker = bakery . new ModelBakerImpl (( rl , m ) -> {
114+ return m . sprite ( );
111115 }, key );
112116 // bypass bakedCache so that dependent models get re-baked and thus retrieve their sprites again
113117 ((IModelBakerImpl )baker ).mfix$ignoreCache ();
114118 ctmModel .bake (baker , spriteGetter , BlockModelRotation .X0_Y0 , key );
115119 }
116120 }
117121 }
118- */
119122 }
120123}
0 commit comments