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

The following examples show how to use net.minecraft.inventory.InventoryCrafting#getStackInRowAndColumn() . 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: FamiliarUndoRecipe.java    From Gadomancy with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean matches(InventoryCrafting inv, World world) {

    boolean foundOldFamiliar = false;

    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            ItemStack itemstack = inv.getStackInRowAndColumn(j, i);

            if(itemstack != null && itemstack.getItem() != null && itemstack.getItem() instanceof ItemFamiliar_Old) {
                if(foundOldFamiliar) return false;
                foundOldFamiliar = true;
            } else if(itemstack != null && itemstack.getItem() != null) {
                return false;
            }
        }
    }

    return foundOldFamiliar;
}
 
Example 2
Source File: RecipeBalloon.java    From archimedes-ships with MIT License 6 votes vote down vote up
@Override
public ItemStack getCraftingResult(InventoryCrafting inventorycrafting)
{
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			ItemStack itemstack = inventorycrafting.getStackInRowAndColumn(i, j);
			if (itemstack == null) continue;
			if (itemstack.getItem() == Item.getItemFromBlock(Blocks.wool))
			{
				ItemStack itemstack1 = inventorycrafting.getStackInRowAndColumn(i, j + 1);
				if (itemstack1 != null && itemstack1.getItem() == Items.string)
				{
					return new ItemStack(ArchimedesShipMod.blockBalloon, 1, itemstack.getItemDamage());
				}
				return null;
			}
			return null;
		}
	}
	return null;
}
 
Example 3
Source File: EnderStorageRecipe.java    From EnderStorage with MIT License 6 votes vote down vote up
private boolean offsetMatchesDyes(InventoryCrafting ic, int col, int row) {
    if (!stackMatches(ic.getStackInRowAndColumn(col + 1, row + 1), Item.getItemFromBlock(EnderStorage.blockEnderChest)))
        return false;

    boolean hasDye = false;
    for(int i = 0; i < 3; i++)
        for(int j = 0; j < 3; j++) {
            //ignore chest slot
            if(i == row + 1 && j == col + 1)
                continue;

            ItemStack stack = ic.getStackInRowAndColumn(j, i);
            if(i == row && getDyeType(stack) >= 0) {
                hasDye = true;
                continue;
            }

            if(stack != null)
                return false;
        }

    return hasDye;
}
 
Example 4
Source File: EnderStorageRecipe.java    From EnderStorage with MIT License 6 votes vote down vote up
public ItemStack getCraftingResult(InventoryCrafting ic) {
    for (int row = 0; row < 2; row++) {
        if (!offsetMatchesDyes(ic, 0, row))
            continue;

        ItemStack freqowner = ic.getStackInRowAndColumn(1, row + 1);
        int freq = freqowner.getItemDamage() & 0xFFF;

        int colour1 = recolour(0, row, freq, ic);
        int colour2 = recolour(1, row, freq, ic);
        int colour3 = recolour(2, row, freq, ic);

        ItemStack result = InventoryUtils.copyStack(freqowner, 1);
        result.setItemDamage(EnderStorageManager.getFreqFromColours(colour3, colour2, colour1) | freqowner.getItemDamage() & 0xF000);
        return result;
    }
    return null;
}
 
Example 5
Source File: RecipeBalloon.java    From archimedes-ships with MIT License 6 votes vote down vote up
@Override
public boolean matches(InventoryCrafting inventorycrafting, World world)
{
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			ItemStack itemstack = inventorycrafting.getStackInRowAndColumn(i, j);
			if (itemstack == null) continue;
			if (itemstack.getItem() == Item.getItemFromBlock(Blocks.wool))
			{
				ItemStack itemstack1 = inventorycrafting.getStackInRowAndColumn(i, j + 1);
				if (itemstack1 != null && itemstack1.getItem() == Items.string)
				{
					return true;
				}
				return false;
			}
			return false;
		}
	}
	return false;
}
 
