Search in sources :

Example 76 with ItemStack

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

the class ModuleCrafterMK3 method tick.

@Override
public void tick() {
    super.tick();
    if (inv.isEmpty()) {
        return;
    }
    if (!_service.isNthTick(6)) {
        return;
    }
    //Add from internal buffer
    List<AdjacentTileEntity> crafters = locateCrafters();
    boolean change = false;
    for (AdjacentTileEntity adjacent : crafters) {
        for (int i = inv.getSizeInventory() - 1; i >= 0; i--) {
            ItemIdentifierStack slot = inv.getIDStackInSlot(i);
            if (slot == null) {
                continue;
            }
            ForgeDirection insertion = adjacent.direction.getOpposite();
            if (getUpgradeManager().hasSneakyUpgrade()) {
                insertion = getUpgradeManager().getSneakyOrientation();
            }
            ItemIdentifierStack toadd = slot.clone();
            toadd.setStackSize(Math.min(toadd.getStackSize(), toadd.getItem().getMaxStackSize()));
            if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING)) {
                toadd.setStackSize(Math.min(toadd.getStackSize(), ((IInventory) adjacent.tileEntity).getInventoryStackLimit()));
                ItemStack added = InventoryHelper.getTransactorFor(adjacent.tileEntity, adjacent.direction.getOpposite()).add(toadd.makeNormalStack(), insertion, true);
                slot.setStackSize(slot.getStackSize() - added.stackSize);
                if (added.stackSize != 0) {
                    change = true;
                }
            } else {
                _service.queueRoutedItem(SimpleServiceLocator.routedItemHelper.createNewTravelItem(toadd), adjacent.direction.getOpposite());
                slot.setStackSize(slot.getStackSize() - toadd.getStackSize());
                change = true;
            }
            if (slot.getStackSize() <= 0) {
                inv.clearInventorySlotContents(i);
            } else {
                inv.setInventorySlotContents(i, slot);
            }
        }
    }
    if (change) {
        inv.markDirty();
        _service.getCacheHolder().trigger(CacheTypes.Inventory);
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ItemStack(net.minecraft.item.ItemStack) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity)

Example 77 with ItemStack

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

the class ModuleElectricBuffer method tick.

@Override
public void tick() {
    if (++currentTickCount < ticksToAction) {
        return;
    }
    currentTickCount = 0;
    IInventoryUtil inv = _service.getPointedInventory(true);
    if (inv == null) {
        return;
    }
    for (int i = 0; i < inv.getSizeInventory(); i++) {
        ItemStack stack = inv.getStackInSlot(i);
        if (stack == null) {
            continue;
        }
        if (SimpleServiceLocator.IC2Proxy.isElectricItem(stack)) {
            Triplet<Integer, SinkReply, List<IFilter>> reply = SimpleServiceLocator.logisticsManager.hasDestinationWithMinPriority(ItemIdentifier.get(stack), _service.getSourceID(), true, FixedPriority.ElectricManager);
            if (reply == null) {
                continue;
            }
            _service.spawnParticle(Particles.OrangeParticle, 2);
            _service.sendStack(inv.decrStackSize(i, 1), reply, ItemSendMode.Normal);
            return;
        }
        continue;
    }
}
Also used : SinkReply(logisticspipes.utils.SinkReply) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) List(java.util.List) ItemStack(net.minecraft.item.ItemStack)

Example 78 with ItemStack

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

the class ItemParts method getSubItems.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void getSubItems(Item par1, CreativeTabs par2CreativeTabs, List par3List) {
    par3List.add(new ItemStack(this, 1, 0));
    par3List.add(new ItemStack(this, 1, 1));
    par3List.add(new ItemStack(this, 1, 2));
    par3List.add(new ItemStack(this, 1, 3));
}
Also used : ItemStack(net.minecraft.item.ItemStack)

Example 79 with ItemStack

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

the class ModuleExtractor method tick.

@Override
public void tick() {
    if (++currentTick < ticksToAction()) {
        return;
    }
    currentTick = 0;
    //Extract Item
    IInventory realInventory = _service.getRealInventory();
    if (realInventory == null) {
        return;
    }
    ForgeDirection extractOrientation = _sneakyDirection;
    if (extractOrientation == ForgeDirection.UNKNOWN) {
        extractOrientation = _service.inventoryOrientation().getOpposite();
    }
    IInventoryUtil targetUtil = _service.getSneakyInventory(extractOrientation, true);
    for (int i = 0; i < targetUtil.getSizeInventory(); i++) {
        ItemStack slot = targetUtil.getStackInSlot(i);
        if (slot == null) {
            continue;
        }
        ItemIdentifier slotitem = ItemIdentifier.get(slot);
        List<Integer> jamList = new LinkedList<>();
        Pair<Integer, SinkReply> reply = _service.hasDestination(slotitem, true, jamList);
        if (reply == null) {
            continue;
        }
        int itemsleft = itemsToExtract();
        while (reply != null) {
            int count = Math.min(itemsleft, slot.stackSize);
            count = Math.min(count, slotitem.getMaxStackSize());
            if (reply.getValue2().maxNumberOfItems > 0) {
                count = Math.min(count, reply.getValue2().maxNumberOfItems);
            }
            while (!_service.useEnergy(neededEnergy() * count) && count > 0) {
                _service.spawnParticle(Particles.OrangeParticle, 2);
                count--;
            }
            if (count <= 0) {
                break;
            }
            ItemStack stackToSend = targetUtil.decrStackSize(i, count);
            if (stackToSend == null || stackToSend.stackSize == 0) {
                break;
            }
            count = stackToSend.stackSize;
            _service.sendStack(stackToSend, reply, itemSendMode());
            itemsleft -= count;
            if (itemsleft <= 0) {
                break;
            }
            slot = targetUtil.getStackInSlot(i);
            if (slot == null) {
                break;
            }
            jamList.add(reply.getValue1());
            reply = _service.hasDestination(ItemIdentifier.get(slot), true, jamList);
        }
        break;
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) SinkReply(logisticspipes.utils.SinkReply) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemStack(net.minecraft.item.ItemStack) LinkedList(java.util.LinkedList)

Example 80 with ItemStack

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

the class ModuleCCBasedQuickSort method handle.

private boolean handle(IInventoryUtil invUtil, int slot, List<CCSinkResponder> list) {
    if (list.isEmpty()) {
        return false;
    }
    ItemIdentifier ident = list.get(0).getStack().getItem();
    ItemStack stack = invUtil.getStackInSlot(slot);
    if (stack == null || !ItemIdentifier.get(stack).equals(ident)) {
        return false;
    }
    final IRouter source = _service.getRouter();
    List<Triplet<Integer, Double, CCSinkResponder>> posibilities = new ArrayList<>();
    for (CCSinkResponder sink : list) {
        if (!sink.isDone()) {
            continue;
        }
        if (sink.getCanSink() < 1) {
            continue;
        }
        IRouter r = SimpleServiceLocator.routerManager.getRouter(sink.getRouterId());
        if (r == null) {
            continue;
        }
        List<ExitRoute> ways = source.getDistanceTo(r);
        double minDistance = Double.MAX_VALUE;
        outer: for (ExitRoute route : ways) {
            for (IFilter filter : route.filters) {
                if (filter.blockRouting() || filter.isFilteredItem(ident) == filter.isBlocked()) {
                    continue outer;
                }
            }
            minDistance = Math.min(route.distanceToDestination, minDistance);
        }
        if (minDistance != Integer.MAX_VALUE) {
            posibilities.add(new Triplet<>(sink.getPriority(), minDistance, sink));
        }
    }
    if (posibilities.isEmpty()) {
        return false;
    }
    Collections.sort(posibilities, (o1, o2) -> {
        int c = o2.getValue1() - o1.getValue1();
        if (c != 0) {
            return c;
        }
        double e = o1.getValue2() - o2.getValue2();
        return e < 0 ? -1 : 1;
    });
    boolean sended = false;
    for (Triplet<Integer, Double, CCSinkResponder> triple : posibilities) {
        CCSinkResponder sink = triple.getValue3();
        if (sink.getCanSink() < 0) {
            continue;
        }
        stack = invUtil.getStackInSlot(slot);
        if (stack == null || stack.stackSize <= 0) {
            continue;
        }
        int amount = Math.min(stack.stackSize, sink.getCanSink());
        ItemStack extracted = invUtil.decrStackSize(slot, amount);
        _service.sendStack(extracted, sink.getRouterId(), ItemSendMode.Fast, null);
        sended = true;
    }
    return sended;
}
Also used : Triplet(logisticspipes.utils.tuples.Triplet) ArrayList(java.util.ArrayList) CCSinkResponder(logisticspipes.proxy.computers.objects.CCSinkResponder) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IRouter(logisticspipes.routing.IRouter) IFilter(logisticspipes.interfaces.routing.IFilter) ItemStack(net.minecraft.item.ItemStack) ExitRoute(logisticspipes.routing.ExitRoute)

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