Some work done on the dust generator

This commit is contained in:
Calclavia 2014-01-09 22:52:37 +08:00
parent 3aaeb5d3d3
commit c5ed109d97
3 changed files with 47 additions and 92 deletions

View file

@ -1,33 +1,8 @@
package resonantinduction.archaic; package resonantinduction.archaic;
import net.minecraft.entity.player.EntityPlayer; import resonantinduction.core.prefab.ProxyBase;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler;
public class CommonProxy implements IGuiHandler public class CommonProxy extends ProxyBase
{ {
public void preInit()
{
}
public void init()
{
}
public void postInit()
{
}
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
return null;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
return null;
}
} }

View file

@ -2,7 +2,6 @@ package resonantinduction.core;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.minecraft.item.Item;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import org.modstats.ModstatInfo; import org.modstats.ModstatInfo;
@ -22,6 +21,7 @@ import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.ModMetadata; import cpw.mods.fml.common.ModMetadata;
import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.network.NetworkRegistry;
@ -88,7 +88,11 @@ public class ResonantInduction
ResonantInduction.LOGGER.fine("Languages Loaded:" + LanguageUtility.loadLanguages(Reference.LANGUAGE_DIRECTORY, Reference.LANGUAGES)); ResonantInduction.LOGGER.fine("Languages Loaded:" + LanguageUtility.loadLanguages(Reference.LANGUAGE_DIRECTORY, Reference.LANGUAGES));
// Set Mod Metadata // Set Mod Metadata
Settings.setModMetadata(metadata, ID, NAME); Settings.setModMetadata(metadata, ID, NAME);
}
@EventHandler
public void postInit(FMLPostInitializationEvent evt)
{
// Generate Dusts // Generate Dusts
ResourceGenerator.generateDusts(); ResourceGenerator.generateDusts();
} }

View file