Example 6
Source File: WoodPostRecipe.java    From GardenCollection with MIT License 6 votes vote down vote up
@Override
public ItemStack getCraftingResult (InventoryCrafting inventory) {
    int size = getGridSize(inventory);
    for (int row = 0; row < size - 1; row++) {
        for (int col = 0; col < size; col++) {
            ItemStack axe = inventory.getStackInRowAndColumn(col, row);
            if (!isValidAxe(axe))
                continue;

            ItemStack wood = inventory.getStackInRowAndColumn(col, row + 1);
            if (wood == null)
                continue;

            Block woodBlock = Block.getBlockFromItem(wood.getItem());
            int woodMeta = wood.getItemDamage();

            if (!WoodRegistry.instance().contains(woodBlock, woodMeta))
                continue;

            if (woodBlock == woodType.getBlock() && woodMeta == woodType.meta)
                return new ItemStack(ModBlocks.thinLog, 4, TileEntityWoodProxy.composeMetadata(woodBlock, woodMeta));
        }
    }

    return null;
}
 
Example 7
Source File: DamageableShapedOreRecipe.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected boolean checkMatch(InventoryCrafting inv, int startX, int startY, boolean mirror)
{
    int[] amounts = getAmounts(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;
            int damage = 0;
            Ingredient target = Ingredient.EMPTY;

            if (subX >= 0 && subY >= 0 && subX < width && subY < height)
            {
                damage = amounts[subX + width * subY];

                if (mirror)
                {
                    target = input.get(width - subX - 1 + subY * width);
                } else
                {
                    target = input.get(subX + subY * width);
                }
            }

            ItemStack slot = inv.getStackInRowAndColumn(x, y);

            if (!target.apply(slot) || damage > slot.getMaxDamage() - slot.getItemDamage() + 1)
            {
                return false;
            }
        }
    }

    return true;
}
 
Example 8
Source File: FamiliarUndoRecipe.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {

    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            ItemStack itemstack = inv.getStackInRowAndColumn(j, i);
            if(itemstack != null && itemstack.getItem() != null && itemstack.getItem() instanceof ItemFamiliar_Old) {
                return ItemFamiliar_Old.getPaybackPackage(itemstack);
            }
        }
    }

    return null;
}
 
Example 9
Source File: BWRecipes.java    From bartworks with MIT License 5 votes vote down vote up
@Override
public boolean matches(InventoryCrafting p_77569_1_, World p_77569_2_) {
    for (int x = 0; x < 3; x++) {
        for (int y = 0; y < 3; y++) {
            ItemStack toCheck = p_77569_1_.getStackInRowAndColumn(y,x);
            ItemStack ref = this.charToStackMap.get(this.shape[x].toCharArray()[y]);
            if (!BW_Util.areStacksEqualOrNull(toCheck,ref))
                return false;
        }
    }
    return true;
}
 
Example 10
Source File: RecipeTippedArrow.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
@Override
public ItemStack getCraftingResult(InventoryCrafting grid) {
	ItemStack potion = grid.getStackInRowAndColumn(1, 1);
	List<PotionEffect> effects = ((LingeringPotion) ModItems.lingering_potion).getEffects(potion);

	ItemStack stack = new ItemStack(ModItems.tipped_arrow, 8);
	if (!effects.isEmpty()) {
		PotionEffect effect = effects.get(0);
		TippedArrow.setEffect(stack, Potion.potionTypes[effect.getPotionID()], effect.getDuration());
	}

	return stack;
}
 
Example 11
Source File: WoodFenceRecipe.java    From GardenCollection with MIT License 5 votes vote down vote up
@Override
public ItemStack getCraftingResult (InventoryCrafting inventory) {
    int size = getGridSize(inventory);
    for (int row = 0; row < size - 1; row++) {
        for (int col = 0; col < size - 2; col++) {
            ItemStack string1 = inventory.getStackInRowAndColumn(col, row);
            ItemStack string2 = inventory.getStackInRowAndColumn(col + 2, row);
            if (string1 == null || string2 == null || string1.getItem() != Items.string || !string1.isItemEqual(string2))
                continue;

            ItemStack wood1 = inventory.getStackInRowAndColumn(col + 1, row);
            ItemStack wood2 = inventory.getStackInRowAndColumn(col + 1, row + 1);
            if (wood1 == null || wood2 == null || !wood1.isItemEqual(wood2))
                continue;
            if (Block.getBlockFromItem(wood1.getItem()) != ModBlocks.thinLog)
                continue;

            Block woodBlock = TileEntityWoodProxy.getBlockFromComposedMetadata(wood1.getItemDamage());
            int woodMeta = TileEntityWoodProxy.getMetaFromComposedMetadata(wood1.getItemDamage());

            if (!WoodRegistry.instance().contains(woodBlock, woodMeta))
                continue;

            if (woodBlock == woodType.getBlock() && woodMeta == woodType.meta)
                return new ItemStack(ModBlocks.thinLogFence, 3, TileEntityWoodProxy.composeMetadata(woodBlock, woodMeta));
        }
    }

    return null;
}
 
