Search in sources :

Example 61 with ItemStack

use of net.minecraft.item.ItemStack in project LogisticsPipes by RS485.

the class LogisticsSolderingTileEntity method getHandlerForRecipe.

public ICraftingResultHandler getHandlerForRecipe() {
    for (SolderingStationRecipe recipe : SolderingStationRecipes.getRecipes()) {
        boolean match = true;
        for (int i = 0; i < 9; i++) {
            ItemStack recipestack = recipe.source[i];
            ItemStack inputStack = inv.getStackInSlot(i);
            if (recipestack == null) {
                if (inputStack != null) {
                    match = false;
                }
                continue;
            } else if (inputStack == null) {
                match = false;
                continue;
            } else {
                if (!itemEquals(recipestack, inputStack)) {
                    match = false;
                }
            }
        }
        if (match) {
            return recipe.handler;
        }
    }
    return null;
}
Also used : SolderingStationRecipe(logisticspipes.recipes.SolderingStationRecipes.SolderingStationRecipe) ItemStack(net.minecraft.item.ItemStack)

Example 62 with ItemStack

use of net.minecraft.item.ItemStack in project LogisticsPipes by RS485.

the class LogisticsSolderingTileEntity method getRecipeForTagetAsItemIdentifierStackList.

public List<ItemIdentifierStack> getRecipeForTagetAsItemIdentifierStackList() {
    LinkedList<ItemIdentifierStack> list = new LinkedList<>();
    ItemStack[] array = getRecipeForTaget();
    if (array != null) {
        for (ItemStack stack : array) {
            if (stack != null) {
                list.addLast(ItemIdentifier.get(stack).makeStack(1));
            } else {
                list.addLast(null);
            }
        }
    }
    return list;
}
Also used : ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ItemStack(net.minecraft.item.ItemStack) LinkedList(java.util.LinkedList)

Example 63 with ItemStack

use of net.minecraft.item.ItemStack in project BluePower by Qmunity.

the class TileCircuitDatabase method copy.

/**
     * Returns true of copy succeeded.
     *
     * @param player
     * @param simulate
     * @return
     */
public boolean copy(EntityPlayer player, ItemStack template, ItemStack target, boolean simulate) {
    if (template != null && target != null) {
        if (template.isItemEqual(target)) {
            IDatabaseSaveable saveable = (IDatabaseSaveable) template.getItem();
            if (saveable.canCopy(template, target)) {
                if (!player.capabilities.isCreativeMode) {
                    List<ItemStack> stacksInTemplate = saveable.getItemsOnStack(template);
                    List<ItemStack> stacksInOutput = saveable.getItemsOnStack(target);
                    if (stacksInTemplate == null)
                        stacksInTemplate = new ArrayList<ItemStack>();
                    if (stacksInOutput == null)
                        stacksInOutput = new ArrayList<ItemStack>();
                    List<ItemStack> traversedItems = new ArrayList<ItemStack>();
                    List<ItemStack> allApplicableItems = new ArrayList<ItemStack>();
                    allApplicableItems.addAll(stacksInTemplate);
                    allApplicableItems.addAll(stacksInOutput);
                    for (ItemStack templateStack : allApplicableItems) {
                        boolean alreadyTraversed = false;
                        for (ItemStack traversedItem : traversedItems) {
                            if (traversedItem.isItemEqual(templateStack) && ItemStack.areItemStackTagsEqual(traversedItem, templateStack)) {
                                alreadyTraversed = true;
                                break;
                            }
                        }
                        if (alreadyTraversed)
                            continue;
                        traversedItems.add(templateStack);
                        int count = 0;
                        for (ItemStack stack : stacksInTemplate) {
                            if (stack.isItemEqual(templateStack) && ItemStack.areItemStackTagsEqual(stack, templateStack)) {
                                count += stack.stackSize;
                            }
                        }
                        for (ItemStack stack : stacksInOutput) {
                            if (stack.isItemEqual(templateStack) && ItemStack.areItemStackTagsEqual(stack, templateStack)) {
                                count -= stack.stackSize;
                            }
                        }
                        // if 5 items are inserted to be copied, the required items are x5.
                        count *= target.stackSize;
                        if (count > 0) {
                            // At this point we need assist from the inventory.
                            ItemStack retrievedStack = templateStack.copy();
                            retrievedStack.stackSize = count;
                            retrievedStack = IOHelper.extract(this, ForgeDirection.UNKNOWN, retrievedStack, true, simulate, 2);
                            if (retrievedStack == null || retrievedStack.stackSize < count)
                                return false;
                        } else if (count < 0) {
                            ItemStack returnedStack = templateStack.copy();
                            returnedStack.stackSize = -count;
                            returnedStack = IOHelper.insert(this, returnedStack, ForgeDirection.UNKNOWN, simulate);
                            if (returnedStack != null && !simulate) {
                                IOHelper.spawnItemInWorld(worldObj, returnedStack, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5);
                            }
                        }
                    }
                }
                if (!simulate) {
                    ItemStack copyStack = template.copy();
                    copyStack.stackSize = target.stackSize;
                    copyInventory.setInventorySlotContents(1, copyStack);
                }
                return true;
            }
        }
    }
    return false;
}
Also used : ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) IDatabaseSaveable(com.bluepowermod.api.item.IDatabaseSaveable)

