Java Code Examples for net.minecraft.inventory.InventoryCrafting#getSizeInventory()

The following examples show how to use net.minecraft.inventory.InventoryCrafting#getSizeInventory() . 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: FacadeRecipe.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Nonnull
@Override
public ItemStack getCraftingResult(@Nonnull InventoryCrafting inv) {
    ItemStack resultStack = getRecipeOutput();
    ItemStack facadeStack = ItemStack.EMPTY;
    for (int i = 0; i < inv.getSizeInventory(); i++) {
        ItemStack itemStack = inv.getStackInSlot(i);
        if (FacadeIngredient.INSTANCE.apply(itemStack)) {
            facadeStack = itemStack;
        }
    }
    if (!facadeStack.isEmpty()) {
        FacadeItem.setFacadeStack(resultStack, facadeStack);
    }
    return resultStack;
}
 
Example 2
Source File: RecipeDyeableItem.java    From WearableBackpacks with MIT License 6 votes vote down vote up
@Override
public boolean matches(InventoryCrafting crafting, World world) {
	// Check if crafting inventory has:
	// - Exactly one dyeable item.
	// - At least one dye.
	// - No other items.
	boolean hasDyeable = false;
	boolean hasDyes = false;
	for (int i = 0; i < crafting.getSizeInventory(); i++) {
		ItemStack stack = crafting.getStackInSlot(i);
		if (stack.isEmpty()) continue;                                         // Ignore empty stacks.
		else if (DyeUtils.isDye(stack)) hasDyes = true;                        // Check for dyes.
		else if (!(stack.getItem() instanceof IDyeableItem)) return false;     // Don't allow non-dyeable items.
		else if (!((IDyeableItem)stack.getItem()).canDye(stack)) return false; // canDye has to return true, too.
		else if (hasDyeable) return false;                                     // Check if we already have one.
		else hasDyeable = true;                                                // Item is dyeable.
	}
	return (hasDyeable && hasDyes);
}
 
Example 3
Source File: RecipeAddPattern.java    From Et-Futurum with The Unlicense 6 votes vote down vote up
@Override
public boolean matches(InventoryCrafting grid, World world) {
	boolean flag = false;

	for (int i = 0; i < grid.getSizeInventory(); i++) {
		ItemStack slot = grid.getStackInSlot(i);

		if (slot != null && slot.getItem() == Item.getItemFromBlock(ModBlocks.banner)) {
			if (flag)
				return false;
			if (TileEntityBanner.getPatterns(slot) >= 6)
				return false;
			flag = true;
		}
	}

	if (!flag)
		return false;
	else
		return getPattern(grid) != null;
}
 
Example 4
Source File: RecipeLogisticToDrone.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean matches(InventoryCrafting inventoryCrafting, World world){
    boolean hasDrone = false, hasPCB = false;
    for(int i = 0; i < inventoryCrafting.getSizeInventory(); i++) {
        ItemStack stack = inventoryCrafting.getStackInSlot(i);
        if(stack != null) {
            if(stack.getItem() == Itemss.logisticsDrone) {
                if(!hasDrone) hasDrone = true;
                else return false;
            } else if(stack.getItem() == Itemss.printedCircuitBoard) {
                if(!hasPCB) hasPCB = true;
                else return false;
            }
        }
    }
    return hasDrone && hasPCB;
}
 
Example 5
Source File: RecipeMountPearl.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
	boolean foundBaseItem = false;
	boolean foundPearl = false;

	for (int i = 0; i < inv.getSizeInventory(); i++) {
		ItemStack stack = inv.getStackInSlot(i);
		if (stack.getItem() instanceof IPearlSwappable) {

			if (stack.getItemDamage() == 0)
				foundBaseItem = true;
		}
		if (stack.getItem() == ModItems.PEARL_NACRE) {
			if (NBTHelper.getBoolean(stack, "infused", false))
				foundPearl = true;
		}

	}
	return foundBaseItem && foundPearl;
}
 