@ -1,30 +1,27 @@
package resonantinduction.core.resource; package resonantinduction.core.resource;
import java.awt.Color; import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set; import java.util.Set;
import javax.imageio.ImageIO;
import net.minecraft.client.Minecraft;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.OreDictionary.OreRegisterEvent; import net.minecraftforge.oredict.OreDictionary.OreRegisterEvent;
import resonantinduction.api.recipe.MachineRecipes; import resonantinduction.api.recipe.MachineRecipes;
import resonantinduction.api.recipe.OreDetectionBlackList;
import resonantinduction.api.recipe.MachineRecipes.RecipeType; import resonantinduction.api.recipe.MachineRecipes.RecipeType;
import resonantinduction.api.recipe.OreDetectionBlackList;
import resonantinduction.core.ResonantInduction; import resonantinduction.core.ResonantInduction;
import resonantinduction.old.Reference; import resonantinduction.old.Reference;
import codechicken.lib.colour.Colour;
import codechicken.lib.colour.ColourRGBA;
import codechicken.lib.render.TextureUtils;
import cpw.mods.fml.relauncher.ReflectionHelper; import cpw.mods.fml.relauncher.ReflectionHelper;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@ -39,13 +36,6 @@ public class ResourceGenerator
public static final Set<String> materialNames = new HashSet<String>(); public static final Set<String> materialNames = new HashSet<String>();
public static final HashMap<String, Integer> materialColors = new HashMap<String, Integer>(); public static final HashMap<String, Integer> materialColors = new HashMap<String, Integer>();
@ForgeSubscribe
@SideOnly(Side.CLIENT)
public void reloadTextures(TextureStitchEvent.Post e)
{
computeColors();
}
@ForgeSubscribe @ForgeSubscribe
public void oreRegisterEvent(OreRegisterEvent evt) public void oreRegisterEvent(OreRegisterEvent evt)
{ {
@ -62,13 +52,13 @@ public class ResourceGenerator
public static void generateDusts() public static void generateDusts()
{ {
for (String materialName : ResourceGenerator.materialNames) for (String materialName : materialNames)
{ {
String name = materialName.substring(0, 1).toUpperCase() + materialName.substring(1); String name = materialName.substring(0, 1).toUpperCase() + materialName.substring(1);
if (OreDictionary.getOres("ore" + name).size() > 0) if (OreDictionary.getOres("ore" + name).size() > 0)
{ {
//if (OreDictionary.getOres("dust" + name).size() == 0) // if (OreDictionary.getOres("dust" + name).size() == 0)
{ {
ItemDust.dusts.add(ResonantInduction.itemDust.getStackFromDust(materialName)); ItemDust.dusts.add(ResonantInduction.itemDust.getStackFromDust(materialName));
OreDictionary.registerOre("dust" + name, ResonantInduction.itemDust.getStackFromDust(materialName)); OreDictionary.registerOre("dust" + name, ResonantInduction.itemDust.getStackFromDust(materialName));
@ -83,81 +73,67 @@ public class ResourceGenerator
} }
} }
@ForgeSubscribe
@SideOnly(Side.CLIENT)
public void reloadTextures(TextureStitchEvent.Post e)
{
computeColors();
}
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public static void computeColors() public static void computeColors()
{ {
for (String ingotName : materialNames) for (String ingotName : materialNames)
{ {
LinkedList<Integer> colorCodes = new LinkedList<Integer>();
// Compute color // Compute color
int totalR = 0; int totalR = 0;
int totalG = 0; int totalG = 0;
int totalB = 0; int totalB = 0;
int colorCount = 0;
for (ItemStack ingotStack : OreDictionary.getOres("ingot" + ingotName.substring(0, 1).toUpperCase() + ingotName.substring(1))) for (ItemStack ingotStack : OreDictionary.getOres("ingot" + ingotName.substring(0, 1).toUpperCase() + ingotName.substring(1)))
{ {
Item theIngot = ingotStack.getItem(); Item theIngot = ingotStack.getItem();
Method o = ReflectionHelper.findMethod(Item.class, theIngot, new String[] { "getIconString", "func_" + "111208_A" });
String iconString;
try try
{ {
iconString = (String) o.invoke(theIngot); Icon icon = theIngot.getIconIndex(ingotStack);
} String iconString = icon.getIconName();
catch (ReflectiveOperationException e1)
{
// e1.printStackTrace();
break;
}
ResourceLocation textureLocation = new ResourceLocation(iconString.replace(":", ":" + Reference.ITEM_TEXTURE_DIRECTORY) + ".png"); if (iconString != null && !iconString.contains("MISSING_ICON_ITEM"))
InputStream inputstream;
try
{
inputstream = Minecraft.getMinecraft().getResourceManager().getResource(textureLocation).getInputStream();
BufferedImage bufferedimage = ImageIO.read(inputstream);
int width = bufferedimage.getWidth();
int height = bufferedimage.getWidth();
for (int x = 0; x < width; x++)
{ {
for (int y = 0; y < height; y++) System.out.println("LOAD:" + iconString);
iconString = iconString.contains(":") ? iconString.replace(":", ":" + Reference.ITEM_TEXTURE_DIRECTORY) + ".png" : Reference.ITEM_TEXTURE_DIRECTORY + iconString;
System.out.println(iconString);
ResourceLocation textureLocation = new ResourceLocation(iconString);
Colour[] colors = TextureUtils.loadTextureColours(textureLocation);
for (Colour color : colors)
{ {
colorCodes.add(bufferedimage.getRGB(x, y)); totalR += color.r;
totalG += color.g;
totalB += color.b;
colorCount++;
} }
} }
} }
catch (IOException e) catch (Exception e)
{ {
// e.printStackTrace(); System.out.println("Failed to compute colors for: " + theIngot);
e.printStackTrace();
} }
} }
if (colorCodes.size() > 0)
if (colorCount > 0)
{ {
for (int colorCode : colorCodes) totalR /= colorCount;
{ totalG /= colorCount;
Color color = new Color(colorCode); totalB /= colorCount;
int resultantColor = new ColourRGBA(totalR, totalG, totalB, 0).rgb();
if (color.getAlpha() != 0)
{
totalR += color.getRed();
totalG += color.getGreen();
totalB += color.getBlue();
}
}
totalR /= colorCodes.size();
totalG /= colorCodes.size();
totalB /= colorCodes.size();
int resultantColor = new Color(totalR, totalG, totalB).brighter().brighter().getRGB();
materialColors.put(ingotName, resultantColor); materialColors.put(ingotName, resultantColor);
} }
if (!materialColors.containsKey(ingotName)) if (!materialColors.containsKey(ingotName))
{ {
materialColors.put(ingotName, 0xFFFFFF); materialColors.put(ingotName, 0xFFFFFF);