Support for items/blocks with multiple OreDict entries
This commit is contained in:
parent
d4fc39274e
commit
6b420d07d2
|
@ -1,5 +1,8 @@
|
|||
package mekanism.client.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import mekanism.common.inventory.container.ContainerDictionary;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.MekanismUtils.ResourceType;
|
||||
|
@ -14,7 +17,7 @@ public class GuiDictionary extends GuiMekanism
|
|||
{
|
||||
public ItemStack itemType;
|
||||
|
||||
public String oreDictName;
|
||||
public List<String> oreDictNames;
|
||||
|
||||
public GuiDictionary(InventoryPlayer inventory)
|
||||
{
|
||||
|
@ -32,9 +35,15 @@ public class GuiDictionary extends GuiMekanism
|
|||
|
||||
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 {
|
||||
fontRenderer.drawString(MekanismUtils.localize("gui.dictionary.noKey"), 9, 57, 0x00CD00);
|
||||
|
@ -121,7 +130,7 @@ public class GuiDictionary extends GuiMekanism
|
|||
itemType = stack.copy();
|
||||
itemType.stackSize = 1;
|
||||
|
||||
oreDictName = MekanismUtils.getOreDictName(itemType);
|
||||
oreDictNames = MekanismUtils.getOreDictName(itemType);
|
||||
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
|
||||
|
||||
return;
|
||||
|
@ -138,12 +147,12 @@ public class GuiDictionary extends GuiMekanism
|
|||
itemType = stack.copy();
|
||||
itemType.stackSize = 1;
|
||||
|
||||
oreDictName = MekanismUtils.getOreDictName(itemType);
|
||||
oreDictNames = MekanismUtils.getOreDictName(itemType);
|
||||
}
|
||||
else if(stack == null && Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))
|
||||
{
|
||||
itemType = null;
|
||||
oreDictName = null;
|
||||
oreDictNames = new ArrayList<String>();
|
||||
}
|
||||
|
||||
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
|
||||
|
|
|
@ -6,6 +6,7 @@ import ic2.api.recipe.RecipeInputOreDict;
|
|||
import ic2.api.recipe.RecipeOutput;
|
||||
import ic2.api.recipe.Recipes;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import mekanism.common.RecipeHandler.Recipe;
|
||||
|
@ -78,18 +79,32 @@ public final class MekanismHooks
|
|||
{
|
||||
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(MekanismUtils.getName(entry.getKey().getInputs().get(0)).startsWith("ingot"))
|
||||
{
|
||||
if(!Recipe.CRUSHER.containsRecipe(entry.getKey().getInputs().get(0)))
|
||||
else if(name.startsWith("ingot"))
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
package mekanism.common.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.api.transmitters.IGridTransmitter;
|
||||
import mekanism.api.transmitters.TransmitterNetworkRegistry;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemDictionary extends ItemMekanism
|
||||
|
@ -32,11 +30,16 @@ public class ItemDictionary extends ItemMekanism
|
|||
if(world.isRemote)
|
||||
{
|
||||
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 {
|
||||
player.addChatMessage(EnumColor.DARK_BLUE + "[Mekanism]" + EnumColor.GREY + " No key.");
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package mekanism.common.miner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import net.minecraft.block.Block;
|
||||
|
@ -27,36 +28,39 @@ public class MOreDictFilter extends MinerFilter
|
|||
return true;
|
||||
}
|
||||
|
||||
String oreKey = MekanismUtils.getOreDictName(itemStack);
|
||||
List<String> oreKeys = MekanismUtils.getOreDictName(itemStack);
|
||||
|
||||
if(oreKey == null)
|
||||
if(oreKeys.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(oreDictName.equals(oreKey))
|
||||
for(String oreKey : oreKeys)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if(oreDictName.endsWith("*") && !oreDictName.startsWith("*"))
|
||||
{
|
||||
if(oreKey.startsWith(oreDictName.substring(0, oreDictName.length()-1)))
|
||||
if(oreDictName.equals(oreKey))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(oreDictName.startsWith("*") && !oreDictName.endsWith("*"))
|
||||
{
|
||||
if(oreKey.endsWith(oreDictName.substring(1)))
|
||||
else if(oreDictName.endsWith("*") && !oreDictName.startsWith("*"))
|
||||
{
|
||||
return true;
|
||||
if(oreKey.startsWith(oreDictName.substring(0, oreDictName.length()-1)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(oreDictName.startsWith("*") && oreDictName.endsWith("*"))
|
||||
{
|
||||
if(oreKey.contains(oreDictName.substring(1, oreDictName.length()-1)))
|
||||
else if(oreDictName.startsWith("*") && !oreDictName.endsWith("*"))
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package mekanism.common.transporter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import mekanism.common.util.InventoryUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
|
@ -18,36 +19,39 @@ public class TOreDictFilter extends TransporterFilter
|
|||
@Override
|
||||
public boolean canFilter(ItemStack itemStack)
|
||||
{
|
||||
String oreKey = MekanismUtils.getOreDictName(itemStack);
|
||||
List<String> oreKeys = MekanismUtils.getOreDictName(itemStack);
|
||||
|
||||
if(oreKey == null)
|
||||
if(oreKeys.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(oreDictName.equals(oreKey) || oreDictName.equals("*"))
|
||||
for(String oreKey : oreKeys)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if(oreDictName.endsWith("*") && !oreDictName.startsWith("*"))
|
||||
{
|
||||
if(oreKey.startsWith(oreDictName.substring(0, oreDictName.length()-1)))
|
||||
if(oreDictName.equals(oreKey) || oreDictName.equals("*"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(oreDictName.startsWith("*") && !oreDictName.endsWith("*"))
|
||||
{
|
||||
if(oreKey.endsWith(oreDictName.substring(1)))
|
||||
else if(oreDictName.endsWith("*") && !oreDictName.startsWith("*"))
|
||||
{
|
||||
return true;
|
||||
if(oreKey.startsWith(oreDictName.substring(0, oreDictName.length()-1)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(oreDictName.startsWith("*") && oreDictName.endsWith("*"))
|
||||
{
|
||||
if(oreKey.contains(oreDictName.substring(1, oreDictName.length()-1)))
|
||||
else if(oreDictName.startsWith("*") && !oreDictName.endsWith("*"))
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,13 +14,13 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.common.DynamicTankCache;
|
||||
import mekanism.common.EnergyDisplay;
|
||||
import mekanism.common.EnergyDisplay.ElectricUnit;
|
||||
import mekanism.common.IActiveState;
|
||||
import mekanism.common.IFactory;
|
||||
import mekanism.common.EnergyDisplay.ElectricUnit;
|
||||
import mekanism.common.IFactory.RecipeType;
|
||||
import mekanism.common.IInvConfiguration;
|
||||
import mekanism.common.IModule;
|
||||
|
@ -469,35 +469,31 @@ public final class MekanismUtils
|
|||
* @param check - ItemStack to check OreDict name of
|
||||
* @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"});
|
||||
|
||||
int idFound = -1;
|
||||
|
||||
for(Map.Entry<Integer, ArrayList<ItemStack>> entry : oreStacks.entrySet())
|
||||
{
|
||||
for(ItemStack stack : entry.getValue())
|
||||
{
|
||||
if(stack.isItemEqual(check))
|
||||
{
|
||||
idFound = entry.getKey();
|
||||
idsFound.add(entry.getKey());
|
||||
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.
|
||||
* @param obj - the Object to retrieve the value from, null if static
|
||||
|
|
Loading…
Reference in a new issue