Support the new Fabric Model Loading API v1

This commit is contained in:
embeddedt 2023-07-12 20:13:50 -04:00
parent c98721056d
commit 083664d858
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
3 changed files with 22 additions and 20 deletions

View File

@ -29,6 +29,18 @@ configurations {
}
}
// TODO remove
repositories {
maven {
name = "Technici4n"
url = "https://raw.githubusercontent.com/Technici4n/Technici4n-maven/master/"
content {
includeGroup "net.fabricmc.fabric-api"
}
}
}
dependencies {
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
testImplementation "net.fabricmc:fabric-loader-junit:${rootProject.fabric_loader_version}"
@ -37,7 +49,8 @@ dependencies {
modIncludeImplementation(fabricApi.module("fabric-lifecycle-events-v1", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
modIncludeImplementation(fabricApi.module("fabric-screen-api-v1", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
modIncludeImplementation(fabricApi.module("fabric-command-api-v2", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
modIncludeImplementation(fabricApi.module("fabric-models-v0", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
modImplementation("net.fabricmc.fabric-api:fabric-models-v0:0.42.42+db7ad43d77") { exclude group: 'net.fabricmc', module: 'fabric-loader' }
modIncludeImplementation("net.fabricmc.fabric-api:fabric-model-loading-api-v1:1.0.0+5544c20277") { exclude group: 'net.fabricmc', module: 'fabric-loader' }
modImplementation(fabricApi.module("fabric-resource-loader-v0", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
modImplementation(fabricApi.module("fabric-data-generation-api-v1", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
modImplementation("com.terraformersmc:modmenu:${rootProject.modmenu_version}") { transitive false }

View File

@ -1,19 +0,0 @@
package org.embeddedt.modernfix.fabric.mixin.perf.dynamic_resources;
import net.fabricmc.fabric.impl.client.model.ModelLoadingRegistryImpl;
import net.minecraft.client.resources.model.ModelBakery;
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
import org.embeddedt.modernfix.annotation.RequiresMod;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(ModelLoadingRegistryImpl.LoaderInstance.class)
@RequiresMod("fabric-models-v0")
@ClientOnlyMixin
public class LoaderInstanceMixin {
@Redirect(method = "finish", at = @At(value = "FIELD", target = "Lnet/fabricmc/fabric/impl/client/model/ModelLoadingRegistryImpl$LoaderInstance;loader:Lnet/minecraft/client/resources/model/ModelBakery;"))
private void keepLoader(ModelLoadingRegistryImpl.LoaderInstance instance, ModelBakery value) {
/* allow loading models to happen later */
}
}

View File

@ -20,6 +20,7 @@ import org.embeddedt.modernfix.api.entrypoint.ModernFixClientIntegration;
import org.embeddedt.modernfix.duck.IExtendedModelBakery;
import org.embeddedt.modernfix.dynamicresources.DynamicBakedModelProvider;
import org.embeddedt.modernfix.dynamicresources.ModelBakeryHelpers;
import org.embeddedt.modernfix.util.CommonModUtil;
import org.objectweb.asm.Opcodes;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final;
@ -34,6 +35,7 @@ import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.lang.reflect.Field;
import java.util.*;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
@ -79,6 +81,12 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
@Redirect(method = "<init>", at = @At(value = "FIELD", opcode = Opcodes.PUTFIELD, target = "Lnet/minecraft/client/resources/model/ModelBakery;blockColors:Lnet/minecraft/client/color/block/BlockColors;"))
private void replaceTopLevelBakedModels(ModelBakery bakery, BlockColors val) {
// TODO remove terrible reflection hack
CommonModUtil.runWithoutCrash(() -> {
Field f = ModelBakery.class.getDeclaredField("fabric_guardGetOrLoadModel");
f.setAccessible(true);
f.setInt((Object)this, -1000);
}, "reflection hack to remove recursion exception");
this.blockColors = val;
this.ignoreModelLoad = true;
this.loadedBakedModels = CacheBuilder.newBuilder()