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.Entry;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import resonantinduction.api.recipe.RecipeResource.FluidStackResource;
@ -14,104 +16,114 @@ import resonantinduction.api.recipe.RecipeResource.OreDictResource;
public final class MachineRecipes
{
public static enum RecipeType
{
CRUSHER, GRINDER, MIXER, SMELTER, SAWMILL;
}
public static enum RecipeType
{
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()
{
for (RecipeType machine : RecipeType.values())
{
this.recipes.put(machine, new HashMap<RecipeResource[], RecipeResource[]>());
}
}
private MachineRecipes()
{
for (RecipeType machine : RecipeType.values())
{
this.recipes.put(machine, new HashMap<RecipeResource[], RecipeResource[]>());
}
}
public RecipeResource getResourceFromObject(Object obj)
{
if (obj instanceof String)
return new OreDictResource((String) obj);
public RecipeResource getResourceFromObject(Object obj)
{
if (obj instanceof String)
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)
return new ItemStackResource((ItemStack) obj);
if (obj instanceof FluidStack)
return new FluidStackResource((FluidStack) obj);
if (obj instanceof FluidStack)
return new FluidStackResource((FluidStack) obj);
if (obj instanceof RecipeResource)
return (RecipeResource) obj;
if (obj instanceof RecipeResource)
return (RecipeResource) obj;
return null;
}
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)
{
this.recipes.get(machine).put(input, output);
}
public void addRecipe(RecipeType machine, Object inputObj, Object... outputObj)
{
RecipeResource input = getResourceFromObject(inputObj);
RecipeResource[] outputs = new RecipeResource[outputObj.length];
public void addRecipe(RecipeType machine, Object inputObj, Object... outputObj)
{
RecipeResource input = getResourceFromObject(inputObj);
RecipeResource[] outputs = new RecipeResource[outputObj.length];
for (int i = 0; i < outputs.length; i++)
{
RecipeResource output = getResourceFromObject(outputObj[i]);
for (int i = 0; i < outputs.length; i++)
{
RecipeResource output = getResourceFromObject(outputObj[i]);
if (input == null || output == null)
throw new RuntimeException("Resonant Induction tried to add invalid machine recipe: " + input + " => " + output);
if (input == null || output == null)
throw new RuntimeException("Resonant Induction tried to add invalid machine recipe: " + input + " => " + output);
outputs[i] = 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)
{
this.recipes.get(machine).remove(input);
}
public Map<RecipeResource[], RecipeResource[]> getRecipes(RecipeType machine)
{
return new HashMap<RecipeResource[], RecipeResource[]>(this.recipes.get(machine));
}
public Map<RecipeResource[], RecipeResource[]> getRecipes(RecipeType machine)
{
return new HashMap<RecipeResource[], RecipeResource[]>(this.recipes.get(machine));
}
public Map<RecipeType, Map<RecipeResource[], RecipeResource[]>> getRecipes()
{
return new HashMap<RecipeType, Map<RecipeResource[], RecipeResource[]>>(this.recipes);
}
public Map<RecipeType, Map<RecipeResource[], RecipeResource[]>> getRecipes()
{
return new HashMap<RecipeType, Map<RecipeResource[], RecipeResource[]>>(this.recipes);
}
public RecipeResource[] getOutput(RecipeType machine, RecipeResource... input)
{
Iterator<Entry<RecipeResource[], RecipeResource[]>> it = this.getRecipes(machine).entrySet().iterator();
public RecipeResource[] getOutput(RecipeType machine, RecipeResource... input)
{
Iterator<Entry<RecipeResource[], RecipeResource[]>> it = this.getRecipes(machine).entrySet().iterator();
while (it.hasNext())
{
Entry<RecipeResource[], RecipeResource[]> entry = it.next();
while (it.hasNext())
{
Entry<RecipeResource[], RecipeResource[]> entry = it.next();
if (Arrays.equals(entry.getKey(), input))
{
return entry.getValue();
}
}
if (Arrays.equals(entry.getKey(), input))
{
return entry.getValue();
}
}
return new RecipeResource[] {};
}
return new RecipeResource[] {};
}
public RecipeResource[] getOutput(RecipeType machine, Object... inputs)
{
RecipeResource[] resourceInputs = new RecipeResource[inputs.length];
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]);
}
for (int i = 0; i < inputs.length; i++)
{
resourceInputs[i] = getResourceFromObject(inputs[i]);
}
return getOutput(machine, resourceInputs);
}
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.SideOnly;
/**
* @author Calclavia
*
*/
/** @author Calclavia */
public class ResourceGenerator
{
public static final ResourceGenerator INSTANCE = new ResourceGenerator();
public static final Set<String> oreDictBlackList = new HashSet<String>();
public static final ResourceGenerator INSTANCE = new ResourceGenerator();
public static final Set<String> oreDictBlackList = new HashSet<String>();
/**
* A list of material names. They are all camelCase reference of ore dictionary names without
* the
* "ore" or "ingot" prefix.
*/
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>();
/** A list of material names. They are all camelCase reference of ore dictionary names without
* the "ore" or "ingot" prefix. */
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
{
oreDictBlackList.add("ingotRefinedIron");
}
static
{
oreDictBlackList.add("ingotRefinedIron");
}
@ForgeSubscribe
public void oreRegisterEvent(OreRegisterEvent evt)
{
if (evt.Name.startsWith("ingot") && !oreDictBlackList.contains(evt.Name))
{
String oreDictName = evt.Name.replace("ingot", "");
String materialName = LanguageUtility.decapitalizeFirst(oreDictName);
@ForgeSubscribe
public void oreRegisterEvent(OreRegisterEvent evt)
{
if (evt.Name.startsWith("ingot") && !oreDictBlackList.contains(evt.Name))
{
String oreDictName = evt.Name.replace("ingot", "");
String materialName = LanguageUtility.decapitalizeFirst(oreDictName);
if (!materialNames.contains(materialName))
{
Settings.CONFIGURATION.load();
boolean allowMaterial = Settings.CONFIGURATION.get("Resource_Generator", "Enable " + oreDictName, true).getBoolean(true);
Settings.CONFIGURATION.save();
if (!materialNames.contains(materialName))
{
Settings.CONFIGURATION.load();
boolean allowMaterial = Settings.CONFIGURATION.get("Resource_Generator", "Enable " + oreDictName, true).getBoolean(true);
Settings.CONFIGURATION.save();
if (!allowMaterial || OreDetectionBlackList.isIngotBlackListed("ingot" + oreDictName) || OreDetectionBlackList.isOreBlackListed("ore" + oreDictName))
return;
if (!allowMaterial || OreDetectionBlackList.isIngotBlackListed("ingot" + oreDictName) || OreDetectionBlackList.isOreBlackListed("ore" + oreDictName))
return;
materialNames.add(materialName);
}
}
}
materialNames.add(materialName);
}
}
}
public static void generateOreResources()
{
OreDictionary.registerOre("ingotGold", Item.ingotGold);
OreDictionary.registerOre("ingotIron", Item.ingotIron);
public static void generateOreResources()
{
OreDictionary.registerOre("ingotGold", Item.ingotGold);
OreDictionary.registerOre("ingotIron", Item.ingotIron);
OreDictionary.registerOre("oreGold", Block.oreGold);
OreDictionary.registerOre("oreIron", Block.oreIron);
OreDictionary.registerOre("oreLapis", Block.oreLapis);
OreDictionary.registerOre("oreGold", Block.oreGold);
OreDictionary.registerOre("oreIron", Block.oreIron);
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)
{
// Caps version of the name
String nameCaps = LanguageUtility.capitalizeFirst(materialName);
for (String materialName : materialNames)
{
// Caps version of the name
String nameCaps = LanguageUtility.capitalizeFirst(materialName);
/**
* Generate molten fluids
*/
Fluid fluidMolten = new Fluid(materialNameToMolten(materialName));
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);
/** Generate molten fluids */
Fluid fluidMolten = new Fluid(materialNameToMolten(materialName));
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);
/**
* Generate dust mixture fluids
*/
Fluid fluidMixture = new Fluid(materialNameToMixture(materialName));
FluidRegistry.registerFluid(fluidMixture);
Block blockFluidMixture = new BlockFluidMixture(fluidMixture);
GameRegistry.registerBlock(blockFluidMixture, "mixture" + nameCaps);
ResonantInduction.blockMixtureFluids.add(blockFluidMixture);
/** Generate dust mixture fluids */
Fluid fluidMixture = new Fluid(materialNameToMixture(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)
{
OreDictionary.registerOre("dust" + nameCaps, ResonantInduction.itemDust.getStackFromMaterial(materialName));
OreDictionary.registerOre("rubble" + nameCaps, ResonantInduction.itemRubble.getStackFromMaterial(materialName));
OreDictionary.registerOre("dustRefined" + nameCaps, ResonantInduction.itemRefinedDust.getStackFromMaterial(materialName));
if (OreDictionary.getOres("ore" + nameCaps).size() > 0)
{
OreDictionary.registerOre("dust" + nameCaps, ResonantInduction.itemDust.getStackFromMaterial(materialName));
OreDictionary.registerOre("rubble" + nameCaps, ResonantInduction.itemRubble.getStackFromMaterial(materialName));
OreDictionary.registerOre("dustRefined" + nameCaps, ResonantInduction.itemRefinedDust.getStackFromMaterial(materialName));
MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER, "ore" + nameCaps, "rubble" + 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.SMELTER, new FluidStack(fluidMolten, FluidContainerRegistry.BUCKET_VOLUME), "ingot" + 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.MIXER, "dust" + nameCaps, "dustRefined" + nameCaps);
MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER, new FluidStack(fluidMolten, FluidContainerRegistry.BUCKET_VOLUME), "ingot" + nameCaps);
ItemStack dust = ResonantInduction.itemDust.getStackFromMaterial(materialName);
FurnaceRecipes.smelting().addSmelting(dust.itemID, dust.getItemDamage(), OreDictionary.getOres("ingot" + nameCaps).get(0).copy(), 0.7f);
ItemStack refinedDust = ResonantInduction.itemRefinedDust.getStackFromMaterial(materialName);
ItemStack smeltResult = OreDictionary.getOres("ingot" + nameCaps).get(0).copy();
smeltResult.stackSize = 2;
FurnaceRecipes.smelting().addSmelting(refinedDust.itemID, refinedDust.getItemDamage(), smeltResult, 0.7f);
}
}
}
ItemStack dust = ResonantInduction.itemDust.getStackFromMaterial(materialName);
FurnaceRecipes.smelting().addSmelting(dust.itemID, dust.getItemDamage(), OreDictionary.getOres("ingot" + nameCaps).get(0).copy(), 0.7f);
ItemStack refinedDust = ResonantInduction.itemRefinedDust.getStackFromMaterial(materialName);
ItemStack smeltResult = OreDictionary.getOres("ingot" + nameCaps).get(0).copy();
smeltResult.stackSize = 2;
FurnaceRecipes.smelting().addSmelting(refinedDust.itemID, refinedDust.getItemDamage(), smeltResult, 0.7f);
}
}
}
@ForgeSubscribe
@SideOnly(Side.CLIENT)
public void reloadTextures(TextureStitchEvent.Post e)
{
computeColors();
}
@ForgeSubscribe
@SideOnly(Side.CLIENT)
public void reloadTextures(TextureStitchEvent.Post e)
{
computeColors();
}
@SideOnly(Side.CLIENT)
public static void computeColors()
{
for (String material : materialNames)
{
// Compute color
int totalR = 0;
int totalG = 0;
int totalB = 0;
@SideOnly(Side.CLIENT)
public static void computeColors()
{
for (String material : materialNames)
{
// Compute color
int totalR = 0;
int totalG = 0;
int totalB = 0;
int colorCount = 0;
int colorCount = 0;
for (ItemStack ingotStack : OreDictionary.getOres("ingot" + material.substring(0, 1).toUpperCase() + material.substring(1)))
{
Item theIngot = ingotStack.getItem();
materialColors.put(material, getAverageColor(ingotStack));
}
for (ItemStack ingotStack : OreDictionary.getOres("ingot" + material.substring(0, 1).toUpperCase() + material.substring(1)))
{
Item theIngot = ingotStack.getItem();
materialColors.put(material, getAverageColor(ingotStack));
}
if (!materialColors.containsKey(material))
{
materialColors.put(material, 0xFFFFFF);
}
}
}
if (!materialColors.containsKey(material))
{
materialColors.put(material, 0xFFFFFF);
}
}
}
/**
* Gets the average color of this item.
*
* @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;
/** Gets the average color of this item.
*
* @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;
int colorCount = 0;
Item item = itemStack.getItem();
int colorCount = 0;
Item item = itemStack.getItem();
try
{
Icon icon = item.getIconIndex(itemStack);
try
{
Icon icon = item.getIconIndex(itemStack);
if (iconColorMap.containsKey(icon))
{
return iconColorMap.get(icon);
}
if (iconColorMap.containsKey(icon))
{
return iconColorMap.get(icon);
}
String iconString = icon.getIconName();
String iconString = icon.getIconName();
if (iconString != null && !iconString.contains("MISSING_ICON_ITEM"))
{
iconString = (iconString.contains(":") ? iconString.replace(":", ":" + Reference.ITEM_TEXTURE_DIRECTORY) : Reference.ITEM_TEXTURE_DIRECTORY + iconString) + ".png";
ResourceLocation textureLocation = new ResourceLocation(iconString);
if (iconString != null && !iconString.contains("MISSING_ICON_ITEM"))
{
iconString = (iconString.contains(":") ? iconString.replace(":", ":" + Reference.ITEM_TEXTURE_DIRECTORY) : Reference.ITEM_TEXTURE_DIRECTORY + iconString) + ".png";
ResourceLocation textureLocation = new ResourceLocation(iconString);
InputStream inputstream = Minecraft.getMinecraft().getResourceManager().getResource(textureLocation).getInputStream();
BufferedImage bufferedimage = ImageIO.read(inputstream);
InputStream inputstream = Minecraft.getMinecraft().getResourceManager().getResource(textureLocation).getInputStream();
BufferedImage bufferedimage = ImageIO.read(inputstream);
int width = bufferedimage.getWidth();
int height = bufferedimage.getWidth();
int width = bufferedimage.getWidth();
int height = bufferedimage.getWidth();
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
Color rgb = new Color(bufferedimage.getRGB(x, y));
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
Color rgb = new Color(bufferedimage.getRGB(x, y));
/**
* Ignore things that are too dark. Standard luma calculation.
*/
double luma = 0.2126 * rgb.getRed() + 0.7152 * rgb.getGreen() + 0.0722 * rgb.getBlue();
/** Ignore things that are too dark. Standard luma calculation. */
double luma = 0.2126 * rgb.getRed() + 0.7152 * rgb.getGreen() + 0.0722 * rgb.getBlue();
if (luma > 40)
{
totalR += rgb.getRed();
totalG += rgb.getGreen();
totalB += rgb.getBlue();
colorCount++;
}
}
}
}
if (luma > 40)
{
totalR += rgb.getRed();
totalG += rgb.getGreen();
totalB += rgb.getBlue();
colorCount++;
}
}
}
}
if (colorCount > 0)
{
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);
}
if (colorCount > 0)
{
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;
}
return 0xFFFFFF;
}
public static String moltenNameToMaterial(String fluidName)
{
return fluidNameToMaterial(fluidName, "molten");
}
public static String moltenNameToMaterial(String fluidName)
{
return fluidNameToMaterial(fluidName, "molten");
}
public static String materialNameToMolten(String fluidName)
{
return materialNameToFluid(fluidName, "molten");
}
public static String materialNameToMolten(String fluidName)
{
return materialNameToFluid(fluidName, "molten");
}
public static String mixtureToMaterial(String fluidName)
{
return fluidNameToMaterial(fluidName, "mixture");
}
public static String mixtureToMaterial(String fluidName)
{
return fluidNameToMaterial(fluidName, "mixture");
}
public static String materialNameToMixture(String fluidName)
{
return materialNameToFluid(fluidName, "mixture");
}
public static String materialNameToMixture(String fluidName)
{
return materialNameToFluid(fluidName, "mixture");
}
public static String fluidNameToMaterial(String fluidName, String type)
{
return LanguageUtility.underscoreToCamel(fluidName).replace(type, "");
}
public static String fluidNameToMaterial(String fluidName, String type)
{
return LanguageUtility.underscoreToCamel(fluidName).replace(type, "");
}
public static String materialNameToFluid(String materialName, String type)
{
return type + "_" + LanguageUtility.camelToLowerUnderscore(materialName);
}
public static String materialNameToFluid(String materialName, String type)
{
return type + "_" + LanguageUtility.camelToLowerUnderscore(materialName);
}
public static Block getMixture(String name)
{
return ResonantInduction.blockMixtureFluids.get((getID(name)));
}
public static Block getMixture(String name)
{
return ResonantInduction.blockMixtureFluids.get((getID(name)));
}
public static Block getMolten(String name)
{
return ResonantInduction.blockMoltenFluid.get((getID(name)));
}
public static Block getMolten(String name)
{
return ResonantInduction.blockMoltenFluid.get((getID(name)));
}
public static int getID(String name)
{
if (!materialNames.contains(name))
{
ResonantInduction.LOGGER.severe("Trying to get invalid material name " + name);
return 0;
}
public static int getID(String name)
{
if (!materialNames.contains(name))
{
ResonantInduction.LOGGER.severe("Trying to get invalid material name " + name);
return 0;
}
return materialNames.indexOf(name);
}
return materialNames.indexOf(name);
}
public static String getName(int id)
{
return materialNames.size() > id ? materialNames.get(id) : null;
}
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;
public static int getColor(String name)
{
if (name != null && materialColors.containsKey(name))
{
return materialColors.get(name);
}
return 0xFFFFFF;
}
}
}

View file

@ -1,7 +1,13 @@
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.TabRI;
import resonantinduction.core.resource.ResourceGenerator;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
@ -10,42 +16,94 @@ import net.minecraft.item.ItemBucket;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
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
*
* @author Darkguardsman */
public class ItemFluidBucket extends ItemBucket
{
private Fluid fluid;
public ItemFluidBucket(int id, Fluid fluid)
public ItemFluidBucket(int id)
{
super(id, fluid.getBlockID());
super(id, 0);
setContainerItem(Item.bucketEmpty);
setUnlocalizedName(Reference.PREFIX + "Bucket_" + fluid.getName());
setTextureName(Reference.PREFIX + "Bucket_" + fluid.getName());
setUnlocalizedName(Reference.PREFIX + "Bucket_Molten");
setTextureName(Reference.PREFIX + "Bucket_Molten");
setCreativeTab(CreativeTabs.tabMisc);
setHasSubtypes(true);
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
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);
}
@Override
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);
}
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;
}
}