Java Code Examples for net.minecraftforge.oredict.OreDictionary#itemMatches()

The following examples show how to use net.minecraftforge.oredict.OreDictionary#itemMatches() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShapelessBloodOrbRecipe.java    From Framez with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
ShapelessBloodOrbRecipe(ShapelessRecipes recipe, Map<ItemStack, String> replacements)
{
    output = recipe.getRecipeOutput();

    for (ItemStack ingred : ((List<ItemStack>) recipe.recipeItems))
    {
        Object finalObj = ingred;
        for (Entry<ItemStack, String> replace : replacements.entrySet())
        {
            if (OreDictionary.itemMatches(replace.getKey(), ingred, false))
            {
                finalObj = OreDictionary.getOres(replace.getValue());
                break;
            }
        }
        input.add(finalObj);
    }
}
 
Example 2
Source File: InventoryUtils.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Checks if the ItemStack <b>stackTarget</b> is valid to be used as a substitution
 * for <b>stackReference</b> via the OreDictionary keys.
 * @param stackTarget
 * @param stackReference
 * @return
 */
public static boolean areItemStacksOreDictMatch(@Nonnull ItemStack stackTarget, @Nonnull ItemStack stackReference)
{
    int[] ids = OreDictionary.getOreIDs(stackReference);

    for (int id : ids)
    {
        List<ItemStack> oreStacks = OreDictionary.getOres(OreDictionary.getOreName(id), false);

        for (ItemStack oreStack : oreStacks)
        {
            if (OreDictionary.itemMatches(stackTarget, oreStack, false))
            {
                return true;
            }
        }
    }

    return false;
}
 
Example 3
Source File: ShapelessOreRecipeTFC.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
ShapelessOreRecipeTFC(ShapelessRecipes recipe, Map<ItemStack, String> replacements)
{
	output = recipe.getRecipeOutput();

	for(ItemStack ingredient : recipe.recipeItems)
	{
		Object finalObj = ingredient;
		for(Entry<ItemStack, String> replace : replacements.entrySet())
		{
			if(OreDictionary.itemMatches(replace.getKey(), ingredient, false))
			{
				finalObj = OreDictionary.getOres(replace.getValue());
				break;
			}
		}
		input.add(finalObj);
	}
}
 
Example 4
Source File: ShapedOreRecipeTFC.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
ShapedOreRecipeTFC(ShapedRecipes recipe, Map<ItemStack, String> replacements)
{
	output = recipe.getRecipeOutput();
	width = recipe.recipeWidth;
	height = recipe.recipeHeight;

	input = new ArrayList<Object>(recipe.recipeItems.length);

	for(int i = 0; i < recipe.recipeItems.length; i++)
	{
		ItemStack ingredient = recipe.recipeItems[i];

		if(ingredient == null) continue;

		input.add(recipe.recipeItems[i]);

		for(Entry<ItemStack, String> replace : replacements.entrySet())
		{
			if(OreDictionary.itemMatches(replace.getKey(), ingredient, true))
			{
				input.set(i, OreDictionary.getOres(replace.getValue()));
				break;
			}
		}
	}
}
 
Example 5
Source File: ItemHelper.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
public static boolean stackMatchesRecipeInput(ItemStack stack, RecipeInput input, boolean checkCount)
{
    if (input.isItemStack())
    {
        ItemStack inputStack = input.getStack().getItemStack();
        if (OreDictionary.itemMatches(inputStack, stack, false)
            && (!checkCount || inputStack.getCount() <= stack.getCount()))
            return true;
    } else
    {
        OreClass oreClass = input.getOreClass();
        if (OreDictionary.containsMatch(false, OreDictionary.getOres(oreClass.getOreName()), stack)
            && (!checkCount || oreClass.getAmount() <= stack.getCount()))
            return true;
    }

    return false;
}
 
Example 6
Source File: ShapedBloodOrbRecipe.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
ShapedBloodOrbRecipe(ShapedRecipes recipe, Map<ItemStack, String> replacements) {
	output = recipe.getRecipeOutput();
	width = recipe.recipeWidth;
	height = recipe.recipeHeight;

	input = new Object[recipe.recipeItems.length];

	for (int i = 0; i < input.length; i++) {
		ItemStack ingred = recipe.recipeItems[i];

		if (ingred == null)
			continue;

		input[i] = recipe.recipeItems[i];

		for (Entry<ItemStack, String> replace : replacements.entrySet()) {
			if (OreDictionary.itemMatches(replace.getKey(), ingred, true)) {
				input[i] = OreDictionary.getOres(replace.getValue());
				break;
			}
		}
	}
}
 
