net.minecraft.inventory.InventoryCrafting Java Examples

The following examples show how to use net.minecraft.inventory.InventoryCrafting. 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: 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 #2
Source File: CraftingManagerTFC.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting craftMatrix, World worldIn)
{
	for (IRecipe irecipe : this.recipes)
	{
		if (irecipe.matches(craftMatrix, worldIn))
		{
			return irecipe.getRemainingItems(craftMatrix);
		}
	}

	NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(craftMatrix.getSizeInventory(), ItemStack.EMPTY);

	/*for (int i = 0; i < nonnulllist.size(); ++i)
	{
		nonnulllist.set(i, craftMatrix.getStackInSlot(i));
	}*/

	return nonnulllist;
}
 
Example #3
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 #4
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 #5
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 #6
Source File: TerminalAddonRecipe.java    From OpenPeripheral-Addons with MIT License 6 votes vote down vote up
@Override
public boolean matches(InventoryCrafting inv, World world) {
	boolean glassesFound = false;
	boolean targetFound = false;

	for (ItemStack itemStack : InventoryUtils.asIterable(inv)) {
		if (itemStack != null) {
			if (itemStack.getItem() instanceof ItemGlasses) {
				if (glassesFound) return false;
				glassesFound = true;
			} else if (isSuitableItem(itemStack)) {
				if (targetFound) return false;
				targetFound = true;
			} else return false;
		}
	}

	return glassesFound && targetFound;
}
 
Example #7
Source File: BlueprintCraftingHandler.java    From Cyberware with MIT License 6 votes vote down vote up
public BlueprintResult(InventoryCrafting inv)
{
	this.ware = null;
	this.canCraft = process(inv);
	if (canCraft)
	{
		remaining = new ItemStack[9];
		remaining[wareStack] = ItemStack.copyItemStack(ware);
		output = ItemBlueprint.getBlueprintForItem(ware);
	}
	else
	{
		remaining = new ItemStack[9];
		output = null;
	}
}
 
Example #8
Source File: RecipeMountPearl.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Nonnull
@Override
public ItemStack getCraftingResult(@Nonnull InventoryCrafting inv) {
	ItemStack pearl = ItemStack.EMPTY;
	ItemStack staff = ItemStack.EMPTY;

	for (int i = 0; i < inv.getSizeInventory(); i++) {
		ItemStack stack = inv.getStackInSlot(i);
		if (stack.getItem() instanceof IPearlSwappable) {
			if (stack.getItemDamage() == 0)
				staff = stack;
		}
		if (stack.getItem() == ModItems.PEARL_NACRE)
			if (NBTHelper.getBoolean(stack, "infused", false))
				pearl = stack;
	}

	ItemStack newStaff = staff.copy();
	SpellUtils.copySpell(pearl, newStaff);
	newStaff.setItemDamage(1);

	return newStaff;
}
 
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: 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 #11
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 #12
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 #13
Source File: RecipeJam.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 jar = ItemStack.EMPTY;

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

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

	ItemStack jamJar = new ItemStack(ModItems.JAR_ITEM);
	NBTHelper.setInt(jamJar, NBTConstants.NBT.FAIRY_COLOR, NBTHelper.getInt(jar, NBTConstants.NBT.FAIRY_COLOR, 0xFFFFFF));
	jamJar.setItemDamage(1);

	return jamJar;
}
 
Example #14
Source File: DamageableShapedOreRecipeTest.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void test_useUpItem()
{
    ShapedOreRecipe recipe = new DamageableShapedOreRecipe(new ResourceLocation("group"),
                                                           new int[] {60}, new ItemStack(Blocks.DIRT),
                                                           "A",
                                                           'A', new ItemStack(Items.WOODEN_SWORD));

    InventoryCrafting inv = new InventoryCrafting(new Container()
    {
        @Override
        public boolean canInteractWith(EntityPlayer playerIn)
        {
            return false;
        }
    }, 3, 3);

    inv.setInventorySlotContents(0, new ItemStack(Items.WOODEN_SWORD));
    assertTrue(recipe.matches(inv, null));

    NonNullList<ItemStack> remaining = recipe.getRemainingItems(inv);
    assertTrue(remaining.get(0).isEmpty());
}
 
