From f3caada13abdc5ea151ce6c63555350665ab4440 Mon Sep 17 00:00:00 2001 From: richardg867 Date: Mon, 22 Apr 2013 13:08:59 -0300 Subject: [PATCH] Complete it, got the bug figured out --- .../client/model/AdvancedModelLoader.java | 2 +- .../client/model/techne/TechneModel.java | 50 ++++++++----------- .../model/techne/TechneModelLoader.java | 1 - 3 files changed, 22 insertions(+), 31 deletions(-) diff --git a/client/net/minecraftforge/client/model/AdvancedModelLoader.java b/client/net/minecraftforge/client/model/AdvancedModelLoader.java index b29ca1cdc..4f2b2deb0 100644 --- a/client/net/minecraftforge/client/model/AdvancedModelLoader.java +++ b/client/net/minecraftforge/client/model/AdvancedModelLoader.java @@ -53,7 +53,7 @@ public class AdvancedModelLoader { FMLLog.severe("The resource name %s is not valid", resourceName); throw new IllegalArgumentException("The resource name is not valid"); } - String suffix = resourceName.substring(i + 1); + String suffix = resourceName.substring(i); IModelCustomLoader loader = instances.get(suffix); if (loader == null) { diff --git a/client/net/minecraftforge/client/model/techne/TechneModel.java b/client/net/minecraftforge/client/model/techne/TechneModel.java index 4e5565080..09d48410e 100644 --- a/client/net/minecraftforge/client/model/techne/TechneModel.java +++ b/client/net/minecraftforge/client/model/techne/TechneModel.java @@ -39,6 +39,9 @@ import net.minecraft.client.renderer.RenderEngine; import net.minecraftforge.client.model.IModelCustom; import net.minecraftforge.client.model.ModelFormatException; +/** + * Techne model importer, based on iChun's Hats importer + */ @SideOnly(Side.CLIENT) public class TechneModel extends ModelBase implements IModelCustom { public static final List cubeTypes = Arrays.asList( @@ -47,7 +50,7 @@ public class TechneModel extends ModelBase implements IModelCustom { ); private String fileName; - private Map zipFile = new HashMap(); + private Map zipContents = new HashMap(); private Map parts = new LinkedHashMap(); private String texture = null; @@ -70,11 +73,16 @@ public class TechneModel extends ModelBase implements IModelCustom { while ((entry = zipInput.getNextEntry()) != null) { byte[] data = new byte[(int) entry.getSize()]; - zipInput.read(data); - zipFile.put(entry.getName(), data); + // For some reason, using read(byte[]) makes reading stall upon reaching a 0x1E byte + int i = 0; + while (zipInput.available() > 0 && i < data.length) + { + data[i++] = (byte)zipInput.read(); + } + zipContents.put(entry.getName(), data); } - byte[] modelXml = zipFile.get("model.xml"); + byte[] modelXml = zipContents.get("model.xml"); if (modelXml == null) { throw new ModelFormatException("Model " + fileName + " contains no model.xml file"); @@ -129,17 +137,13 @@ public class TechneModel extends ModelBase implements IModelCustom { shapeName = "Shape #" + (i + 1); } + String shapeType = null; Node type = shapeAttributes.getNamedItem("type"); - if (type == null) + if (type != null) { - throw new ModelFormatException("Shape [" + shapeName + "] in " + fileName + " has no type"); + shapeType = type.getNodeValue(); } - String shapeType = type.getNodeValue(); - if (shapeType == null) - { - throw new ModelFormatException("Shape [" + shapeName + "] in " + fileName + " has an invalid type"); - } - if (!cubeTypes.contains(shapeType)) + if (shapeType != null && !cubeTypes.contains(shapeType)) { FMLLog.warning("Model shape [" + shapeName + "] in " + fileName + " is not a cube, ignoring"); continue; @@ -235,15 +239,14 @@ public class TechneModel extends ModelBase implements IModelCustom { { if (!textureNameSet) { - try { - byte[] textureEntry = zipFile.get(texture); + byte[] textureEntry = zipContents.get(texture); if (textureEntry == null) { throw new ModelFormatException("Model " + fileName + " has no such texture " + texture); } - System.out.println(textureEntry.length); + BufferedImage image = ImageIO.read(new ByteArrayInputStream(textureEntry)); textureName = Minecraft.getMinecraft().renderEngine.allocateAndSetupTexture(image); textureNameSet = true; @@ -254,17 +257,6 @@ public class TechneModel extends ModelBase implements IModelCustom { } catch (IOException e) { - try - { - FileOutputStream fileOutput = new FileOutputStream("techne_texture_debug.png"); - fileOutput.write(zipFile.get(texture)); - fileOutput.flush(); - fileOutput.close(); - } - catch (Throwable e1) - { - } - throw new ModelFormatException("Texture for model " + fileName + " could not be read", e); } } @@ -296,12 +288,12 @@ public class TechneModel extends ModelBase implements IModelCustom { @Override public void renderPart(String partName) - { - bindTexture(); - + { ModelRenderer part = parts.get(partName); if (part != null) { + bindTexture(); + part.renderWithRotation(1.0F); } } diff --git a/client/net/minecraftforge/client/model/techne/TechneModelLoader.java b/client/net/minecraftforge/client/model/techne/TechneModelLoader.java index 0c9f182c8..c9dd469b3 100644 --- a/client/net/minecraftforge/client/model/techne/TechneModelLoader.java +++ b/client/net/minecraftforge/client/model/techne/TechneModelLoader.java @@ -9,7 +9,6 @@ import net.minecraftforge.client.model.IModelCustom; import net.minecraftforge.client.model.IModelCustomLoader; import net.minecraftforge.client.model.ModelFormatException; -@SideOnly(Side.CLIENT) public class TechneModelLoader implements IModelCustomLoader { @Override