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

The following examples show how to use net.minecraft.inventory.InventoryCrafting#setInventorySlotContents() . 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: ModHandler.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static Pair<IRecipe, ItemStack> getRecipeOutput(World world, ItemStack... recipe) {
    if (recipe == null || recipe.length == 0)
        return ImmutablePair.of(null, ItemStack.EMPTY);

    if (world == null) world = DummyWorld.INSTANCE;

    InventoryCrafting craftingGrid = new InventoryCrafting(new DummyContainer(), 3, 3);

    for (int i = 0; i < 9 && i < recipe.length; i++) {
        ItemStack recipeStack = recipe[i];
        if (recipeStack != null && !recipeStack.isEmpty()) {
            craftingGrid.setInventorySlotContents(i, recipeStack);
        }
    }

    for (IRecipe tmpRecipe : CraftingManager.REGISTRY) {
        if (tmpRecipe.matches(craftingGrid, world)) {
            ItemStack itemStack = tmpRecipe.getCraftingResult(craftingGrid);
            return ImmutablePair.of(tmpRecipe, itemStack);
        }
    }

    return ImmutablePair.of(null, ItemStack.EMPTY);
}
 
Example 2
Source File: DamageableShapelessOreRecipeTest.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void test_useUpItem()
{
    DamageableShapelessOreRecipe recipe = new DamageableShapelessOreRecipe(new ResourceLocation("group"),
                                                                           new int[] {60}, new ItemStack(Blocks.DIRT), new ItemStack(Items.WOODEN_SWORD));
    InventoryCrafting inv = new InventoryCrafting(new Container()
    {
        @Override
        public boolean canInteractWith(EntityPlayer playerIn)
        {
            return false;
        }
    }, 3, 3);
    inv.setInventorySlotContents(3, new ItemStack(Items.WOODEN_SWORD));

    assertTrue(recipe.matches(inv, null));
    NonNullList<ItemStack> remaining = recipe.getRemainingItems(inv);
    assertTrue(remaining.get(3).isEmpty());
}
 
Example 3
Source File: DamageableShapelessOreRecipeTest.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
private void doTest(boolean inOrder, boolean enoughDamage)
{
    DamageableShapelessOreRecipe recipe = new DamageableShapelessOreRecipe(new ResourceLocation("group"),
                                                                           new int[] {enoughDamage ? 5 : 5000, 0},
                                                                           new ItemStack(Blocks.DIRT), new ItemStack(Items.WOODEN_SWORD), new ItemStack(Items.APPLE));
    InventoryCrafting inv = new InventoryCrafting(new Container()
    {
        @Override
        public boolean canInteractWith(EntityPlayer playerIn)
        {
            return false;
        }
    }, 3, 3);
    inv.setInventorySlotContents(inOrder ? 3 : 4, new ItemStack(Items.WOODEN_SWORD));
    inv.setInventorySlotContents(inOrder ? 4 : 3, new ItemStack(Items.APPLE));

    assertSame(enoughDamage, recipe.matches(inv, null));

    if (enoughDamage)
    {
        NonNullList<ItemStack> remaining = recipe.getRemainingItems(inv);
        assertSame(Items.WOODEN_SWORD, remaining.get(inOrder ? 3 : 4).getItem());
        assertEquals(5, remaining.get(inOrder ? 3 : 4).getItemDamage());
    }
}
 
Example 4
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 5
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 6
Source File: DamageableShapedOreRecipeTest.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
private void doTest(boolean mirror, boolean enoughDamage)
{
    ShapedOreRecipe recipe = new DamageableShapedOreRecipe(new ResourceLocation("group"),
                                                           new int[] {0, 0, enoughDamage ? 5 : 5000, 0}, new ItemStack(Blocks.DIRT),
                                                           "AA", "BA",
                                                           'A', new ItemStack(Blocks.DIRT),
                                                           'B', new ItemStack(Items.WOODEN_SWORD))
            .setMirrored(mirror);

    InventoryCrafting inv = new InventoryCrafting(new Container()
    {
        @Override
        public boolean canInteractWith(EntityPlayer playerIn)
        {
            return false;
        }
    }, 3, 3);
    inv.setInventorySlotContents(4, new ItemStack(Blocks.DIRT));
    inv.setInventorySlotContents(5, new ItemStack(Blocks.DIRT));
    inv.setInventorySlotContents(mirror ? 8 : 7, new ItemStack(Items.WOODEN_SWORD));
    inv.setInventorySlotContents(mirror ? 7 : 8, new ItemStack(Blocks.DIRT));

    assertSame(enoughDamage, recipe.matches(inv, null));

    if (enoughDamage)
    {
        NonNullList<ItemStack> remaining = recipe.getRemainingItems(inv);
        assertSame(Items.WOODEN_SWORD, remaining.get(mirror ? 8 : 7).getItem());
        assertEquals(5, remaining.get(mirror ? 8 : 7).getItemDamage());
    }
}
 
Example 7
Source File: PlayerInventory.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
public static void loadBagInventory(ItemStack is, Container c)
{
	if(is != null && is.hasTagCompound())
	{
		NBTTagList nbttaglist = is.getTagCompound().getTagList("Items", 10);
		containerInv = new InventoryCrafting(c, 4, 2);
		for(int i = 0; i < nbttaglist.tagCount(); i++)
		{
			NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
			byte byte0 = nbttagcompound1.getByte("Slot");
			if(byte0 >= 0 && byte0 < 8)
				containerInv.setInventorySlotContents(byte0, new ItemStack(nbttagcompound1));
		}
	}
}
 
