mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 00:07:45 +00:00
Models now load from resource packs
Models must now be loaded from resource packs using the standard resource pack reference. For example, to load a model named "assets/mymod/models/mymodel.obj", you would call AdvancedModelLoader.loadModel("mymod:models/mymodel.obj");
Closes #670
This commit is contained in:
1 parent
df0b1751e6
commit
b149ccbc17
6 files changed
+45
-33
No files matched your search
@@ -1,10 +1,10 @@
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.obj.ObjModelLoader;
|
||||
import net.minecraftforge.client.model.techne.TechneModelLoader;
|
||||
|
||||
@@ -40,34 +40,29 @@ public class AdvancedModelLoader {
|
||||
|
||||
/**
|
||||
* Load the model from the supplied classpath resolvable resource name
|
||||
* @param resourceName The resource name
|
||||
* @param resource The resource name
|
||||
* @return A model
|
||||
* @throws IllegalArgumentException if the resource name cannot be understood
|
||||
* @throws ModelFormatException if the underlying model handler cannot parse the model format
|
||||
*/
|
||||
public static IModelCustom loadModel(String resourceName) throws IllegalArgumentException, ModelFormatException
|
||||
public static IModelCustom loadModel(ResourceLocation resource) throws IllegalArgumentException, ModelFormatException
|
||||
{
|
||||
int i = resourceName.lastIndexOf('.');
|
||||
String name = resource.getResourcePath();
|
||||
int i = name.lastIndexOf('.');
|
||||
if (i == -1)
|
||||
{
|
||||
FMLLog.severe("The resource name %s is not valid", resourceName);
|
||||
FMLLog.severe("The resource name %s is not valid", resource);
|
||||
throw new IllegalArgumentException("The resource name is not valid");
|
||||
}
|
||||
String suffix = resourceName.substring(i+1);
|
||||
String suffix = name.substring(i+1);
|
||||
IModelCustomLoader loader = instances.get(suffix);
|
||||
if (loader == null)
|
||||
{
|
||||
FMLLog.severe("The resource name %s is not supported", resourceName);
|
||||
FMLLog.severe("The resource name %s is not supported", resource);
|
||||
throw new IllegalArgumentException("The resource name is not supported");
|
||||
}
|
||||
|
||||
URL resource = AdvancedModelLoader.class.getResource(resourceName);
|
||||
if (resource == null)
|
||||
{
|
||||
FMLLog.severe("The resource name %s could not be found", resourceName);
|
||||
throw new IllegalArgumentException("The resource name could not be found");
|
||||
}
|
||||
return loader.loadInstance(resourceName, resource);
|
||||
return loader.loadInstance(resource);
|
||||
}
|
||||
|
||||
public static Collection<String> getSupportedSuffixes()
|
||||
|
||||
@@ -3,6 +3,8 @@ package net.minecraftforge.client.model;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
/**
|
||||
* Instances of this class act as factories for their model type
|
||||
*
|
||||
@@ -22,10 +24,9 @@ public interface IModelCustomLoader {
|
||||
String[] getSuffixes();
|
||||
/**
|
||||
* Load a model instance from the supplied path
|
||||
* @param resourceName The resource name to load
|
||||
* @param resource The URL associated with the classloader resource
|
||||
* @param resource The ResourceLocation of the model
|
||||
* @return A model instance
|
||||
* @throws ModelFormatException if the model format is not correct
|
||||
*/
|
||||
IModelCustom loadInstance(String resourceName, URL resource) throws ModelFormatException;
|
||||
IModelCustom loadInstance(ResourceLocation resource) throws ModelFormatException;
|
||||
}
|
||||
@@ -3,11 +3,13 @@ package net.minecraftforge.client.model.obj;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.IModelCustom;
|
||||
import net.minecraftforge.client.model.IModelCustomLoader;
|
||||
import net.minecraftforge.client.model.ModelFormatException;
|
||||
|
||||
public class ObjModelLoader implements IModelCustomLoader {
|
||||
public class ObjModelLoader implements IModelCustomLoader
|
||||
{
|
||||
|
||||
@Override
|
||||
public String getType()
|
||||
@@ -23,9 +25,8 @@ public class ObjModelLoader implements IModelCustomLoader {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModelCustom loadInstance(String resourceName, URL resource) throws ModelFormatException
|
||||
public IModelCustom loadInstance(ResourceLocation resource) throws ModelFormatException
|
||||
{
|
||||
return new WavefrontObject(resourceName, resource);
|
||||
return new WavefrontObject(resource);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,7 +9,10 @@ import java.util.ArrayList;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.IModelCustom;
|
||||
import net.minecraftforge.client.model.ModelFormatException;
|
||||
|
||||
@@ -46,13 +49,14 @@ public class WavefrontObject implements IModelCustom
|
||||
private GroupObject currentGroupObject;
|
||||
private String fileName;
|
||||
|
||||
public WavefrontObject(String fileName, URL resource) throws ModelFormatException
|
||||
public WavefrontObject(ResourceLocation resource) throws ModelFormatException
|
||||
{
|
||||
this.fileName = fileName;
|
||||
this.fileName = resource.toString();
|
||||
|
||||
try
|
||||
{
|
||||
loadObjModel(resource.openStream());
|
||||
IResource res = Minecraft.getMinecraft().getResourceManager().getResource(resource);
|
||||
loadObjModel(res.getInputStream());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -31,10 +32,11 @@ import org.xml.sax.SAXException;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.model.ModelBase;
|
||||
import net.minecraft.client.model.ModelRenderer;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.IModelCustom;
|
||||
import net.minecraftforge.client.model.ModelFormatException;
|
||||
import net.minecraftforge.client.model.obj.GroupObject;
|
||||
@@ -57,17 +59,26 @@ public class TechneModel extends ModelBase implements IModelCustom {
|
||||
private int textureName;
|
||||
private boolean textureNameSet = false;
|
||||
|
||||
public TechneModel(String fileName, URL resource) throws ModelFormatException
|
||||
public TechneModel(ResourceLocation resource) throws ModelFormatException
|
||||
{
|
||||
this.fileName = fileName;
|
||||
loadTechneModel(resource);
|
||||
this.fileName = resource.toString();
|
||||
|
||||
try
|
||||
{
|
||||
IResource res = Minecraft.getMinecraft().getResourceManager().getResource(resource);
|
||||
loadTechneModel(res.getInputStream());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new ModelFormatException("IO Exception reading model format", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadTechneModel(URL fileURL) throws ModelFormatException
|
||||
private void loadTechneModel(InputStream stream) throws ModelFormatException
|
||||
{
|
||||
try
|
||||
{
|
||||
ZipInputStream zipInput = new ZipInputStream(fileURL.openStream());
|
||||
ZipInputStream zipInput = new ZipInputStream(stream);
|
||||
|
||||
ZipEntry entry;
|
||||
while ((entry = zipInput.getNextEntry()) != null)
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.net.URL;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.IModelCustom;
|
||||
import net.minecraftforge.client.model.IModelCustomLoader;
|
||||
import net.minecraftforge.client.model.ModelFormatException;
|
||||
@@ -25,9 +25,9 @@ public class TechneModelLoader implements IModelCustomLoader {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModelCustom loadInstance(String resourceName, URL resource) throws ModelFormatException
|
||||
public IModelCustom loadInstance(ResourceLocation resource) throws ModelFormatException
|
||||
{
|
||||
return new TechneModel(resourceName, resource);
|
||||
return new TechneModel(resource);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user