Search in sources :

Example 16 with IPipeServiceProvider

use of logisticspipes.interfaces.IPipeServiceProvider in project LogisticsPipes by RS485.

the class ModuleCrafter method openAttachedGui.

/**
 * Triggers opening the first possible crafting provider or inventory GUI by using onBlockActivated.
 *
 * @return true, if a GUI was opened (server-side only)
 */
public boolean openAttachedGui(EntityPlayer player) {
    if (MainProxy.isClient(player.world)) {
        if (player instanceof EntityPlayerMP) {
            player.closeScreen();
        } else if (player instanceof EntityPlayerSP) {
            player.closeScreen();
        }
        MainProxy.sendPacketToServer(PacketHandler.getPacket(CraftingPipeOpenConnectedGuiPacket.class).setModulePos(this));
        return false;
    }
    final IPipeServiceProvider service = _service;
    if (service == null)
        return false;
    final IWorldProvider worldProvider = _world;
    if (worldProvider == null)
        return false;
    // hack to avoid wrenching blocks
    int savedEquipped = player.inventory.currentItem;
    boolean foundSlot = false;
    // try to find a empty slot
    for (int i = 0; i < 9; i++) {
        if (player.inventory.getStackInSlot(i).isEmpty()) {
            foundSlot = true;
            player.inventory.currentItem = i;
            break;
        }
    }
    // okay, anything that's a block?
    if (!foundSlot) {
        for (int i = 0; i < 9; i++) {
            ItemStack is = player.inventory.getStackInSlot(i);
            if (is.getItem() instanceof ItemBlock) {
                foundSlot = true;
                player.inventory.currentItem = i;
                break;
            }
        }
    }
    // give up and select whatever is right of the current slot
    if (!foundSlot) {
        player.inventory.currentItem = (player.inventory.currentItem + 1) % 9;
    }
    final boolean guiOpened = service.getAvailableAdjacent().neighbors().keySet().stream().anyMatch(neighbor -> {
        if (neighbor.canHandleItems() || SimpleServiceLocator.craftingRecipeProviders.stream().anyMatch(provider -> provider.canOpenGui(neighbor.getTileEntity()))) {
            final BlockPos pos = neighbor.getTileEntity().getPos();
            IBlockState blockState = worldProvider.getWorld().getBlockState(pos);
            return !blockState.getBlock().isAir(blockState, worldProvider.getWorld(), pos) && blockState.getBlock().onBlockActivated(worldProvider.getWorld(), pos, neighbor.getTileEntity().getWorld().getBlockState(pos), player, EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0);
        } else {
            return false;
        }
    });
    if (!guiOpened) {
        LogisticsPipes.log.warn("Ignored open attached GUI request at " + player.world + " @ " + getBlockPos());
    }
    player.inventory.currentItem = savedEquipped;
    return guiOpened;
}
Also used : CPipeSatelliteImportBack(logisticspipes.network.packets.cpipe.CPipeSatelliteImportBack) ChassiTargetInformation(logisticspipes.pipes.PipeLogisticsChassis.ChassiTargetInformation) NeighborTileEntity(network.rs485.logisticspipes.connection.NeighborTileEntity) BitSetProperty(network.rs485.logisticspipes.property.BitSetProperty) Constants(net.minecraftforge.common.util.Constants) EnumHand(net.minecraft.util.EnumHand) MainProxy(logisticspipes.proxy.MainProxy) FluidCraftingAmount(logisticspipes.network.packets.pipe.FluidCraftingAmount) SinkReply(logisticspipes.utils.SinkReply) HUDStopModuleWatchingPacket(logisticspipes.network.packets.hud.HUDStopModuleWatchingPacket) ItemCraftingTemplate(logisticspipes.request.ItemCraftingTemplate) Map(java.util.Map) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) NewGuiHandler(logisticspipes.network.NewGuiHandler) LogisticsExtraPromise(logisticspipes.routing.LogisticsExtraPromise) LogisticsManager(logisticspipes.logistics.LogisticsManager) PacketHandler(logisticspipes.network.PacketHandler) ExitRoute(logisticspipes.routing.ExitRoute) UUIDPropertyKt(network.rs485.logisticspipes.property.UUIDPropertyKt) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) IFilter(logisticspipes.interfaces.routing.IFilter) BooleanProperty(network.rs485.logisticspipes.property.BooleanProperty) LogisticsCraftingTableTileEntity(logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity) BufferMode(logisticspipes.utils.SinkReply.BufferMode) CraftingModuleInHand(logisticspipes.network.guis.module.inhand.CraftingModuleInHand) IItemIdentifierInventory(network.rs485.logisticspipes.inventory.IItemIdentifierInventory) UUIDListProperty(network.rs485.logisticspipes.property.UUIDListProperty) CraftingPipeOpenConnectedGuiPacket(logisticspipes.network.packets.cpipe.CraftingPipeOpenConnectedGuiPacket) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) CraftingModuleSlot(logisticspipes.network.guis.module.inpipe.CraftingModuleSlot) InventoryProperty(network.rs485.logisticspipes.property.InventoryProperty) IWorldProvider(logisticspipes.interfaces.IWorldProvider) LogisticsDictPromise(logisticspipes.routing.LogisticsDictPromise) FuzzyUtil(network.rs485.logisticspipes.util.FuzzyUtil) Nullable(javax.annotation.Nullable) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) BlockPos(net.minecraft.util.math.BlockPos) LogisticsExtraDictPromise(logisticspipes.routing.LogisticsExtraDictPromise) DelayedGeneric(logisticspipes.utils.DelayedGeneric) ItemSendMode(logisticspipes.pipes.basic.CoreRoutedPipe.ItemSendMode) CPipeSatelliteImport(logisticspipes.network.packets.cpipe.CPipeSatelliteImport) HUDStartModuleWatchingPacket(logisticspipes.network.packets.hud.HUDStartModuleWatchingPacket) IResource(logisticspipes.request.resources.IResource) IBlockState(net.minecraft.block.state.IBlockState) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) TileEntity(net.minecraft.tileentity.TileEntity) ItemBlock(net.minecraft.item.ItemBlock) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) ModuleInHandGuiProvider(logisticspipes.network.abstractguis.ModuleInHandGuiProvider) PipeItemsSatelliteLogistics(logisticspipes.pipes.PipeItemsSatelliteLogistics) IRouter(logisticspipes.routing.IRouter) IRequestFluid(logisticspipes.interfaces.routing.IRequestFluid) ItemUpgrade(logisticspipes.items.ItemUpgrade) ICraftingTemplate(logisticspipes.request.ICraftingTemplate) LogisticsPipes(logisticspipes.LogisticsPipes) Particles(logisticspipes.pipefxhandlers.Particles) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) DictCraftingTemplate(logisticspipes.request.DictCraftingTemplate) NBTTagList(net.minecraft.nbt.NBTTagList) FluidIdentifier(logisticspipes.utils.FluidIdentifier) ICraftItems(logisticspipes.interfaces.routing.ICraftItems) LPNeighborTileEntityKt(network.rs485.logisticspipes.connection.LPNeighborTileEntityKt) IAdditionalTargetInformation(logisticspipes.interfaces.routing.IAdditionalTargetInformation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ModernPacket(logisticspipes.network.abstractpackets.ModernPacket) Collection(java.util.Collection) FluidResource(logisticspipes.request.resources.FluidResource) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) IFuzzyRecipeProvider(logisticspipes.proxy.interfaces.IFuzzyRecipeProvider) UUID(java.util.UUID) RequestTreeNode(logisticspipes.request.RequestTreeNode) DictResource(logisticspipes.request.resources.DictResource) TransportMode(logisticspipes.logisticspipes.IRoutedItem.TransportMode) Objects(java.util.Objects) IItemSpaceControl(logisticspipes.interfaces.routing.IItemSpaceControl) List(java.util.List) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) CacheTypes(logisticspipes.utils.CacheHolder.CacheTypes) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Pair(logisticspipes.utils.tuples.Pair) IHUDModuleHandler(logisticspipes.interfaces.IHUDModuleHandler) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) Gui(network.rs485.logisticspipes.module.Gui) Property(network.rs485.logisticspipes.property.Property) IPromise(logisticspipes.request.IPromise) AdjacentUtilKt(network.rs485.logisticspipes.connection.AdjacentUtilKt) ItemResource(logisticspipes.request.resources.ItemResource) Getter(lombok.Getter) ModuleCoordinatesGuiProvider(logisticspipes.network.abstractguis.ModuleCoordinatesGuiProvider) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) IReqCraftingTemplate(logisticspipes.request.IReqCraftingTemplate) ResourceType(logisticspipes.routing.order.IOrderInfoProvider.ResourceType) CoordinatesPacket(logisticspipes.network.abstractpackets.CoordinatesPacket) IBitSet(network.rs485.logisticspipes.property.IBitSet) IntListProperty(network.rs485.logisticspipes.property.IntListProperty) IntegerProperty(network.rs485.logisticspipes.property.IntegerProperty) ImmutableList(com.google.common.collect.ImmutableList) IRequestItems(logisticspipes.interfaces.routing.IRequestItems) IModuleWatchReciver(logisticspipes.interfaces.IModuleWatchReciver) ISlotUpgradeManager(logisticspipes.interfaces.ISlotUpgradeManager) DelayQueue(java.util.concurrent.DelayQueue) WeakReference(java.lang.ref.WeakReference) PipeFluidSatellite(logisticspipes.pipes.PipeFluidSatellite) Nonnull(javax.annotation.Nonnull) IHUDModuleRenderer(logisticspipes.interfaces.IHUDModuleRenderer) IGuiOpenControler(logisticspipes.interfaces.IGuiOpenControler) FixedPriority(logisticspipes.utils.SinkReply.FixedPriority) CraftingPipeUpdatePacket(logisticspipes.network.packets.pipe.CraftingPipeUpdatePacket) EnumFacing(net.minecraft.util.EnumFacing) LogisticsPromise(logisticspipes.routing.LogisticsPromise) RequestTree(logisticspipes.request.RequestTree) UUIDProperty(network.rs485.logisticspipes.property.UUIDProperty) BitSet(java.util.BitSet) IWorldProvider(logisticspipes.interfaces.IWorldProvider) IBlockState(net.minecraft.block.state.IBlockState) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock)

