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

The following examples show how to use net.minecraft.inventory.InventoryCrafting#getStackInSlot() . 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: RecipeCrudeHaloInfusion.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Nonnull
@Override
public NonNullList<ItemStack> getRemainingItems(@Nonnull InventoryCrafting inv) {
	NonNullList<ItemStack> remainingItems = ForgeHooks.defaultRecipeGetRemainingItems(inv);

	ItemStack gluestick;
	for (int i = 0; i < inv.getSizeInventory(); i++) {
		ItemStack stack = inv.getStackInSlot(i);
		if (stack.getItem() == Items.SLIME_BALL) {
			gluestick = stack.copy();
			remainingItems.set(i, gluestick);
			break;
		}
	}

	return remainingItems;
}
 
Example 2
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 3
Source File: RecipeShapedFluid.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) {
	NonNullList<ItemStack> remains = ForgeHooks.defaultRecipeGetRemainingItems(inv);
	for (int i = 0; i < height * width; i++) {
		ItemStack stack = inv.getStackInSlot(i);
		NonNullList<Ingredient> matchedIngredients = this.input;
		if (matchedIngredients.get(i) instanceof IngredientFluidStack) {
			if (!stack.isEmpty()) {
				ItemStack copy = stack.copy();
				copy.setCount(1);
				remains.set(i, copy);
			}
			IFluidHandlerItem handler = FluidUtil.getFluidHandler(remains.get(i));
			if (handler != null) {
				FluidStack fluid = ((IngredientFluidStack) matchedIngredients.get(i)).getFluid();
				handler.drain(fluid.amount, true);
				remains.set(i, handler.getContainer());
			}
		}
	}
	return remains;
}
 
Example 4
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 5
Source File: RecipeShapelessFluid.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean matches(InventoryCrafting matrix, World world) {
	ArrayList<Ingredient> required = new ArrayList<>(getIngredients());

	for (int i = 0; i < matrix.getSizeInventory(); i++) {
		ItemStack slot = matrix.getStackInSlot(i);
		if (!slot.isEmpty()) {
			boolean inRecipe = false;
			Iterator<Ingredient> iterator = required.iterator();
			while (iterator.hasNext()) {
				Ingredient next = iterator.next();
				if (next.apply(slot)) {
					inRecipe = true;
					iterator.remove();
					break;
				}
			}
			if (!inRecipe)
				return false;
		}
	}
	return required.isEmpty();
}
 
Example 6
Source File: RecipePneumaticHelmet.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean matches(InventoryCrafting inventory, World world){

    for(int i = 0; i < inventory.getSizeInventory(); i++) {
        if(i != 4 && i < 6) {
            if(inventory.getStackInSlot(i) == null) return false;
        } else {
            if(inventory.getStackInSlot(i) != null) return false;
        }
    }

    if(inventory.getStackInRowAndColumn(0, 0).getItem() != Itemss.airCanister) return false;
    // System.out.println("still ok");
    if(inventory.getStackInRowAndColumn(1, 0).getItem() != Itemss.printedCircuitBoard) return false;
    if(inventory.getStackInRowAndColumn(2, 0).getItem() != Itemss.airCanister) return false;
    if(inventory.getStackInRowAndColumn(0, 1).getItem() != Itemss.airCanister) return false;
    if(inventory.getStackInRowAndColumn(2, 1).getItem() != Itemss.airCanister) return false;
    return true;
}
 
Example 7
Source File: RecipeColorDrone.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, hasDye = false;
    for(int i = 0; i < inventoryCrafting.getSizeInventory(); i++) {
        ItemStack stack = inventoryCrafting.getStackInSlot(i);
        if(stack != null) {
            if(stack.getItem() == Itemss.drone) {
                if(!hasDrone) hasDrone = true;
                else return false;
            } else if(TileEntityPlasticMixer.getDyeIndex(stack) >= 0) {
                if(!hasDye) hasDye = true;
                else return false;
            }
        }
    }
    return hasDrone && hasDye;
}
 
Example 8
Source File: ShapedMetadataOreRecipe.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
@Nonnull
public ItemStack getCraftingResult(InventoryCrafting inv)
{
    ItemStack result = super.getCraftingResult(inv);

    for (int i = 0; i < inv.getSizeInventory(); i++)
    {
        ItemStack tmp = inv.getStackInSlot(i);

        // Take or merge the NBT from the first item on the crafting grid that matches the set "source" item
        if (tmp.isEmpty() == false && tmp.getItem() == this.sourceItem)
        {
            result.setItemDamage(tmp.getMetadata() | this.mask);

            break;
        }
    }

    return result;
}
 
