Add hook to load custom mrls/rls not attached to a block or item. (#6010)

This commit is contained in:
Vincent Lee 2019-08-15 11:03:57 -07:00 committed by LexManos
parent 94621fecd1
commit 8c04651301
2 changed files with 39 additions and 185 deletions

View file

@ -9,7 +9,20 @@
private final Map<ResourceLocation, IUnbakedModel> field_217851_H = Maps.newHashMap();
private final Map<ResourceLocation, IBakedModel> field_217852_I = Maps.newHashMap();
private final AtlasTexture.SheetData field_217853_J;
@@ -288,7 +288,7 @@
@@ -142,6 +142,12 @@
p_i51735_4_.func_219895_b("special");
this.func_217843_a(new ModelResourceLocation("minecraft:trident_in_hand#inventory"));
+ for (ResourceLocation rl : getSpecialModels()) {
+ // Same as func_217843_a but without restricting to MRL's
+ IUnbakedModel iunbakedmodel = this.func_209597_a(rl);
+ this.field_217849_F.put(rl, iunbakedmodel);
+ this.field_217851_H.put(rl, iunbakedmodel);
+ }
p_i51735_4_.func_219895_b("textures");
Set<String> set = Sets.newLinkedHashSet();
Set<ResourceLocation> set1 = this.field_217851_H.values().stream().flatMap((p_217838_2_) -> {
@@ -288,7 +294,7 @@
{
lvt_13_5_ = this.field_177598_f.func_199004_b(resourcelocation1).stream().map((p_217839_1_) -> {
try (InputStream inputstream = p_217839_1_.func_199027_b()) {
@ -18,7 +31,7 @@
return pair2;
} catch (Exception exception1) {
throw new ModelBakery.BlockStateDefinitionException(String.format("Exception loading blockstate definition: '%s' in resourcepack: '%s': %s", p_217839_1_.func_199029_a(), p_217839_1_.func_199026_d(), exception1.getMessage()));
@@ -404,7 +404,12 @@
@@ -404,7 +410,12 @@
@Nullable
public IBakedModel func_217845_a(ResourceLocation p_217845_1_, ISprite p_217845_2_) {
@ -32,7 +45,7 @@
if (this.field_217850_G.containsKey(triple)) {
return this.field_217850_G.get(triple);
} else {
@@ -412,11 +417,11 @@
@@ -412,11 +423,11 @@
if (iunbakedmodel instanceof BlockModel) {
BlockModel blockmodel = (BlockModel)iunbakedmodel;
if (blockmodel.func_178310_f() == field_177606_o) {
@ -46,3 +59,14 @@
this.field_217850_G.put(triple, ibakedmodel);
return ibakedmodel;
}
@@ -471,6 +482,10 @@
return this.field_225367_M;
}
+ public Set<ResourceLocation> getSpecialModels() {
+ return java.util.Collections.emptySet();
+ }
+
@OnlyIn(Dist.CLIENT)
static class BlockStateDefinitionException extends RuntimeException {
public BlockStateDefinitionException(String p_i49526_1_) {

View file

@ -145,194 +145,24 @@ public final class ModelLoader extends ModelBakery
ModelLoaderRegistry.clearModelCache(manager);
}
// TODO lots of commented code here - we need to reevaluate what exactly this class needs to do in the new system, which is difficult with no mappings. So let's get everything compiling first.
// This code has mostly been ported to 1.13
/*
@Nonnull
@Override
public IRegistry<ModelResourceLocation, IBakedModel> setupModelRegistry()
{
Map<ModelResourceLocation, IUnbakedModel> map = Maps.<ModelResourceLocation, IUnbakedModel>newHashMap();
private static Set<ResourceLocation> specialModels = new HashSet<>();
if (ClientModLoader.isErrored()) // skip loading models if we're just going to show a fatal error screen
return bakedRegistry;
isLoading = true;
missingModel = ModelLoaderRegistry.getMissingModel();
stateModels.put(MODEL_MISSING, missingModel);
final Set<ResourceLocation> textures = Sets.newHashSet(ModelLoaderRegistry.getTextures());
textures.remove(MissingTextureSprite.getLocation());
textures.addAll(LOCATIONS_BUILTIN_TEXTURES);
textureMap.stitch(resourceManager, textures);
STATE_CONTAINER_OVERRIDES.forEach((p_209602_2_, p_209602_3_) -> {
p_209602_3_.getValidStates().forEach((p_209601_3_) -> {
this.getUnbakedModel(map, BlockModelShapes.getModelLocation(p_209602_2_, p_209601_3_));
});
});
for(ResourceLocation resourcelocation : Item.REGISTRY.getKeys()) {
this.getUnbakedModel(map, new ModelResourceLocation(resourcelocation, "inventory"));
}
this.getUnbakedModel(map, new ModelResourceLocation("minecraft:trident_in_hand#inventory"));
Set<String> set = Sets.<String>newLinkedHashSet();
Set<ResourceLocation> set1 = (Set)map.values().stream().<ResourceLocation>flatMap((p_209595_2_) -> {
return p_209595_2_.getTextures(this::getUnbakedModel, set).stream();
}).collect(Collectors.toSet());
set1.addAll(LOCATIONS_BUILTIN_TEXTURES);
set.forEach((p_209588_0_) -> {
LOGGER.warn("Unable to resolve texture reference: {}", (Object)p_209588_0_);
});
this.textureMap.stitch(this.resourceManager, set1);
map.forEach((p_209599_1_, p_209599_2_) -> {
IBakedModel ibakedmodel = p_209599_2_.bake(this::getUnbakedModel, this.textureMap::getSprite, ModelRotation.X0_Y0, false);
if (ibakedmodel != null) {
this.bakedRegistry.putObject(p_209599_1_, ibakedmodel);
}
});
return this.bakedRegistry;
IBakedModel missingBaked = missingModel.bake(defaultModelGetter(), defaultTextureGetter(), missingModel.getDefaultState(), false, DefaultVertexFormats.ITEM);
Map<IUnbakedModel, IBakedModel> bakedModels = Maps.newHashMap();
HashMultimap<IUnbakedModel, ModelResourceLocation> models = HashMultimap.create();
Multimaps.invertFrom(Multimaps.forMap(stateModels), models);
ProgressBar bakeBar = ProgressManager.push("ModelLoader: baking", models.keySet().size());
for(IUnbakedModel model : models.keySet())
{
String modelLocations = "[" + Joiner.on(", ").join(models.get(model)) + "]";
bakeBar.step(modelLocations);
if(model == getMissingModel())
{
bakedModels.put(model, missingBaked);
}
else
{
try
{
bakedModels.put(model, model.bake(defaultModelGetter(), defaultTextureGetter(), model.getDefaultState(), false, DefaultVertexFormats.ITEM));
}
catch (Exception e)
{
LOGGER.error("Exception baking model for location(s) {}:", modelLocations, e);
bakedModels.put(model, missingBaked);
}
}
}
ProgressManager.pop(bakeBar);
for (Entry<ModelResourceLocation, IUnbakedModel> e : stateModels.entrySet())
{
bakedRegistry.putObject(e.getKey(), bakedModels.get(e.getValue()));
}
return bakedRegistry;
}
protected void loadBlocks()
{
List<Block> blocks = StreamSupport.stream(Block.REGISTRY.spliterator(), false)
.filter(block -> block.getRegistryName() != null)
.sorted(Comparator.comparing(b -> b.getRegistryName().toString()))
.collect(Collectors.toList());
ProgressBar blockBar = ProgressManager.push("ModelLoader: blocks", blocks.size());
for(Block block : blocks)
{
blockBar.step(block.getRegistryName().toString());
for(ResourceLocation location : mapper.getBlockstateLocations(block))
{
loadBlock(mapper, block, location);
}
}
ProgressManager.pop(blockBar);
/**
* Indicate to vanilla that it should load and bake the given model, even if no blocks or
* items use it. This is useful if e.g. you have baked models only for entity renderers.
* Call during {@link net.minecraftforge.client.event.ModelRegistryEvent}
* @param rl The model, either {@link ModelResourceLocation} to point to a blockstate variant,
* or plain {@link ResourceLocation} to point directly to a json in the models folder.
*/
public static void addSpecialModel(ResourceLocation rl) {
specialModels.add(rl);
}
@Override
protected void registerVariant(@Nullable ModelBlockDefinition definition, ModelResourceLocation location)
{
IUnbakedModel model;
try
{
model = ModelLoaderRegistry.getModel(location);
}
catch(Exception e)
{
storeException(location, e);
model = ModelLoaderRegistry.getMissingModel(location, e);
}
stateModels.put(location, model);
public Set<ResourceLocation> getSpecialModels() {
return specialModels;
}
@Override
protected void registerMultipartVariant(ModelBlockDefinition definition, Collection<ModelResourceLocation> locations)
{
for (ModelResourceLocation location : locations)
{
multipartDefinitions.put(location, definition);
registerVariant(null, location);
}
}
private void storeException(ResourceLocation location, Exception exception)
{
loadingExceptions.put(location, exception);
}
@Override
protected void loadItemModels()
{
registerVariantNames();
List<Item> items = StreamSupport.stream(Item.REGISTRY.spliterator(), false)
.filter(item -> item.getRegistryName() != null)
.sorted(Comparator.comparing(i -> i.getRegistryName().toString()))
.collect(Collectors.toList());
ProgressBar itemBar = ProgressManager.push("ModelLoader: items", items.size());
for(Item item : items)
{
itemBar.step(item.getRegistryName().toString());
for(String s : getVariantNames(item))
{
ResourceLocation file = getItemLocation(s);
ModelResourceLocation memory = getInventoryVariant(s);
IUnbakedModel model = ModelLoaderRegistry.getMissingModel();
Exception exception = null;
try
{
model = ModelLoaderRegistry.getModel(memory);
}
catch (Exception blockstateException)
{
try
{
model = ModelLoaderRegistry.getModel(file);
ModelLoaderRegistry.addAlias(memory, file);
}
catch (Exception normalException)
{
exception = new ItemLoadingException("Could not load item model either from the normal location " + file + " or from the blockstate", normalException, blockstateException);
}
}
if (exception != null)
{
storeException(memory, exception);
model = ModelLoaderRegistry.getMissingModel(memory, exception);
}
stateModels.put(memory, model);
}
}
ProgressManager.pop(itemBar);
}
*/
/**
* Hooked from ModelBakery, allows using MRLs that don't end with "inventory" for items.
*/