Implemented vanilla block recipes for grinder

This commit is contained in:
Robert Seifert 2014-02-25 17:27:30 -05:00
parent 2c9966c632
commit 1291d760c7
3 changed files with 388 additions and 321 deletions

View file

@ -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 Block)
return new ItemStackResource(new ItemStack((Block) obj));
if (obj instanceof Item)
return new ItemStackResource(new ItemStack((Item) obj));
if (obj instanceof ItemStack)
return new ItemStackResource((ItemStack) obj);
if (obj instanceof ItemStack) if (obj instanceof FluidStack)
return new ItemStackResource((ItemStack) obj); return new FluidStackResource((FluidStack) obj);
if (obj instanceof FluidStack) if (obj instanceof RecipeResource)
return new FluidStackResource((FluidStack) obj); return (RecipeResource) obj;
if (obj instanceof RecipeResource) return null;
return (RecipeResource) obj; }
return null; public void addRecipe(RecipeType machine, RecipeResource[] input, RecipeResource[] output)
} {
this.recipes.get(machine).put(input, output);
}
public void addRecipe(RecipeType machine, RecipeResource[] input, RecipeResource[] output) public void addRecipe(RecipeType machine, Object inputObj, Object... outputObj)
{ {
this.recipes.get(machine).put(input, output); RecipeResource input = getResourceFromObject(inputObj);
} RecipeResource[] outputs = new RecipeResource[outputObj.length];
public void addRecipe(RecipeType machine, Object inputObj, Object... outputObj) for (int i = 0; i < outputs.length; i++)
{ {
RecipeResource input = getResourceFromObject(inputObj); RecipeResource output = getResourceFromObject(outputObj[i]);
RecipeResource[] outputs = new RecipeResource[outputObj.length];
for (int i = 0; i < outputs.length; i++) if (input == null || output == null)
{ throw new RuntimeException("Resonant Induction tried to add invalid machine recipe: " + input + " => " + output);
RecipeResource output = getResourceFromObject(outputObj[i]);
if (input == null || output == null) outputs[i] = output;
throw new RuntimeException("Resonant Induction tried to add invalid machine recipe: " + input + " => " + output); }
outputs[i] = output; addRecipe(machine, new RecipeResource[] { input }, outputs);
} }
addRecipe(machine, new RecipeResource[] { input }, outputs); public void removeRecipe(RecipeType machine, RecipeResource[] input)
} {
this.recipes.get(machine).remove(input);
}
public void removeRecipe(RecipeType machine, RecipeResource[] input) public Map<RecipeResource[], RecipeResource[]> getRecipes(RecipeType machine)
{ {
this.recipes.get(machine).remove(input); return new HashMap<RecipeResource[], RecipeResource[]>(this.recipes.get(machine));
} }
public Map<RecipeResource[], RecipeResource[]> getRecipes(RecipeType machine) public Map<RecipeType, Map<RecipeResource[], RecipeResource[]>> getRecipes()
{ {
return new HashMap<RecipeResource[], RecipeResource[]>(this.recipes.get(machine)); return new HashMap<RecipeType, Map<RecipeResource[], RecipeResource[]>>(this.recipes);
} }
public Map<RecipeType, Map<RecipeResource[], RecipeResource[]>> getRecipes() public RecipeResource[] getOutput(RecipeType machine, RecipeResource... input)
{ {
return new HashMap<RecipeType, Map<RecipeResource[], RecipeResource[]>>(this.recipes); Iterator<Entry<RecipeResource[], RecipeResource[]>> it = this.getRecipes(machine).entrySet().iterator();
}
public RecipeResource[] getOutput(RecipeType machine, RecipeResource... input) while (it.hasNext())
{ {
Iterator<Entry<RecipeResource[], RecipeResource[]>> it = this.getRecipes(machine).entrySet().iterator(); Entry<RecipeResource[], RecipeResource[]> entry = it.next();
while (it.hasNext()) if (Arrays.equals(entry.getKey(), input))
{ {
Entry<RecipeResource[], RecipeResource[]> entry = it.next(); return entry.getValue();
}
}
if (Arrays.equals(entry.getKey(), input)) return new RecipeResource[] {};
{ }
return entry.getValue();
}
}
return new RecipeResource[] {}; public RecipeResource[] getOutput(RecipeType machine, Object... inputs)
} {
RecipeResource[] resourceInputs = new RecipeResource[inputs.length];
public RecipeResource[] getOutput(RecipeType machine, Object... inputs) for (int i = 0; i < inputs.length; i++)
{ {
RecipeResource[] resourceInputs = new RecipeResource[inputs.length]; resourceInputs[i] = getResourceFromObject(inputs[i]);
}
for (int i = 0; i < inputs.length; i++) return getOutput(machine, resourceInputs);
{ }
resourceInputs[i] = getResourceFromObject(inputs[i]);
}
return getOutput(machine, resourceInputs);
}
} }

