Merge remote-tracking branch 'origin/1.19.2' into 1.19.4
This commit is contained in:
commit
2cb5acb9f9
|
|
@ -9,9 +9,12 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||||
import net.minecraft.client.resources.model.BakedModel;
|
import net.minecraft.client.resources.model.BakedModel;
|
||||||
import net.minecraft.client.resources.model.BlockModelRotation;
|
import net.minecraft.client.resources.model.BlockModelRotation;
|
||||||
import net.minecraft.client.resources.model.ModelBakery;
|
import net.minecraft.client.resources.model.ModelBakery;
|
||||||
|
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.util.RandomSource;
|
import net.minecraft.util.RandomSource;
|
||||||
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import org.apache.commons.lang3.tuple.Triple;
|
import org.apache.commons.lang3.tuple.Triple;
|
||||||
import org.embeddedt.modernfix.duck.IExtendedModelBakery;
|
import org.embeddedt.modernfix.duck.IExtendedModelBakery;
|
||||||
|
|
@ -107,6 +110,25 @@ public class DynamicBakedModelProvider implements Map<ResourceLocation, BakedMod
|
||||||
return permanentOverrides.containsValue(o) || bakedCache.containsValue(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
|
@Override
|
||||||
public BakedModel get(Object o) {
|
public BakedModel get(Object o) {
|
||||||
BakedModel model = permanentOverrides.getOrDefault(o, SENTINEL);
|
BakedModel model = permanentOverrides.getOrDefault(o, SENTINEL);
|
||||||
|
|
@ -120,11 +142,11 @@ public class DynamicBakedModelProvider implements Map<ResourceLocation, BakedMod
|
||||||
model = missingModel;
|
model = missingModel;
|
||||||
}
|
}
|
||||||
if(model == missingModel) {
|
if(model == missingModel) {
|
||||||
// to correctly emulate the original map, we return null for missing models
|
// to correctly emulate the original map, we return null for missing models, unless they are top-level
|
||||||
permanentOverrides.put((ResourceLocation) o, null);
|
model = isVanillaTopLevelModel((ResourceLocation)o) ? model : null;
|
||||||
return null;
|
permanentOverrides.put((ResourceLocation) o, model);
|
||||||
} else
|
}
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -172,6 +172,14 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
|
||||||
return ImmutableList.of();
|
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;
|
private BiFunction<ResourceLocation, Material, TextureAtlasSprite> textureGetter;
|
||||||
|
|
||||||
@Inject(method = "bakeModels", at = @At("HEAD"))
|
@Inject(method = "bakeModels", at = @At("HEAD"))
|
||||||
|
|
|
||||||
|
|
@ -146,6 +146,14 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
|
||||||
return ImmutableList.of();
|
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;
|
private BiFunction<ResourceLocation, Material, TextureAtlasSprite> textureGetter;
|
||||||
|
|
||||||
@Inject(method = "bakeModels", at = @At("HEAD"))
|
@Inject(method = "bakeModels", at = @At("HEAD"))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user