mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 11:59:25 +00:00
Allow IModel to express itself as a vanilla parent (#5195)
* Fix errors caused by fancy missing model being non-vanilla parent * Switch instanceof checks to a default IModel method * Small code tweaks
This commit is contained in:
1 parent
4e1f7138ee
commit
f9c2f715fd
3 files changed
+23
-11
No files matched your search
@@ -32,6 +32,7 @@ import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverrideList;
|
||||
import net.minecraft.client.renderer.block.model.ModelBlock;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
@@ -95,6 +96,12 @@ final class FancyMissingModel implements IModel
|
||||
return ImmutableList.of(font2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ModelBlock> asVanillaModel()
|
||||
{
|
||||
return missingModel.asVanillaModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
|
||||
{
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.Optional;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ModelBlock;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -121,4 +122,8 @@ public interface IModel
|
||||
default IModel retexture(ImmutableMap<String, String> textures) {
|
||||
return this;
|
||||
}
|
||||
|
||||
default Optional<ModelBlock> asVanillaModel() {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
@@ -375,23 +375,17 @@ public final class ModelLoader extends ModelBakery
|
||||
public Collection<ResourceLocation> getTextures()
|
||||
{
|
||||
// setting parent here to make textures resolve properly
|
||||
if(model.getParentLocation() != null)
|
||||
ResourceLocation parentLocation = model.getParentLocation();
|
||||
if(parentLocation != null && model.parent == null)
|
||||
{
|
||||
if(model.getParentLocation().getResourcePath().equals("builtin/generated"))
|
||||
if(parentLocation.getResourcePath().equals("builtin/generated"))
|
||||
{
|
||||
model.parent = MODEL_GENERATED;
|
||||
}
|
||||
else
|
||||
{
|
||||
IModel parent = ModelLoaderRegistry.getModelOrLogError(model.getParentLocation(), "Could not load vanilla model parent '" + model.getParentLocation() + "' for '" + model);
|
||||
if(parent instanceof VanillaModelWrapper)
|
||||
{
|
||||
model.parent = ((VanillaModelWrapper) parent).model;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException("vanilla model '" + model + "' can't have non-vanilla parent");
|
||||
}
|
||||
model.parent = ModelLoaderRegistry.getModelOrLogError(parentLocation, "Could not load vanilla model parent '" + parentLocation + "' for '" + model + "'")
|
||||
.asVanillaModel().orElseThrow(() -> new IllegalStateException("vanilla model '" + model + "' can't have non-vanilla parent"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -621,6 +615,12 @@ public final class ModelLoader extends ModelBakery
|
||||
}
|
||||
return new VanillaModelWrapper(location, model, value, animation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ModelBlock> asVanillaModel()
|
||||
{
|
||||
return Optional.of(model);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class WeightedRandomModel implements IModel
|
||||
|
||||
Reference in new issue
Block a user