Example 12
Source File: CustomWoodShapedRecipe.java    From AgriCraft with MIT License 5 votes vote down vote up
public Optional<CustomWoodType> inferMaterial(InventoryCrafting ic) {
    for (int r = 0; r < ic.getWidth(); r++) {
        for (int c = 0; c < ic.getHeight(); c++) {
            final ItemStack stack = ic.getStackInRowAndColumn(r, c);
            final Optional<CustomWoodType> material = CustomWoodTypeRegistry.getFromStack(stack);
            if (material.isPresent()) {
                return material;
            }
        }
    }
    return Optional.empty();
}
 
Example 13
Source File: WoodBlockRecipe.java    From GardenCollection with MIT License 5 votes vote down vote up
@Override
public ItemStack getCraftingResult (InventoryCrafting inventory) {
    int size = getGridSize(inventory);
    for (int row = 0; row < size - 1; row++) {
        for (int col = 0; col < size - 1; col++) {
            ItemStack wood1 = inventory.getStackInRowAndColumn(col, row);
            ItemStack wood2 = inventory.getStackInRowAndColumn(col, row + 1);
            ItemStack wood3 = inventory.getStackInRowAndColumn(col + 1, row);
            ItemStack wood4 = inventory.getStackInRowAndColumn(col + 1, row + 1);
            if (wood1 == null || wood2 == null || wood3 == null || wood4 == null)
                continue;
            if (!wood1.isItemEqual(wood2) || !wood1.isItemEqual(wood3) || !wood1.isItemEqual(wood4))
                continue;
            if (Block.getBlockFromItem(wood1.getItem()) != ModBlocks.thinLog)
                continue;

            Block woodBlock = TileEntityWoodProxy.getBlockFromComposedMetadata(wood1.getItemDamage());
            int woodMeta = TileEntityWoodProxy.getMetaFromComposedMetadata(wood1.getItemDamage());

            if (!WoodRegistry.instance().contains(woodBlock, woodMeta))
                continue;

            if (woodBlock == woodType.getBlock() && woodMeta == woodType.meta)
                return new ItemStack(woodBlock, 1, woodMeta);
        }
    }

    return null;
}
 