Example 7
Source File: WandHandler.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static boolean containsMatch(boolean strict, List<ItemStack> inputs, ItemStack... targets) {
    for (ItemStack input : inputs) {
        for (ItemStack target : targets) {
            if (OreDictionary.itemMatches(input, target, strict)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 8
Source File: ShapelessBloodOrbRecipe.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
ShapelessBloodOrbRecipe(ShapelessRecipes recipe, Map<ItemStack, String> replacements) {
	output = recipe.getRecipeOutput();

	for (ItemStack ingred : ((List<ItemStack>) recipe.recipeItems)) {
		Object finalObj = ingred;
		for (Entry<ItemStack, String> replace : replacements.entrySet()) {
			if (OreDictionary.itemMatches(replace.getKey(), ingred, false)) {
				finalObj = OreDictionary.getOres(replace.getValue());
				break;
			}
		}
		input.add(finalObj);
	}
}
 
Example 9
Source File: TileWarpCore.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public void onInventoryUpdated() {
	//Needs completion
	if(itemInPorts.isEmpty() /*&& !worldObj.isRemote*/) {
		attemptCompleteStructure(world.getBlockState(pos));
	}
	
	if(getSpaceObject() == null || getSpaceObject().getFuelAmount() == getSpaceObject().getMaxFuelAmount())
		return;
	for(IInventory inv : itemInPorts) {
		for(int i = 0; i < inv.getSizeInventory(); i++) {
			ItemStack stack = inv.getStackInSlot(i);
			int amt = 0;
			if(stack != null && OreDictionary.itemMatches(MaterialRegistry.getItemStackFromMaterialAndType("Dilithium", AllowedProducts.getProductByName("CRYSTAL")), stack, false)) {
				int stackSize = stack.getCount();
				if(!world.isRemote)
					amt = getSpaceObject().addFuel(Configuration.fuelPointsPerDilithium*stack.getCount());
				else
					amt = Math.min(getSpaceObject().getFuelAmount() + 10*stack.getCount(), getSpaceObject().getMaxFuelAmount()) - getSpaceObject().getFuelAmount();//
				inv.decrStackSize(i, amt/10);
				inv.markDirty();
				
				//If full
				if(stackSize/10 != amt)
					return;
			}
		}
	}
}
 
Example 10
Source File: EnderStorageRecipe.java    From EnderStorage with MIT License 5 votes vote down vote up
public static int getDyeType(ItemStack item) {
    if (item == null) return -1;
    if (item.getItem() == Items.dye)
        return item.getItemDamage();
    for (int i = 0; i < 16; i++) {
        for (ItemStack target : OreDictionary.getOres(oreDictionaryNames[i]))
            if (OreDictionary.itemMatches(target, item, false))
                return i;
    }
    return -1;
}
 
Example 11
Source File: DestinationProviderItems.java    From Signals with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isSameOreDictStack(ItemStack stack1, ItemStack stack2){
    int[] oredictIds = OreDictionary.getOreIDs(stack1);
    for(int oredictId : oredictIds) {
        List<ItemStack> oreDictStacks = OreDictionary.getOres(OreDictionary.getOreName(oredictId));
        for(ItemStack oreDictStack : oreDictStacks) {
            if(OreDictionary.itemMatches(oreDictStack, stack2, false)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 12
Source File: PneumaticCraftUtils.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isSameOreDictStack(ItemStack stack1, ItemStack stack2){
    int[] oredictIds = OreDictionary.getOreIDs(stack1);
    for(int oredictId : oredictIds) {
        List<ItemStack> oreDictStacks = OreDictionary.getOres(OreDictionary.getOreName(oredictId));
        for(ItemStack oreDictStack : oreDictStacks) {
            if(OreDictionary.itemMatches(oreDictStack, stack2, false)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 13
Source File: ItemFilterDeserializer.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean accepts(ItemStack stack)
{
    if (itemStack == ItemStack.EMPTY)
    {
        itemStack = wrappedStack.getItemStack();
    }
    return !itemStack.isEmpty() && OreDictionary.itemMatches(itemStack, stack, false);
}
 
Example 14
Source File: ItemJackHammer.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
@Override
public boolean getIsRepairable(ItemStack stackMe, ItemStack stackItem) {
	return OreDictionary.itemMatches(OreDictionary.getOres("stickTitanium").get(0), stackItem, false);//super.getIsRepairable(p_82789_1_, p_82789_2_);
}
 
Example 15
Source File: ShapelessBloodOrbRecipe.java    From Framez with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public boolean matches(InventoryCrafting var1, World world)
{
    ArrayList<Object> required = new ArrayList<Object>(input);

    for (int x = 0; x < var1.getSizeInventory(); x++)
    {
        ItemStack slot = var1.getStackInSlot(x);

        if (slot != null)
        {
            boolean inRecipe = false;
            Iterator<Object> req = required.iterator();

            while (req.hasNext())
            {
                boolean match = false;

                Object next = req.next();

                //If target is integer, then we should be check the blood orb value of the item instead
                if (next instanceof Integer)
                {
                    if (slot != null && slot.getItem() instanceof IBloodOrb)
                    {
                        IBloodOrb orb = (IBloodOrb) slot.getItem();
                        if (orb.getOrbLevel() < (Integer) next)
                        {
                            return false;
                        }
                    } else return false;
                } else if (next instanceof ItemStack)
                {
                    match = OreDictionary.itemMatches((ItemStack) next, slot, false);
                } else if (next instanceof ArrayList)
                {
                    Iterator<ItemStack> itr = ((ArrayList<ItemStack>) next).iterator();
                    while (itr.hasNext() && !match)
                    {
                        match = OreDictionary.itemMatches(itr.next(), slot, false);
                    }
                }

                if (match)
                {
                    inRecipe = true;
                    required.remove(next);
                    break;
                }
            }

            if (!inRecipe)
            {
                return false;
            }
        }
    }

    return required.isEmpty();
}
 
Example 16
Source File: ShapedBloodOrbRecipe.java    From Framez with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private boolean checkMatch(InventoryCrafting inv, int startX, int startY, boolean mirror)
{
    for (int x = 0; x < MAX_CRAFT_GRID_WIDTH; x++)
    {
        for (int y = 0; y < MAX_CRAFT_GRID_HEIGHT; y++)
        {
            int subX = x - startX;
            int subY = y - startY;
            Object target = null;

            if (subX >= 0 && subY >= 0 && subX < width && subY < height)
            {
                if (mirror)
                {
                    target = input[width - subX - 1 + subY * width];
                } else
                {
                    target = input[subX + subY * width];
                }
            }

            ItemStack slot = inv.getStackInRowAndColumn(x, y);
            //If target is integer, then we should be check the blood orb value of the item instead
            if (target instanceof Integer)
            {
                if (slot != null && slot.getItem() instanceof IBloodOrb)
                {
                    IBloodOrb orb = (IBloodOrb) slot.getItem();
                    if (orb.getOrbLevel() < (Integer) target)
                    {
                        return false;
                    }
                } else return false;
            } else if (target instanceof ItemStack)
            {
                if (!OreDictionary.itemMatches((ItemStack) target, slot, false))
                {
                    return false;
                }
            } else if (target instanceof ArrayList)
            {
                boolean matched = false;

                Iterator<ItemStack> itr = ((ArrayList<ItemStack>) target).iterator();
                while (itr.hasNext() && !matched)
                {
                    matched = OreDictionary.itemMatches(itr.next(), slot, false);
                }

                if (!matched)
                {
                    return false;
                }
            } else if (target == null && slot != null)
            {
                return false;
            }
        }
    }

    return true;
}
 
Example 17
Source File: ShapelessBloodOrbRecipe.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public boolean matches(InventoryCrafting var1, World world) {
	ArrayList<Object> required = new ArrayList<Object>(input);

	for (int x = 0; x < var1.getSizeInventory(); x++) {
		ItemStack slot = var1.getStackInSlot(x);

		if (slot != null) {
			boolean inRecipe = false;
			Iterator<Object> req = required.iterator();

			while (req.hasNext()) {
				boolean match = false;

				Object next = req.next();

				//If target is integer, then we should be check the blood orb value of the item instead
				if(next instanceof Integer) {
					if(slot != null && slot.getItem() instanceof IBloodOrb) {
						IBloodOrb orb = (IBloodOrb) slot.getItem();
						if(orb.getOrbLevel() < (Integer)next) {
							return false;
						}
					} else return false;
				} else if (next instanceof ItemStack) {
					match = OreDictionary.itemMatches((ItemStack) next, slot, false);
				} else if (next instanceof ArrayList) {
					Iterator<ItemStack> itr = ((ArrayList<ItemStack>) next).iterator();
					while (itr.hasNext() && !match) {
						match = OreDictionary.itemMatches(itr.next(), slot, false);
					}
				}

				if (match) {
					inRecipe = true;
					required.remove(next);
					break;
				}
			}

			if (!inRecipe) {
				return false;
			}
		}
	}

	return required.isEmpty();
}
 
Example 18
Source File: ShapedBloodOrbRecipe.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private boolean checkMatch(InventoryCrafting inv, int startX, int startY, boolean mirror) {
	for (int x = 0; x < MAX_CRAFT_GRID_WIDTH; x++) {
		for (int y = 0; y < MAX_CRAFT_GRID_HEIGHT; y++) {
			int subX = x - startX;
			int subY = y - startY;
			Object target = null;

			if (subX >= 0 && subY >= 0 && subX < width && subY < height) {
				if (mirror) {
					target = input[width - subX - 1 + subY * width];
				} else {
					target = input[subX + subY * width];
				}
			}
			
			ItemStack slot = inv.getStackInRowAndColumn(x, y);
			//If target is integer, then we should be check the blood orb value of the item instead
			if(target instanceof Integer) {
				if(slot != null && slot.getItem() instanceof IBloodOrb) {
					IBloodOrb orb = (IBloodOrb) slot.getItem();
					if(orb.getOrbLevel() < (Integer)target) {
						return false;
					}
				} else return false;
			} else if (target instanceof ItemStack) {
				if (!OreDictionary.itemMatches((ItemStack) target, slot, false)) {
					return false;
				}
			} else if (target instanceof ArrayList) {
				boolean matched = false;

				Iterator<ItemStack> itr = ((ArrayList<ItemStack>) target).iterator();
				while (itr.hasNext() && !matched) {
					matched = OreDictionary.itemMatches(itr.next(), slot, false);
				}

				if (!matched) {
					return false;
				}
			} else if (target == null && slot != null) {
				return false;
			}
		}
	}

	return true;
}
 
Example 19
Source File: ShapelessOreRecipeTFC.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean matches(InventoryCrafting var1, World world)
{
	ArrayList<Object> required = new ArrayList<Object>(input);

	for (int x = 0; x < var1.getSizeInventory(); x++)
	{
		ItemStack slot = var1.getStackInSlot(x);

		if (slot != ItemStack.EMPTY)
		{
			boolean inRecipe = false;
			Iterator<Object> req = required.iterator();

			while (req.hasNext())
			{
				boolean match = false;

				Object next = req.next();

				if (next instanceof ItemStack)
				{
					match = OreDictionary.itemMatches((ItemStack)next, slot, false);
				}
				else if (next instanceof List)
				{
					Iterator<ItemStack> itr = ((List<ItemStack>)next).iterator();
					while (itr.hasNext() && !match)
					{
						match = OreDictionary.itemMatches(itr.next(), slot, false);
					}
				}

				if (match)
				{
					if(!tempMatch(slot))
					{
						break;
					}
					inRecipe = true;
					required.remove(next);
					break;
				}


			}

			if (!inRecipe)
			{
				return false;
			}
		}
	}



	return required.isEmpty();
}
 
Example 20
Source File: ShapelessOreRecipeTFC.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Used to check if a recipe matches current crafting inventory
 */
@Override
public boolean matches(NonNullList<ItemStack> var1, World world)
{
	ArrayList<Object> required = new ArrayList<Object>(input);

	for (int x = 0; x < var1.size(); x++)
	{
		ItemStack slot = var1.get(x);

		if (slot != ItemStack.EMPTY)
		{
			boolean inRecipe = false;
			Iterator<Object> req = required.iterator();

			while (req.hasNext())
			{
				boolean match = false;

				Object next = req.next();

				if (next instanceof ItemStack)
				{
					match = OreDictionary.itemMatches((ItemStack)next, slot, false);
				}
				else if (next instanceof List)
				{
					Iterator<ItemStack> itr = ((List<ItemStack>)next).iterator();
					while (itr.hasNext() && !match)
					{
						match = OreDictionary.itemMatches(itr.next(), slot, false);
					}
				}

				if (match)
				{
					if(!tempMatch(slot))
					{
						break;
					}
					inRecipe = true;
					required.remove(next);
					break;
				}


			}

			if (!inRecipe)
			{
				return false;
			}
		}
	}



	return required.isEmpty();
}