Example 17 with IPipeServiceProvider

use of logisticspipes.interfaces.IPipeServiceProvider in project LogisticsPipes by RS485.

the class ModuleCrafter method canProvide.

@Override
public void canProvide(RequestTreeNode tree, RequestTree root, List<IFilter> filters) {
    final IPipeServiceProvider service = _service;
    if (service == null)
        return;
    if (!service.getItemOrderManager().hasExtras() || tree.hasBeenQueried(service.getItemOrderManager())) {
        return;
    }
    IResource requestedItem = tree.getRequestType();
    if (!canCraft(requestedItem)) {
        return;
    }
    for (IFilter filter : filters) {
        if (filter.isBlocked() == filter.isFilteredItem(requestedItem) || filter.blockProvider()) {
            return;
        }
    }
    int remaining = 0;
    for (LogisticsItemOrder extra : service.getItemOrderManager()) {
        if (extra.getType() == ResourceType.EXTRA) {
            if (extra.getResource().getItem().equals(requestedItem.getAsItem())) {
                remaining += extra.getResource().stack.getStackSize();
            }
        }
    }
    final ItemIdentifierStack craftedItem = getCraftedItem();
    if (craftedItem == null)
        return;
    remaining -= root.getAllPromissesFor(this, craftedItem.getItem());
    if (remaining < 1) {
        return;
    }
    if (getUpgradeManager().isFuzzyUpgrade() && outputFuzzy().nextSetBit(0) != -1) {
        DictResource dict = new DictResource(craftedItem, null).loadFromBitSet(outputFuzzy().copyValue());
        LogisticsExtraDictPromise promise = new LogisticsExtraDictPromise(dict, Math.min(remaining, tree.getMissingAmount()), this, true);
        tree.addPromise(promise);
    } else {
        LogisticsExtraPromise promise = new LogisticsExtraPromise(craftedItem.getItem(), Math.min(remaining, tree.getMissingAmount()), this, true);
        tree.addPromise(promise);
    }
    tree.setQueried(service.getItemOrderManager());
}
Also used : IFilter(logisticspipes.interfaces.routing.IFilter) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) DictResource(logisticspipes.request.resources.DictResource) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) LogisticsExtraDictPromise(logisticspipes.routing.LogisticsExtraDictPromise) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) IResource(logisticspipes.request.resources.IResource) LogisticsExtraPromise(logisticspipes.routing.LogisticsExtraPromise)