Example #15
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 #16
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 #17
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 #18
Source File: ProgWidgetCrafting.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
public InventoryCrafting getCraftingGrid(){
    InventoryCrafting invCrafting = new InventoryCrafting(new Container(){
        @Override
        public boolean canInteractWith(EntityPlayer p_75145_1_){
            return false;
        }

    }, 3, 3);
    for(int y = 0; y < 3; y++) {
        ProgWidgetItemFilter itemFilter = (ProgWidgetItemFilter)getConnectedParameters()[y];
        for(int x = 0; x < 3 && itemFilter != null; x++) {
            invCrafting.setInventorySlotContents(y * 3 + x, itemFilter.getFilter());
            itemFilter = (ProgWidgetItemFilter)itemFilter.getConnectedParameters()[0];
        }
    }
    return invCrafting;
}
 
Example #19
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 #20
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 #21
Source File: ProgWidgetCrafting.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
public static IRecipe getRecipe(World world, ICraftingWidget widget){
    InventoryCrafting craftingGrid = widget.getCraftingGrid();
    for(IRecipe recipe : (List<IRecipe>)CraftingManager.getInstance().getRecipeList()) {
        if(recipe.matches(craftingGrid, world)) {
            return recipe;
        }
    }
    return null;
}
 
Example #22
Source File: ReflectionUtil.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Container getCraftingContainer(InventoryCrafting inventory) {
	try {
		return (Container) INVENTORYCRAFTING_EVENTHANDLER.get(inventory);
	} catch (IllegalAccessException ex) {
		Game.logger().error("could not get inventory eventhandler");
		return null;
	}
}
 
Example #23
Source File: CustomWoodShapedRecipe.java    From AgriCraft with MIT License 5 votes vote down vote up
@Override
public ItemStack getCraftingResult(InventoryCrafting ic) {
    final ItemStack result = super.getCraftingResult(ic);
    final Optional<CustomWoodType> material = inferMaterial(ic);
    if (material.isPresent()) {
        final NBTTagCompound tag = StackHelper.getTag(result);
        material.get().writeToNBT(tag);
        result.setTagCompound(tag);
    }
    return result;
}
 
Example #24
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 #25
Source File: TileCraftingGrid.java    From Translocators with MIT License 5 votes vote down vote up
private void rotateItems(InventoryCrafting inv) {
    int[] slots = new int[]{0, 1, 2, 5, 8, 7, 6, 3};
    ItemStack[] arrangement = new ItemStack[9];
    arrangement[4] = inv.getStackInSlot(4);

    for (int i = 0; i < 8; i++)
        arrangement[slots[(i + 2) % 8]] = inv.getStackInSlot(slots[i]);

    for (int i = 0; i < 9; i++)
        inv.setInventorySlotContents(i, arrangement[i]);
}
 
Example #26
Source File: TofuEventLoader.java    From TofuCraftReload with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onCrafting(PlayerEvent.ItemCraftedEvent event) {
       EntityPlayer player = event.player;
       ItemStack item = event.crafting;
	IInventory craftMatrix = event.craftMatrix;
	
	if(craftMatrix instanceof InventoryCrafting){
	InventoryCrafting craftMatrix1 = (InventoryCrafting) craftMatrix;
	IRecipe recipe = ForgeRegistries.RECIPES.getValue(new ResourceLocation(TofuMain.MODID, "soymilk_cloth"));
	if(recipe!=null){
		if(!item.isEmpty()&&recipe.matches(craftMatrix1, player.world))
			player.inventory.addItemStackToInventory(new ItemStack(ItemLoader.material,1,11));
		}
	}
}
 
Example #27
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 #28
Source File: RecipeManometer.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();
    output.setItemDamage(getCanister(inventory).getItemDamage());
    //System.out.println("output damage: " + output.getItemDamage());
    return output;
}
 
Example #29
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 #30
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;
}