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;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler;
import resonantinduction.core.prefab.ProxyBase;
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 net.minecraft.item.Item;
import net.minecraftforge.common.MinecraftForge;
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.SidedProxy;
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.network.NetworkMod;
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));
// Set Mod Metadata
Settings.setModMetadata(metadata, ID, NAME);
}
@EventHandler
public void postInit(FMLPostInitializationEvent evt)
{
// Generate Dusts
ResourceGenerator.generateDusts();
}

View file

@ -1,30 +1,27 @@
package resonantinduction.core.resource;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;
import javax.imageio.ImageIO;
import net.minecraft.client.Minecraft;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.OreDictionary.OreRegisterEvent;
import resonantinduction.api.recipe.MachineRecipes;
import resonantinduction.api.recipe.OreDetectionBlackList;
import resonantinduction.api.recipe.MachineRecipes.RecipeType;
import resonantinduction.api.recipe.OreDetectionBlackList;
import resonantinduction.core.ResonantInduction;
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.Side;
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 HashMap<String, Integer> materialColors = new HashMap<String, Integer>();
@ForgeSubscribe
@SideOnly(Side.CLIENT)
public void reloadTextures(TextureStitchEvent.Post e)
{
computeColors();
}
@ForgeSubscribe
public void oreRegisterEvent(OreRegisterEvent evt)
{
@ -62,13 +52,13 @@ public class ResourceGenerator
public static void generateDusts()
{
for (String materialName : ResourceGenerator.materialNames)
for (String materialName : materialNames)
{
String name = materialName.substring(0, 1).toUpperCase() + materialName.substring(1);
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));
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)
public static void computeColors()
{
for (String ingotName : materialNames)
{
LinkedList<Integer> colorCodes = new LinkedList<Integer>();
// Compute color
int totalR = 0;
int totalG = 0;
int totalB = 0;
int colorCount = 0;
for (ItemStack ingotStack : OreDictionary.getOres("ingot" + ingotName.substring(0, 1).toUpperCase() + ingotName.substring(1)))
{
Item theIngot = ingotStack.getItem();
Method o = ReflectionHelper.findMethod(Item.class, theIngot, new String[] { "getIconString", "func_" + "111208_A" });
String iconString;
try
{
iconString = (String) o.invoke(theIngot);
}
catch (ReflectiveOperationException e1)
{
// e1.printStackTrace();
break;
}
Icon icon = theIngot.getIconIndex(ingotStack);
String iconString = icon.getIconName();
ResourceLocation textureLocation = new ResourceLocation(iconString.replace(":", ":" + Reference.ITEM_TEXTURE_DIRECTORY) + ".png");
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++)
if (iconString != null && !iconString.contains("MISSING_ICON_ITEM"))
{
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)
{
Color color = new Color(colorCode);
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();
totalR /= colorCount;
totalG /= colorCount;
totalB /= colorCount;
int resultantColor = new ColourRGBA(totalR, totalG, totalB, 0).rgb();
materialColors.put(ingotName, resultantColor);
}
if (!materialColors.containsKey(ingotName))
{
materialColors.put(ingotName, 0xFFFFFF);