Example 18 with IPipeServiceProvider

use of logisticspipes.interfaces.IPipeServiceProvider in project LogisticsPipes by RS485.

the class ModuleCrafter method registerExtras.

@Override
public void registerExtras(IPromise promise) {
    final IPipeServiceProvider service = _service;
    if (service == null)
        return;
    if (promise instanceof LogisticsDictPromise) {
        service.getItemOrderManager().addExtra(((LogisticsDictPromise) promise).getResource());
    } else {
        ItemIdentifierStack stack = new ItemIdentifierStack(promise.getItemType(), promise.getAmount());
        service.getItemOrderManager().addExtra(new DictResource(stack, null));
    }
}
Also used : IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) LogisticsDictPromise(logisticspipes.routing.LogisticsDictPromise) DictResource(logisticspipes.request.resources.DictResource) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack)

Example 19 with IPipeServiceProvider

use of logisticspipes.interfaces.IPipeServiceProvider in project LogisticsPipes by RS485.

the class ModuleCrafter method spaceFor.

protected int spaceFor(@Nonnull ItemStack stack, ItemIdentifier item, boolean includeInTransit) {
    Pair<String, ItemIdentifier> key = new Pair<>("spaceFor", item);
    final IPipeServiceProvider service = _service;
    if (service == null)
        return 0;
    Object cache = service.getCacheHolder().getCacheFor(CacheTypes.Inventory, key);
    int onRoute = 0;
    if (includeInTransit) {
        onRoute = service.countOnRoute(item);
    }
    if (cache != null) {
        return ((Integer) cache) - onRoute;
    }
    if (includeInTransit) {
        stack = stack.copy();
        stack.grow(onRoute);
    }
    final ISlotUpgradeManager upgradeManager = Objects.requireNonNull(getUpgradeManager());
    final ItemStack finalStack = stack;
    final Integer count = AdjacentUtilKt.sneakyInventoryUtils(service.getAvailableAdjacent(), upgradeManager).stream().map(invUtil -> invUtil.roomForItem(finalStack)).reduce(Integer::sum).orElse(0);
    service.getCacheHolder().setCache(CacheTypes.Inventory, key, count);
    return count - onRoute;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) ItemStack(net.minecraft.item.ItemStack) ISlotUpgradeManager(logisticspipes.interfaces.ISlotUpgradeManager) Pair(logisticspipes.utils.tuples.Pair)

