Fix dynresources compat with Fabric API

This commit is contained in:
embeddedt 2023-05-01 21:18:19 -04:00
parent 25237eee8c
commit 6d8f90d303
No known key found for this signature in database
GPG Key ID: A69433EC199B5613

View File

@ -36,11 +36,11 @@ import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
@ -57,9 +57,6 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
@Shadow @Final public static ModelResourceLocation MISSING_MODEL_LOCATION;
@Dynamic
@Shadow(remap = false) protected abstract BlockModel method_4718(ResourceLocation location) throws IOException;
@Shadow @Final protected ResourceManager resourceManager;
@Shadow private AtlasSet atlasSet;
@Shadow @Final private Set<ResourceLocation> loadingStack;
@ -130,12 +127,12 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
private Set<ResourceLocation> blockStateFiles;
private Set<ResourceLocation> modelFiles;
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/resources/model/ModelBakery;loadBlockModel(Lnet/minecraft/resources/ResourceLocation;)Lnet/minecraft/client/renderer/block/model/BlockModel;", ordinal = 0))
private BlockModel captureMissingModel(ModelBakery bakery, ResourceLocation location) throws IOException {
this.missingModel = this.method_4718(location);
@ModifyArg(method = "<init>", at = @At(value = "INVOKE", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", ordinal = 0), index = 1)
private Object captureMissingModel(Object model) {
this.missingModel = (UnbakedModel)model;
this.blockStateFiles = new HashSet<>();
this.modelFiles = new HashSet<>();
return (BlockModel)this.missingModel;
return this.missingModel;
}
/**
@ -145,6 +142,8 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
*/
@Inject(method = "loadTopLevel", at = @At("HEAD"), cancellable = true)
private void addTopLevelFile(ModelResourceLocation location, CallbackInfo ci) {
if(location == MISSING_MODEL_LOCATION)
return; /* needed for FAPI compat */
ci.cancel();
if(Objects.equals(location.getVariant(), "inventory")) {
modelFiles.add(new ResourceLocation(location.getNamespace(), "item/" + location.getPath()));