Example 64 with ItemStack

use of net.minecraft.item.ItemStack in project BluePower by Qmunity.

the class TileManager method acceptItemFromTube.

@Override
public TubeStack acceptItemFromTube(TubeStack stack, ForgeDirection from, boolean simulate) {
    if (from == getFacingDirection().getOpposite()) {
        // if (!isBufferEmpty()) return stack;
        int itemsAccepted = acceptedItems(stack.stack);
        if (itemsAccepted > 0) {
            if (itemsAccepted >= stack.stack.stackSize) {
                ItemStack rejectedStack = IOHelper.insert(getTileCache(getFacingDirection()), stack.stack, from, simulate);
                if (rejectedStack == null || rejectedStack.stackSize != stack.stack.stackSize) {
                    if (!simulate) {
                        rejectTicker = 0;
                        sendUpdatePacket();
                    }
                }
                if (rejectedStack == null) {
                    return null;
                } else {
                    stack.stack = rejectedStack;
                    return stack;
                }
            }
            TubeStack injectedStack = stack.copy();
            stack.stack.stackSize -= itemsAccepted;
            injectedStack.stack.stackSize = itemsAccepted;
            ItemStack rejectedStack = IOHelper.insert(getTileCache(getFacingDirection()), injectedStack.stack, from, simulate);
            if (rejectedStack == null || rejectedStack.stackSize != injectedStack.stack.stackSize) {
                if (!simulate) {
                    rejectTicker = 0;
                    sendUpdatePacket();
                }
            }
            if (rejectedStack != null) {
                stack.stack.stackSize += rejectedStack.stackSize;
            }
        }
    }
    stack.setTarget(null, null);
    return super.acceptItemFromTube(stack, from, simulate);
}
Also used : TubeStack(com.bluepowermod.part.tube.TubeStack) ItemStack(net.minecraft.item.ItemStack)

Example 65 with ItemStack

use of net.minecraft.item.ItemStack in project BluePower by Qmunity.

the class TileManager method retrieveItemsFromManagers.

private void retrieveItemsFromManagers() {
    PneumaticTube tube = MultipartCompatibility.getPart(worldObj, xCoord + getOutputDirection().offsetX, yCoord + getOutputDirection().offsetY, zCoord + getOutputDirection().offsetZ, PneumaticTube.class);
    if (tube != null) {
        for (ItemStack stack : inventory) {
            int acceptedItems = acceptedItems(stack);
            if (acceptedItems > 0) {
                ItemStack retrievingStack = stack.copy();
                retrievingStack.stackSize = retrievingStack.getMaxStackSize();
                if (tube.getLogic().retrieveStack(this, getOutputDirection(), retrievingStack, filterColor))
                    return;
            }
        }
    }
}
Also used : PneumaticTube(com.bluepowermod.part.tube.PneumaticTube) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemStack (net.minecraft.item.ItemStack)9052 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)941 ArrayList (java.util.ArrayList)733 TileEntity (net.minecraft.tileentity.TileEntity)555 BlockPos (net.minecraft.util.math.BlockPos)551 EntityPlayer (net.minecraft.entity.player.EntityPlayer)526 IBlockState (net.minecraft.block.state.IBlockState)505 Block (net.minecraft.block.Block)494 Item (net.minecraft.item.Item)465 Slot (net.minecraft.inventory.Slot)448 EntityItem (net.minecraft.entity.item.EntityItem)423 Nonnull (javax.annotation.Nonnull)356 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)330 FluidStack (net.minecraftforge.fluids.FluidStack)289 NBTTagList (net.minecraft.nbt.NBTTagList)280 World (net.minecraft.world.World)277 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)269 ResourceLocation (net.minecraft.util.ResourceLocation)260 List (java.util.List)223 EnumFacing (net.minecraft.util.EnumFacing)208