Example 6
Source File: RecipeManometer.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean matches(InventoryCrafting inventory, World world){

    boolean gaugeFound = false;
    boolean canisterFound = false;
    for(int i = 0; i < inventory.getSizeInventory(); i++) {
        ItemStack stack = inventory.getStackInSlot(i);
        if(stack != null) {
            if(stack.getItem() == Itemss.pressureGauge) {
                if(gaugeFound) return false;
                gaugeFound = true;
            } else if(stack.getItem() == Itemss.airCanister) {
                if(canisterFound) return false;
                canisterFound = true;
            } else return false;
        }
    }
    return gaugeFound && canisterFound;
}
 
Example 7
Source File: RecipeGunAmmo.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ItemStack getCraftingResult(InventoryCrafting invCrafting){
    ItemStack potion = null;
    ItemStack ammo = null;
    for(int i = 0; i < invCrafting.getSizeInventory(); i++) {
        ItemStack stack = invCrafting.getStackInSlot(i);
        if(stack != null) {
            if(stack.getItem() == Items.potionitem) {
                potion = stack;
            } else {
                ammo = stack;
            }
        }
    }
    ammo = ammo.copy();
    ItemGunAmmo.setPotion(ammo, potion);
    return ammo;
}
 
Example 8
Source File: RecipeJam.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
	boolean foundJar = false;
	boolean foundSword = false;

	for (int i = 0; i < inv.getSizeInventory(); i++) {
		ItemStack stack = inv.getStackInSlot(i);
		if (stack.getItem() == ModItems.JAR_ITEM) {
			if (stack.getItemDamage() == 2)
				foundJar = true;

		} else if (stack.getItem() == Items.GOLDEN_SWORD)
			foundSword = true;
	}
	return foundJar && foundSword;
}
 
Example 9
Source File: RecipeDyeableItem.java    From WearableBackpacks with MIT License 6 votes vote down vote up
@Override
public ItemStack getCraftingResult(InventoryCrafting crafting) {
	// Collect dyeable item and dyes.
	ItemStack dyeable = ItemStack.EMPTY;;
	List<ItemStack> dyes = new ArrayList<ItemStack>();
	for (int i = 0; i < crafting.getSizeInventory(); i++) {
		ItemStack stack = crafting.getStackInSlot(i);
		if (stack.isEmpty()) continue;
		else if (DyeUtils.isDye(stack)) dyes.add(stack);
		else if (!(stack.getItem() instanceof IDyeableItem)) return ItemStack.EMPTY;
		else if (!((IDyeableItem)stack.getItem()).canDye(stack)) return ItemStack.EMPTY;
		else if (!dyeable.isEmpty()) return ItemStack.EMPTY;
		else dyeable = stack.copy();
	}
	if (dyes.isEmpty()) return ItemStack.EMPTY;
	// Caclulate and set resulting item's color.
	int oldColor = NbtUtils.get(dyeable, -1, "display", "color");
	int newColor = DyeUtils.getColorFromDyes(oldColor, dyes);
	NbtUtils.set(dyeable, newColor, "display", "color");
	return dyeable;
}
 
Example 10
Source File: FacadeRecipe.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean matches(InventoryCrafting inv, World worldIn) {
    boolean[] matched = new boolean[ingredients.size()];
    mainLoop: for (int i = 0; i < inv.getSizeInventory(); i++) {
        ItemStack itemStack = inv.getStackInSlot(i);
        if (itemStack.isEmpty()) continue;
        for (int j = 0; j < matched.length; j++) {
            if(!ingredients.get(j).apply(itemStack)) continue;
            if (matched[j]) return false; //already matched
            matched[j] = true;
            continue mainLoop;
        }
        //reached there, no match
        return false;
    }
    for (boolean b : matched) {
        if (!b) return false;
    }
    return true;
}
 
Example 11
Source File: RecipeCopyJournal.java    From AgriCraft with MIT License 5 votes vote down vote up
@Override
public ItemStack getCraftingResult(InventoryCrafting invCrafting) {
    for (int i = 0; i < invCrafting.getSizeInventory(); i++) {
        ItemStack stack = invCrafting.getStackInSlot(i);
        if (StackHelper.isValid(stack, ItemJournal.class)) {
            return invCrafting.getStackInSlot(i).copy();
        }
    }
    return ItemStack.EMPTY;
}
 
