Support for items/blocks with multiple OreDict entries

This commit is contained in:
Aidan C. Brady 2013-12-22 18:28:49 -05:00
parent d4fc39274e
commit 6b420d07d2
6 changed files with 102 additions and 81 deletions

View file

@ -1,5 +1,8 @@
package mekanism.client.gui; package mekanism.client.gui;
import java.util.ArrayList;
import java.util.List;
import mekanism.common.inventory.container.ContainerDictionary; import mekanism.common.inventory.container.ContainerDictionary;
import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType; import mekanism.common.util.MekanismUtils.ResourceType;
@ -14,7 +17,7 @@ public class GuiDictionary extends GuiMekanism
{ {
public ItemStack itemType; public ItemStack itemType;
public String oreDictName; public List<String> oreDictNames;
public GuiDictionary(InventoryPlayer inventory) public GuiDictionary(InventoryPlayer inventory)
{ {
@ -32,9 +35,15 @@ public class GuiDictionary extends GuiMekanism
if(itemType != null) if(itemType != null)
{ {
if(oreDictName != null && !oreDictName.isEmpty()) if(!oreDictNames.isEmpty())
{ {
fontRenderer.drawString(MekanismUtils.localize("gui.dictionary.key") + ": " + oreDictName, 9, 57, 0x00CD00); int currentY = 57;
for(String name : oreDictNames)
{
fontRenderer.drawString(MekanismUtils.localize("gui.dictionary.key") + ": " + name, 9, currentY, 0x00CD00);
currentY += 9;
}
} }
else { else {
fontRenderer.drawString(MekanismUtils.localize("gui.dictionary.noKey"), 9, 57, 0x00CD00); fontRenderer.drawString(MekanismUtils.localize("gui.dictionary.noKey"), 9, 57, 0x00CD00);
@ -121,7 +130,7 @@ public class GuiDictionary extends GuiMekanism
itemType = stack.copy(); itemType = stack.copy();
itemType.stackSize = 1; itemType.stackSize = 1;
oreDictName = MekanismUtils.getOreDictName(itemType); oreDictNames = MekanismUtils.getOreDictName(itemType);
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F); mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
return; return;
@ -138,12 +147,12 @@ public class GuiDictionary extends GuiMekanism
itemType = stack.copy(); itemType = stack.copy();
itemType.stackSize = 1; itemType.stackSize = 1;
oreDictName = MekanismUtils.getOreDictName(itemType); oreDictNames = MekanismUtils.getOreDictName(itemType);
} }
else if(stack == null && Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) else if(stack == null && Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))
{ {
itemType = null; itemType = null;
oreDictName = null; oreDictNames = new ArrayList<String>();
} }
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F); mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);

View file

@ -6,6 +6,7 @@ import ic2.api.recipe.RecipeInputOreDict;
import ic2.api.recipe.RecipeOutput; import ic2.api.recipe.RecipeOutput;
import ic2.api.recipe.Recipes; import ic2.api.recipe.Recipes;
import java.util.List;
import java.util.Map; import java.util.Map;
import mekanism.common.RecipeHandler.Recipe; import mekanism.common.RecipeHandler.Recipe;
@ -78,18 +79,32 @@ public final class MekanismHooks
{ {
if(!entry.getKey().getInputs().isEmpty()) if(!entry.getKey().getInputs().isEmpty())
{ {
if(MekanismUtils.getName(entry.getKey().getInputs().get(0)).startsWith("ore")) List<String> names = MekanismUtils.getOreDictName(entry.getKey().getInputs().get(0));
for(String name : names)
{ {
if(!Recipe.ENRICHMENT_CHAMBER.containsRecipe(entry.getKey().getInputs().get(0))) boolean did = false;
if(name.startsWith("ore"))
{ {
RecipeHandler.addEnrichmentChamberRecipe(entry.getKey().getInputs().get(0), entry.getValue().items.get(0)); if(!Recipe.ENRICHMENT_CHAMBER.containsRecipe(entry.getKey().getInputs().get(0)))
{
RecipeHandler.addEnrichmentChamberRecipe(entry.getKey().getInputs().get(0), entry.getValue().items.get(0));
did = true;
}
} }
} else if(name.startsWith("ingot"))
else if(MekanismUtils.getName(entry.getKey().getInputs().get(0)).startsWith("ingot"))
{
if(!Recipe.CRUSHER.containsRecipe(entry.getKey().getInputs().get(0)))
{ {
RecipeHandler.addCrusherRecipe(entry.getKey().getInputs().get(0), entry.getValue().items.get(0)); if(!Recipe.CRUSHER.containsRecipe(entry.getKey().getInputs().get(0)))
{
RecipeHandler.addCrusherRecipe(entry.getKey().getInputs().get(0), entry.getValue().items.get(0));
did = true;
}
}
if(did)
{
break;
} }
} }
} }

View file

@ -1,15 +1,13 @@
package mekanism.common.item; package mekanism.common.item;
import java.util.List;
import mekanism.api.EnumColor; import mekanism.api.EnumColor;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.api.transmitters.TransmitterNetworkRegistry;
import mekanism.common.Mekanism; import mekanism.common.Mekanism;
import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatMessageComponent;
import net.minecraft.world.World; import net.minecraft.world.World;
public class ItemDictionary extends ItemMekanism public class ItemDictionary extends ItemMekanism
@ -32,11 +30,16 @@ public class ItemDictionary extends ItemMekanism
if(world.isRemote) if(world.isRemote)
{ {
ItemStack testStack = new ItemStack(block, 1, world.getBlockMetadata(x, y, z)); ItemStack testStack = new ItemStack(block, 1, world.getBlockMetadata(x, y, z));
String name = MekanismUtils.getOreDictName(testStack); List<String> names = MekanismUtils.getOreDictName(testStack);
if(name != null && !name.isEmpty()) if(!names.isEmpty())
{ {
player.addChatMessage(EnumColor.DARK_BLUE + "[Mekanism]" + EnumColor.GREY + " Key found: " + EnumColor.DARK_GREEN + name); player.addChatMessage(EnumColor.DARK_BLUE + "[Mekanism]" + EnumColor.GREY + " Key(s) found:");
for(String name : names)
{
player.addChatMessage(EnumColor.DARK_GREEN + " - " + name);
}
} }
else { else {
player.addChatMessage(EnumColor.DARK_BLUE + "[Mekanism]" + EnumColor.GREY + " No key."); player.addChatMessage(EnumColor.DARK_BLUE + "[Mekanism]" + EnumColor.GREY + " No key.");

View file

@ -1,6 +1,7 @@
package mekanism.common.miner; package mekanism.common.miner;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -27,36 +28,39 @@ public class MOreDictFilter extends MinerFilter
return true; return true;
} }
String oreKey = MekanismUtils.getOreDictName(itemStack); List<String> oreKeys = MekanismUtils.getOreDictName(itemStack);
if(oreKey == null) if(oreKeys.isEmpty())
{ {
return false; return false;
} }
if(oreDictName.equals(oreKey)) for(String oreKey : oreKeys)
{ {
return true; if(oreDictName.equals(oreKey))
}
else if(oreDictName.endsWith("*") && !oreDictName.startsWith("*"))
{
if(oreKey.startsWith(oreDictName.substring(0, oreDictName.length()-1)))
{ {
return true; return true;
} }
} else if(oreDictName.endsWith("*") && !oreDictName.startsWith("*"))
else if(oreDictName.startsWith("*") && !oreDictName.endsWith("*"))
{
if(oreKey.endsWith(oreDictName.substring(1)))
{ {
return true; if(oreKey.startsWith(oreDictName.substring(0, oreDictName.length()-1)))
{
return true;
}
} }
} else if(oreDictName.startsWith("*") && !oreDictName.endsWith("*"))
else if(oreDictName.startsWith("*") && oreDictName.endsWith("*"))
{
if(oreKey.contains(oreDictName.substring(1, oreDictName.length()-1)))
{ {
return true; if(oreKey.endsWith(oreDictName.substring(1)))
{
return true;
}
}
else if(oreDictName.startsWith("*") && oreDictName.endsWith("*"))
{
if(oreKey.contains(oreDictName.substring(1, oreDictName.length()-1)))
{
return true;
}
} }
} }

View file

@ -1,6 +1,7 @@
package mekanism.common.transporter; package mekanism.common.transporter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import mekanism.common.util.InventoryUtils; import mekanism.common.util.InventoryUtils;
import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils;
@ -18,36 +19,39 @@ public class TOreDictFilter extends TransporterFilter
@Override @Override
public boolean canFilter(ItemStack itemStack) public boolean canFilter(ItemStack itemStack)
{ {
String oreKey = MekanismUtils.getOreDictName(itemStack); List<String> oreKeys = MekanismUtils.getOreDictName(itemStack);
if(oreKey == null) if(oreKeys.isEmpty())
{ {
return false; return false;
} }
if(oreDictName.equals(oreKey) || oreDictName.equals("*")) for(String oreKey : oreKeys)
{ {
return true; if(oreDictName.equals(oreKey) || oreDictName.equals("*"))
}
else if(oreDictName.endsWith("*") && !oreDictName.startsWith("*"))
{
if(oreKey.startsWith(oreDictName.substring(0, oreDictName.length()-1)))
{ {
return true; return true;
} }
} else if(oreDictName.endsWith("*") && !oreDictName.startsWith("*"))
else if(oreDictName.startsWith("*") && !oreDictName.endsWith("*"))
{
if(oreKey.endsWith(oreDictName.substring(1)))
{ {
return true; if(oreKey.startsWith(oreDictName.substring(0, oreDictName.length()-1)))
{
return true;
}
} }
} else if(oreDictName.startsWith("*") && !oreDictName.endsWith("*"))
else if(oreDictName.startsWith("*") && oreDictName.endsWith("*"))
{
if(oreKey.contains(oreDictName.substring(1, oreDictName.length()-1)))
{ {
return true; if(oreKey.endsWith(oreDictName.substring(1)))
{
return true;
}
}
else if(oreDictName.startsWith("*") && oreDictName.endsWith("*"))
{
if(oreKey.contains(oreDictName.substring(1, oreDictName.length()-1)))
{
return true;
}
} }
} }

View file

@ -14,13 +14,13 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import mekanism.api.EnumColor;
import mekanism.api.Coord4D; import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.common.DynamicTankCache; import mekanism.common.DynamicTankCache;
import mekanism.common.EnergyDisplay; import mekanism.common.EnergyDisplay;
import mekanism.common.EnergyDisplay.ElectricUnit;
import mekanism.common.IActiveState; import mekanism.common.IActiveState;
import mekanism.common.IFactory; import mekanism.common.IFactory;
import mekanism.common.EnergyDisplay.ElectricUnit;
import mekanism.common.IFactory.RecipeType; import mekanism.common.IFactory.RecipeType;
import mekanism.common.IInvConfiguration; import mekanism.common.IInvConfiguration;
import mekanism.common.IModule; import mekanism.common.IModule;
@ -469,35 +469,31 @@ public final class MekanismUtils
* @param check - ItemStack to check OreDict name of * @param check - ItemStack to check OreDict name of
* @return OreDict name * @return OreDict name
*/ */
public static String getOreDictName(ItemStack check) public static List<String> getOreDictName(ItemStack check)
{ {
List<Integer> idsFound = new ArrayList<Integer>();
HashMap<Integer, ArrayList<ItemStack>> oreStacks = (HashMap<Integer, ArrayList<ItemStack>>)MekanismUtils.getPrivateValue(null, OreDictionary.class, new String[] {"oreStacks"}); HashMap<Integer, ArrayList<ItemStack>> oreStacks = (HashMap<Integer, ArrayList<ItemStack>>)MekanismUtils.getPrivateValue(null, OreDictionary.class, new String[] {"oreStacks"});
int idFound = -1;
for(Map.Entry<Integer, ArrayList<ItemStack>> entry : oreStacks.entrySet()) for(Map.Entry<Integer, ArrayList<ItemStack>> entry : oreStacks.entrySet())
{ {
for(ItemStack stack : entry.getValue()) for(ItemStack stack : entry.getValue())
{ {
if(stack.isItemEqual(check)) if(stack.isItemEqual(check))
{ {
idFound = entry.getKey(); idsFound.add(entry.getKey());
break; break;
} }
} }
if(idFound != -1)
{
break;
}
} }
if(idFound == -1) List<String> ret = new ArrayList<String>();
for(Integer id : idsFound)
{ {
return null; ret.add(OreDictionary.getOreName(id));
} }
return OreDictionary.getOreName(idFound); return ret;
} }
/** /**
@ -921,16 +917,6 @@ public final class MekanismUtils
} }
} }
/**
* Gets the OreDictionary-registered name of an ItemStack.
* @param itemStack - ItemStack to check
* @return name of the ItemStack
*/
public static String getName(ItemStack itemStack)
{
return OreDictionary.getOreName(OreDictionary.getOreID(itemStack));
}
/** /**
* Retrieves a private value from a defined class and field. * Retrieves a private value from a defined class and field.
* @param obj - the Object to retrieve the value from, null if static * @param obj - the Object to retrieve the value from, null if static