Implemented vanilla block recipes for grinder
This commit is contained in:
parent
2c9966c632
commit
1291d760c7
3 changed files with 388 additions and 321 deletions
|
@ -6,6 +6,8 @@ import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import resonantinduction.api.recipe.RecipeResource.FluidStackResource;
|
import resonantinduction.api.recipe.RecipeResource.FluidStackResource;
|
||||||
|
@ -14,104 +16,114 @@ import resonantinduction.api.recipe.RecipeResource.OreDictResource;
|
||||||
|
|
||||||
public final class MachineRecipes
|
public final class MachineRecipes
|
||||||
{
|
{
|
||||||
public static enum RecipeType
|
public static enum RecipeType
|
||||||
{
|
{
|
||||||
CRUSHER, GRINDER, MIXER, SMELTER, SAWMILL;
|
CRUSHER,
|
||||||
}
|
GRINDER,
|
||||||
|
MIXER,
|
||||||
|
SMELTER,
|
||||||
|
SAWMILL;
|
||||||
|
}
|
||||||
|
|
||||||
private final Map<RecipeType, Map<RecipeResource[], RecipeResource[]>> recipes = new HashMap<RecipeType, Map<RecipeResource[], RecipeResource[]>>();
|
private final Map<RecipeType, Map<RecipeResource[], RecipeResource[]>> recipes = new HashMap<RecipeType, Map<RecipeResource[], RecipeResource[]>>();
|
||||||
|
|
||||||
public static final MachineRecipes INSTANCE = new MachineRecipes();
|
public static final MachineRecipes INSTANCE = new MachineRecipes();
|
||||||
|
|
||||||
private MachineRecipes()
|
private MachineRecipes()
|
||||||
{
|
{
|
||||||
for (RecipeType machine : RecipeType.values())
|
for (RecipeType machine : RecipeType.values())
|
||||||
{
|
{
|
||||||
this.recipes.put(machine, new HashMap<RecipeResource[], RecipeResource[]>());
|
this.recipes.put(machine, new HashMap<RecipeResource[], RecipeResource[]>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public RecipeResource getResourceFromObject(Object obj)
|
public RecipeResource getResourceFromObject(Object obj)
|
||||||
{
|
{
|
||||||
if (obj instanceof String)
|
if (obj instanceof String)
|
||||||
return new OreDictResource((String) obj);
|
return new OreDictResource((String) obj);
|
||||||
|
|
||||||
if (obj instanceof ItemStack)
|
if (obj instanceof Block)
|
||||||
return new ItemStackResource((ItemStack) obj);
|
return new ItemStackResource(new ItemStack((Block) obj));
|
||||||
|
|
||||||
if (obj instanceof FluidStack)
|
if (obj instanceof Item)
|
||||||
return new FluidStackResource((FluidStack) obj);
|
return new ItemStackResource(new ItemStack((Item) obj));
|
||||||
|
|
||||||
if (obj instanceof RecipeResource)
|
if (obj instanceof ItemStack)
|
||||||
return (RecipeResource) obj;
|
return new ItemStackResource((ItemStack) obj);
|
||||||
|
|
||||||
return null;
|
if (obj instanceof FluidStack)
|
||||||
}
|
return new FluidStackResource((FluidStack) obj);
|
||||||
|
|
||||||
public void addRecipe(RecipeType machine, RecipeResource[] input, RecipeResource[] output)
|
if (obj instanceof RecipeResource)
|
||||||
{
|
return (RecipeResource) obj;
|
||||||
this.recipes.get(machine).put(input, output);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addRecipe(RecipeType machine, Object inputObj, Object... outputObj)
|
return null;
|
||||||
{
|
}
|
||||||
RecipeResource input = getResourceFromObject(inputObj);
|
|
||||||
RecipeResource[] outputs = new RecipeResource[outputObj.length];
|
|
||||||
|
|
||||||
for (int i = 0; i < outputs.length; i++)
|
public void addRecipe(RecipeType machine, RecipeResource[] input, RecipeResource[] output)
|
||||||
{
|
{
|
||||||
RecipeResource output = getResourceFromObject(outputObj[i]);
|
this.recipes.get(machine).put(input, output);
|
||||||
|
}
|
||||||
|
|
||||||
if (input == null || output == null)
|
public void addRecipe(RecipeType machine, Object inputObj, Object... outputObj)
|
||||||
throw new RuntimeException("Resonant Induction tried to add invalid machine recipe: " + input + " => " + output);
|
{
|
||||||
|
RecipeResource input = getResourceFromObject(inputObj);
|
||||||
|
RecipeResource[] outputs = new RecipeResource[outputObj.length];
|
||||||
|
|
||||||
outputs[i] = output;
|
for (int i = 0; i < outputs.length; i++)
|
||||||
}
|
{
|
||||||
|
RecipeResource output = getResourceFromObject(outputObj[i]);
|
||||||
|
|
||||||
addRecipe(machine, new RecipeResource[] { input }, outputs);
|
if (input == null || output == null)
|
||||||
}
|
throw new RuntimeException("Resonant Induction tried to add invalid machine recipe: " + input + " => " + output);
|
||||||
|
|
||||||
public void removeRecipe(RecipeType machine, RecipeResource[] input)
|
outputs[i] = output;
|
||||||
{
|
}
|
||||||
this.recipes.get(machine).remove(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<RecipeResource[], RecipeResource[]> getRecipes(RecipeType machine)
|
addRecipe(machine, new RecipeResource[] { input }, outputs);
|
||||||
{
|
}
|
||||||
return new HashMap<RecipeResource[], RecipeResource[]>(this.recipes.get(machine));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<RecipeType, Map<RecipeResource[], RecipeResource[]>> getRecipes()
|
public void removeRecipe(RecipeType machine, RecipeResource[] input)
|
||||||
{
|
{
|
||||||
return new HashMap<RecipeType, Map<RecipeResource[], RecipeResource[]>>(this.recipes);
|
this.recipes.get(machine).remove(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RecipeResource[] getOutput(RecipeType machine, RecipeResource... input)
|
public Map<RecipeResource[], RecipeResource[]> getRecipes(RecipeType machine)
|
||||||
{
|
{
|
||||||
Iterator<Entry<RecipeResource[], RecipeResource[]>> it = this.getRecipes(machine).entrySet().iterator();
|
return new HashMap<RecipeResource[], RecipeResource[]>(this.recipes.get(machine));
|
||||||
|
}
|
||||||
|
|
||||||
while (it.hasNext())
|
public Map<RecipeType, Map<RecipeResource[], RecipeResource[]>> getRecipes()
|
||||||
{
|
{
|
||||||
Entry<RecipeResource[], RecipeResource[]> entry = it.next();
|
return new HashMap<RecipeType, Map<RecipeResource[], RecipeResource[]>>(this.recipes);
|
||||||
|
}
|
||||||
|
|
||||||
if (Arrays.equals(entry.getKey(), input))
|
public RecipeResource[] getOutput(RecipeType machine, RecipeResource... input)
|
||||||
{
|
{
|
||||||
return entry.getValue();
|
Iterator<Entry<RecipeResource[], RecipeResource[]>> it = this.getRecipes(machine).entrySet().iterator();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new RecipeResource[] {};
|
while (it.hasNext())
|
||||||
}
|
{
|
||||||
|
Entry<RecipeResource[], RecipeResource[]> entry = it.next();
|
||||||
|
|
||||||
public RecipeResource[] getOutput(RecipeType machine, Object... inputs)
|
if (Arrays.equals(entry.getKey(), input))
|
||||||
{
|
{
|
||||||
RecipeResource[] resourceInputs = new RecipeResource[inputs.length];
|
return entry.getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < inputs.length; i++)
|
return new RecipeResource[] {};
|
||||||
{
|
}
|
||||||
resourceInputs[i] = getResourceFromObject(inputs[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return getOutput(machine, resourceInputs);
|
public RecipeResource[] getOutput(RecipeType machine, Object... inputs)
|
||||||
}
|
{
|
||||||
|
RecipeResource[] resourceInputs = new RecipeResource[inputs.length];
|
||||||
|
|
||||||
|
for (int i = 0; i < inputs.length; i++)
|
||||||
|
{
|
||||||
|
resourceInputs[i] = getResourceFromObject(inputs[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return getOutput(machine, resourceInputs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,282 +39,279 @@ import cpw.mods.fml.common.registry.GameRegistry;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
/**
|
/** @author Calclavia */
|
||||||
* @author Calclavia
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ResourceGenerator
|
public class ResourceGenerator
|
||||||
{
|
{
|
||||||
public static final ResourceGenerator INSTANCE = new ResourceGenerator();
|
public static final ResourceGenerator INSTANCE = new ResourceGenerator();
|
||||||
public static final Set<String> oreDictBlackList = new HashSet<String>();
|
public static final Set<String> oreDictBlackList = new HashSet<String>();
|
||||||
|
|
||||||
/**
|
/** A list of material names. They are all camelCase reference of ore dictionary names without
|
||||||
* A list of material names. They are all camelCase reference of ore dictionary names without
|
* the "ore" or "ingot" prefix. */
|
||||||
* the
|
public static final List<String> materialNames = new ArrayList<String>();
|
||||||
* "ore" or "ingot" prefix.
|
public static final HashMap<String, Integer> materialColors = new HashMap<String, Integer>();
|
||||||
*/
|
private static final HashMap<Icon, Integer> iconColorMap = new HashMap<Icon, Integer>();
|
||||||
public static final List<String> materialNames = new ArrayList<String>();
|
|
||||||
public static final HashMap<String, Integer> materialColors = new HashMap<String, Integer>();
|
|
||||||
private static final HashMap<Icon, Integer> iconColorMap = new HashMap<Icon, Integer>();
|
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
oreDictBlackList.add("ingotRefinedIron");
|
oreDictBlackList.add("ingotRefinedIron");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ForgeSubscribe
|
@ForgeSubscribe
|
||||||
public void oreRegisterEvent(OreRegisterEvent evt)
|
public void oreRegisterEvent(OreRegisterEvent evt)
|
||||||
{
|
{
|
||||||
if (evt.Name.startsWith("ingot") && !oreDictBlackList.contains(evt.Name))
|
if (evt.Name.startsWith("ingot") && !oreDictBlackList.contains(evt.Name))
|
||||||
{
|
{
|
||||||
String oreDictName = evt.Name.replace("ingot", "");
|
String oreDictName = evt.Name.replace("ingot", "");
|
||||||
String materialName = LanguageUtility.decapitalizeFirst(oreDictName);
|
String materialName = LanguageUtility.decapitalizeFirst(oreDictName);
|
||||||
|
|
||||||
if (!materialNames.contains(materialName))
|
if (!materialNames.contains(materialName))
|
||||||
{
|
{
|
||||||
Settings.CONFIGURATION.load();
|
Settings.CONFIGURATION.load();
|
||||||
boolean allowMaterial = Settings.CONFIGURATION.get("Resource_Generator", "Enable " + oreDictName, true).getBoolean(true);
|
boolean allowMaterial = Settings.CONFIGURATION.get("Resource_Generator", "Enable " + oreDictName, true).getBoolean(true);
|
||||||
Settings.CONFIGURATION.save();
|
Settings.CONFIGURATION.save();
|
||||||
|
|
||||||
if (!allowMaterial || OreDetectionBlackList.isIngotBlackListed("ingot" + oreDictName) || OreDetectionBlackList.isOreBlackListed("ore" + oreDictName))
|
if (!allowMaterial || OreDetectionBlackList.isIngotBlackListed("ingot" + oreDictName) || OreDetectionBlackList.isOreBlackListed("ore" + oreDictName))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
materialNames.add(materialName);
|
materialNames.add(materialName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void generateOreResources()
|
public static void generateOreResources()
|
||||||
{
|
{
|
||||||
OreDictionary.registerOre("ingotGold", Item.ingotGold);
|
OreDictionary.registerOre("ingotGold", Item.ingotGold);
|
||||||
OreDictionary.registerOre("ingotIron", Item.ingotIron);
|
OreDictionary.registerOre("ingotIron", Item.ingotIron);
|
||||||
|
|
||||||
OreDictionary.registerOre("oreGold", Block.oreGold);
|
OreDictionary.registerOre("oreGold", Block.oreGold);
|
||||||
OreDictionary.registerOre("oreIron", Block.oreIron);
|
OreDictionary.registerOre("oreIron", Block.oreIron);
|
||||||
OreDictionary.registerOre("oreLapis", Block.oreLapis);
|
OreDictionary.registerOre("oreLapis", Block.oreLapis);
|
||||||
|
|
||||||
MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER, new FluidStack(FluidRegistry.LAVA, FluidContainerRegistry.BUCKET_VOLUME), new ItemStack(Block.stone));
|
//Vanilla fluid recipes
|
||||||
|
MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER, new FluidStack(FluidRegistry.LAVA, FluidContainerRegistry.BUCKET_VOLUME), new ItemStack(Block.stone));
|
||||||
|
|
||||||
for (String materialName : materialNames)
|
//Vanilla crusher recipes
|
||||||
{
|
MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER, Block.cobblestone, Block.gravel);
|
||||||
// Caps version of the name
|
MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER, Block.stone, Block.cobblestone);
|
||||||
String nameCaps = LanguageUtility.capitalizeFirst(materialName);
|
MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER, Block.chest, new ItemStack(Block.planks, 7, 0));
|
||||||
|
|
||||||
/**
|
//Vanilla grinder recipes
|
||||||
* Generate molten fluids
|
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER, Block.cobblestone, Block.sand);
|
||||||
*/
|
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER, Block.gravel, Block.sand);
|
||||||
Fluid fluidMolten = new Fluid(materialNameToMolten(materialName));
|
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER, Block.glass, Block.sand);
|
||||||
fluidMolten.setDensity(7);
|
|
||||||
fluidMolten.setViscosity(5000);
|
|
||||||
fluidMolten.setTemperature(273 + 1538);
|
|
||||||
FluidRegistry.registerFluid(fluidMolten);
|
|
||||||
Block blockFluidMaterial = new BlockFluidMaterial(fluidMolten);
|
|
||||||
GameRegistry.registerBlock(blockFluidMaterial, "molten" + nameCaps);
|
|
||||||
ResonantInduction.blockMoltenFluid.add(blockFluidMaterial);
|
|
||||||
|
|
||||||
/**
|
for (String materialName : materialNames)
|
||||||
* Generate dust mixture fluids
|
{
|
||||||
*/
|
// Caps version of the name
|
||||||
Fluid fluidMixture = new Fluid(materialNameToMixture(materialName));
|
String nameCaps = LanguageUtility.capitalizeFirst(materialName);
|
||||||
FluidRegistry.registerFluid(fluidMixture);
|
|
||||||
Block blockFluidMixture = new BlockFluidMixture(fluidMixture);
|
|
||||||
GameRegistry.registerBlock(blockFluidMixture, "mixture" + nameCaps);
|
|
||||||
ResonantInduction.blockMixtureFluids.add(blockFluidMixture);
|
|
||||||
|
|
||||||
if (OreDictionary.getOres("ore" + nameCaps).size() > 0)
|
/** Generate molten fluids */
|
||||||
{
|
Fluid fluidMolten = new Fluid(materialNameToMolten(materialName));
|
||||||
OreDictionary.registerOre("dust" + nameCaps, ResonantInduction.itemDust.getStackFromMaterial(materialName));
|
fluidMolten.setDensity(7);
|
||||||
OreDictionary.registerOre("rubble" + nameCaps, ResonantInduction.itemRubble.getStackFromMaterial(materialName));
|
fluidMolten.setViscosity(5000);
|
||||||
OreDictionary.registerOre("dustRefined" + nameCaps, ResonantInduction.itemRefinedDust.getStackFromMaterial(materialName));
|
fluidMolten.setTemperature(273 + 1538);
|
||||||
|
FluidRegistry.registerFluid(fluidMolten);
|
||||||
|
Block blockFluidMaterial = new BlockFluidMaterial(fluidMolten);
|
||||||
|
GameRegistry.registerBlock(blockFluidMaterial, "molten" + nameCaps);
|
||||||
|
ResonantInduction.blockMoltenFluid.add(blockFluidMaterial);
|
||||||
|
|
||||||
MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER, "ore" + nameCaps, "rubble" + nameCaps);
|
/** Generate dust mixture fluids */
|
||||||
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER, "rubble" + nameCaps, "dust" + nameCaps, "dust" + nameCaps);
|
Fluid fluidMixture = new Fluid(materialNameToMixture(materialName));
|
||||||
MachineRecipes.INSTANCE.addRecipe(RecipeType.MIXER, "dust" + nameCaps, "dustRefined" + nameCaps);
|
FluidRegistry.registerFluid(fluidMixture);
|
||||||
MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER, new FluidStack(fluidMolten, FluidContainerRegistry.BUCKET_VOLUME), "ingot" + nameCaps);
|
Block blockFluidMixture = new BlockFluidMixture(fluidMixture);
|
||||||
|
GameRegistry.registerBlock(blockFluidMixture, "mixture" + nameCaps);
|
||||||
|
ResonantInduction.blockMixtureFluids.add(blockFluidMixture);
|
||||||
|
|
||||||
ItemStack dust = ResonantInduction.itemDust.getStackFromMaterial(materialName);
|
if (OreDictionary.getOres("ore" + nameCaps).size() > 0)
|
||||||
FurnaceRecipes.smelting().addSmelting(dust.itemID, dust.getItemDamage(), OreDictionary.getOres("ingot" + nameCaps).get(0).copy(), 0.7f);
|
{
|
||||||
ItemStack refinedDust = ResonantInduction.itemRefinedDust.getStackFromMaterial(materialName);
|
OreDictionary.registerOre("dust" + nameCaps, ResonantInduction.itemDust.getStackFromMaterial(materialName));
|
||||||
ItemStack smeltResult = OreDictionary.getOres("ingot" + nameCaps).get(0).copy();
|
OreDictionary.registerOre("rubble" + nameCaps, ResonantInduction.itemRubble.getStackFromMaterial(materialName));
|
||||||
smeltResult.stackSize = 2;
|
OreDictionary.registerOre("dustRefined" + nameCaps, ResonantInduction.itemRefinedDust.getStackFromMaterial(materialName));
|
||||||
FurnaceRecipes.smelting().addSmelting(refinedDust.itemID, refinedDust.getItemDamage(), smeltResult, 0.7f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ForgeSubscribe
|
MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER, "ore" + nameCaps, "rubble" + nameCaps);
|
||||||
@SideOnly(Side.CLIENT)
|
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER, "rubble" + nameCaps, "dust" + nameCaps, "dust" + nameCaps);
|
||||||
public void reloadTextures(TextureStitchEvent.Post e)
|
MachineRecipes.INSTANCE.addRecipe(RecipeType.MIXER, "dust" + nameCaps, "dustRefined" + nameCaps);
|
||||||
{
|
MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER, new FluidStack(fluidMolten, FluidContainerRegistry.BUCKET_VOLUME), "ingot" + nameCaps);
|
||||||
computeColors();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
ItemStack dust = ResonantInduction.itemDust.getStackFromMaterial(materialName);
|
||||||
public static void computeColors()
|
FurnaceRecipes.smelting().addSmelting(dust.itemID, dust.getItemDamage(), OreDictionary.getOres("ingot" + nameCaps).get(0).copy(), 0.7f);
|
||||||
{
|
ItemStack refinedDust = ResonantInduction.itemRefinedDust.getStackFromMaterial(materialName);
|
||||||
for (String material : materialNames)
|
ItemStack smeltResult = OreDictionary.getOres("ingot" + nameCaps).get(0).copy();
|
||||||
{
|
smeltResult.stackSize = 2;
|
||||||
// Compute color
|
FurnaceRecipes.smelting().addSmelting(refinedDust.itemID, refinedDust.getItemDamage(), smeltResult, 0.7f);
|
||||||
int totalR = 0;
|
}
|
||||||
int totalG = 0;
|
}
|
||||||
int totalB = 0;
|
}
|
||||||
|
|
||||||
int colorCount = 0;
|
@ForgeSubscribe
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public void reloadTextures(TextureStitchEvent.Post e)
|
||||||
|
{
|
||||||
|
computeColors();
|
||||||
|
}
|
||||||
|
|
||||||
for (ItemStack ingotStack : OreDictionary.getOres("ingot" + material.substring(0, 1).toUpperCase() + material.substring(1)))
|
@SideOnly(Side.CLIENT)
|
||||||
{
|
public static void computeColors()
|
||||||
Item theIngot = ingotStack.getItem();
|
{
|
||||||
materialColors.put(material, getAverageColor(ingotStack));
|
for (String material : materialNames)
|
||||||
}
|
{
|
||||||
|
// Compute color
|
||||||
|
int totalR = 0;
|
||||||
|
int totalG = 0;
|
||||||
|
int totalB = 0;
|
||||||
|
|
||||||
if (!materialColors.containsKey(material))
|
int colorCount = 0;
|
||||||
{
|
|
||||||
materialColors.put(material, 0xFFFFFF);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
for (ItemStack ingotStack : OreDictionary.getOres("ingot" + material.substring(0, 1).toUpperCase() + material.substring(1)))
|
||||||
* Gets the average color of this item.
|
{
|
||||||
*
|
Item theIngot = ingotStack.getItem();
|
||||||
* @param itemStack
|
materialColors.put(material, getAverageColor(ingotStack));
|
||||||
* @return The RGB hexadecimal color code.
|
}
|
||||||
*/
|
|
||||||
@SideOnly(Side.CLIENT)
|
|
||||||
public static int getAverageColor(ItemStack itemStack)
|
|
||||||
{
|
|
||||||
int totalR = 0;
|
|
||||||
int totalG = 0;
|
|
||||||
int totalB = 0;
|
|
||||||
|
|
||||||
int colorCount = 0;
|
if (!materialColors.containsKey(material))
|
||||||
Item item = itemStack.getItem();
|
{
|
||||||
|
materialColors.put(material, 0xFFFFFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try
|
/** Gets the average color of this item.
|
||||||
{
|
*
|
||||||
Icon icon = item.getIconIndex(itemStack);
|
* @param itemStack
|
||||||
|
* @return The RGB hexadecimal color code. */
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public static int getAverageColor(ItemStack itemStack)
|
||||||
|
{
|
||||||
|
int totalR = 0;
|
||||||
|
int totalG = 0;
|
||||||
|
int totalB = 0;
|
||||||
|
|
||||||
if (iconColorMap.containsKey(icon))
|
int colorCount = 0;
|
||||||
{
|
Item item = itemStack.getItem();
|
||||||
return iconColorMap.get(icon);
|
|
||||||
}
|
|
||||||
|
|
||||||
String iconString = icon.getIconName();
|
try
|
||||||
|
{
|
||||||
|
Icon icon = item.getIconIndex(itemStack);
|
||||||
|
|
||||||
if (iconString != null && !iconString.contains("MISSING_ICON_ITEM"))
|
if (iconColorMap.containsKey(icon))
|
||||||
{
|
{
|
||||||
iconString = (iconString.contains(":") ? iconString.replace(":", ":" + Reference.ITEM_TEXTURE_DIRECTORY) : Reference.ITEM_TEXTURE_DIRECTORY + iconString) + ".png";
|
return iconColorMap.get(icon);
|
||||||
ResourceLocation textureLocation = new ResourceLocation(iconString);
|
}
|
||||||
|
|
||||||
InputStream inputstream = Minecraft.getMinecraft().getResourceManager().getResource(textureLocation).getInputStream();
|
String iconString = icon.getIconName();
|
||||||
BufferedImage bufferedimage = ImageIO.read(inputstream);
|
|
||||||
|
|
||||||
int width = bufferedimage.getWidth();
|
if (iconString != null && !iconString.contains("MISSING_ICON_ITEM"))
|
||||||
int height = bufferedimage.getWidth();
|
{
|
||||||
|
iconString = (iconString.contains(":") ? iconString.replace(":", ":" + Reference.ITEM_TEXTURE_DIRECTORY) : Reference.ITEM_TEXTURE_DIRECTORY + iconString) + ".png";
|
||||||
|
ResourceLocation textureLocation = new ResourceLocation(iconString);
|
||||||
|
|
||||||
for (int x = 0; x < width; x++)
|
InputStream inputstream = Minecraft.getMinecraft().getResourceManager().getResource(textureLocation).getInputStream();
|
||||||
{
|
BufferedImage bufferedimage = ImageIO.read(inputstream);
|
||||||
for (int y = 0; y < height; y++)
|
|
||||||
{
|
|
||||||
Color rgb = new Color(bufferedimage.getRGB(x, y));
|
|
||||||
|
|
||||||
/**
|
int width = bufferedimage.getWidth();
|
||||||
* Ignore things that are too dark. Standard luma calculation.
|
int height = bufferedimage.getWidth();
|
||||||
*/
|
|
||||||
double luma = 0.2126 * rgb.getRed() + 0.7152 * rgb.getGreen() + 0.0722 * rgb.getBlue();
|
|
||||||
|
|
||||||
if (luma > 40)
|
for (int x = 0; x < width; x++)
|
||||||
{
|
{
|
||||||
totalR += rgb.getRed();
|
for (int y = 0; y < height; y++)
|
||||||
totalG += rgb.getGreen();
|
{
|
||||||
totalB += rgb.getBlue();
|
Color rgb = new Color(bufferedimage.getRGB(x, y));
|
||||||
colorCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (colorCount > 0)
|
/** Ignore things that are too dark. Standard luma calculation. */
|
||||||
{
|
double luma = 0.2126 * rgb.getRed() + 0.7152 * rgb.getGreen() + 0.0722 * rgb.getBlue();
|
||||||
totalR /= colorCount;
|
|
||||||
totalG /= colorCount;
|
|
||||||
totalB /= colorCount;
|
|
||||||
int averageColor = new Color(totalR, totalG, totalB).brighter().getRGB();
|
|
||||||
iconColorMap.put(icon, averageColor);
|
|
||||||
return averageColor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
ResonantInduction.LOGGER.fine("Failed to compute colors for: " + item);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0xFFFFFF;
|
if (luma > 40)
|
||||||
}
|
{
|
||||||
|
totalR += rgb.getRed();
|
||||||
|
totalG += rgb.getGreen();
|
||||||
|
totalB += rgb.getBlue();
|
||||||
|
colorCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static String moltenNameToMaterial(String fluidName)
|
if (colorCount > 0)
|
||||||
{
|
{
|
||||||
return fluidNameToMaterial(fluidName, "molten");
|
totalR /= colorCount;
|
||||||
}
|
totalG /= colorCount;
|
||||||
|
totalB /= colorCount;
|
||||||
|
int averageColor = new Color(totalR, totalG, totalB).brighter().getRGB();
|
||||||
|
iconColorMap.put(icon, averageColor);
|
||||||
|
return averageColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
ResonantInduction.LOGGER.fine("Failed to compute colors for: " + item);
|
||||||
|
}
|
||||||
|
|
||||||
public static String materialNameToMolten(String fluidName)
|
return 0xFFFFFF;
|
||||||
{
|
}
|
||||||
return materialNameToFluid(fluidName, "molten");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String mixtureToMaterial(String fluidName)
|
public static String moltenNameToMaterial(String fluidName)
|
||||||
{
|
{
|
||||||
return fluidNameToMaterial(fluidName, "mixture");
|
return fluidNameToMaterial(fluidName, "molten");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String materialNameToMixture(String fluidName)
|
public static String materialNameToMolten(String fluidName)
|
||||||
{
|
{
|
||||||
return materialNameToFluid(fluidName, "mixture");
|
return materialNameToFluid(fluidName, "molten");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String fluidNameToMaterial(String fluidName, String type)
|
public static String mixtureToMaterial(String fluidName)
|
||||||
{
|
{
|
||||||
return LanguageUtility.underscoreToCamel(fluidName).replace(type, "");
|
return fluidNameToMaterial(fluidName, "mixture");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String materialNameToFluid(String materialName, String type)
|
public static String materialNameToMixture(String fluidName)
|
||||||
{
|
{
|
||||||
return type + "_" + LanguageUtility.camelToLowerUnderscore(materialName);
|
return materialNameToFluid(fluidName, "mixture");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Block getMixture(String name)
|
public static String fluidNameToMaterial(String fluidName, String type)
|
||||||
{
|
{
|
||||||
return ResonantInduction.blockMixtureFluids.get((getID(name)));
|
return LanguageUtility.underscoreToCamel(fluidName).replace(type, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Block getMolten(String name)
|
public static String materialNameToFluid(String materialName, String type)
|
||||||
{
|
{
|
||||||
return ResonantInduction.blockMoltenFluid.get((getID(name)));
|
return type + "_" + LanguageUtility.camelToLowerUnderscore(materialName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getID(String name)
|
public static Block getMixture(String name)
|
||||||
{
|
{
|
||||||
if (!materialNames.contains(name))
|
return ResonantInduction.blockMixtureFluids.get((getID(name)));
|
||||||
{
|
}
|
||||||
ResonantInduction.LOGGER.severe("Trying to get invalid material name " + name);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return materialNames.indexOf(name);
|
public static Block getMolten(String name)
|
||||||
}
|
{
|
||||||
|
return ResonantInduction.blockMoltenFluid.get((getID(name)));
|
||||||
|
}
|
||||||
|
|
||||||
public static String getName(int id)
|
public static int getID(String name)
|
||||||
{
|
{
|
||||||
return materialNames.size() > id ? materialNames.get(id) : null;
|
if (!materialNames.contains(name))
|
||||||
}
|
{
|
||||||
|
ResonantInduction.LOGGER.severe("Trying to get invalid material name " + name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
public static int getColor(String name)
|
return materialNames.indexOf(name);
|
||||||
{
|
}
|
||||||
if (name != null && materialColors.containsKey(name))
|
|
||||||
{
|
|
||||||
return materialColors.get(name);
|
|
||||||
}
|
|
||||||
return 0xFFFFFF;
|
|
||||||
|
|
||||||
}
|
public static String getName(int id)
|
||||||
|
{
|
||||||
|
return materialNames.size() > id ? materialNames.get(id) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getColor(String name)
|
||||||
|
{
|
||||||
|
if (name != null && materialColors.containsKey(name))
|
||||||
|
{
|
||||||
|
return materialColors.get(name);
|
||||||
|
}
|
||||||
|
return 0xFFFFFF;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,13 @@
|
||||||
package resonantinduction.core.resource.item;
|
package resonantinduction.core.resource.item;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import calclavia.lib.utility.LanguageUtility;
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
import resonantinduction.core.Reference;
|
import resonantinduction.core.Reference;
|
||||||
import resonantinduction.core.TabRI;
|
import resonantinduction.core.TabRI;
|
||||||
|
import resonantinduction.core.resource.ResourceGenerator;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.creativetab.CreativeTabs;
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
@ -10,42 +16,94 @@ import net.minecraft.item.ItemBucket;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.fluids.Fluid;
|
import net.minecraftforge.fluids.Fluid;
|
||||||
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
/** Modified version of the MC bucket to meet the needs of a dynamic fluid registry system
|
/** Modified version of the MC bucket to meet the needs of a dynamic fluid registry system
|
||||||
*
|
*
|
||||||
* @author Darkguardsman */
|
* @author Darkguardsman */
|
||||||
public class ItemFluidBucket extends ItemBucket
|
public class ItemFluidBucket extends ItemBucket
|
||||||
{
|
{
|
||||||
private Fluid fluid;
|
public ItemFluidBucket(int id)
|
||||||
|
|
||||||
public ItemFluidBucket(int id, Fluid fluid)
|
|
||||||
{
|
{
|
||||||
super(id, fluid.getBlockID());
|
super(id, 0);
|
||||||
setContainerItem(Item.bucketEmpty);
|
setContainerItem(Item.bucketEmpty);
|
||||||
setUnlocalizedName(Reference.PREFIX + "Bucket_" + fluid.getName());
|
setUnlocalizedName(Reference.PREFIX + "Bucket_Molten");
|
||||||
setTextureName(Reference.PREFIX + "Bucket_" + fluid.getName());
|
setTextureName(Reference.PREFIX + "Bucket_Molten");
|
||||||
setCreativeTab(CreativeTabs.tabMisc);
|
setCreativeTab(CreativeTabs.tabMisc);
|
||||||
setHasSubtypes(true);
|
setHasSubtypes(true);
|
||||||
setMaxDamage(0);
|
setMaxDamage(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getItemDisplayName(ItemStack is)
|
||||||
|
{
|
||||||
|
String dustName = getMaterialFromStack(is);
|
||||||
|
|
||||||
|
if (dustName != null)
|
||||||
|
{
|
||||||
|
List<ItemStack> list = OreDictionary.getOres("ingot" + dustName.substring(0, 1).toUpperCase() + dustName.substring(1));
|
||||||
|
|
||||||
|
if (list.size() > 0)
|
||||||
|
{
|
||||||
|
ItemStack type = list.get(0);
|
||||||
|
|
||||||
|
String name = type.getDisplayName().replace(LanguageUtility.getLocal("misc.resonantinduction.ingot"), "").replaceAll("^ ", "").replaceAll(" $", "");
|
||||||
|
return (LanguageUtility.getLocal(this.getUnlocalizedName() + ".name")).replace("%v", name).replace(" ", " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack onItemRightClick(ItemStack bucket, World world, EntityPlayer player)
|
public ItemStack onItemRightClick(ItemStack bucket, World world, EntityPlayer player)
|
||||||
{
|
{
|
||||||
if (fluid == null || Block.blocksList[fluid.getBlockID()] == null)
|
|
||||||
{
|
|
||||||
return bucket;
|
|
||||||
}
|
|
||||||
return super.onItemRightClick(bucket, world, player);
|
return super.onItemRightClick(bucket, world, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean tryPlaceContainedLiquid(World par1World, int par2, int par3, int par4)
|
public boolean tryPlaceContainedLiquid(World par1World, int par2, int par3, int par4)
|
||||||
{
|
{
|
||||||
if (fluid == null || Block.blocksList[fluid.getBlockID()] == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return super.tryPlaceContainedLiquid(par1World, par2, par3, par4);
|
return super.tryPlaceContainedLiquid(par1World, par2, par3, par4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getMaterialFromStack(ItemStack itemStack)
|
||||||
|
{
|
||||||
|
if (ResourceGenerator.materialNames.size() > itemStack.getItemDamage())
|
||||||
|
return ResourceGenerator.materialNames.get(itemStack.getItemDamage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getStackFromMaterial(String name)
|
||||||
|
{
|
||||||
|
ItemStack itemStack = new ItemStack(this);
|
||||||
|
itemStack.setItemDamage(ResourceGenerator.materialNames.indexOf(name));
|
||||||
|
return itemStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
|
||||||
|
{
|
||||||
|
for (String materialName : ResourceGenerator.materialNames)
|
||||||
|
{
|
||||||
|
par3List.add(getStackFromMaterial(materialName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public int getColorFromItemStack(ItemStack itemStack, int par2)
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Auto-color based on the texture of the ingot.
|
||||||
|
*/
|
||||||
|
String name = ItemOreResource.getMaterialFromStack(itemStack);
|
||||||
|
|
||||||
|
if (ResourceGenerator.materialColors.containsKey(name))
|
||||||
|
{
|
||||||
|
return ResourceGenerator.materialColors.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 16777215;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue