Search in sources :

Example 1 with LogisticsModule

use of logisticspipes.modules.abstractmodules.LogisticsModule in project LogisticsPipes by RS485.

the class GuiChassiPipe method actionPerformed.

@Override
protected void actionPerformed(GuiButton guibutton) {
    if (guibutton.id >= 0 && guibutton.id <= 7) {
        LogisticsModule module = _chassiPipe.getLogisticsModule().getSubModule(guibutton.id);
        if (module != null) {
            final ModernPacket packet = PacketHandler.getPacket(ChassisGUI.class).setButtonID(guibutton.id).setPosX(_chassiPipe.getX()).setPosY(_chassiPipe.getY()).setPosZ(_chassiPipe.getZ());
            MainProxy.sendPacketToServer(packet);
        }
    }
}
Also used : ModernPacket(logisticspipes.network.abstractpackets.ModernPacket) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule)

Example 2 with LogisticsModule

use of logisticspipes.modules.abstractmodules.LogisticsModule in project LogisticsPipes by RS485.

the class ChassiTransportLayer method stillWantItem.

@Override
public boolean stillWantItem(IRoutedItem item) {
    LogisticsModule module = _chassiPipe.getLogisticsModule();
    if (module == null) {
        _chassiPipe.notifyOfItemArival(item.getInfo());
        return false;
    }
    if (!_chassiPipe.isEnabled()) {
        _chassiPipe.notifyOfItemArival(item.getInfo());
        return false;
    }
    SinkReply reply = module.sinksItem(item.getItemIdentifierStack().getItem(), -1, 0, true, false);
    if (reply == null || reply.maxNumberOfItems < 0) {
        _chassiPipe.notifyOfItemArival(item.getInfo());
        return false;
    }
    if (reply.maxNumberOfItems > 0 && item.getItemIdentifierStack().getStackSize() > reply.maxNumberOfItems) {
        ForgeDirection o = _chassiPipe.getPointedOrientation();
        if (o == null || o == ForgeDirection.UNKNOWN) {
            o = ForgeDirection.UP;
        }
        item.split(reply.maxNumberOfItems, o);
    }
    return true;
}
Also used : SinkReply(logisticspipes.utils.SinkReply) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 3 with LogisticsModule

use of logisticspipes.modules.abstractmodules.LogisticsModule in project LogisticsPipes by RS485.

the class ChassiModule method sinksItem.

@Override
public SinkReply sinksItem(ItemIdentifier item, int bestPriority, int bestCustomPriority, boolean allowDefault, boolean includeInTransit) {
    SinkReply bestresult = null;
    for (LogisticsModule module : modules) {
        if (module != null) {
            SinkReply result = module.sinksItem(item, bestPriority, bestCustomPriority, allowDefault, includeInTransit);
            if (result != null && result.maxNumberOfItems >= 0) {
                bestresult = result;
                bestPriority = result.fixedPriority.ordinal();
                bestCustomPriority = result.customPriority;
            }
        }
    }
    if (bestresult == null) {
        return null;
    }
    //Always deny items when we can't put the item anywhere
    IInventoryUtil invUtil = parentChassis.getSneakyInventory(false, ModulePositionType.SLOT, ((ChassiTargetInformation) bestresult.addInfo).getModuleSlot());
    if (invUtil == null) {
        return null;
    }
    int roomForItem = invUtil.roomForItem(item);
    if (roomForItem < 1) {
        return null;
    }
    if (includeInTransit) {
        int onRoute = parentChassis.countOnRoute(item);
        roomForItem = invUtil.roomForItem(item, onRoute + item.getMaxStackSize());
        roomForItem -= onRoute;
        if (roomForItem < 1) {
            return null;
        }
    }
    if (bestresult.maxNumberOfItems == 0) {
        return new SinkReply(bestresult, roomForItem);
    }
    return new SinkReply(bestresult, Math.min(bestresult.maxNumberOfItems, roomForItem));
}
Also used : SinkReply(logisticspipes.utils.SinkReply) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil)

Example 4 with LogisticsModule

