Search in sources :

Example 1 with InventoryCrafting

use of net.minecraft.inventory.InventoryCrafting in project BluePower by Qmunity.

the class TileProjectTable method getCraftingGrid.

public InventoryCrafting getCraftingGrid(Container listener) {
    InventoryCrafting inventoryCrafting = new InventoryCrafting(listener, 3, 3) {

        @Override
        public void setInventorySlotContents(int slot, ItemStack stack) {
            super.setInventorySlotContents(slot, stack);
            updateCraftingGrid();
        }

        @Override
        public ItemStack decrStackSize(int p_70298_1_, int p_70298_2_) {
            ItemStack stack = super.decrStackSize(p_70298_1_, p_70298_2_);
            updateCraftingGrid();
            return stack;
        }
    };
    if (stackListFieldInventoryCrafting == null) {
        stackListFieldInventoryCrafting = ReflectionHelper.findField(InventoryCrafting.class, "field_70466_a", "stackList");
    }
    try {
        // Inject the array, so when stacks are being set to null by the
        stackListFieldInventoryCrafting.set(inventoryCrafting, craftingGrid);
        // container it'll make it's way over to the actual stacks.
        return inventoryCrafting;
    } catch (Exception e) {
        BluePower.log.error("This is about to go wrong, Project Table getCraftingGrid:");
        e.printStackTrace();
        return null;
    }
}
Also used : InventoryCrafting(net.minecraft.inventory.InventoryCrafting) ItemStack(net.minecraft.item.ItemStack)

Example 2 with InventoryCrafting

use of net.minecraft.inventory.InventoryCrafting in project LogisticsPipes by RS485.

the class ImmibisCraftingTableMk2 method importRecipe.

@Override
public boolean importRecipe(TileEntity tile, ItemIdentifierInventory inventory) {
    try {
        if (tileAutoCraftingMk2.isInstance(tile)) {
            // Import recipeInputs
            ItemStack[][] recipe = (ItemStack[][]) tileAutoCraftingMk2.getField("recipeInputs").get(tile);
            // Not really a AutoCraftingInventory, but same content
            InventoryCrafting tempCraftingInv = new InventoryCrafting(new Container() {

                @Override
                public boolean canInteractWith(EntityPlayer entityplayer) {
                    return false;
                }

                @Override
                public void onCraftMatrixChanged(IInventory par1iInventory) {
                }
            }, 3, 3);
            for (int i = 0; i < 9; i++) {
                if (recipe[i].length > 0) {
                    tempCraftingInv.setInventorySlotContents(i, recipe[i][0]);
                    inventory.setInventorySlotContents(i, recipe[i][0]);
                } else {
                    inventory.clearInventorySlotContents(i);
                }
            }
            // Compact
            int slotCount = 0;
            for (int i = 0; i < 9; i++) {
                ItemStack slotStack = inventory.getStackInSlot(i);
                inventory.clearInventorySlotContents(i);
                if (slotStack != null && slotStack.getItem() != null) {
                    int count = 1;
                    for (int j = i + 1; j < 9; j++) {
                        ItemStack tempStack = inventory.getStackInSlot(j);
                        if (tempStack != null && ItemIdentifier.get(slotStack).equals(ItemIdentifier.get(tempStack))) {
                            inventory.clearInventorySlotContents(j);
                            count++;
                        }
                    }
                    slotStack.stackSize = count;
                    inventory.setInventorySlotContents(slotCount, slotStack);
                    slotCount++;
                }
            }
            ItemStack result = null;
            for (IRecipe r : CraftingUtil.getRecipeList()) {
                if (r.matches(tempCraftingInv, tile.getWorldObj())) {
                    result = r.getCraftingResult(tempCraftingInv);
                    break;
                }
            }
            inventory.setInventorySlotContents(9, result);
            return true;
        }
    } catch (IllegalArgumentException | NoSuchFieldException e) {
        LogisticsPipes.log.fatal("Error while importing recipe from Tubestuff's AutoCraftingMk2");
        e.printStackTrace();
    } catch (Exception e) {
        LogisticsPipes.log.error("Got a problem on ImmibisCraftingTableMk2 CraftingRecipeProvider:");
        LogisticsPipes.log.error(e.getMessage());
    }
    return false;
}
Also used : IInventory(net.minecraft.inventory.IInventory) IRecipe(net.minecraft.item.crafting.IRecipe) InventoryCrafting(net.minecraft.inventory.InventoryCrafting) Container(net.minecraft.inventory.Container) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack)

Example 3 with InventoryCrafting

use of net.minecraft.inventory.InventoryCrafting in project BetterStorage by copygirl.

the class VanillaStationCrafting method findVanillaRecipe.

public static VanillaStationCrafting findVanillaRecipe(InventoryCraftingStation inv) {
    World world = ((inv.entity != null) ? inv.entity.getWorldObj() : WorldUtils.getLocalWorld());
    InventoryCrafting crafting = new InventoryCrafting(new FakeContainer(), 3, 3);
    for (int i = 0; i < inv.crafting.length; i++) crafting.setInventorySlotContents(i, ItemStack.copyItemStack(inv.crafting[i]));
    IRecipe recipe = findRecipe(crafting, world);
    if (recipe == null)
        return null;
    return new VanillaStationCrafting(world, recipe, inv.crafting, recipe.getCraftingResult(crafting));
}
Also used : IRecipe(net.minecraft.item.crafting.IRecipe) World(net.minecraft.world.World) InventoryCrafting(net.minecraft.inventory.InventoryCrafting)

Example 4 with InventoryCrafting

use of net.minecraft.inventory.InventoryCrafting in project PneumaticCraft by MineMaarten.

the class ProgWidgetCrafting method getCraftingGrid.

@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;
}
Also used : Container(net.minecraft.inventory.Container) EntityPlayer(net.minecraft.entity.player.EntityPlayer) InventoryCrafting(net.minecraft.inventory.InventoryCrafting)

Example 5 with InventoryCrafting

use of net.minecraft.inventory.InventoryCrafting in project LogisticsPipes by RS485.

the class RollingMachine method importRecipe.

@Override
public boolean importRecipe(TileEntity tile, ItemIdentifierInventory inventory) {
    if (!tileRollingMachineClass.isInstance(tile)) {
        return false;
    }
    InventoryCrafting craftMatrix = getCraftMatrix(tile);
    if (craftMatrix == null) {
        return false;
    }
    ItemStack result = getResult(craftMatrix, tile.getWorldObj());
    if (result == null) {
        return false;
    }
    inventory.setInventorySlotContents(9, result);
    // Import
    for (int i = 0; i < craftMatrix.getSizeInventory(); i++) {
        if (i >= inventory.getSizeInventory() - 2) {
            break;
        }
        final ItemStack newStack = craftMatrix.getStackInSlot(i) == null ? null : craftMatrix.getStackInSlot(i).copy();
        inventory.setInventorySlotContents(i, newStack);
    }
    inventory.compact_first(9);
    return true;
}
Also used : InventoryCrafting(net.minecraft.inventory.InventoryCrafting) ItemStack(net.minecraft.item.ItemStack)

Aggregations

InventoryCrafting (net.minecraft.inventory.InventoryCrafting)5 ItemStack (net.minecraft.item.ItemStack)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 Container (net.minecraft.inventory.Container)2 IRecipe (net.minecraft.item.crafting.IRecipe)2 IInventory (net.minecraft.inventory.IInventory)1 World (net.minecraft.world.World)1