Example 12
Source File: RecipeGun.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack getCraftingResult(InventoryCrafting inventory){
    if(!matches(inventory, null)) return null;
    ItemStack output = getRecipeOutput();
    for(int i = 0; i < inventory.getSizeInventory(); i++) {
        if(inventory.getStackInSlot(i) != null && inventory.getStackInSlot(i).getItem() == Itemss.airCanister) {
            output.setItemDamage(inventory.getStackInSlot(i).getItemDamage());
        }
    }
    return output;
}
 
Example 13
Source File: RecipeCrudeHaloDefusion.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {

	boolean hasHalo = false;
	for (int i = 0; i < inv.getSizeInventory(); i++) {
		ItemStack stack = inv.getStackInSlot(i);
		if (stack.getItem() == ModItems.FAKE_HALO) {
			if (hasHalo) return false;
			hasHalo = true;
		} else if (!stack.isEmpty()) return false;
	}

	return hasHalo;
}
 
Example 14
Source File: RecipeCopyJournal.java    From AgriCraft with MIT License 5 votes vote down vote up
@Override
public boolean matches(InventoryCrafting invCrafting, World world) {
    boolean foundJournal = false;
    boolean foundBook = false;
    for (int i = 0; i < invCrafting.getSizeInventory(); i++) {
        ItemStack stackAtIndex = invCrafting.getStackInSlot(i);
        if (!stackAtIndex.isEmpty() && stackAtIndex.getItem() != null) {
            if (stackAtIndex.getItem() instanceof ItemJournal) {
                if (!foundJournal) {
                    foundJournal = true;
                } else {
                    // There can't be two journals!
                    // Scandalous!
                    return false;
                }
            } else if (stackAtIndex.getItem() == Items.WRITABLE_BOOK) {
                if (!foundBook) {
                    foundBook = true;
                } else {
                    // There can only be one true king!
                    return false;
                }
            }
        }
    }
    return foundJournal && foundBook;
}
 
Example 15
Source File: RecipeCrudeHaloInfusion.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
	ItemStack foundHalo = ItemStack.EMPTY;
	boolean foundGlueStick = false;

	int availableItems = 0;
	for (int i = 0; i < inv.getSizeInventory(); i++) {
		ItemStack stack = inv.getStackInSlot(i);
		if (stack.getItem() == Items.SLIME_BALL) {
			if (foundGlueStick) return false;
			foundGlueStick = true;
		} else if (stack.getItem() == ModItems.FAKE_HALO) {
			if (!foundHalo.isEmpty()) return false;
			foundHalo = stack;
		} else if (HaloInfusionItemRegistry.isHaloInfusionItem(stack))
			availableItems++;
		else if (!stack.isEmpty()) {
			return false;
		}
	}

	if (!foundGlueStick || foundHalo.isEmpty() || availableItems <= 0) return false;

	NBTTagList slots = NBTHelper.getList(foundHalo, "slots", NBTTagString.class);
	if (slots == null) return availableItems <= 7;

	int freeSlots = 0;
	for (int j = 0; j < slots.tagCount(); j++) {
		if (freeSlots >= 7) break;
		String string = slots.getStringTagAt(j);
		HaloInfusionItem infusionItem = HaloInfusionItemRegistry.getItemFromName(string);
		if (infusionItem == HaloInfusionItemRegistry.EMPTY) freeSlots++;
	}

	return freeSlots >= availableItems;
}
 
Example 16
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 17
Source File: RecipeDuplicatePattern.java    From Et-Futurum with The Unlicense 4 votes vote down vote up
@Override
public boolean matches(InventoryCrafting grid, World world) {
	ItemStack itemstack = null;
	ItemStack itemstack1 = null;

	for (int i = 0; i < grid.getSizeInventory(); i++) {
		ItemStack slot = grid.getStackInSlot(i);

		if (slot != null) {
			if (slot.getItem() != Item.getItemFromBlock(ModBlocks.banner))
				return false;

			if (itemstack != null && itemstack1 != null)
				return false;

			int colour = TileEntityBanner.getBaseColor(slot);
			boolean flag = TileEntityBanner.getPatterns(slot) > 0;

			if (itemstack != null) {
				if (flag)
					return false;

				if (colour != TileEntityBanner.getBaseColor(itemstack))
					return false;

				itemstack1 = slot;
			} else if (itemstack1 != null) {
				if (!flag)
					return false;

				if (colour != TileEntityBanner.getBaseColor(itemstack1))
					return false;

				itemstack = slot;
			} else if (flag)
				itemstack = slot;
			else
				itemstack1 = slot;
		}
	}

	return itemstack != null && itemstack1 != null;
}
 