use of logisticspipes.modules.abstractmodules.LogisticsModule in project LogisticsPipes by RS485.

the class ModuleInHandGuiProvider method getLogisticsModule.

public final LogisticsModule getLogisticsModule(EntityPlayer player) {
    ItemStack item = player.inventory.mainInventory[invSlot];
    if (item == null) {
        return null;
    }
    LogisticsModule module = LogisticsPipes.ModuleItem.getModuleForItem(item, null, new DummyWorldProvider(player.getEntityWorld()), null);
    module.registerPosition(ModulePositionType.IN_HAND, invSlot);
    ItemModuleInformationManager.readInformation(item, module);
    return module;
}
Also used : DummyWorldProvider(logisticspipes.utils.DummyWorldProvider) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) ItemStack(net.minecraft.item.ItemStack)

Example 5 with LogisticsModule

use of logisticspipes.modules.abstractmodules.LogisticsModule in project LogisticsPipes by RS485.

the class PipeLogisticsChassi method getSpecificInterests.

@Override
public Set<ItemIdentifier> getSpecificInterests() {
    Set<ItemIdentifier> l1 = new TreeSet<>();
    //if we don't have a pointed inventory we can't be interested in anything
    if (getRealInventory() == null) {
        return l1;
    }
    for (int moduleIndex = 0; moduleIndex < getChassiSize(); moduleIndex++) {
        LogisticsModule module = _module.getSubModule(moduleIndex);
        if (module != null && module.interestedInAttachedInventory()) {
            IInventoryUtil inv = getSneakyInventory(false, module.getSlot(), module.getPositionInt());
            if (inv == null) {
                continue;
            }
            Set<ItemIdentifier> items = inv.getItems();
            l1.addAll(items);
            //also add tag-less variants ... we should probably add a module.interestedIgnoringNBT at some point
            l1.addAll(items.stream().map(ItemIdentifier::getIgnoringNBT).collect(Collectors.toList()));
            boolean modulesInterestedInUndamged = false;
            for (int i = 0; i < getChassiSize(); i++) {
                if (_module.getSubModule(moduleIndex).interestedInUndamagedID()) {
                    modulesInterestedInUndamged = true;
                    break;
                }
            }
            if (modulesInterestedInUndamged) {
                l1.addAll(items.stream().map(ItemIdentifier::getUndamaged).collect(Collectors.toList()));
            }
            // no need to check other modules for interest in the inventory, when we know that 1 already is.
            break;
        }
    }
    for (int i = 0; i < getChassiSize(); i++) {
        LogisticsModule module = _module.getSubModule(i);
        if (module != null) {
            Collection<ItemIdentifier> current = module.getSpecificInterests();
            if (current != null) {
                l1.addAll(current);
            }
        }
    }
    return l1;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) TreeSet(java.util.TreeSet) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil)

Aggregations

LogisticsModule (logisticspipes.modules.abstractmodules.LogisticsModule)16 ILegacyActiveModule (logisticspipes.interfaces.ILegacyActiveModule)4 ItemStack (net.minecraft.item.ItemStack)4 SinkReply (logisticspipes.utils.SinkReply)3 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)2 IRequireReliableTransport (logisticspipes.interfaces.routing.IRequireReliableTransport)2 TreeSet (java.util.TreeSet)1 GuiChassiPipe (logisticspipes.gui.GuiChassiPipe)1 IBufferItems (logisticspipes.interfaces.IBufferItems)1 IFilter (logisticspipes.interfaces.routing.IFilter)1 ItemModule (logisticspipes.items.ItemModule)1 LogisticsGuiModule (logisticspipes.modules.abstractmodules.LogisticsGuiModule)1 ModernPacket (logisticspipes.network.abstractpackets.ModernPacket)1 ChassiePipeModuleContent (logisticspipes.network.packets.pipe.ChassiePipeModuleContent)1 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)1 LogisticsOrder (logisticspipes.routing.order.LogisticsOrder)1 DummyWorldProvider (logisticspipes.utils.DummyWorldProvider)1 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)1 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1