diff --git a/src/main/java/resonantinduction/ClientProxy.java b/src/main/java/resonantinduction/ClientProxy.java index 3b4f76d43..e52552de7 100644 --- a/src/main/java/resonantinduction/ClientProxy.java +++ b/src/main/java/resonantinduction/ClientProxy.java @@ -7,6 +7,7 @@ import net.minecraft.world.World; import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.common.MinecraftForge; import resonantinduction.core.render.BlockRenderingHandler; +import resonantinduction.machine.crusher.ItemDust; import resonantinduction.multimeter.PartMultimeter; import resonantinduction.multimeter.RenderRIItem; import resonantinduction.transport.battery.RenderBattery; @@ -46,6 +47,12 @@ public class ClientProxy extends CommonProxy ClientRegistry.bindTileEntitySpecialRenderer(TileBattery.class, new RenderBattery()); } + @Override + public void postInit() + { + ItemDust.computeColors(); + } + @Override public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { diff --git a/src/main/java/resonantinduction/CommonProxy.java b/src/main/java/resonantinduction/CommonProxy.java index 245049014..7bcef589e 100644 --- a/src/main/java/resonantinduction/CommonProxy.java +++ b/src/main/java/resonantinduction/CommonProxy.java @@ -25,6 +25,11 @@ public class CommonProxy implements IGuiHandler } + public void postInit() + { + + } + @Override public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { diff --git a/src/main/java/resonantinduction/ResonantInduction.java b/src/main/java/resonantinduction/ResonantInduction.java index d1df44d19..90aa84dde 100644 --- a/src/main/java/resonantinduction/ResonantInduction.java +++ b/src/main/java/resonantinduction/ResonantInduction.java @@ -300,6 +300,7 @@ public class ResonantInduction /** Auto-gen dusts */ ItemDust.postInit(); + ResonantInduction.proxy.postInit(); /** Inject new furnace tile class */ replaceTileEntity(TileEntityFurnace.class, TileAdvancedFurnace.class); diff --git a/src/main/java/resonantinduction/machine/crusher/ItemDust.java b/src/main/java/resonantinduction/machine/crusher/ItemDust.java index 9a208a7d7..85d994cef 100644 --- a/src/main/java/resonantinduction/machine/crusher/ItemDust.java +++ b/src/main/java/resonantinduction/machine/crusher/ItemDust.java @@ -1,15 +1,23 @@ package resonantinduction.machine.crusher; import java.awt.Color; -import java.util.ArrayList; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedList; import java.util.List; import java.util.Set; +import javax.imageio.ImageIO; + +import net.minecraft.client.Minecraft; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ResourceLocation; import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary.OreRegisterEvent; @@ -27,8 +35,9 @@ import cpw.mods.fml.relauncher.SideOnly; */ public class ItemDust extends ItemBase { - public static final Set ingots = new HashSet(); + public static final Set ingotNames = new HashSet(); public static final Set dusts = new HashSet(); + public static final HashMap ingotColors = new HashMap(); public ItemDust(int id) { @@ -49,13 +58,13 @@ public class ItemDust extends ItemBase if (evt.Name.startsWith("ingot")) { String ingotName = evt.Name.replace("ingot", ""); - ingots.add(ingotName.toLowerCase()); + ingotNames.add(ingotName.toLowerCase()); } } public static void postInit() { - for (String ingotName : ingots) + for (String ingotName : ingotNames) { String dustName = "dust" + ingotName.substring(0, 1).toUpperCase() + ingotName.substring(1); @@ -63,13 +72,40 @@ public class ItemDust extends ItemBase { dusts.add(getStackFromDust(ingotName)); OreDictionary.registerOre(dustName, getStackFromDust(ingotName)); + } + } + } - // Compute color - int totalR = 0; - int totalG = 0; - int totalB = 0; + @SideOnly(Side.CLIENT) + public static void computeColors() + { + for (String ingotName : ingotNames) + { + // Compute color + int totalR = 0; + int totalG = 0; + int totalB = 0; - ArrayList colorCodes = new ArrayList(); + ResourceLocation textureLocation = new ResourceLocation(""); + InputStream inputstream; + try + { + inputstream = Minecraft.getMinecraft().getResourceManager().getResource(textureLocation).getInputStream(); + + BufferedImage bufferedimage = ImageIO.read(inputstream); + + LinkedList colorCodes = new LinkedList(); + + int width = bufferedimage.getWidth(); + int height = bufferedimage.getWidth(); + + for (int x = 0; x < width; x++) + { + for (int y = 0; y < height; y++) + { + colorCodes.add(bufferedimage.getRGB(x, y)); + } + } if (colorCodes.size() > 0) { @@ -86,8 +122,13 @@ public class ItemDust extends ItemBase totalB /= colorCodes.size(); int resultantColor = new Color(totalR, totalG, totalB).getRGB(); + ingotColors.put(ingotName, resultantColor); } } + catch (IOException e) + { + e.printStackTrace(); + } } }