Example 18
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 19
Source File: BlueprintCraftingHandler.java    From Cyberware with MIT License 4 votes vote down vote up
private boolean process(InventoryCrafting inv)
{
	boolean hasBlankBlueprint = false;
	for (int i = 0; i < inv.getSizeInventory(); i++)
	{
		ItemStack stack = inv.getStackInSlot(i);
		if (stack != null)
		{
			if (stack.getItem() instanceof IDeconstructable)
			{
				if (ware == null)
				{
					ware = stack;
					wareStack = i;
				}
				else
				{
					return false;
				}
			}
			else if (stack.getItem() == CyberwareContent.blueprint
					&& (!stack.hasTagCompound()
					|| !stack.getTagCompound().hasKey("blueprintItem")))
			{
				if (!hasBlankBlueprint)
				{
					hasBlankBlueprint = true;
				}
				else
				{
					return false;
				}
			}
			else
			{
				return false;
			}
			
		}
	}
	return ware != null && hasBlankBlueprint;
}
 
Example 20
Source File: BWCoreStaticReplacementMethodes.java    From bartworks with MIT License 4 votes vote down vote up
@SuppressWarnings("ALL")
public static ItemStack findCachedMatchingRecipe(InventoryCrafting inventoryCrafting, World world) {
    int i = 0;
    ItemStack itemstack = null;
    ItemStack itemstack1 = null;
    int j;

    for (j = 0; j < inventoryCrafting.getSizeInventory(); ++j)
    {
        ItemStack itemstack2 = inventoryCrafting.getStackInSlot(j);

        if (itemstack2 != null)
        {
            if (i == 0)
            {
                itemstack = itemstack2;
            }

            if (i == 1)
            {
                itemstack1 = itemstack2;
            }

            ++i;
        }
    }

    if (i == 2 && itemstack.getItem() == itemstack1.getItem() && itemstack.stackSize == 1 && itemstack1.stackSize == 1 && itemstack.getItem().isRepairable())
    {
        Item item = itemstack.getItem();
        int j1 = item.getMaxDamage() - itemstack.getItemDamageForDisplay();
        int k = item.getMaxDamage() - itemstack1.getItemDamageForDisplay();
        int l = j1 + k + item.getMaxDamage() * 5 / 100;
        int i1 = item.getMaxDamage() - l;

        if (i1 < 0)
        {
            i1 = 0;
        }

        return new ItemStack(itemstack.getItem(), 1, i1);
    } else {
        IRecipe iPossibleRecipe = null;
        int index = 0;
        for (Iterator<IRecipe> it = RECENTLYUSEDRECIPES.iterator(); it.hasNext(); ++index) {
            IRecipe RECENTLYUSEDRECIPE = it.next();
            if (RECENTLYUSEDRECIPE.matches(inventoryCrafting, world)) {
                iPossibleRecipe = RECENTLYUSEDRECIPE;
                break;
            }
        }

        if (iPossibleRecipe != null) {
            RECENTLYUSEDRECIPES.addPrioToNode(index);
            return iPossibleRecipe.getCraftingResult(inventoryCrafting);
        }

        ItemStack stack = null;

        HashSet<IRecipe> recipeSet = new NonNullWrappedHashSet<>();
        List recipeList = CraftingManager.getInstance().getRecipeList();

        for (int k = 0; k < recipeList.size(); k++) {
            recipeSet.add((IRecipe) recipeList.get(k));
        }

        Object[] arr = recipeSet.parallelStream().filter(r -> r.matches(inventoryCrafting, world)).toArray();

        if (arr.length == 0)
            return null;

        IRecipe recipe = (IRecipe) arr[0];
        stack = recipe.getCraftingResult(inventoryCrafting);

        if (arr.length != 1)
            return stack;

        if (stack != null)
            RECENTLYUSEDRECIPES.addLast(recipe);

        return stack;
    }
}