Example 8
Source File: TileCraftingGrid.java    From Translocators with MIT License 5 votes vote down vote up
private InventoryCrafting getCraftMatrix() {
    InventoryCrafting craftMatrix = new InventoryCrafting(new Container()
    {
        @Override
        public boolean canInteractWith(EntityPlayer entityplayer) {
            return true;
        }
    }, 3, 3);

    for (int i = 0; i < 9; i++)
        craftMatrix.setInventorySlotContents(i, items[i]);

    return craftMatrix;
}
 
Example 9
Source File: TileCraftingGrid.java    From Translocators with MIT License 5 votes vote down vote up
private void doCraft(ItemStack mresult, InventoryCrafting craftMatrix, EntityPlayer player) {
    giveOrDropItem(mresult, player);

    FMLCommonHandler.instance().firePlayerCraftingEvent(player, mresult, craftMatrix);
    mresult.onCrafting(worldObj, player, mresult.stackSize);

    for (int slot = 0; slot < 9; ++slot) {
        ItemStack stack = craftMatrix.getStackInSlot(slot);
        if (stack == null)
            continue;

        craftMatrix.decrStackSize(slot, 1);
        if (stack.getItem().hasContainerItem(stack)) {
            ItemStack container = stack.getItem().getContainerItem(stack);

            if (container != null) {
                if (container.isItemStackDamageable() && container.getItemDamage() > container.getMaxDamage())
                    container = null;

                craftMatrix.setInventorySlotContents(slot, container);
            }
        }
    }

    for (int i = 0; i < 9; i++)
        items[i] = craftMatrix.getStackInSlot(i);
}
 
Example 10
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 11
Source File: ProgWidgetCC.java    From PneumaticCraft with GNU General Public License v3.0 5 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 i = 0; i < 9; i++)
        invCrafting.setInventorySlotContents(i, craftingGrid[i]);
    return invCrafting;
}
 
Example 12
Source File: ComputerCraftUtils.java    From OpenModsLib with MIT License 5 votes vote down vote up
private static void addTurtleForUpgrade(List<ItemStack> result, IRecipe recipe, ItemStack turtle, ItemStack left, ItemStack right) {
	final InventoryCrafting inv = new InventoryCrafting(DUMMY_CONTAINER, 3, 3);
	inv.setInventorySlotContents(0, left);
	inv.setInventorySlotContents(1, turtle);
	inv.setInventorySlotContents(2, right);

	final ItemStack upgradedTurtle = recipe.getCraftingResult(inv);
	if (upgradedTurtle != null) result.add(upgradedTurtle);
}
 
Example 13
Source File: ECPrivatePatternInventory.java    From ExtraCells1 with MIT License 5 votes vote down vote up
public boolean doesRecipeExist(ICraftingPatternMAC pattern)
{
	InventoryCrafting inv = new InventoryCrafting(new ContainerWorkbench(new InventoryPlayer(null), gridTE.getWorld(), 0, 0, 0)
	{
		public void onCraftMatrixChanged(IInventory par1IInventory)
		{
		}
	}, 3, 3);
	for (int i = 0; i < pattern.getCraftingMatrix().length; i++)
	{
		inv.setInventorySlotContents(i, pattern.getCraftingMatrix()[i]);
	}
	ItemStack thing = CraftingManager.getInstance().findMatchingRecipe(inv, gridTE.getWorld());
	return ItemStack.areItemStacksEqual(thing, pattern.getOutput());
}
 
Example 14
Source File: ProgWidgetCrafting.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean shouldExecute(){
    IRecipe recipe = ProgWidgetCrafting.getRecipe(drone.getWorld(), widget);
    if(recipe == null) return false;
    InventoryCrafting craftingGrid = widget.getCraftingGrid();
    for(int crafted = 0; !((ICountWidget)widget).useCount() || crafted < ((ICountWidget)widget).getCount(); crafted++) {
        List<ItemStack>[] equivalentsList = new List[9];
        for(int i = 0; i < equivalentsList.length; i++) {
            ItemStack originalStack = craftingGrid.getStackInSlot(i);
            if(originalStack != null) {
                List<ItemStack> equivalents = new ArrayList<ItemStack>();
                for(int j = 0; j < drone.getInventory().getSizeInventory(); j++) {
                    ItemStack droneStack = drone.getInventory().getStackInSlot(j);
                    if(droneStack != null && (droneStack.getItem() == originalStack.getItem() || PneumaticCraftUtils.isSameOreDictStack(droneStack, originalStack))) {
                        equivalents.add(droneStack);
                    }
                }
                if(equivalents.isEmpty()) return false;
                equivalentsList[i] = equivalents;
            }
        }

        int[] curIndexes = new int[9];
        boolean first = true;
        boolean hasCrafted = false;
        while(first || count(curIndexes, equivalentsList)) {
            first = false;
            InventoryCrafting craftMatrix = new InventoryCrafting(new Container(){
                @Override
                public boolean canInteractWith(EntityPlayer p_75145_1_){
                    return false;
                }

            }, 3, 3);
            for(int i = 0; i < 9; i++) {
                ItemStack stack = equivalentsList[i] == null ? null : equivalentsList[i].get(curIndexes[i]);
                craftMatrix.setInventorySlotContents(i, stack);
            }
            if(recipe.matches(craftMatrix, drone.getWorld())) {
                if(craft(recipe.getCraftingResult(craftMatrix), craftMatrix)) {
                    hasCrafted = true;
                    break;
                }
            }
        }
        if(!hasCrafted) return false;
    }
    return false;
}