View file

@ -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));
//Vanilla crusher recipes
MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER, Block.cobblestone, Block.gravel);
MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER, Block.stone, Block.cobblestone);
MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER, Block.chest, new ItemStack(Block.planks, 7, 0));
//Vanilla grinder recipes
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER, Block.cobblestone, Block.sand);
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER, Block.gravel, Block.sand);
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER, Block.glass, Block.sand);
for (String materialName : materialNames) for (String materialName : materialNames)
{ {
// Caps version of the name // Caps version of the name
String nameCaps = LanguageUtility.capitalizeFirst(materialName); String nameCaps = LanguageUtility.capitalizeFirst(materialName);
/** /** Generate molten fluids */
* Generate molten fluids Fluid fluidMolten = new Fluid(materialNameToMolten(materialName));
*/ fluidMolten.setDensity(7);
Fluid fluidMolten = new Fluid(materialNameToMolten(materialName)); fluidMolten.setViscosity(5000);
fluidMolten.setDensity(7); fluidMolten.setTemperature(273 + 1538);
fluidMolten.setViscosity(5000); FluidRegistry.registerFluid(fluidMolten);
fluidMolten.setTemperature(273 + 1538); Block blockFluidMaterial = new BlockFluidMaterial(fluidMolten);
FluidRegistry.registerFluid(fluidMolten); GameRegistry.registerBlock(blockFluidMaterial, "molten" + nameCaps);
Block blockFluidMaterial = new BlockFluidMaterial(fluidMolten); ResonantInduction.blockMoltenFluid.add(blockFluidMaterial);
GameRegistry.registerBlock(blockFluidMaterial, "molten" + nameCaps);
ResonantInduction.blockMoltenFluid.add(blockFluidMaterial);
/** /** Generate dust mixture fluids */
* Generate dust mixture fluids Fluid fluidMixture = new Fluid(materialNameToMixture(materialName));
*/ FluidRegistry.registerFluid(fluidMixture);
Fluid fluidMixture = new Fluid(materialNameToMixture(materialName)); Block blockFluidMixture = new BlockFluidMixture(fluidMixture);
FluidRegistry.registerFluid(fluidMixture); GameRegistry.registerBlock(blockFluidMixture, "mixture" + nameCaps);
Block blockFluidMixture = new BlockFluidMixture(fluidMixture); ResonantInduction.blockMixtureFluids.add(blockFluidMixture);
GameRegistry.registerBlock(blockFluidMixture, "mixture" + nameCaps);
ResonantInduction.blockMixtureFluids.add(blockFluidMixture);
if (OreDictionary.getOres("ore" + nameCaps).size() > 0) if (OreDictionary.getOres("ore" + nameCaps).size() > 0)
{ {
OreDictionary.registerOre("dust" + nameCaps, ResonantInduction.itemDust.getStackFromMaterial(materialName)); OreDictionary.registerOre("dust" + nameCaps, ResonantInduction.itemDust.getStackFromMaterial(materialName));
OreDictionary.registerOre("rubble" + nameCaps, ResonantInduction.itemRubble.getStackFromMaterial(materialName)); OreDictionary.registerOre("rubble" + nameCaps, ResonantInduction.itemRubble.getStackFromMaterial(materialName));
OreDictionary.registerOre("dustRefined" + nameCaps, ResonantInduction.itemRefinedDust.getStackFromMaterial(materialName)); OreDictionary.registerOre("dustRefined" + nameCaps, ResonantInduction.itemRefinedDust.getStackFromMaterial(materialName));
MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER, "ore" + nameCaps, "rubble" + nameCaps); MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER, "ore" + nameCaps, "rubble" + nameCaps);
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER, "rubble" + nameCaps, "dust" + nameCaps, "dust" + nameCaps); MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER, "rubble" + nameCaps, "dust" + nameCaps, "dust" + nameCaps);
MachineRecipes.INSTANCE.addRecipe(RecipeType.MIXER, "dust" + nameCaps, "dustRefined" + nameCaps); MachineRecipes.INSTANCE.addRecipe(RecipeType.MIXER, "dust" + nameCaps, "dustRefined" + nameCaps);
MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER, new FluidStack(fluidMolten, FluidContainerRegistry.BUCKET_VOLUME), "ingot" + nameCaps); MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER, new FluidStack(fluidMolten, FluidContainerRegistry.BUCKET_VOLUME), "ingot" + nameCaps);
ItemStack dust = ResonantInduction.itemDust.getStackFromMaterial(materialName); ItemStack dust = ResonantInduction.itemDust.getStackFromMaterial(materialName);
FurnaceRecipes.smelting().addSmelting(dust.itemID, dust.getItemDamage(), OreDictionary.getOres("ingot" + nameCaps).get(0).copy(), 0.7f); FurnaceRecipes.smelting().addSmelting(dust.itemID, dust.getItemDamage(), OreDictionary.getOres("ingot" + nameCaps).get(0).copy(), 0.7f);
ItemStack refinedDust = ResonantInduction.itemRefinedDust.getStackFromMaterial(materialName); ItemStack refinedDust = ResonantInduction.itemRefinedDust.getStackFromMaterial(materialName);
ItemStack smeltResult = OreDictionary.getOres("ingot" + nameCaps).get(0).copy(); ItemStack smeltResult = OreDictionary.getOres("ingot" + nameCaps).get(0).copy();
smeltResult.stackSize = 2; smeltResult.stackSize = 2;
FurnaceRecipes.smelting().addSmelting(refinedDust.itemID, refinedDust.getItemDamage(), smeltResult, 0.7f); FurnaceRecipes.smelting().addSmelting(refinedDust.itemID, refinedDust.getItemDamage(), smeltResult, 0.7f);
} }
} }
} }
@ForgeSubscribe @ForgeSubscribe
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void reloadTextures(TextureStitchEvent.Post e) public void reloadTextures(TextureStitchEvent.Post e)
{ {
computeColors(); computeColors();
} }
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public static void computeColors() public static void computeColors()
{ {
for (String material : materialNames) for (String material : materialNames)
{ {
// 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; int colorCount = 0;
for (ItemStack ingotStack : OreDictionary.getOres("ingot" + material.substring(0, 1).toUpperCase() + material.substring(1))) for (ItemStack ingotStack : OreDictionary.getOres("ingot" + material.substring(0, 1).toUpperCase() + material.substring(1)))
{ {
Item theIngot = ingotStack.getItem(); Item theIngot = ingotStack.getItem();
materialColors.put(material, getAverageColor(ingotStack)); materialColors.put(material, getAverageColor(ingotStack));
} }
if (!materialColors.containsKey(material)) if (!materialColors.containsKey(material))
{ {
materialColors.put(material, 0xFFFFFF); materialColors.put(material, 0xFFFFFF);
} }
} }
} }
/** /** Gets the average color of this item.
* Gets the average color of this item. *
* * @param itemStack
* @param itemStack * @return The RGB hexadecimal color code. */
* @return The RGB hexadecimal color code. @SideOnly(Side.CLIENT)
*/ public static int getAverageColor(ItemStack itemStack)
@SideOnly(Side.CLIENT) {
public static int getAverageColor(ItemStack itemStack) int totalR = 0;
{ int totalG = 0;
int totalR = 0; int totalB = 0;
int totalG = 0;
int totalB = 0;
int colorCount = 0; int colorCount = 0;
Item item = itemStack.getItem(); Item item = itemStack.getItem();
try try
{ {
Icon icon = item.getIconIndex(itemStack); Icon icon = item.getIconIndex(itemStack);
if (iconColorMap.containsKey(icon)) if (iconColorMap.containsKey(icon))
{ {
return iconColorMap.get(icon); return iconColorMap.get(icon);
} }
String iconString = icon.getIconName(); String iconString = icon.getIconName();
if (iconString != null && !iconString.contains("MISSING_ICON_ITEM")) if (iconString != null && !iconString.contains("MISSING_ICON_ITEM"))
{ {
iconString = (iconString.contains(":") ? iconString.replace(":", ":" + Reference.ITEM_TEXTURE_DIRECTORY) : Reference.ITEM_TEXTURE_DIRECTORY + iconString) + ".png"; iconString = (iconString.contains(":") ? iconString.replace(":", ":" + Reference.ITEM_TEXTURE_DIRECTORY) : Reference.ITEM_TEXTURE_DIRECTORY + iconString) + ".png";
ResourceLocation textureLocation = new ResourceLocation(iconString); ResourceLocation textureLocation = new ResourceLocation(iconString);
InputStream inputstream = Minecraft.getMinecraft().getResourceManager().getResource(textureLocation).getInputStream(); InputStream inputstream = Minecraft.getMinecraft().getResourceManager().getResource(textureLocation).getInputStream();
BufferedImage bufferedimage = ImageIO.read(inputstream); BufferedImage bufferedimage = ImageIO.read(inputstream);
int width = bufferedimage.getWidth(); int width = bufferedimage.getWidth();
int height = bufferedimage.getWidth(); int height = bufferedimage.getWidth();
for (int x = 0; x < width; x++) for (int x = 0; x < width; x++)
{ {
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {
Color rgb = new Color(bufferedimage.getRGB(x, y)); Color rgb = new Color(bufferedimage.getRGB(x, y));
/** /** Ignore things that are too dark. Standard luma calculation. */
* Ignore things that are too dark. Standard luma calculation. double luma = 0.2126 * rgb.getRed() + 0.7152 * rgb.getGreen() + 0.0722 * rgb.getBlue();
*/
double luma = 0.2126 * rgb.getRed() + 0.7152 * rgb.getGreen() + 0.0722 * rgb.getBlue();
if (luma > 40) if (luma > 40)
{ {
totalR += rgb.getRed(); totalR += rgb.getRed();
totalG += rgb.getGreen(); totalG += rgb.getGreen();
totalB += rgb.getBlue(); totalB += rgb.getBlue();
colorCount++; colorCount++;
} }
} }
} }
} }
if (colorCount > 0) if (colorCount > 0)
{ {
totalR /= colorCount; totalR /= colorCount;
totalG /= colorCount; totalG /= colorCount;
totalB /= colorCount; totalB /= colorCount;
int averageColor = new Color(totalR, totalG, totalB).brighter().getRGB(); int averageColor = new Color(totalR, totalG, totalB).brighter().getRGB();
iconColorMap.put(icon, averageColor); iconColorMap.put(icon, averageColor);
return averageColor; return averageColor;
} }
} }
catch (Exception e) catch (Exception e)
{ {
ResonantInduction.LOGGER.fine("Failed to compute colors for: " + item); ResonantInduction.LOGGER.fine("Failed to compute colors for: " + item);
} }
return 0xFFFFFF; return 0xFFFFFF;
} }
public static String moltenNameToMaterial(String fluidName) public static String moltenNameToMaterial(String fluidName)
{ {
return fluidNameToMaterial(fluidName, "molten"); return fluidNameToMaterial(fluidName, "molten");
} }
public static String materialNameToMolten(String fluidName) public static String materialNameToMolten(String fluidName)
{ {
return materialNameToFluid(fluidName, "molten"); return materialNameToFluid(fluidName, "molten");
} }
public static String mixtureToMaterial(String fluidName) public static String mixtureToMaterial(String fluidName)
{ {
return fluidNameToMaterial(fluidName, "mixture"); return fluidNameToMaterial(fluidName, "mixture");
} }
public static String materialNameToMixture(String fluidName) public static String materialNameToMixture(String fluidName)
{ {
return materialNameToFluid(fluidName, "mixture"); return materialNameToFluid(fluidName, "mixture");
} }
public static String fluidNameToMaterial(String fluidName, String type) public static String fluidNameToMaterial(String fluidName, String type)
{ {
return LanguageUtility.underscoreToCamel(fluidName).replace(type, ""); return LanguageUtility.underscoreToCamel(fluidName).replace(type, "");
} }
public static String materialNameToFluid(String materialName, String type) public static String materialNameToFluid(String materialName, String type)
{ {
return type + "_" + LanguageUtility.camelToLowerUnderscore(materialName); return type + "_" + LanguageUtility.camelToLowerUnderscore(materialName);
} }
public static Block getMixture(String name) public static Block getMixture(String name)
{ {
return ResonantInduction.blockMixtureFluids.get((getID(name))); return ResonantInduction.blockMixtureFluids.get((getID(name)));
} }
public static Block getMolten(String name) public static Block getMolten(String name)
{ {
return ResonantInduction.blockMoltenFluid.get((getID(name))); return ResonantInduction.blockMoltenFluid.get((getID(name)));
} }
public static int getID(String name) public static int getID(String name)
{ {
if (!materialNames.contains(name)) if (!materialNames.contains(name))
{ {
ResonantInduction.LOGGER.severe("Trying to get invalid material name " + name); ResonantInduction.LOGGER.severe("Trying to get invalid material name " + name);
return 0; return 0;
} }
return materialNames.indexOf(name); return materialNames.indexOf(name);
} }
public static String getName(int id) public static String getName(int id)
{ {
return materialNames.size() > id ? materialNames.get(id) : null; return materialNames.size() > id ? materialNames.get(id) : null;
} }
public static int getColor(String name) public static int getColor(String name)
{ {
if (name != null && materialColors.containsKey(name)) if (name != null && materialColors.containsKey(name))
{ {
return materialColors.get(name); return materialColors.get(name);
} }
return 0xFFFFFF; return 0xFFFFFF;
} }
} }

View file

@ -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;
}
} }