From 0139a894f0118adcccbfc0476b5a15bb5575f061 Mon Sep 17 00:00:00 2001 From: tterrag1098 Date: Wed, 22 Apr 2015 18:00:56 -0400 Subject: [PATCH] Implement ISubmapManager for custom IIcon handling --- .../chisel/carving/CarvableHelper.java | 30 +++++++++++++++---- .../chisel/carving/CarvableVariation.java | 3 ++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/cricketcraft/chisel/carving/CarvableHelper.java b/src/main/java/com/cricketcraft/chisel/carving/CarvableHelper.java index d068a488..10f0143b 100644 --- a/src/main/java/com/cricketcraft/chisel/carving/CarvableHelper.java +++ b/src/main/java/com/cricketcraft/chisel/carving/CarvableHelper.java @@ -2,7 +2,6 @@ package com.cricketcraft.chisel.carving; import java.util.ArrayList; import java.util.List; -import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.BlockPane; @@ -14,6 +13,8 @@ import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraftforge.oredict.OreDictionary; +import org.apache.commons.lang3.ArrayUtils; + import com.cricketcraft.chisel.Chisel; import com.cricketcraft.chisel.client.render.CTM; import com.cricketcraft.chisel.client.render.TextureSubmap; @@ -46,16 +47,21 @@ public class CarvableHelper { R16("r16"), R9("r9"), R4("r4"), - NORMAL; + NORMAL, + CUSTOM; + private static final TextureType[] VALUES; private String[] suffixes; + static { + VALUES = ArrayUtils.subarray(values(), 0, values().length - 1); + } private TextureType(String... suffixes) { this.suffixes = suffixes.length == 0 ? new String[] { "" } : suffixes; } public static TextureType getTypeFor(String path) { - for (TextureType t : values()) { + for (TextureType t : VALUES) { boolean matches = true; for (String s : t.suffixes) { String res = "".equals(s) ? path + ".png" : path + "-" + s + ".png"; @@ -67,12 +73,10 @@ public class CarvableHelper { return t; } } - return null; + return CUSTOM; } } - private static final Random rand = new Random(); - public ArrayList variations = new ArrayList(); CarvableVariation[] map = new CarvableVariation[16]; public boolean forbidChiseling = false; @@ -95,6 +99,10 @@ public class CarvableHelper { } public void addVariation(String description, int metadata, String texture, Block block, int blockMeta) { + addVariation(description, metadata, texture, block, blockMeta); + } + + public void addVariation(String description, int metadata, String texture, Block block, int blockMeta, ISubmapManager customManager) { if (variations.size() >= 16) return; @@ -112,6 +120,10 @@ public class CarvableHelper { variation.texture = texture; String path = "/assets/" + Chisel.MOD_ID + "/textures/blocks/" + variation.texture; variation.type = (TextureType) TextureType.getTypeFor(path); + if (variation.type == TextureType.CUSTOM && customManager == null) { + throw new IllegalArgumentException(String.format("Could not find texture for block %s, and no custom texture manager was provided.", block)); + } + variation.manager = customManager; } else { variation.block = block; variation.type = TextureType.TOPBOTSIDE; @@ -178,6 +190,8 @@ public class CarvableHelper { return variation.variations9.icons[4]; case R4: return variation.variations9.icons[0]; + case CUSTOM: + return variation.manager.getIcon(side, metadata); } return GeneralClient.getMissingIcon(); @@ -297,6 +311,8 @@ public class CarvableHelper { // rand.setSeed(indexRan); // Broken return variation.variations9.icons[ /* rand */indexRan % ((variation.type == TextureType.R9) ? 9 : 4)]; + case CUSTOM: + return variation.manager.getIcon(world, x, y, z, side); } return GeneralClient.getMissingIcon(); @@ -413,6 +429,8 @@ public class CarvableHelper { case R4: variation.variations9 = new TextureSubmap(register.registerIcon(modName + ":" + variation.texture + "-r4"), 2, 2); break; + case CUSTOM: + variation.manager.registerIcons(modName, block, register); } } } diff --git a/src/main/java/com/cricketcraft/chisel/carving/CarvableVariation.java b/src/main/java/com/cricketcraft/chisel/carving/CarvableVariation.java index 9d3254f4..30e3d866 100644 --- a/src/main/java/com/cricketcraft/chisel/carving/CarvableVariation.java +++ b/src/main/java/com/cricketcraft/chisel/carving/CarvableVariation.java @@ -4,6 +4,7 @@ import net.minecraft.block.Block; import net.minecraft.client.resources.I18n; import net.minecraft.util.IIcon; +import com.cricketcraft.chisel.carving.CarvableHelper.ISubmapManager; import com.cricketcraft.chisel.carving.CarvableHelper.TextureType; import com.cricketcraft.chisel.client.render.TextureSubmap; @@ -29,6 +30,8 @@ public class CarvableVariation { public TextureSubmap submap; public TextureSubmap submapSmall; + + public ISubmapManager manager; public String getDescription() { return I18n.format(descriptionUnloc);