Example 20 with IPipeServiceProvider

use of logisticspipes.interfaces.IPipeServiceProvider in project LogisticsPipes by RS485.

the class ModuleCrafter method fullFill.

@Override
public LogisticsItemOrder fullFill(LogisticsPromise promise, IRequestItems destination, IAdditionalTargetInformation info) {
    final IPipeServiceProvider service = _service;
    if (service == null)
        return null;
    if (promise instanceof LogisticsExtraDictPromise) {
        service.getItemOrderManager().removeExtras(((LogisticsExtraDictPromise) promise).getResource());
    }
    if (promise instanceof LogisticsExtraPromise) {
        service.getItemOrderManager().removeExtras(new DictResource(new ItemIdentifierStack(promise.item, promise.numberOfItems), null));
    }
    if (promise instanceof LogisticsDictPromise) {
        service.spawnParticle(Particles.WhiteParticle, 2);
        return service.getItemOrderManager().addOrder(((LogisticsDictPromise) promise).getResource(), destination, ResourceType.CRAFTING, info);
    }
    service.spawnParticle(Particles.WhiteParticle, 2);
    return service.getItemOrderManager().addOrder(new ItemIdentifierStack(promise.item, promise.numberOfItems), destination, ResourceType.CRAFTING, info);
}
Also used : IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) LogisticsDictPromise(logisticspipes.routing.LogisticsDictPromise) DictResource(logisticspipes.request.resources.DictResource) LogisticsExtraDictPromise(logisticspipes.routing.LogisticsExtraDictPromise) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) LogisticsExtraPromise(logisticspipes.routing.LogisticsExtraPromise)

Aggregations

IPipeServiceProvider (logisticspipes.interfaces.IPipeServiceProvider)27 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)14 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)14 ItemStack (net.minecraft.item.ItemStack)13 Nonnull (javax.annotation.Nonnull)11 SinkReply (logisticspipes.utils.SinkReply)10 IAdditionalTargetInformation (logisticspipes.interfaces.routing.IAdditionalTargetInformation)9 DictResource (logisticspipes.request.resources.DictResource)9 List (java.util.List)8 Objects (java.util.Objects)8 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)8 ISlotUpgradeManager (logisticspipes.interfaces.ISlotUpgradeManager)8 LogisticsItemOrder (logisticspipes.routing.order.LogisticsItemOrder)8 Pair (logisticspipes.utils.tuples.Pair)8 ArrayList (java.util.ArrayList)7 Collection (java.util.Collection)7 ItemResource (logisticspipes.request.resources.ItemResource)7 Property (network.rs485.logisticspipes.property.Property)7 ImmutableList (com.google.common.collect.ImmutableList)6 Map (java.util.Map)6