Example 9
Source File: RecipeUnmountPearl.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
@Nonnull
public ItemStack getCraftingResult(@Nonnull InventoryCrafting inv) {
	ItemStack foundStaff = ItemStack.EMPTY;

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

			if (stack.getItemDamage() == 1) {
				foundStaff = stack;
				break;
			}
		}
	}

	if (foundStaff.isEmpty()) return ItemStack.EMPTY;

	ItemStack infusedPearl = new ItemStack(ModItems.PEARL_NACRE);
	SpellUtils.copySpell(foundStaff, infusedPearl);

	return infusedPearl;
}
 
Example 10
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 11
Source File: RecipeSteroidSyringe.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 foundSyringe = false;
	boolean foundMana = false;
	boolean foundNacre = false;
	boolean foundLava = false;
	boolean foundDevilDust = false;

	ItemStack mana = FluidUtil.getFilledBucket(new FluidStack(ModFluids.MANA.getActual(), 1));
	ItemStack nacre = FluidUtil.getFilledBucket(new FluidStack(ModFluids.NACRE.getActual(), 1));

	for (int i = 0; i < inv.getSizeInventory(); i++) {
		ItemStack stack = inv.getStackInSlot(i);
		if (stack.getItem() == ModItems.SYRINGE && stack.getItemDamage() == 0) foundSyringe = true;
		if (ItemStack.areItemStacksEqual(mana, stack)) foundMana = true;
		if (ItemStack.areItemStacksEqual(nacre, stack)) foundNacre = true;
		if (stack.getItem() == Items.LAVA_BUCKET) foundLava = true;
		if (stack.getItem() == ModItems.DEVIL_DUST) foundDevilDust = true;
	}
	return foundSyringe && foundMana && foundDevilDust && foundLava && foundNacre;
}
 
Example 12
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 13
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 14
Source File: CyberwareDyingHandler.java    From Cyberware with MIT License 5 votes vote down vote up
/**
 * Used to check if a recipe matches current crafting inventory
 */
public boolean matches(InventoryCrafting inv, World worldIn)
{
	ItemStack itemstack = null;
	List<ItemStack> list = Lists.<ItemStack>newArrayList();

	for (int i = 0; i < inv.getSizeInventory(); ++i)
	{
		ItemStack itemstack1 = inv.getStackInSlot(i);

		if (itemstack1 != null)
		{
			if (itemstack1.getItem() instanceof ItemArmor)
			{
				ItemArmor itemarmor = (ItemArmor)itemstack1.getItem();

				if (itemarmor.getArmorMaterial() != CyberwareContent.trenchMat || itemstack != null)
				{
					return false;
				}

				itemstack = itemstack1;
			}
			else
			{
				if (itemstack1.getItem() != Items.DYE)
				{
					return false;
				}

				list.add(itemstack1);
			}
		}
	}

	return itemstack != null && !list.isEmpty();
}
 
Example 15
Source File: CyberwareDyingHandler.java    From Cyberware with MIT License 5 votes vote down vote up
public ItemStack[] getRemainingItems(InventoryCrafting inv)
{
	ItemStack[] aitemstack = new ItemStack[inv.getSizeInventory()];

	for (int i = 0; i < aitemstack.length; ++i)
	{
		ItemStack itemstack = inv.getStackInSlot(i);
		aitemstack[i] = net.minecraftforge.common.ForgeHooks.getContainerItem(itemstack);
	}

	return aitemstack;
}
 
Example 16
Source File: CustomItemReturnShapedOreRecipeRecipe.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) {
    NonNullList<ItemStack> remainingItems = super.getRemainingItems(inv);
    for (int i = 0; i < remainingItems.size(); i++) {
        if (!remainingItems.get(i).isEmpty()) continue;
        ItemStack stackInSlot = inv.getStackInSlot(i);
        //if specified item should be returned back, copy it with amount 1 and add to remaining items
        if (shouldItemReturn(stackInSlot)) {
            ItemStack remainingItem = GTUtility.copyAmount(1, stackInSlot);
            remainingItems.set(i, remainingItem);
        }
    }
    return remainingItems;
}
 
Example 17
Source File: RecipeDuplicatePattern.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
@Override
public ItemStack getCraftingResult(InventoryCrafting grid) {
	for (int i = 0; i < grid.getSizeInventory(); i++) {
		ItemStack slot = grid.getStackInSlot(i);

		if (slot != null && TileEntityBanner.getPatterns(slot) > 0) {
			ItemStack copy = slot.copy();
			copy.stackSize = 2;
			return copy;
		}
	}

	return null;
}
 
Example 18
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 19
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;
    }
}
 
Example 20
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();
}