Search in sources :

Example 86 with ItemStack

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

the class PipeItemsRequestLogistics method getProvidedItems.

/* IRequestAPI */
@Override
public List<ItemStack> getProvidedItems() {
    if (stillNeedReplace()) {
        return new ArrayList<>();
    }
    Map<ItemIdentifier, Integer> items = SimpleServiceLocator.logisticsManager.getAvailableItems(getRouter().getIRoutersByCost());
    List<ItemStack> list = new ArrayList<>(items.size());
    for (Entry<ItemIdentifier, Integer> item : items.entrySet()) {
        ItemStack is = item.getKey().unsafeMakeNormalStack(item.getValue());
        list.add(is);
    }
    return list;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 87 with ItemStack

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

the class PipeItemsRequestLogistics method simulateRequest.

@Override
public SimulationResult simulateRequest(ItemStack wanted) {
    final List<IResource> used = new ArrayList<>();
    final List<IResource> missing = new ArrayList<>();
    RequestTree.simulate(ItemIdentifier.get(wanted).makeStack(wanted.stackSize), this, new RequestLog() {

        @Override
        public void handleMissingItems(List<IResource> items) {
            missing.addAll(items);
        }

        @Override
        public void handleSucessfullRequestOf(IResource item, LinkedLogisticsOrderList parts) {
        }

        @Override
        public void handleSucessfullRequestOfList(List<IResource> items, LinkedLogisticsOrderList parts) {
            used.addAll(items);
        }
    });
    List<ItemStack> usedList = new ArrayList<>(used.size());
    List<ItemStack> missingList = new ArrayList<>(missing.size());
    for (IResource e : used) {
        if (e instanceof ItemResource) {
            usedList.add(((ItemResource) e).getItem().unsafeMakeNormalStack(e.getRequestedAmount()));
        } else if (e instanceof DictResource) {
            usedList.add(((DictResource) e).getItem().unsafeMakeNormalStack(e.getRequestedAmount()));
        }
    }
    for (IResource e : missing) {
        if (e instanceof ItemResource) {
            missingList.add(((ItemResource) e).getItem().unsafeMakeNormalStack(e.getRequestedAmount()));
        } else if (e instanceof DictResource) {
            missingList.add(((DictResource) e).getItem().unsafeMakeNormalStack(e.getRequestedAmount()));
        }
    }
    SimulationResult r = new SimulationResult();
    r.used = usedList;
    r.missing = missingList;
    return r;
}
Also used : LinkedLogisticsOrderList(logisticspipes.routing.order.LinkedLogisticsOrderList) RequestLog(logisticspipes.request.RequestLog) ArrayList(java.util.ArrayList) DictResource(logisticspipes.request.resources.DictResource) ItemStack(net.minecraft.item.ItemStack) ItemResource(logisticspipes.request.resources.ItemResource) IResource(logisticspipes.request.resources.IResource)

Example 88 with ItemStack

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

the class PipeLogisticsChassi method onAllowedRemoval.

@Override
public void onAllowedRemoval() {
    _moduleInventory.removeListener(this);
    if (MainProxy.isServer(getWorld())) {
        for (int i = 0; i < getChassiSize(); i++) {
            LogisticsModule x = _module.getSubModule(i);
            if (x instanceof ILegacyActiveModule) {
                ILegacyActiveModule y = (ILegacyActiveModule) x;
                y.onBlockRemoval();
            }
        }
        for (int i = 0; i < _moduleInventory.getSizeInventory(); i++) {
            ItemIdentifierStack ms = _moduleInventory.getIDStackInSlot(i);
            if (ms != null) {
                ItemStack s = ms.makeNormalStack();
                ItemModuleInformationManager.saveInfotmation(s, getLogisticsModule().getSubModule(i));
                _moduleInventory.setInventorySlotContents(i, s);
            }
        }
        _moduleInventory.dropContents(getWorld(), getX(), getY(), getZ());
    }
}
Also used : ILegacyActiveModule(logisticspipes.interfaces.ILegacyActiveModule) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ItemStack(net.minecraft.item.ItemStack)

Example 89 with ItemStack

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

the class LogisticsTileGenericPipe method injectItem.

//@Override
//@ModDependentMethod(modId="BuildCraft|Transport")
@Override
public int injectItem(ItemStack payload, boolean doAdd, ForgeDirection from) {
    if (LogisticsBlockGenericPipe.isValid(pipe) && pipe.transport != null && isPipeConnected(from)) {
        if (doAdd && MainProxy.isServer(getWorldObj())) {
            ItemStack leftStack = payload.copy();
            int lastIterLeft;
            do {
                lastIterLeft = leftStack.stackSize;
                LPTravelingItem.LPTravelingItemServer travelingItem = SimpleServiceLocator.routedItemHelper.createNewTravelItem(leftStack);
                leftStack.stackSize = pipe.transport.injectItem(travelingItem, from.getOpposite());
            } while (leftStack.stackSize != lastIterLeft && leftStack.stackSize != 0);
            return payload.stackSize - leftStack.stackSize;
        }
    }
    return 0;
}
Also used : LPTravelingItem(logisticspipes.transport.LPTravelingItem) ItemStack(net.minecraft.item.ItemStack)

Example 90 with ItemStack

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

the class PipeItemsInvSysConnector method checkOneConnectedInv.

private boolean checkOneConnectedInv(IInventoryUtil inv, ForgeDirection dir) {
    boolean contentchanged = false;
    if (!itemsOnRoute.isEmpty()) {
        // don't check the inventory if you don't want anything
        List<ItemIdentifier> items = new ArrayList<>(itemsOnRoute.keySet());
        items.retainAll(inv.getItems());
        Map<ItemIdentifier, Integer> amounts = null;
        if (!items.isEmpty()) {
            amounts = inv.getItemsAndCount();
        }
        for (ItemIdentifier ident : items) {
            if (!amounts.containsKey(ident)) {
                continue;
            }
            int itemAmount = amounts.get(ident);
            List<ItemRoutingInformation> needs = itemsOnRoute.get(ident);
            for (Iterator<ItemRoutingInformation> iterator = needs.iterator(); iterator.hasNext(); ) {
                ItemRoutingInformation need = iterator.next();
                if (need.getItem().getStackSize() <= itemAmount) {
                    if (!useEnergy(6)) {
                        return contentchanged;
                    }
                    ItemStack toSend = inv.getMultipleItems(ident, need.getItem().getStackSize());
                    if (toSend == null) {
                        return contentchanged;
                    }
                    if (toSend.stackSize != need.getItem().getStackSize()) {
                        if (inv instanceof ITransactor) {
                            ((ITransactor) inv).add(toSend, dir.getOpposite(), true);
                        } else {
                            container.getWorldObj().spawnEntityInWorld(ItemIdentifierStack.getFromStack(toSend).makeEntityItem(getWorld(), container.xCoord, container.yCoord, container.zCoord));
                        }
                        new UnsupportedOperationException("The extracted amount didn't match the requested one. (" + inv + ")").printStackTrace();
                        return contentchanged;
                    }
                    sendStack(need, dir);
                    // finished with this need, we sent part of a stack, lets see if anyone where needs the current item type.
                    iterator.remove();
                    contentchanged = true;
                    if (needs.isEmpty()) {
                        itemsOnRoute.remove(ident);
                    }
                    //Refresh Available Items
                    amounts = inv.getItemsAndCount();
                    if (amounts.containsKey(ident)) {
                        itemAmount = amounts.get(ident);
                    } else {
                        itemAmount = 0;
                        break;
                    }
                }
            }
        }
    }
    return contentchanged;
}
Also used : ArrayList(java.util.ArrayList) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) ItemStack(net.minecraft.item.ItemStack) ITransactor(logisticspipes.utils.transactor.ITransactor)

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