mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 19:15:32 +00:00
Fixed model error reporting, fixed model errors in test mods that shouldn't happen, fixed custom texture loading, made more things private/final.
This commit is contained in:
1 parent
2bdb614fda
commit
b81a13d010
26 files changed
+308
-278
No files matched your search
@@ -163,6 +163,7 @@ public class BlockStateLoader
|
||||
public IModel process(IModel base)
|
||||
{
|
||||
int size = parts.size();
|
||||
// FIXME: should missing base be handled this way?
|
||||
boolean hasBase = base != ModelLoaderRegistry.getMissingModel();
|
||||
|
||||
if (hasBase)
|
||||
@@ -182,7 +183,7 @@ public class BlockStateLoader
|
||||
{
|
||||
SubModel part = entry.getValue();
|
||||
|
||||
IModel model = ModelLoaderRegistry.getModel(part.getModelLocation());
|
||||
IModel model = ModelLoaderRegistry.getModelOrLogError(part.getModelLocation(), "Unable to load block sub-model: \'" + part.getModelLocation());
|
||||
|
||||
IModelState partState = new ModelStateComposition(baseTr, part.getState());
|
||||
|
||||
|
||||
@@ -14,5 +14,5 @@ public interface ICustomModelLoader extends IResourceManagerReloadListener
|
||||
/*
|
||||
* loads (or reloads) specified model
|
||||
*/
|
||||
public IModel loadModel(ResourceLocation modelLocation);
|
||||
public IModel loadModel(ResourceLocation modelLocation) throws Exception;
|
||||
}
|
||||
@@ -29,7 +29,7 @@ import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
public class ItemLayerModel implements IRetexturableModel
|
||||
public final class ItemLayerModel implements IRetexturableModel
|
||||
{
|
||||
public static final ItemLayerModel instance = new ItemLayerModel(ImmutableList.<ResourceLocation>of());
|
||||
|
||||
@@ -108,7 +108,7 @@ public class ItemLayerModel implements IRetexturableModel
|
||||
return new BakedItemModel(builder.build(), particle, map, overrides, null);
|
||||
}
|
||||
|
||||
private static class BakedItemModel implements IPerspectiveAwareModel
|
||||
private static final class BakedItemModel implements IPerspectiveAwareModel
|
||||
{
|
||||
private final ImmutableList<BakedQuad> quads;
|
||||
private final TextureAtlasSprite particle;
|
||||
@@ -170,7 +170,7 @@ public class ItemLayerModel implements IRetexturableModel
|
||||
}
|
||||
}
|
||||
|
||||
public ImmutableList<BakedQuad> getQuadsForSprite(int tint, TextureAtlasSprite sprite, VertexFormat format, Optional<TRSRTransformation> transform)
|
||||
public static ImmutableList<BakedQuad> getQuadsForSprite(int tint, TextureAtlasSprite sprite, VertexFormat format, Optional<TRSRTransformation> transform)
|
||||
{
|
||||
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
|
||||
|
||||
@@ -240,7 +240,7 @@ public class ItemLayerModel implements IRetexturableModel
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
protected boolean isTransparent(int[] pixels, int uMax, int vMax, int u, int v)
|
||||
private static boolean isTransparent(int[] pixels, int uMax, int vMax, int u, int v)
|
||||
{
|
||||
return (pixels[u + (vMax - 1 - v) * uMax] >> 24 & 0xFF) == 0;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
public class ModelDynBucket implements IModel, IModelCustomData, IRetexturableModel
|
||||
public final class ModelDynBucket implements IModel, IModelCustomData, IRetexturableModel
|
||||
{
|
||||
public static final ModelResourceLocation LOCATION = new ModelResourceLocation(new ResourceLocation("forge", "dynbucket"), "inventory");
|
||||
|
||||
@@ -51,12 +51,12 @@ public class ModelDynBucket implements IModel, IModelCustomData, IRetexturableMo
|
||||
|
||||
public static final IModel MODEL = new ModelDynBucket();
|
||||
|
||||
protected final ResourceLocation baseLocation;
|
||||
protected final ResourceLocation liquidLocation;
|
||||
protected final ResourceLocation coverLocation;
|
||||
private final ResourceLocation baseLocation;
|
||||
private final ResourceLocation liquidLocation;
|
||||
private final ResourceLocation coverLocation;
|
||||
|
||||
protected final Fluid fluid;
|
||||
protected final boolean flipGas;
|
||||
private final Fluid fluid;
|
||||
private final boolean flipGas;
|
||||
|
||||
public ModelDynBucket()
|
||||
{
|
||||
@@ -223,7 +223,7 @@ public class ModelDynBucket implements IModel, IModelCustomData, IRetexturableMo
|
||||
}
|
||||
}
|
||||
|
||||
protected static final class BakedDynBucketOverrideHandler extends ItemOverrideList
|
||||
private static final class BakedDynBucketOverrideHandler extends ItemOverrideList
|
||||
{
|
||||
public static final BakedDynBucketOverrideHandler INSTANCE = new BakedDynBucketOverrideHandler();
|
||||
private BakedDynBucketOverrideHandler()
|
||||
@@ -277,7 +277,7 @@ public class ModelDynBucket implements IModel, IModelCustomData, IRetexturableMo
|
||||
}
|
||||
|
||||
// the dynamic bucket is based on the empty bucket
|
||||
protected static class BakedDynBucket implements IPerspectiveAwareModel
|
||||
private static final class BakedDynBucket implements IPerspectiveAwareModel
|
||||
{
|
||||
|
||||
private final ModelDynBucket parent;
|
||||
|
||||
@@ -43,7 +43,7 @@ import com.google.common.collect.Maps;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
public class ModelFluid implements IModelCustomData
|
||||
public final class ModelFluid implements IModelCustomData
|
||||
{
|
||||
public static final ModelFluid waterModel = new ModelFluid(FluidRegistry.WATER);
|
||||
public static final ModelFluid lavaModel = new ModelFluid(FluidRegistry.LAVA);
|
||||
@@ -95,7 +95,7 @@ public class ModelFluid implements IModelCustomData
|
||||
}
|
||||
}
|
||||
|
||||
public static class BakedFluid implements IPerspectiveAwareModel
|
||||
private static final class BakedFluid implements IPerspectiveAwareModel
|
||||
{
|
||||
private static final int x[] = { 0, 0, 1, 1 };
|
||||
private static final int z[] = { 0, 1, 1, 0 };
|
||||
@@ -126,16 +126,6 @@ public class ModelFluid implements IModelCustomData
|
||||
private final boolean gas;
|
||||
private final EnumMap<EnumFacing, List<BakedQuad>> faceQuads;
|
||||
|
||||
public BakedFluid(Optional<TRSRTransformation> transformation, VertexFormat format, int color, TextureAtlasSprite still, TextureAtlasSprite flowing, boolean gas)
|
||||
{
|
||||
this(transformation, format, color, still, flowing, gas, Optional.<IExtendedBlockState>absent());
|
||||
}
|
||||
|
||||
public BakedFluid(Optional<TRSRTransformation> transformation, VertexFormat format, int color, TextureAtlasSprite still, TextureAtlasSprite flowing, boolean gas, Optional<IExtendedBlockState> stateOption)
|
||||
{
|
||||
this(transformation, ImmutableMap.<TransformType, TRSRTransformation>of(), format, color, still, flowing, gas, stateOption);
|
||||
}
|
||||
|
||||
public BakedFluid(Optional<TRSRTransformation> transformation, ImmutableMap<TransformType, TRSRTransformation> transforms, VertexFormat format, int color, TextureAtlasSprite still, TextureAtlasSprite flowing, boolean gas, Optional<IExtendedBlockState> stateOption)
|
||||
{
|
||||
this(transformation, transforms, format, color, still, flowing, gas, stateOption.isPresent(), getCorners(stateOption), getFlow(stateOption));
|
||||
|
||||
@@ -10,12 +10,8 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.*;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -26,15 +22,24 @@ import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.BlockPart;
|
||||
import net.minecraft.client.renderer.block.model.BlockPartFace;
|
||||
import net.minecraft.client.renderer.block.model.BlockPartRotation;
|
||||
import net.minecraft.client.renderer.block.model.BuiltInModel;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
|
||||
import net.minecraft.client.renderer.block.model.ItemModelGenerator;
|
||||
import net.minecraft.client.renderer.block.model.ModelBakery;
|
||||
import net.minecraft.client.renderer.block.model.ModelBlock;
|
||||
import net.minecraft.client.renderer.block.model.ModelBlockDefinition;
|
||||
import net.minecraft.client.renderer.block.model.ModelBlockDefinition.MissingVariantException;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.block.model.ModelRotation;
|
||||
import net.minecraft.client.renderer.block.model.MultipartBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.SimpleBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.Variant;
|
||||
import net.minecraft.client.renderer.block.model.VariantList;
|
||||
import net.minecraft.client.renderer.block.model.WeightedBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.multipart.Multipart;
|
||||
import net.minecraft.client.renderer.block.model.multipart.Selector;
|
||||
import net.minecraft.client.renderer.block.statemap.IStateMapper;
|
||||
import net.minecraft.client.renderer.texture.IIconCreator;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
@@ -42,22 +47,13 @@ import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.renderer.block.model.BuiltInModel;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ModelBakery;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.block.model.ModelRotation;
|
||||
import net.minecraft.client.renderer.block.model.SimpleBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.WeightedBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.multipart.Multipart;
|
||||
import net.minecraft.client.renderer.block.model.multipart.Selector;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.registry.IRegistry;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.IRegistry;
|
||||
import net.minecraftforge.client.model.animation.Animation;
|
||||
import net.minecraftforge.client.model.animation.IAnimatedModel;
|
||||
import net.minecraftforge.client.model.animation.IClip;
|
||||
@@ -78,9 +74,18 @@ import net.minecraftforge.fml.common.registry.RegistryDelegate;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
public class ModelLoader extends ModelBakery
|
||||
public final class ModelLoader extends ModelBakery
|
||||
{
|
||||
private final Map<ModelResourceLocation, IModel> stateModels = Maps.newHashMap();
|
||||
private final Set<ModelResourceLocation> missingVariants = Sets.newHashSet();
|
||||
@@ -110,7 +115,7 @@ public class ModelLoader extends ModelBakery
|
||||
isLoading = true;
|
||||
loadBlocks();
|
||||
loadVariantItemModels();
|
||||
missingModel = ModelLoaderRegistry.getModel(new ResourceLocation(MODEL_MISSING.getResourceDomain(), MODEL_MISSING.getResourcePath()));
|
||||
missingModel = ModelLoaderRegistry.getMissingModel();
|
||||
stateModels.put(MODEL_MISSING, missingModel);
|
||||
|
||||
final Set<ResourceLocation> textures = Sets.newHashSet(ModelLoaderRegistry.getTextures());
|
||||
@@ -181,7 +186,17 @@ public class ModelLoader extends ModelBakery
|
||||
@Override
|
||||
protected void registerVariant(ModelBlockDefinition definition, ModelResourceLocation location)
|
||||
{
|
||||
stateModels.put(location, ModelLoaderRegistry.getModel(location));
|
||||
IModel model;
|
||||
try
|
||||
{
|
||||
model = ModelLoaderRegistry.getModel(location);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
storeException(location, e);
|
||||
model = getMissingModel();
|
||||
}
|
||||
stateModels.put(location, model);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -189,7 +204,7 @@ public class ModelLoader extends ModelBakery
|
||||
{
|
||||
for (ModelResourceLocation location : locations)
|
||||
{
|
||||
stateModels.put(location, ModelLoaderRegistry.getModel(location));
|
||||
registerVariant(null, location);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,25 +250,27 @@ public class ModelLoader extends ModelBakery
|
||||
ResourceLocation file = getItemLocation(s);
|
||||
ModelResourceLocation memory = getInventoryVariant(s);
|
||||
itemBar.step(memory.toString());
|
||||
IModel model = ModelLoaderRegistry.getMissingModel();
|
||||
Exception exception = null;
|
||||
try
|
||||
{
|
||||
IModel model = ModelLoaderRegistry.getModel(file);
|
||||
if(model == getMissingModel())
|
||||
{
|
||||
// try blockstate json if the item model is missing
|
||||
FMLLog.fine("Item json isn't found for '" + memory + "', trying to load the variant from the blockstate json");
|
||||
try
|
||||
{
|
||||
model = ModelLoaderRegistry.getModel(memory);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
storeException(memory, new Exception("Could not load item model either from the normal location " + file + " or from the blockstate", exception));
|
||||
}
|
||||
}
|
||||
stateModels.put(memory, model);
|
||||
model = ModelLoaderRegistry.getModel(file);
|
||||
}
|
||||
catch (Exception exception)
|
||||
catch(Exception e)
|
||||
{
|
||||
// try blockstate json if the item model is missing
|
||||
FMLLog.fine("Item json isn't found for '" + memory + "', trying to load the variant from the blockstate json");
|
||||
try
|
||||
{
|
||||
model = ModelLoaderRegistry.getModel(memory);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = new Exception("Could not load item model either from the normal location " + file + " or from the blockstate", ex);
|
||||
}
|
||||
}
|
||||
stateModels.put(memory, model);
|
||||
if(exception != null)
|
||||
{
|
||||
storeException(memory, exception);
|
||||
}
|
||||
@@ -282,7 +299,7 @@ public class ModelLoader extends ModelBakery
|
||||
for(String s : getVariantNames(Items.bucket))
|
||||
{
|
||||
ModelResourceLocation memory = getInventoryVariant(s);
|
||||
IModel model = ModelLoaderRegistry.getModel(new ResourceLocation("forge", "item/bucket"));
|
||||
IModel model = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation("forge", "item/bucket"));
|
||||
// only on successful load, otherwise continue using the old model
|
||||
if(model != getMissingModel())
|
||||
{
|
||||
@@ -309,7 +326,7 @@ public class ModelLoader extends ModelBakery
|
||||
for(String s : getVariantNames(Items.milk_bucket))
|
||||
{
|
||||
ModelResourceLocation memory = getInventoryVariant(s);
|
||||
IModel model = ModelLoaderRegistry.getModel(new ResourceLocation("forge", "item/bucket_milk"));
|
||||
IModel model = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation("forge", "item/bucket_milk"));
|
||||
// only on successful load, otherwise continue using the old model
|
||||
if(model != getMissingModel())
|
||||
{
|
||||
@@ -348,7 +365,7 @@ public class ModelLoader extends ModelBakery
|
||||
return new ResourceLocation(model.getResourceDomain(), model.getResourcePath() + ".json");
|
||||
}
|
||||
|
||||
private class VanillaModelWrapper implements IRetexturableModel, IModelSimpleProperties, IModelUVLock, IAnimatedModel
|
||||
private final class VanillaModelWrapper implements IRetexturableModel, IModelSimpleProperties, IModelUVLock, IAnimatedModel
|
||||
{
|
||||
private final ResourceLocation location;
|
||||
private final ModelBlock model;
|
||||
@@ -372,7 +389,7 @@ public class ModelLoader extends ModelBakery
|
||||
{
|
||||
set.add(dep);
|
||||
// TODO: check if this can go somewhere else, random access to global things is bad
|
||||
stateModels.put(getInventoryVariant(dep.toString()), ModelLoaderRegistry.getModel(dep));
|
||||
stateModels.put(getInventoryVariant(dep.toString()), ModelLoaderRegistry.getModelOrLogError(dep, "Could not load override model " + dep + " for model " + location));
|
||||
}
|
||||
}
|
||||
if(model.getParentLocation() != null && !model.getParentLocation().getResourcePath().startsWith("builtin/"))
|
||||
@@ -393,11 +410,7 @@ public class ModelLoader extends ModelBakery
|
||||
}
|
||||
else
|
||||
{
|
||||
IModel parent = ModelLoaderRegistry.getModel(model.getParentLocation());
|
||||
if(parent == getMissingModel())
|
||||
{
|
||||
FMLLog.warning("Could not load vanilla model parent '" + model.getParentLocation() + "' for '" + model);
|
||||
}
|
||||
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;
|
||||
@@ -629,7 +642,7 @@ public class ModelLoader extends ModelBakery
|
||||
}
|
||||
}
|
||||
|
||||
private static class WeightedRandomModel implements IModel
|
||||
private static final class WeightedRandomModel implements IModel
|
||||
{
|
||||
private final List<Variant> variants;
|
||||
private final List<ResourceLocation> locations = new ArrayList<ResourceLocation>();
|
||||
@@ -637,7 +650,7 @@ public class ModelLoader extends ModelBakery
|
||||
private final List<IModel> models = new ArrayList<IModel>();
|
||||
private final IModelState defaultState;
|
||||
|
||||
public WeightedRandomModel(ResourceLocation parent, VariantList variants)
|
||||
public WeightedRandomModel(ResourceLocation parent, VariantList variants) throws Exception
|
||||
{
|
||||
this.variants = variants.getVariantList();
|
||||
ImmutableList.Builder<Pair<IModel, IModelState>> builder = ImmutableList.builder();
|
||||
@@ -646,21 +659,11 @@ public class ModelLoader extends ModelBakery
|
||||
ResourceLocation loc = v.getModelLocation();
|
||||
locations.add(loc);
|
||||
|
||||
IModel model = null;
|
||||
try
|
||||
{
|
||||
model = ModelLoaderRegistry.getModel(loc);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
/*
|
||||
* Vanilla eats this, which makes it only show variants that have models.
|
||||
* But that doesn't help debugging, so we maintain the missing model
|
||||
* so that resource pack makers have a hint that their states are broken.
|
||||
*/
|
||||
FMLLog.getLogger().error("Unable to load block model: \'" + loc + "\' for variant: \'" + parent, e);
|
||||
model = ModelLoaderRegistry.getMissingModel();
|
||||
}
|
||||
/*
|
||||
* Vanilla eats this, which makes it only show variants that have models.
|
||||
* But that doesn't help debugging, so throw the exception
|
||||
*/
|
||||
IModel model = ModelLoaderRegistry.getModel(loc);
|
||||
|
||||
// FIXME: is this the place? messes up dependency and texture resolution
|
||||
if (v instanceof ISmartVariant)
|
||||
@@ -668,7 +671,7 @@ public class ModelLoader extends ModelBakery
|
||||
model = ((ISmartVariant)v).process(model);
|
||||
for(ResourceLocation location : model.getDependencies())
|
||||
{
|
||||
ModelLoaderRegistry.getModel(location);
|
||||
ModelLoaderRegistry.getModelOrMissing(location);
|
||||
}
|
||||
//FMLLog.getLogger().error("Exception resolving indirect dependencies for model" + loc, e);
|
||||
textures.addAll(model.getTextures()); // Kick this, just in case.
|
||||
@@ -680,6 +683,7 @@ public class ModelLoader extends ModelBakery
|
||||
|
||||
if (models.size() == 0) //If all variants are missing, add one with the missing model and default rotation.
|
||||
{
|
||||
// FIXME: log this?
|
||||
IModel missing = ModelLoaderRegistry.getMissingModel();
|
||||
models.add(missing);
|
||||
builder.add(Pair.<IModel, IModelState>of(missing, TRSRTransformation.identity()));
|
||||
@@ -728,7 +732,14 @@ public class ModelLoader extends ModelBakery
|
||||
{
|
||||
if (missingModel == null)
|
||||
{
|
||||
missingModel = VanillaLoader.instance.loadModel(new ResourceLocation(MODEL_MISSING.getResourceDomain(), MODEL_MISSING.getResourcePath()));
|
||||
try
|
||||
{
|
||||
missingModel = VanillaLoader.instance.loadModel(new ResourceLocation(MODEL_MISSING.getResourceDomain(), MODEL_MISSING.getResourcePath()));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw new RuntimeException("Missing the missing model, this should never happen");
|
||||
}
|
||||
}
|
||||
return missingModel;
|
||||
}
|
||||
@@ -738,7 +749,7 @@ public class ModelLoader extends ModelBakery
|
||||
return itemModel;
|
||||
}
|
||||
|
||||
static enum VanillaLoader implements ICustomModelLoader
|
||||
protected static enum VanillaLoader implements ICustomModelLoader
|
||||
{
|
||||
instance;
|
||||
|
||||
@@ -764,7 +775,7 @@ public class ModelLoader extends ModelBakery
|
||||
return true;
|
||||
}
|
||||
|
||||
public IModel loadModel(ResourceLocation modelLocation)
|
||||
public IModel loadModel(ResourceLocation modelLocation) throws Exception
|
||||
{
|
||||
String modelPath = modelLocation.getResourcePath();
|
||||
if(modelLocation.getResourcePath().startsWith("models/"))
|
||||
@@ -773,21 +784,8 @@ public class ModelLoader extends ModelBakery
|
||||
}
|
||||
ResourceLocation armatureLocation = new ResourceLocation(modelLocation.getResourceDomain(), "armatures/" + modelPath + ".json");
|
||||
ModelBlockAnimation animation = Animation.INSTANCE.loadVanillaAnimation(armatureLocation);
|
||||
ModelBlock model = null;
|
||||
try
|
||||
{
|
||||
model = loader.loadModel(modelLocation);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
// FIXME better error reporting?
|
||||
FMLLog.getLogger().error("Unable to load vanilla model " + modelLocation, e);
|
||||
}
|
||||
if(model != null)
|
||||
{
|
||||
return loader.new VanillaModelWrapper(modelLocation, model, false, animation);
|
||||
}
|
||||
return ModelLoaderRegistry.getMissingModel();
|
||||
ModelBlock model = loader.loadModel(modelLocation);
|
||||
return loader.new VanillaModelWrapper(modelLocation, model, false, animation);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -797,7 +795,7 @@ public class ModelLoader extends ModelBakery
|
||||
}
|
||||
}
|
||||
|
||||
public static class White extends TextureAtlasSprite
|
||||
public static final class White extends TextureAtlasSprite
|
||||
{
|
||||
public static ResourceLocation loc = new ResourceLocation("white");
|
||||
public static White instance = new White();
|
||||
@@ -824,6 +822,7 @@ public class ModelLoader extends ModelBakery
|
||||
int[][] pixels = new int[Minecraft.getMinecraft().gameSettings.mipmapLevels + 1][];
|
||||
pixels[0] = new int[image.getWidth() * image.getHeight()];
|
||||
image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels[0], 0, image.getWidth());
|
||||
this.clearFramesTextureData();
|
||||
this.framesTextureData.add(pixels);
|
||||
return false;
|
||||
}
|
||||
@@ -1045,7 +1044,7 @@ public class ModelLoader extends ModelBakery
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModel loadModel(ResourceLocation modelLocation)
|
||||
public IModel loadModel(ResourceLocation modelLocation) throws Exception
|
||||
{
|
||||
ModelResourceLocation variant = (ModelResourceLocation) modelLocation;
|
||||
ModelBlockDefinition definition = loader.getModelBlockDefinition(variant);
|
||||
@@ -1060,9 +1059,8 @@ public class ModelLoader extends ModelBakery
|
||||
{
|
||||
return new MultipartModel(new ResourceLocation(variant.getResourceDomain(), variant.getResourcePath()), definition.getMultipartData());
|
||||
}
|
||||
// FIXME log missing model?
|
||||
throw e;
|
||||
}
|
||||
return ModelLoaderRegistry.getMissingModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1078,7 +1076,7 @@ public class ModelLoader extends ModelBakery
|
||||
private final Multipart multipart;
|
||||
private final ImmutableMap<Selector, IModel> partModels;
|
||||
|
||||
public MultipartModel(ResourceLocation location, Multipart multipart)
|
||||
public MultipartModel(ResourceLocation location, Multipart multipart) throws Exception
|
||||
{
|
||||
this.location = location;
|
||||
this.multipart = multipart;
|
||||
|
||||
@@ -69,7 +69,7 @@ public class ModelLoaderRegistry
|
||||
* ResourceLocation argument will be passed directly to the custom model loaders,
|
||||
* ModelResourceLocation argument will be loaded through the blockstate system.
|
||||
*/
|
||||
public static IModel getModel(ResourceLocation location)
|
||||
public static IModel getModel(ResourceLocation location) throws Exception
|
||||
{
|
||||
IModel model;
|
||||
if(cache.containsKey(location)) return cache.get(location);
|
||||
@@ -77,7 +77,7 @@ public class ModelLoaderRegistry
|
||||
{
|
||||
if(location.getClass() == loading.getClass() && location.equals(loading))
|
||||
{
|
||||
throw new IllegalStateException("circular model dependencies, stack: [" + Joiner.on(", ").join(loadingModels) + "]");
|
||||
throw new LoaderException("circular model dependencies, stack: [" + Joiner.on(", ").join(loadingModels) + "]");
|
||||
}
|
||||
}
|
||||
loadingModels.addLast(location);
|
||||
@@ -93,15 +93,14 @@ public class ModelLoaderRegistry
|
||||
{
|
||||
if(accepted != null)
|
||||
{
|
||||
FMLLog.severe("2 loaders (%s and %s) want to load the same model %s", accepted, loader, location);
|
||||
throw new IllegalStateException("2 loaders want to load the same model");
|
||||
throw new LoaderException(String.format("2 loaders (%s and %s) want to load the same model %s", accepted, loader, location));
|
||||
}
|
||||
accepted = loader;
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
FMLLog.log(Level.ERROR, e, "Exception checking if model %s can be loaded with loader %s, skipping", location, loader);
|
||||
throw new LoaderException(String.format("Exception checking if model %s can be loaded with loader %s, skipping", location, loader), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,31 +119,25 @@ public class ModelLoaderRegistry
|
||||
|
||||
if(accepted == null)
|
||||
{
|
||||
FMLLog.severe("no suitable loader found for the model %s, skipping", location);
|
||||
model = getMissingModel();
|
||||
throw new LoaderException("no suitable loader found for the model " + location + ", skipping");
|
||||
}
|
||||
else
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
model = accepted.loadModel(actual);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
FMLLog.log(Level.ERROR, e, "Exception loading model %s with loader %s, skipping", location, accepted);
|
||||
model = getMissingModel();
|
||||
}
|
||||
if(model == getMissingModel())
|
||||
{
|
||||
FMLLog.log(Level.ERROR, "Loader %s returned missing model while loading model %s", accepted, location);
|
||||
}
|
||||
if(model == null)
|
||||
{
|
||||
FMLLog.log(Level.ERROR, "Loader %s returned null while loading model %s", accepted, location);
|
||||
model = getMissingModel();
|
||||
}
|
||||
textures.addAll(model.getTextures());
|
||||
model = accepted.loadModel(actual);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw new LoaderException(String.format("Exception loading model %s with loader %s, skipping", location, accepted), e);
|
||||
}
|
||||
if(model == getMissingModel())
|
||||
{
|
||||
throw new LoaderException(String.format("Loader %s returned missing model while loading model %s", accepted, location));
|
||||
}
|
||||
if(model == null)
|
||||
{
|
||||
throw new LoaderException(String.format("Loader %s returned null while loading model %s", accepted, location));
|
||||
}
|
||||
textures.addAll(model.getTextures());
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -157,11 +150,42 @@ public class ModelLoaderRegistry
|
||||
cache.put(location, model);
|
||||
for (ResourceLocation dep : model.getDependencies())
|
||||
{
|
||||
getModel(dep);
|
||||
getModelOrMissing(dep);
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this if you don't care about the exception and want some model anyway.
|
||||
*/
|
||||
public static IModel getModelOrMissing(ResourceLocation location)
|
||||
{
|
||||
try
|
||||
{
|
||||
return getModel(location);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
return getMissingModel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this if you want the model, but need to log the error.
|
||||
*/
|
||||
public static IModel getModelOrLogError(ResourceLocation location, String error)
|
||||
{
|
||||
try
|
||||
{
|
||||
return getModel(location);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
FMLLog.getLogger().error(error, e);
|
||||
return getMissingModel();
|
||||
}
|
||||
}
|
||||
|
||||
public static IModel getMissingModel()
|
||||
{
|
||||
return ModelLoader.VanillaLoader.instance.getLoader().getMissingModel();
|
||||
@@ -180,4 +204,19 @@ public class ModelLoaderRegistry
|
||||
{
|
||||
return textures;
|
||||
}
|
||||
|
||||
public static class LoaderException extends Exception
|
||||
{
|
||||
public LoaderException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
|
||||
public LoaderException(String message, Throwable cause)
|
||||
{
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
public class MultiLayerModel implements IModelCustomData
|
||||
public final class MultiLayerModel implements IModelCustomData
|
||||
{
|
||||
public static final MultiLayerModel instance = new MultiLayerModel(ImmutableMap.<Optional<BlockRenderLayer>, ModelResourceLocation>of());
|
||||
|
||||
@@ -58,7 +58,7 @@ public class MultiLayerModel implements IModelCustomData
|
||||
ImmutableMap.Builder<Optional<BlockRenderLayer>, IBakedModel> builder = ImmutableMap.builder();
|
||||
for(Optional<BlockRenderLayer> key : models.keySet())
|
||||
{
|
||||
IModel model = ModelLoaderRegistry.getModel(models.get(key));
|
||||
IModel model = ModelLoaderRegistry.getModelOrLogError(models.get(key), "Couldn't load MultiLayerModel dependency: " + models.get(key));
|
||||
builder.put(key, model.bake(new ModelStateComposition(state, model.getDefaultState()), format, bakedTextureGetter));
|
||||
}
|
||||
return builder.build();
|
||||
@@ -115,7 +115,7 @@ public class MultiLayerModel implements IModelCustomData
|
||||
return new ModelResourceLocation("builtin/missing", "missing");
|
||||
}
|
||||
|
||||
public static class MultiLayerBakedModel implements IPerspectiveAwareModel
|
||||
private static final class MultiLayerBakedModel implements IPerspectiveAwareModel
|
||||
{
|
||||
private final ImmutableMap<Optional<BlockRenderLayer>, IBakedModel> models;
|
||||
private final ImmutableMap<TransformType, TRSRTransformation> cameraTransforms;;
|
||||
|
||||
@@ -32,21 +32,16 @@ import com.google.common.collect.Sets;
|
||||
|
||||
// TODO: Switch to vanilla class, or to something similar
|
||||
@Deprecated
|
||||
public class MultiModel implements IModel
|
||||
public final class MultiModel implements IModel
|
||||
{
|
||||
public static class Baked implements IPerspectiveAwareModel
|
||||
private static final class Baked implements IPerspectiveAwareModel
|
||||
{
|
||||
protected final IBakedModel base;
|
||||
protected final ImmutableMap<String, IBakedModel> parts;
|
||||
private final IBakedModel base;
|
||||
private final ImmutableMap<String, IBakedModel> parts;
|
||||
|
||||
protected final IBakedModel internalBase;
|
||||
protected ImmutableMap<Optional<EnumFacing>, ImmutableList<BakedQuad>> quads;
|
||||
protected final ImmutableMap<TransformType, Pair<Baked, TRSRTransformation>> transforms;
|
||||
|
||||
public Baked(IBakedModel base, ImmutableMap<String, IBakedModel> parts)
|
||||
{
|
||||
this(null, false, base, parts);
|
||||
}
|
||||
private final IBakedModel internalBase;
|
||||
private ImmutableMap<Optional<EnumFacing>, ImmutableList<BakedQuad>> quads;
|
||||
private final ImmutableMap<TransformType, Pair<Baked, TRSRTransformation>> transforms;
|
||||
|
||||
public Baked(ResourceLocation location, boolean perspective, IBakedModel base, ImmutableMap<String, IBakedModel> parts)
|
||||
{
|
||||
@@ -148,16 +143,6 @@ public class MultiModel implements IModel
|
||||
return quads.get(Optional.fromNullable(side));
|
||||
}
|
||||
|
||||
public IBakedModel getBaseModel()
|
||||
{
|
||||
return base;
|
||||
}
|
||||
|
||||
public Map<String, IBakedModel> getParts()
|
||||
{
|
||||
return parts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType)
|
||||
{
|
||||
@@ -173,10 +158,10 @@ public class MultiModel implements IModel
|
||||
}
|
||||
}
|
||||
|
||||
protected final ResourceLocation location;
|
||||
protected final IModel base;
|
||||
protected final IModelState baseState;
|
||||
protected final Map<String, Pair<IModel, IModelState>> parts;
|
||||
private final ResourceLocation location;
|
||||
private final IModel base;
|
||||
private final IModelState baseState;
|
||||
private final Map<String, Pair<IModel, IModelState>> parts;
|
||||
|
||||
public MultiModel(ResourceLocation location, IModel base, IModelState baseState, ImmutableMap<String, Pair<IModel, IModelState>> parts)
|
||||
{
|
||||
@@ -186,16 +171,6 @@ public class MultiModel implements IModel
|
||||
this.parts = parts;
|
||||
}
|
||||
|
||||
public MultiModel(IModel base, IModelState baseState, ImmutableMap<String, Pair<IModel, IModelState>> parts)
|
||||
{
|
||||
this(null, base, baseState, parts);
|
||||
}
|
||||
|
||||
public MultiModel(IModel base, IModelState baseState, Map<String, Pair<IModel, IModelState>> parts)
|
||||
{
|
||||
this(null, base, baseState, ImmutableMap.copyOf(parts));
|
||||
}
|
||||
|
||||
public MultiModel(ResourceLocation location, IModel base, IModelState baseState, Map<String, Pair<IModel, IModelState>> parts)
|
||||
{
|
||||
this(location, base, baseState, ImmutableMap.copyOf(parts));
|
||||
@@ -254,22 +229,6 @@ public class MultiModel implements IModel
|
||||
return new Baked(location, true, bakedBase, mapBuilder.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The base model of this MultiModel. May be null.
|
||||
*/
|
||||
public IModel getBaseModel()
|
||||
{
|
||||
return base;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A map of the submodel name to its IModel and IModelState.
|
||||
*/
|
||||
public Map<String, Pair<IModel, IModelState>> getParts()
|
||||
{
|
||||
return parts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModelState getDefaultState()
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
public class MultiModelState implements IModelState
|
||||
public final class MultiModelState implements IModelState
|
||||
{
|
||||
private final ImmutableMap<MultiModelPart, ? extends IModelState> states;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.google.common.collect.ImmutableMap;
|
||||
/*
|
||||
* Simple implementation of IModelState via a map and a default value.
|
||||
*/
|
||||
public class SimpleModelState implements IModelState
|
||||
public final class SimpleModelState implements IModelState
|
||||
{
|
||||
private final ImmutableMap<? extends IModelPart, TRSRTransformation> map;
|
||||
private final Optional<TRSRTransformation> def;
|
||||
|
||||
@@ -30,7 +30,7 @@ import com.google.common.base.Optional;
|
||||
* should be comparable to using Matrix4f directly.
|
||||
* Immutable.
|
||||
*/
|
||||
public class TRSRTransformation implements IModelState, ITransformation
|
||||
public final class TRSRTransformation implements IModelState, ITransformation
|
||||
{
|
||||
private final Matrix4f matrix;
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ public final class Clips
|
||||
*/
|
||||
public static IClip getModelClipNode(ResourceLocation modelLocation, String clipName)
|
||||
{
|
||||
IModel model = ModelLoaderRegistry.getModel(modelLocation);
|
||||
IModel model = ModelLoaderRegistry.getModelOrMissing(modelLocation);
|
||||
if(model instanceof IAnimatedModel)
|
||||
{
|
||||
Optional<? extends IClip> clip = ((IAnimatedModel)model).getClip(clipName);
|
||||
|
||||
@@ -25,15 +25,25 @@ import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.*;
|
||||
import net.minecraftforge.client.model.animation.IClip;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraftforge.client.model.ICustomModelLoader;
|
||||
import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.client.model.IModelCustomData;
|
||||
import net.minecraftforge.client.model.IModelPart;
|
||||
import net.minecraftforge.client.model.IModelSimpleProperties;
|
||||
import net.minecraftforge.client.model.IModelState;
|
||||
import net.minecraftforge.client.model.IPerspectiveAwareModel;
|
||||
import net.minecraftforge.client.model.IRetexturableModel;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.client.model.ModelStateComposition;
|
||||
import net.minecraftforge.client.model.TRSRTransformation;
|
||||
import net.minecraftforge.client.model.animation.IAnimatedModel;
|
||||
import net.minecraftforge.client.model.animation.IClip;
|
||||
import net.minecraftforge.client.model.animation.IJoint;
|
||||
import net.minecraftforge.client.model.b3d.B3DModel.Animation;
|
||||
import net.minecraftforge.client.model.b3d.B3DModel.Face;
|
||||
import net.minecraftforge.client.model.b3d.B3DModel.IKind;
|
||||
import net.minecraftforge.client.model.b3d.B3DModel.Key;
|
||||
import net.minecraftforge.client.model.b3d.B3DModel.Mesh;
|
||||
import net.minecraftforge.client.model.b3d.B3DModel.Node;
|
||||
@@ -48,7 +58,6 @@ import net.minecraftforge.fml.common.FMLLog;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Objects;
|
||||
@@ -69,7 +78,7 @@ import com.google.gson.JsonParser;
|
||||
* To enable for your mod call instance.addDomain(modid).
|
||||
* If you need more control over accepted resources - extend the class, and register a new instance with ModelLoaderRegistry.
|
||||
*/
|
||||
public class B3DLoader implements ICustomModelLoader
|
||||
public final class B3DLoader implements ICustomModelLoader
|
||||
{
|
||||
public static final B3DLoader instance = new B3DLoader();
|
||||
|
||||
@@ -95,7 +104,7 @@ public class B3DLoader implements ICustomModelLoader
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public IModel loadModel(ResourceLocation modelLocation)
|
||||
public IModel loadModel(ResourceLocation modelLocation) throws Exception
|
||||
{
|
||||
ResourceLocation file = new ResourceLocation(modelLocation.getResourceDomain(), modelLocation.getResourcePath());
|
||||
if(!cache.containsKey(file))
|
||||
@@ -121,12 +130,12 @@ public class B3DLoader implements ICustomModelLoader
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
FMLLog.log(Level.ERROR, e, "Exception loading model %s with B3D loader, skipping", modelLocation);
|
||||
cache.put(file, null);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
B3DModel model = cache.get(file);
|
||||
if(model == null) return ModelLoaderRegistry.getMissingModel();
|
||||
if(model == null) throw new ModelLoaderRegistry.LoaderException("Error loading model previously: " + file);
|
||||
if(!(model.getRoot().getKind() instanceof Mesh))
|
||||
{
|
||||
return new ModelWrapper(modelLocation, model, ImmutableSet.<String>of(), true, true, 1);
|
||||
@@ -134,7 +143,7 @@ public class B3DLoader implements ICustomModelLoader
|
||||
return new ModelWrapper(modelLocation, model, ImmutableSet.of(((Node<Mesh>)model.getRoot()).getName()), true, true, 1);
|
||||
}
|
||||
|
||||
public static class B3DState implements IModelState
|
||||
public static final class B3DState implements IModelState
|
||||
{
|
||||
private final Animation animation;
|
||||
private final int frame;
|
||||
@@ -304,7 +313,7 @@ public class B3DLoader implements ICustomModelLoader
|
||||
}
|
||||
}
|
||||
|
||||
public static class NodeJoint implements IJoint
|
||||
static final class NodeJoint implements IJoint
|
||||
{
|
||||
private final Node<?> node;
|
||||
|
||||
@@ -380,27 +389,7 @@ public class B3DLoader implements ICustomModelLoader
|
||||
}
|
||||
}
|
||||
|
||||
public static class PartWrapper<K extends IKind<K>> implements IModelPart
|
||||
{
|
||||
private final Node<K> node;
|
||||
|
||||
public static <K extends IKind<K>> PartWrapper<K> create(Node<K> node)
|
||||
{
|
||||
return new PartWrapper<K>(node);
|
||||
}
|
||||
|
||||
public PartWrapper(Node<K> node)
|
||||
{
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
public Node<K> getNode()
|
||||
{
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ModelWrapper implements IRetexturableModel, IModelCustomData, IModelSimpleProperties, IAnimatedModel
|
||||
private static final class ModelWrapper implements IRetexturableModel, IModelCustomData, IModelSimpleProperties, IAnimatedModel
|
||||
{
|
||||
private final ResourceLocation modelLocation;
|
||||
private final B3DModel model;
|
||||
@@ -591,7 +580,7 @@ public class B3DLoader implements ICustomModelLoader
|
||||
}
|
||||
}
|
||||
|
||||
private static class BakedWrapper implements IPerspectiveAwareModel
|
||||
private static final class BakedWrapper implements IPerspectiveAwareModel
|
||||
{
|
||||
private final Node<?> node;
|
||||
private final IModelState state;
|
||||
@@ -697,7 +686,7 @@ public class B3DLoader implements ICustomModelLoader
|
||||
return quads;
|
||||
}
|
||||
|
||||
protected void generateQuads(ImmutableList.Builder<BakedQuad> builder, Node<?> node, final IModelState state)
|
||||
private void generateQuads(ImmutableList.Builder<BakedQuad> builder, Node<?> node, final IModelState state)
|
||||
{
|
||||
for(Node<?> child : node.getNodes().values())
|
||||
{
|
||||
@@ -828,7 +817,6 @@ public class B3DLoader implements ICustomModelLoader
|
||||
return IPerspectiveAwareModel.MapWrapper.handlePerspective(this, state, cameraTransformType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemOverrideList getOverrides()
|
||||
{
|
||||
// TODO handle items
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.minecraftforge.client.model.obj;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
@@ -22,7 +21,7 @@ import org.apache.logging.log4j.Level;
|
||||
* To enable your mod call instance.addDomain(modid).
|
||||
* If you need more control over accepted resources - extend the class, and register a new instance with ModelLoaderRegistry.
|
||||
*/
|
||||
public class OBJLoader implements ICustomModelLoader {
|
||||
public final class OBJLoader implements ICustomModelLoader {
|
||||
public static final OBJLoader instance = new OBJLoader();
|
||||
private IResourceManager manager;
|
||||
private final Set<String> enabledDomains = new HashSet<String>();
|
||||
@@ -45,44 +44,37 @@ public class OBJLoader implements ICustomModelLoader {
|
||||
return enabledDomains.contains(modelLocation.getResourceDomain()) && modelLocation.getResourcePath().endsWith(".obj");
|
||||
}
|
||||
|
||||
public IModel loadModel(ResourceLocation modelLocation)
|
||||
public IModel loadModel(ResourceLocation modelLocation) throws Exception
|
||||
{
|
||||
ResourceLocation file = new ResourceLocation(modelLocation.getResourceDomain(), modelLocation.getResourcePath());
|
||||
if (!cache.containsKey(file))
|
||||
{
|
||||
IResource resource = null;
|
||||
try
|
||||
{
|
||||
IResource resource = null;
|
||||
try
|
||||
{
|
||||
resource = manager.getResource(file);
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
if (modelLocation.getResourcePath().startsWith("models/block/"))
|
||||
resource = manager.getResource(new ResourceLocation(file.getResourceDomain(), "models/item/" + file.getResourcePath().substring("models/block/".length())));
|
||||
else if (modelLocation.getResourcePath().startsWith("models/item/"))
|
||||
resource = manager.getResource(new ResourceLocation(file.getResourceDomain(), "models/block/" + file.getResourcePath().substring("models/item/".length())));
|
||||
else throw e;
|
||||
}
|
||||
OBJModel.Parser parser = new OBJModel.Parser(resource, manager);
|
||||
OBJModel model = null;
|
||||
try
|
||||
{
|
||||
model = parser.parse();
|
||||
}
|
||||
finally
|
||||
{
|
||||
cache.put(modelLocation, model);
|
||||
}
|
||||
resource = manager.getResource(file);
|
||||
}
|
||||
catch (IOException e)
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
cache.put(modelLocation, null);
|
||||
if (modelLocation.getResourcePath().startsWith("models/block/"))
|
||||
resource = manager.getResource(new ResourceLocation(file.getResourceDomain(), "models/item/" + file.getResourcePath().substring("models/block/".length())));
|
||||
else if (modelLocation.getResourcePath().startsWith("models/item/"))
|
||||
resource = manager.getResource(new ResourceLocation(file.getResourceDomain(), "models/block/" + file.getResourcePath().substring("models/item/".length())));
|
||||
else throw e;
|
||||
}
|
||||
OBJModel.Parser parser = new OBJModel.Parser(resource, manager);
|
||||
OBJModel model = null;
|
||||
try
|
||||
{
|
||||
model = parser.parse();
|
||||
}
|
||||
finally
|
||||
{
|
||||
cache.put(modelLocation, model);
|
||||
}
|
||||
}
|
||||
OBJModel model = cache.get(file);
|
||||
if (model == null) return ModelLoaderRegistry.getMissingModel();
|
||||
if (model == null) throw new ModelLoaderRegistry.LoaderException("Error loading model previously: " + file);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user