Merge remote-tracking branch 'origin/main' into 1.18
This commit is contained in:
commit
33687254cd
|
|
@ -62,7 +62,8 @@ import java.util.function.Function;
|
|||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Mixin(ModelBakery.class)
|
||||
/* high priority so that our injectors are added before other mods' */
|
||||
@Mixin(value = ModelBakery.class, priority = 600)
|
||||
public abstract class ModelBakeryMixin {
|
||||
|
||||
private static final boolean debugDynamicModelLoading = Boolean.getBoolean("modernfix.debugDynamicModelLoading");
|
||||
|
|
@ -100,6 +101,8 @@ public abstract class ModelBakeryMixin {
|
|||
|
||||
@Shadow @Final public static BlockModel BLOCK_ENTITY_MARKER;
|
||||
|
||||
@Shadow public abstract UnbakedModel getModel(ResourceLocation modelLocation);
|
||||
|
||||
private Cache<Triple<ResourceLocation, Transformation, Boolean>, BakedModel> loadedBakedModels;
|
||||
private Cache<ResourceLocation, UnbakedModel> loadedModels;
|
||||
|
||||
|
|
@ -162,8 +165,9 @@ public abstract class ModelBakeryMixin {
|
|||
* @reason don't actually load the model. instead, keep track of if we need to load a blockstate or a model,
|
||||
* and save the info into the two lists
|
||||
*/
|
||||
@Overwrite
|
||||
private void loadTopLevel(ModelResourceLocation location) {
|
||||
@Inject(method = "loadTopLevel", at = @At("HEAD"), cancellable = true)
|
||||
private void addTopLevelFile(ModelResourceLocation location, CallbackInfo ci) {
|
||||
ci.cancel();
|
||||
if(Objects.equals(location.getVariant(), "inventory")) {
|
||||
modelFiles.add(new ResourceLocation(location.getNamespace(), "item/" + location.getPath()));
|
||||
} else {
|
||||
|
|
@ -338,13 +342,15 @@ public abstract class ModelBakeryMixin {
|
|||
* @author embeddedt
|
||||
* @reason synchronize
|
||||
*/
|
||||
@Overwrite
|
||||
public UnbakedModel getModel(ResourceLocation modelLocation) {
|
||||
if(modelLocation.equals(MISSING_MODEL_LOCATION))
|
||||
return missingModel;
|
||||
@Inject(method = "getModel", at = @At("HEAD"), cancellable = true)
|
||||
public void getOrLoadModelDynamic(ResourceLocation modelLocation, CallbackInfoReturnable<UnbakedModel> cir) {
|
||||
if(modelLocation.equals(MISSING_MODEL_LOCATION)) {
|
||||
cir.setReturnValue(missingModel);
|
||||
return;
|
||||
}
|
||||
UnbakedModel existing = this.unbakedCache.get(modelLocation);
|
||||
if (existing != null) {
|
||||
return existing;
|
||||
cir.setReturnValue(existing);
|
||||
} else {
|
||||
synchronized(this) {
|
||||
if (this.loadingStack.contains(modelLocation)) {
|
||||
|
|
@ -381,7 +387,7 @@ public abstract class ModelBakeryMixin {
|
|||
UnbakedModel result = smallLoadingCache.getOrDefault(modelLocation, iunbakedmodel);
|
||||
// We are done with loading, so clear this cache to allow GC of any unneeded models
|
||||
smallLoadingCache.clear();
|
||||
return result;
|
||||
cir.setReturnValue(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -430,12 +436,12 @@ public abstract class ModelBakeryMixin {
|
|||
return ImmutableList.copyOf(finalList);
|
||||
}
|
||||
|
||||
@Overwrite(remap = false)
|
||||
public BakedModel bake(ResourceLocation arg, ModelState arg2, Function<Material, TextureAtlasSprite> textureGetter) {
|
||||
@Inject(method = "bake(Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/client/resources/model/ModelState;Ljava/util/function/Function;)Lnet/minecraft/client/resources/model/BakedModel;", at = @At("HEAD"), cancellable = true, remap = false)
|
||||
public void getOrLoadBakedModelDynamic(ResourceLocation arg, ModelState arg2, Function<Material, TextureAtlasSprite> textureGetter, CallbackInfoReturnable<BakedModel> cir) {
|
||||
Triple<ResourceLocation, Transformation, Boolean> triple = Triple.of(arg, arg2.getRotation(), arg2.isUvLocked());
|
||||
BakedModel existing = this.bakedCache.get(triple);
|
||||
if (existing != null) {
|
||||
return existing;
|
||||
cir.setReturnValue(existing);
|
||||
} else if (this.atlasSet == null) {
|
||||
throw new IllegalStateException("bake called too early");
|
||||
} else {
|
||||
|
|
@ -457,7 +463,7 @@ public abstract class ModelBakeryMixin {
|
|||
DynamicModelBakeEvent event = new DynamicModelBakeEvent(arg, iunbakedmodel, ibakedmodel, (ForgeModelBakery)(Object)this);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
this.bakedCache.put(triple, event.getModel());
|
||||
return event.getModel();
|
||||
cir.setReturnValue(event.getModel());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user