Merge remote-tracking branch 'origin/1.19.4' into 1.20
This commit is contained in:
commit
5165cf20c8
|
|
@ -9,9 +9,12 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
|||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.BlockModelRotation;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
import org.embeddedt.modernfix.duck.IExtendedModelBakery;
|
||||
|
|
@ -106,6 +109,25 @@ public class DynamicBakedModelProvider implements Map<ResourceLocation, BakedMod
|
|||
public boolean containsValue(Object o) {
|
||||
return permanentOverrides.containsValue(o) || bakedCache.containsValue(o);
|
||||
}
|
||||
|
||||
private static boolean isVanillaTopLevelModel(ResourceLocation location) {
|
||||
if(location instanceof ModelResourceLocation) {
|
||||
try {
|
||||
ModelResourceLocation mrl = (ModelResourceLocation)location;
|
||||
ResourceLocation registryKey = new ResourceLocation(mrl.getNamespace(), mrl.getPath());
|
||||
// check for standard inventory model
|
||||
if(mrl.getVariant().equals("inventory") && BuiltInRegistries.ITEM.containsKey(registryKey))
|
||||
return true;
|
||||
Optional<Block> blockOpt = BuiltInRegistries.BLOCK.getOptional(registryKey);
|
||||
if(blockOpt.isPresent()) {
|
||||
return ModelBakeryHelpers.getBlockStatesForMRL(blockOpt.get().getStateDefinition(), mrl).size() > 0;
|
||||
}
|
||||
} catch(RuntimeException ignored) {
|
||||
// can occur if the MRL is not valid for that blockstate, ignore
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel get(Object o) {
|
||||
|
|
@ -120,11 +142,11 @@ public class DynamicBakedModelProvider implements Map<ResourceLocation, BakedMod
|
|||
model = missingModel;
|
||||
}
|
||||
if(model == missingModel) {
|
||||
// to correctly emulate the original map, we return null for missing models
|
||||
permanentOverrides.put((ResourceLocation) o, null);
|
||||
return null;
|
||||
} else
|
||||
return model;
|
||||
// to correctly emulate the original map, we return null for missing models, unless they are top-level
|
||||
model = isVanillaTopLevelModel((ResourceLocation)o) ? model : null;
|
||||
permanentOverrides.put((ResourceLocation) o, model);
|
||||
}
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -174,6 +174,14 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
|
|||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a copy of the top-level model list to avoid CME if more models get loaded here.
|
||||
*/
|
||||
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Ljava/util/Map;values()Ljava/util/Collection;", ordinal = 0))
|
||||
private Collection<?> copyTopLevelModelList(Map<?, ?> map) {
|
||||
return new ArrayList<>(map.values());
|
||||
}
|
||||
|
||||
private BiFunction<ResourceLocation, Material, TextureAtlasSprite> textureGetter;
|
||||
|
||||
@Inject(method = "bakeModels", at = @At("HEAD"))
|
||||
|
|
|
|||
|
|
@ -146,6 +146,14 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
|
|||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a copy of the top-level model list to avoid CME if more models get loaded here.
|
||||
*/
|
||||
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Ljava/util/Map;values()Ljava/util/Collection;", ordinal = 0))
|
||||
private Collection<?> copyTopLevelModelList(Map<?, ?> map) {
|
||||
return new ArrayList<>(map.values());
|
||||
}
|
||||
|
||||
private BiFunction<ResourceLocation, Material, TextureAtlasSprite> textureGetter;
|
||||
|
||||
@Inject(method = "bakeModels", at = @At("HEAD"))
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user