Example 14
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 15
Source File: ShapedOreRecipeTFC.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
protected 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.get(width - subX - 1 + subY * width);
				}
				else
				{
					target = input.get(subX + subY * width);
				}
			}

			if(target == null)
				continue;

			ItemStack slot = inv.getStackInRowAndColumn(x, y);

			if (target instanceof ItemStack)
			{
				if (!OreDictionary.itemMatches((ItemStack)target, slot, false))
				{
					return false;
				}
			}
			else if (target instanceof List)
			{
				boolean matched = false;

				Iterator<ItemStack> itr = ((List<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;
			}

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

		}
	}

	return true;
}
 
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: EntangledQBlockRecipe.java    From qcraft-mod with Apache License 2.0 4 votes vote down vote up
@Override
public ItemStack getCraftingResult( InventoryCrafting inventory )
{
    // Find the eos
    int eosPosX = -1;
    int eosPosY = -1;
    for( int y = 0; y < 3; ++y )
    {
        for( int x = 0; x < 3; ++x )
        {
            ItemStack item = inventory.getStackInRowAndColumn( x, y );
            if( item != null &&
                    item.getItem() == QCraft.Items.eos &&
                    item.getItemDamage() == ItemEOS.SubType.Entanglement )
            {
                eosPosX = x;
                eosPosY = y;
                break;
            }
        }
    }

    // Fail if no eos found:
    if( eosPosX < 0 || eosPosX < 0 )
    {
        return null;
    }

    // Find ODB
    int subType = -1;
    int[] types = null;
    int entanglementFrequency = -1;
    int odbsFound = 0;
    for( int x = 0; x < 3; ++x )
    {
        for( int y = 0; y < 3; ++y )
        {
            if( !( x == eosPosX && y == eosPosY ) )
            {
                if( ( x == eosPosX - 1 || x == eosPosX + 1 ) && y == eosPosY )
                {
                    // Find ODBs
                    ItemStack odb = inventory.getStackInRowAndColumn( x, y );
                    if( odb != null && odb.getItem() instanceof ItemQBlock )
                    {
                        if( odbsFound == 0 )
                        {
                            // First ODB, treat as template
                            subType = ItemQBlock.getSubType( odb );
                            types = ItemQBlock.getTypes( odb );
                            entanglementFrequency = ItemQBlock.getEntanglementFrequency( odb );
                        }
                        else
                        {
                            // Subsequent ODBs, must match
                            int odbFrequency = ItemQBlock.getEntanglementFrequency( odb );
                            if( ItemQBlock.getSubType( odb ) == subType &&
                                    ItemQBlock.compareTypes( ItemQBlock.getTypes( odb ), types ) &&
                                    ( ( entanglementFrequency < 0 ) || ( odbFrequency < 0 ) ) )
                            {
                                entanglementFrequency = ( odbFrequency >= 0 ) ? odbFrequency : entanglementFrequency;
                            }
                            else
                            {
                                return null;
                            }
                        }
                        odbsFound++;
                    }
                    else
                    {
                        return null;
                    }
                }
                else
                {
                    // Ensure empty
                    if( inventory.getStackInRowAndColumn( x, y ) != null )
                    {
                        return null;
                    }
                }
            }
        }
    }

    // Check the types exist
    if( types == null || odbsFound < 2 )
    {
        return null;
    }

    // Determine frequency
    if( entanglementFrequency < 0 )
    {
        entanglementFrequency = 0; // This will be assigned after crafting
    }

    // Create item
    return ItemQBlock.create( subType, types, entanglementFrequency, odbsFound );
}
 
Example 18
Source File: EntangledQuantumComputerRecipe.java    From qcraft-mod with Apache License 2.0 4 votes vote down vote up
@Override
public ItemStack getCraftingResult( InventoryCrafting inventory )
{
    // Find the eos
    int eosPosX = -1;
    int eosPosY = -1;
    for( int y = 0; y < 3; ++y )
    {
        for( int x = 0; x < 3; ++x )
        {
            ItemStack item = inventory.getStackInRowAndColumn( x, y );
            if( item != null &&
                    item.getItem() == QCraft.Items.eos &&
                    item.getItemDamage() == ItemEOS.SubType.Entanglement )
            {
                eosPosX = x;
                eosPosY = y;
                break;
            }
        }
    }

    // Fail if no eos found:
    if( eosPosX < 0 || eosPosX < 0 )
    {
        return null;
    }

    // Find computer
    int computersFound = 0;
    for( int x = 0; x < 3; ++x )
    {
        for( int y = 0; y < 3; ++y )
        {
            if( !( x == eosPosX && y == eosPosY ) )
            {
                if( ( x == eosPosX - 1 || x == eosPosX + 1 ) && y == eosPosY )
                {
                    // Find computer (must be unentangled)
                    ItemStack odb = inventory.getStackInRowAndColumn( x, y );
                    if( odb != null && odb.getItem() instanceof ItemQuantumComputer )
                    {
                        if( ItemQuantumComputer.getEntanglementFrequency( odb ) >= 0 )
                        {
                            return null;
                        }
                        computersFound++;
                    }
                    else
                    {
                        return null;
                    }
                }
                else
                {
                    // Ensure empty
                    if( inventory.getStackInRowAndColumn( x, y ) != null )
                    {
                        return null;
                    }
                }
            }
        }
    }

    // Check computer is found
    if( computersFound != 2 )
    {
        return null;
    }

    // Determine frequency
    int entanglementFrequency = 0; // Will be filled in after crafting

    // Create item
    return ItemQuantumComputer.create( entanglementFrequency, computersFound );
}