Search in sources :

Example 16 with Adjacent

use of network.rs485.logisticspipes.connection.Adjacent in project LogisticsPipes by RS485.

the class CoreRoutedPipe method getConnectedRawInventories.

protected List<IInventory> getConnectedRawInventories() {
    if (_cachedAdjacentInventories == null) {
        WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(container);
        _cachedAdjacentInventories = worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).map(adjacent -> (IInventory) adjacent.tileEntity).collect(Collectors.toList());
    }
    return _cachedAdjacentInventories;
}
Also used : Arrays(java.util.Arrays) OrientationsUtil(logisticspipes.utils.OrientationsUtil) IRequireReliableFluidTransport(logisticspipes.interfaces.routing.IRequireReliableFluidTransport) IOrderInfoProvider(logisticspipes.routing.order.IOrderInfoProvider) MainProxy(logisticspipes.proxy.MainProxy) ILogisticsPowerProvider(logisticspipes.api.ILogisticsPowerProvider) Configs(logisticspipes.config.Configs) SinkReply(logisticspipes.utils.SinkReply) PipeController(logisticspipes.network.guis.pipe.PipeController) Map(java.util.Map) TransportLayer(logisticspipes.logisticspipes.TransportLayer) LogisticsRenderPipe(logisticspipes.renderer.LogisticsRenderPipe) LogisticsSecurityTileEntity(logisticspipes.blocks.LogisticsSecurityTileEntity) DebugLogController(logisticspipes.pipes.basic.debug.DebugLogController) NewGuiHandler(logisticspipes.network.NewGuiHandler) ILPPositionProvider(logisticspipes.interfaces.ILPPositionProvider) ModulePositionType(logisticspipes.modules.abstractmodules.LogisticsModule.ModulePositionType) CCConstants(logisticspipes.proxy.cc.CCConstants) LogisticsOrderManager(logisticspipes.routing.order.LogisticsOrderManager) PipeSignTypes(logisticspipes.network.packets.pipe.PipeSignTypes) CacheHolder(logisticspipes.utils.CacheHolder) LogisticsGuiModule(logisticspipes.modules.abstractmodules.LogisticsGuiModule) Set(java.util.Set) PacketHandler(logisticspipes.network.PacketHandler) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ExitRoute(logisticspipes.routing.ExitRoute) ISecurityProvider(logisticspipes.interfaces.ISecurityProvider) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) IFilter(logisticspipes.interfaces.routing.IFilter) IClientState(logisticspipes.interfaces.IClientState) ParticleFX(logisticspipes.network.packets.pipe.ParticleFX) PipeFXRenderHandler(logisticspipes.pipefxhandlers.PipeFXRenderHandler) FluidStack(net.minecraftforge.fluids.FluidStack) ModDependentMethod(logisticspipes.asm.ModDependentMethod) ITrackStatistics(logisticspipes.logisticspipes.ITrackStatistics) ArrayList(java.util.ArrayList) StatUpdate(logisticspipes.network.packets.pipe.StatUpdate) UpgradeManager(logisticspipes.pipes.upgrades.UpgradeManager) ItemStack(net.minecraft.item.ItemStack) ISubSystemPowerProvider(logisticspipes.interfaces.ISubSystemPowerProvider) StatusEntry(logisticspipes.pipes.basic.debug.StatusEntry) IWorldProvider(logisticspipes.interfaces.IWorldProvider) LogisticsItemOrderManager(logisticspipes.routing.order.LogisticsItemOrderManager) World(net.minecraft.world.World) SecuritySettings(logisticspipes.security.SecuritySettings) IPipeUpgradeManager(logisticspipes.interfaces.IPipeUpgradeManager) TreeMap(java.util.TreeMap) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) IWatchingHandler(logisticspipes.interfaces.IWatchingHandler) PipeTransportLayer(logisticspipes.logisticspipes.PipeTransportLayer) TileEntity(net.minecraft.tileentity.TileEntity) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) IRouter(logisticspipes.routing.IRouter) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) Textures(logisticspipes.textures.Textures) Item(net.minecraft.item.Item) LogisticsPipes(logisticspipes.LogisticsPipes) Particles(logisticspipes.pipefxhandlers.Particles) Random(java.util.Random) CCType(logisticspipes.proxy.computers.interfaces.CCType) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) PriorityBlockingQueue(java.util.concurrent.PriorityBlockingQueue) IRequireReliableTransport(logisticspipes.interfaces.routing.IRequireReliableTransport) NBTTagList(net.minecraft.nbt.NBTTagList) FluidIdentifier(logisticspipes.utils.FluidIdentifier) SidedInventoryMinecraftAdapter(logisticspipes.utils.SidedInventoryMinecraftAdapter) CCCommand(logisticspipes.proxy.computers.interfaces.CCCommand) ILPTEInformation(logisticspipes.asm.te.ILPTEInformation) IAdditionalTargetInformation(logisticspipes.interfaces.routing.IAdditionalTargetInformation) IQueueCCEvent(logisticspipes.interfaces.IQueueCCEvent) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ModernPacket(logisticspipes.network.abstractpackets.ModernPacket) ConnectionPipeType(logisticspipes.routing.pathfinder.IPipeInformationProvider.ConnectionPipeType) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) RouteLayer(logisticspipes.logisticspipes.RouteLayer) Triplet(logisticspipes.utils.tuples.Triplet) UUID(java.util.UUID) IHighlightPlacementRenderer(logisticspipes.renderer.newpipe.IHighlightPlacementRenderer) LPDataOutput(network.rs485.logisticspipes.util.LPDataOutput) Collectors(java.util.stream.Collectors) TransportMode(logisticspipes.logisticspipes.IRoutedItem.TransportMode) ServerRouter(logisticspipes.routing.ServerRouter) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) ItemPipeSignCreator(logisticspipes.items.ItemPipeSignCreator) List(java.util.List) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Pair(logisticspipes.utils.tuples.Pair) Entry(java.util.Map.Entry) Queue(java.util.Queue) GuiIDs(logisticspipes.network.GuiIDs) IPipeSign(logisticspipes.pipes.signs.IPipeSign) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) Getter(lombok.Getter) CCSecurtiyCheck(logisticspipes.proxy.computers.interfaces.CCSecurtiyCheck) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) RequestSignPacket(logisticspipes.network.packets.pipe.RequestSignPacket) PermissionException(logisticspipes.security.PermissionException) CrashReportCategory(net.minecraft.crash.CrashReportCategory) Minecraft(net.minecraft.client.Minecraft) IRequestItems(logisticspipes.interfaces.routing.IRequestItems) ISlotUpgradeManager(logisticspipes.interfaces.ISlotUpgradeManager) ExtractionMode(logisticspipes.logisticspipes.ExtractionMode) ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) LPTravelingItemServer(logisticspipes.transport.LPTravelingItem.LPTravelingItemServer) LinkedList(java.util.LinkedList) LPConstants(logisticspipes.LPConstants) InventoryHelper(logisticspipes.utils.InventoryHelper) LPDataInput(network.rs485.logisticspipes.util.LPDataInput) CCDirectCall(logisticspipes.proxy.computers.interfaces.CCDirectCall) TextureType(logisticspipes.textures.Textures.TextureType) PipeTransportLogistics(logisticspipes.transport.PipeTransportLogistics) IInventory(net.minecraft.inventory.IInventory) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) BitSet(java.util.BitSet) Collections(java.util.Collections) IInventory(net.minecraft.inventory.IInventory) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper)

Example 17 with Adjacent

use of network.rs485.logisticspipes.connection.Adjacent in project LogisticsPipes by RS485.

the class PowerSupplierHandler method update.

public void update() {
    if (SimpleServiceLocator.cofhPowerProxy.isAvailable() && pipe.getUpgradeManager().hasRFPowerSupplierUpgrade()) {
        //Use Buffer
        Stream<AdjacentTileEntity> adjacentTileEntityStream = new WorldCoordinatesWrapper(pipe.container).getAdjacentTileEntities();
        double globalNeed = 0;
        double[] need = new double[(int) adjacentTileEntityStream.count()];
        adjacentTileEntityStream = new WorldCoordinatesWrapper(pipe.container).getAdjacentTileEntities();
        int i = 0;
        Iterator<AdjacentTileEntity> adjacentIt = adjacentTileEntityStream.iterator();
        while (adjacentIt.hasNext()) {
            AdjacentTileEntity adjacent = adjacentIt.next();
            if (SimpleServiceLocator.cofhPowerProxy.isEnergyReceiver(adjacent.tileEntity)) {
                if (pipe.canPipeConnect(adjacent.tileEntity, adjacent.direction)) {
                    ICoFHEnergyReceiver energyReceiver = SimpleServiceLocator.cofhPowerProxy.getEnergyReceiver(adjacent.tileEntity);
                    ForgeDirection oppositeDir = adjacent.direction.getOpposite();
                    if (energyReceiver.canConnectEnergy(oppositeDir)) {
                        globalNeed += need[i] = (energyReceiver.getMaxEnergyStored(oppositeDir) - energyReceiver.getEnergyStored(oppositeDir));
                    }
                }
            }
            ++i;
        }
        if (globalNeed != 0 && !Double.isNaN(globalNeed)) {
            double fullfillable = Math.min(1, internalBufferRF / globalNeed);
            i = 0;
            adjacentIt = adjacentTileEntityStream.iterator();
            while (adjacentIt.hasNext()) {
                AdjacentTileEntity adjacent = adjacentIt.next();
                if (SimpleServiceLocator.cofhPowerProxy.isEnergyReceiver(adjacent.tileEntity)) {
                    if (pipe.canPipeConnect(adjacent.tileEntity, adjacent.direction)) {
                        ICoFHEnergyReceiver energyReceiver = SimpleServiceLocator.cofhPowerProxy.getEnergyReceiver(adjacent.tileEntity);
                        ForgeDirection oppositeDir = adjacent.direction.getOpposite();
                        if (energyReceiver.canConnectEnergy(oppositeDir)) {
                            if (internalBufferRF + 1 < need[i] * fullfillable) {
                                return;
                            }
                            int used = energyReceiver.receiveEnergy(oppositeDir, (int) (need[i] * fullfillable), false);
                            if (used > 0) {
                                pipe.container.addLaser(adjacent.direction, 0.5F, LogisticsPowerProviderTileEntity.RF_COLOR, false, true);
                                internalBufferRF -= used;
                            }
                            if (internalBufferRF < 0) {
                                internalBufferRF = 0;
                                return;
                            }
                        }
                    }
                }
                ++i;
            }
        }
        //Rerequest Buffer
        List<Pair<ISubSystemPowerProvider, List<IFilter>>> provider = pipe.getRouter().getSubSystemPowerProvider();
        double available = 0;
        outer: for (Pair<ISubSystemPowerProvider, List<IFilter>> pair : provider) {
            for (IFilter filter : pair.getValue2()) {
                if (filter.blockPower()) {
                    continue outer;
                }
            }
            if (pair.getValue1().usePaused()) {
                continue;
            }
            if (!pair.getValue1().getBrand().equals("RF")) {
                continue;
            }
            available += pair.getValue1().getPowerLevel();
        }
        if (available > 0) {
            double neededPower = PowerSupplierHandler.INTERNAL_RF_BUFFER_MAX - internalBufferRF;
            if (neededPower > 0) {
                if (pipe.useEnergy((int) (neededPower / 100), false)) {
                    outer: for (Pair<ISubSystemPowerProvider, List<IFilter>> pair : provider) {
                        for (IFilter filter : pair.getValue2()) {
                            if (filter.blockPower()) {
                                continue outer;
                            }
                        }
                        if (pair.getValue1().usePaused()) {
                            continue;
                        }
                        if (!pair.getValue1().getBrand().equals("RF")) {
                            continue;
                        }
                        double requestamount = neededPower * (pair.getValue1().getPowerLevel() / available);
                        pair.getValue1().requestPower(pipe.getRouterId(), requestamount);
                    }
                }
            }
        }
    }
    if (SimpleServiceLocator.IC2Proxy.hasIC2() && pipe.getUpgradeManager().getIC2PowerLevel() > 0) {
        //Use Buffer
        Stream<AdjacentTileEntity> adjacentTileEntityStream = new WorldCoordinatesWrapper(pipe.container).getAdjacentTileEntities();
        double globalNeed = 0;
        double[] need = new double[(int) adjacentTileEntityStream.count()];
        adjacentTileEntityStream = new WorldCoordinatesWrapper(pipe.container).getAdjacentTileEntities();
        int i = 0;
        Iterator<AdjacentTileEntity> adjacentIt = adjacentTileEntityStream.iterator();
        while (adjacentIt.hasNext()) {
            AdjacentTileEntity adjacent = adjacentIt.next();
            if (SimpleServiceLocator.IC2Proxy.isEnergySink(adjacent.tileEntity)) {
                if (pipe.canPipeConnect(adjacent.tileEntity, adjacent.direction)) {
                    if (SimpleServiceLocator.IC2Proxy.acceptsEnergyFrom(adjacent.tileEntity, pipe.container, adjacent.direction.getOpposite())) {
                        globalNeed += need[i] = SimpleServiceLocator.IC2Proxy.demandedEnergyUnits(adjacent.tileEntity);
                    }
                }
            }
            ++i;
        }
        if (globalNeed != 0 && !Double.isNaN(globalNeed)) {
            double fullfillable = Math.min(1, internalBufferIC2 / globalNeed);
            i = 0;
            adjacentIt = adjacentTileEntityStream.iterator();
            while (adjacentIt.hasNext()) {
                AdjacentTileEntity adjacent = adjacentIt.next();
                if (SimpleServiceLocator.IC2Proxy.isEnergySink(adjacent.tileEntity) && pipe.canPipeConnect(adjacent.tileEntity, adjacent.direction) && SimpleServiceLocator.IC2Proxy.acceptsEnergyFrom(adjacent.tileEntity, pipe.container, adjacent.direction.getOpposite())) {
                    if (internalBufferIC2 + 1 < need[i] * fullfillable) {
                        return;
                    }
                    double toUse = Math.min(pipe.getUpgradeManager().getIC2PowerLevel(), need[i] * fullfillable);
                    double unUsed = SimpleServiceLocator.IC2Proxy.injectEnergyUnits(adjacent.tileEntity, adjacent.direction.getOpposite(), toUse);
                    double used = toUse - unUsed;
                    if (used > 0) {
                        //MainProxy.sendPacketToAllWatchingChunk(this.pipe.getX(), this.pipe.getZ(), MainProxy.getDimensionForWorld(this.pipe.getWorld()), PacketHandler.getPacket(PowerPacketLaser.class).setColor(LogisticsPowerProviderTileEntity.IC2_COLOR).setPos(this.pipe.getLPPosition()).setRenderBall(true).setDir(adTile.orientation).setLength(0.5F));
                        pipe.container.addLaser(adjacent.direction, 0.5F, LogisticsPowerProviderTileEntity.IC2_COLOR, false, true);
                        internalBufferIC2 -= used;
                    }
                    if (internalBufferIC2 < 0) {
                        internalBufferIC2 = 0;
                        return;
                    }
                }
                ++i;
            }
        }
        //Rerequest Buffer
        List<Pair<ISubSystemPowerProvider, List<IFilter>>> provider = pipe.getRouter().getSubSystemPowerProvider();
        double available = 0;
        outer: for (Pair<ISubSystemPowerProvider, List<IFilter>> pair : provider) {
            for (IFilter filter : pair.getValue2()) {
                if (filter.blockPower()) {
                    continue outer;
                }
            }
            if (pair.getValue1().usePaused()) {
                continue;
            }
            if (!pair.getValue1().getBrand().equals("EU")) {
                continue;
            }
            available += pair.getValue1().getPowerLevel();
        }
        if (available > 0) {
            double neededPower = PowerSupplierHandler.INTERNAL_IC2_BUFFER_MAX - internalBufferIC2;
            if (neededPower > 0) {
                if (pipe.useEnergy((int) (neededPower / 10000), false)) {
                    outer: for (Pair<ISubSystemPowerProvider, List<IFilter>> pair : provider) {
                        for (IFilter filter : pair.getValue2()) {
                            if (filter.blockPower()) {
                                continue outer;
                            }
                        }
                        if (pair.getValue1().usePaused()) {
                            continue;
                        }
                        if (!pair.getValue1().getBrand().equals("EU")) {
                            continue;
                        }
                        double requestamount = neededPower * (pair.getValue1().getPowerLevel() / available);
                        pair.getValue1().requestPower(pipe.getRouterId(), requestamount);
                    }
                }
            }
        }
    }
}
Also used : IFilter(logisticspipes.interfaces.routing.IFilter) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity) ICoFHEnergyReceiver(logisticspipes.proxy.cofh.subproxies.ICoFHEnergyReceiver) Pair(logisticspipes.utils.tuples.Pair)

Example 18 with Adjacent

use of network.rs485.logisticspipes.connection.Adjacent in project LogisticsPipes by RS485.

the class LogisticsTileGenericPipe method scheduleNeighborChange.

@Override
public void scheduleNeighborChange() {
    tilePart.scheduleNeighborChange();
    tdPart.scheduleNeighborChange();
    blockNeighborChange = true;
    boolean[] connected = new boolean[6];
    new WorldCoordinatesWrapper(this).getAdjacentTileEntities().filter(adjacent -> SimpleServiceLocator.ccProxy.isTurtle(adjacent.tileEntity)).forEach(adjacent -> connected[adjacent.direction.ordinal()] = true);
    for (int i = 0; i < 6; i++) {
        if (!connected[i]) {
            turtleConnect[i] = false;
        }
    }
}
Also used : Arrays(java.util.Arrays) ILPPipe(logisticspipes.api.ILPPipe) OrientationsUtil(logisticspipes.utils.OrientationsUtil) ModDependentField(logisticspipes.asm.ModDependentField) IPipeConnection(buildcraft.api.transport.IPipeConnection) Item(net.minecraft.item.Item) LogisticsPipes(logisticspipes.LogisticsPipes) LogisticsSolidTileEntity(logisticspipes.blocks.LogisticsSolidTileEntity) Level(org.apache.logging.log4j.Level) IPipeInformationProvider(logisticspipes.routing.pathfinder.IPipeInformationProvider) MainProxy(logisticspipes.proxy.MainProxy) Block(net.minecraft.block.Block) StackTraceUtil(logisticspipes.utils.StackTraceUtil) ITDPart(logisticspipes.proxy.td.subproxies.ITDPart) Fluid(net.minecraftforge.fluids.Fluid) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ModernPacket(logisticspipes.network.abstractpackets.ModernPacket) PipeTileStatePacket(logisticspipes.network.packets.pipe.PipeTileStatePacket) Packet(net.minecraft.network.Packet) Side(cpw.mods.fml.relauncher.Side) LogisticsTileRenderController(logisticspipes.renderer.LogisticsTileRenderController) SideOnly(cpw.mods.fml.relauncher.SideOnly) CCObjectWrapper(logisticspipes.proxy.computers.wrapper.CCObjectWrapper) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) Set(java.util.Set) AxisAlignedBB(net.minecraft.util.AxisAlignedBB) PacketHandler(logisticspipes.network.PacketHandler) IBCTilePart(logisticspipes.proxy.buildcraft.subproxies.IBCTilePart) IConnectionOverrideResult(logisticspipes.proxy.buildcraft.subproxies.IConnectionOverrideResult) LPDataOutput(network.rs485.logisticspipes.util.LPDataOutput) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) LPPositionSet(logisticspipes.utils.LPPositionSet) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) Info(logisticspipes.utils.StackTraceUtil.Info) List(java.util.List) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) Stream(java.util.stream.Stream) SidedEnvironment(li.cil.oc.api.network.SidedEnvironment) IOCTile(logisticspipes.proxy.opencomputers.IOCTile) FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) IFilter(logisticspipes.interfaces.routing.IFilter) LogicController(logisticspipes.logic.LogicController) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IClientState(logisticspipes.interfaces.IClientState) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) FluidStack(net.minecraftforge.fluids.FluidStack) TileGenericPipe(buildcraft.transport.TileGenericPipe) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) PipeRenderState(logisticspipes.renderer.state.PipeRenderState) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) ILPPipeTile(logisticspipes.api.ILPPipeTile) IPipe(buildcraft.api.transport.IPipe) DoubleCoordinatesType(network.rs485.logisticspipes.world.DoubleCoordinatesType) Context(li.cil.oc.api.machine.Context) Message(li.cil.oc.api.network.Message) Getter(lombok.Getter) HashMap(java.util.HashMap) ModDependentMethod(logisticspipes.asm.ModDependentMethod) HashSet(java.util.HashSet) ItemStack(net.minecraft.item.ItemStack) BaseWrapperClass(logisticspipes.proxy.opencomputers.asm.BaseWrapperClass) CrashReportCategory(net.minecraft.crash.CrashReportCategory) ModDependentInterface(logisticspipes.asm.ModDependentInterface) Environment(li.cil.oc.api.network.Environment) IBCPluggableState(logisticspipes.proxy.buildcraft.subproxies.IBCPluggableState) LPConstants(logisticspipes.LPConstants) Node(li.cil.oc.api.network.Node) LPDataInput(network.rs485.logisticspipes.util.LPDataInput) World(net.minecraft.world.World) Arguments(li.cil.oc.api.machine.Arguments) IPipeTile(buildcraft.api.transport.IPipeTile) IItemDuct(cofh.api.transport.IItemDuct) ManagedPeripheral(li.cil.oc.api.network.ManagedPeripheral) EnumColor(buildcraft.api.core.EnumColor) TileBuffer(logisticspipes.utils.TileBuffer) IComputerAccess(dan200.computercraft.api.peripheral.IComputerAccess) PipeItemsFirewall(logisticspipes.pipes.PipeItemsFirewall) ILogicControllerTile(logisticspipes.logic.interfaces.ILogicControllerTile) IIconProvider(logisticspipes.renderer.IIconProvider) TileEntity(net.minecraft.tileentity.TileEntity) LPTravelingItem(logisticspipes.transport.LPTravelingItem) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper)

Example 19 with Adjacent

use of network.rs485.logisticspipes.connection.Adjacent in project LogisticsPipes by RS485.

the class LogisticsEventListener method onPlayerInteract.

@SubscribeEvent
public void onPlayerInteract(final PlayerInteractEvent event) {
    if (MainProxy.isServer(event.entityPlayer.worldObj)) {
        if (event.action == Action.LEFT_CLICK_BLOCK) {
            final TileEntity tile = event.entityPlayer.worldObj.getTileEntity(event.x, event.y, event.z);
            if (tile instanceof LogisticsTileGenericPipe) {
                if (((LogisticsTileGenericPipe) tile).pipe instanceof CoreRoutedPipe) {
                    if (!((CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe).canBeDestroyedByPlayer(event.entityPlayer)) {
                        event.setCanceled(true);
                        event.entityPlayer.addChatComponentMessage(new ChatComponentTranslation("lp.chat.permissiondenied"));
                        ((LogisticsTileGenericPipe) tile).scheduleNeighborChange();
                        event.entityPlayer.worldObj.markBlockForUpdate(tile.xCoord, tile.yCoord, tile.zCoord);
                        ((CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe).delayTo = System.currentTimeMillis() + 200;
                        ((CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe).repeatFor = 10;
                    } else {
                        ((CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe).setDestroyByPlayer();
                    }
                }
            }
        }
        if (event.action == Action.RIGHT_CLICK_BLOCK) {
            WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(event.entityPlayer.worldObj, event.x, event.y, event.z);
            TileEntity tileEntity = worldCoordinates.getTileEntity();
            if (tileEntity instanceof TileEntityChest || SimpleServiceLocator.ironChestProxy.isIronChest(tileEntity)) {
                //@formatter:off
                List<WeakReference<ModuleQuickSort>> list = worldCoordinates.getAdjacentTileEntities().filter(adjacent -> adjacent.tileEntity instanceof LogisticsTileGenericPipe).filter(adjacent -> ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe instanceof PipeLogisticsChassi).filter(adjacent -> ((PipeLogisticsChassi) ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe).getPointedOrientation() == adjacent.direction.getOpposite()).map(adjacent -> (PipeLogisticsChassi) ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe).flatMap(pipeLogisticsChassi -> Arrays.stream(pipeLogisticsChassi.getModules().getModules())).filter(logisticsModule -> logisticsModule instanceof ModuleQuickSort).map(logisticsModule -> new WeakReference<>((ModuleQuickSort) logisticsModule)).collect(Collectors.toList());
                if (!list.isEmpty()) {
                    LogisticsEventListener.chestQuickSortConnection.put(event.entityPlayer, list);
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Action(net.minecraftforge.event.entity.player.PlayerInteractEvent.Action) Arrays(java.util.Arrays) ModuleQuickSort(logisticspipes.modules.ModuleQuickSort) MainProxy(logisticspipes.proxy.MainProxy) VersionChecker(logisticspipes.ticks.VersionChecker) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) Configs(logisticspipes.config.Configs) ChestGuiOpened(logisticspipes.network.packets.chassis.ChestGuiOpened) ChatComponentText(net.minecraft.util.ChatComponentText) LogisticsHUDRenderer(logisticspipes.renderer.LogisticsHUDRenderer) LogisticsGuiOverrenderer(logisticspipes.renderer.LogisticsGuiOverrenderer) Map(java.util.Map) FMLClientHandler(cpw.mods.fml.client.FMLClientHandler) PlayerLoggedInEvent(cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent) PlayerLoggedOutEvent(cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent) ClientConnectedToServerEvent(cpw.mods.fml.common.network.FMLNetworkEvent.ClientConnectedToServerEvent) EntityItem(net.minecraft.entity.item.EntityItem) ChestGuiClosed(logisticspipes.network.packets.chassis.ChestGuiClosed) Side(cpw.mods.fml.relauncher.Side) SideOnly(cpw.mods.fml.relauncher.SideOnly) UnWatch(net.minecraftforge.event.world.ChunkWatchEvent.UnWatch) WorldEvent(net.minecraftforge.event.world.WorldEvent) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PacketHandler(logisticspipes.network.PacketHandler) Collectors(java.util.stream.Collectors) List(java.util.List) EntityJoinWorldEvent(net.minecraftforge.event.entity.EntityJoinWorldEvent) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) PipeLogisticsChassi(logisticspipes.pipes.PipeLogisticsChassi) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent) PlayerIdentifier(logisticspipes.utils.PlayerIdentifier) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) Queue(java.util.Queue) PlayerConfig(logisticspipes.config.PlayerConfig) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) Setter(lombok.Setter) Getter(lombok.Getter) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) GuiReopenPacket(logisticspipes.network.packets.gui.GuiReopenPacket) HashMap(java.util.HashMap) PlayerConfigToClientPacket(logisticspipes.network.packets.PlayerConfigToClientPacket) Watch(net.minecraftforge.event.world.ChunkWatchEvent.Watch) TileEntityChest(net.minecraft.tileentity.TileEntityChest) ItemStack(net.minecraft.item.ItemStack) IItemAdvancedExistance(logisticspipes.interfaces.IItemAdvancedExistance) TextureStitchEvent(net.minecraftforge.client.event.TextureStitchEvent) EntityClientPlayerMP(net.minecraft.client.entity.EntityClientPlayerMP) WeakReference(java.lang.ref.WeakReference) LinkedList(java.util.LinkedList) PlayerInteractEvent(net.minecraftforge.event.entity.player.PlayerInteractEvent) WeakHashMap(java.util.WeakHashMap) IOException(java.io.IOException) GuiChest(net.minecraft.client.gui.inventory.GuiChest) GuiOpenEvent(net.minecraftforge.client.event.GuiOpenEvent) QuickSortChestMarkerStorage(logisticspipes.utils.QuickSortChestMarkerStorage) TileEntity(net.minecraft.tileentity.TileEntity) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) AllArgsConstructor(lombok.AllArgsConstructor) TileEntityChest(net.minecraft.tileentity.TileEntityChest) PipeLogisticsChassi(logisticspipes.pipes.PipeLogisticsChassi) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) WeakReference(java.lang.ref.WeakReference) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) ModuleQuickSort(logisticspipes.modules.ModuleQuickSort) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 20 with Adjacent

use of network.rs485.logisticspipes.connection.Adjacent in project LogisticsPipes by RS485.

the class ModuleProvider method sendStack.

// returns -1 on permanently failed, don't try another stack this tick
// returns 0 on "unable to do this delivery"
public int sendStack(ItemIdentifierStack stack, int maxCount, int destination, IAdditionalTargetInformation info) {
    final IPipeServiceProvider service = _service;
    if (service == null)
        return -1;
    ItemIdentifier item = stack.getItem();
    Iterator<Pair<IInventoryUtil, EnumFacing>> iterator = service.getAvailableAdjacent().inventories().stream().flatMap(neighbor -> {
        final IInventoryUtil invUtil = getInventoryUtilWithMode(neighbor);
        if (invUtil == null)
            return Stream.empty();
        return Stream.of(new Pair<>(invUtil, neighbor.getDirection()));
    }).iterator();
    while (iterator.hasNext()) {
        final Pair<IInventoryUtil, EnumFacing> current = iterator.next();
        int available = current.getValue1().itemCount(item);
        if (available == 0) {
            continue;
        }
        int wanted = Math.min(available, stack.getStackSize());
        wanted = Math.min(wanted, maxCount);
        wanted = Math.min(wanted, item.getMaxStackSize());
        IRouter dRtr = SimpleServiceLocator.routerManager.getServerRouter(destination);
        if (dRtr == null) {
            service.getItemOrderManager().sendFailed();
            return 0;
        }
        SinkReply reply = LogisticsManager.canSink(stack.makeNormalStack(), dRtr, null, true, stack.getItem(), null, true, false);
        boolean defersend = false;
        if (reply != null) {
            // some pipes are not aware of the space in the adjacent inventory, so they return null
            if (reply.maxNumberOfItems < wanted) {
                wanted = reply.maxNumberOfItems;
                if (wanted <= 0) {
                    service.getItemOrderManager().deferSend();
                    return 0;
                }
                defersend = true;
            }
        }
        if (!service.canUseEnergy(wanted * neededEnergy())) {
            return -1;
        }
        ItemStack removed = current.getValue1().getMultipleItems(item, wanted);
        if (removed.isEmpty()) {
            continue;
        }
        int sent = removed.getCount();
        service.useEnergy(sent * neededEnergy());
        final IRoutedItem routedItem = service.sendStack(removed, destination, itemSendMode(), info, current.getValue2());
        service.getItemOrderManager().sendSuccessfull(sent, defersend, routedItem);
        return sent;
    }
    service.getItemOrderManager().sendFailed();
    return 0;
}
Also used : ModuleInHandGuiProvider(logisticspipes.network.abstractguis.ModuleInHandGuiProvider) IRouter(logisticspipes.routing.IRouter) NeighborTileEntity(network.rs485.logisticspipes.connection.NeighborTileEntity) SneakyModuleDirectionUpdate(logisticspipes.network.packets.modules.SneakyModuleDirectionUpdate) Particles(logisticspipes.pipefxhandlers.Particles) CCType(logisticspipes.proxy.computers.interfaces.CCType) MainProxy(logisticspipes.proxy.MainProxy) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) SinkReply(logisticspipes.utils.SinkReply) HUDStopModuleWatchingPacket(logisticspipes.network.packets.hud.HUDStopModuleWatchingPacket) Map(java.util.Map) CCCommand(logisticspipes.proxy.computers.interfaces.CCCommand) IAdditionalTargetInformation(logisticspipes.interfaces.routing.IAdditionalTargetInformation) IProvideItems(logisticspipes.interfaces.routing.IProvideItems) NewGuiHandler(logisticspipes.network.NewGuiHandler) Collection(java.util.Collection) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) LogisticsManager(logisticspipes.logistics.LogisticsManager) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) IModuleInventoryReceive(logisticspipes.interfaces.IModuleInventoryReceive) PacketHandler(logisticspipes.network.PacketHandler) RequestTreeNode(logisticspipes.request.RequestTreeNode) DictResource(logisticspipes.request.resources.DictResource) Collectors(java.util.stream.Collectors) SneakyDirection(network.rs485.logisticspipes.module.SneakyDirection) ProviderModuleInHand(logisticspipes.network.guis.module.inhand.ProviderModuleInHand) Objects(java.util.Objects) NullableEnumProperty(network.rs485.logisticspipes.property.NullableEnumProperty) List(java.util.List) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) Stream(java.util.stream.Stream) IFilter(logisticspipes.interfaces.routing.IFilter) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BooleanProperty(network.rs485.logisticspipes.property.BooleanProperty) Pair(logisticspipes.utils.tuples.Pair) IHUDModuleHandler(logisticspipes.interfaces.IHUDModuleHandler) Gui(network.rs485.logisticspipes.module.Gui) EnumProperty(network.rs485.logisticspipes.property.EnumProperty) Property(network.rs485.logisticspipes.property.Property) ProviderMode(network.rs485.logisticspipes.inventory.ProviderMode) ItemResource(logisticspipes.request.resources.ItemResource) IItemIdentifierInventory(network.rs485.logisticspipes.inventory.IItemIdentifierInventory) ModuleCoordinatesGuiProvider(logisticspipes.network.abstractguis.ModuleCoordinatesGuiProvider) LogisticsOrder(logisticspipes.routing.order.LogisticsOrder) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) ResourceType(logisticspipes.routing.order.IOrderInfoProvider.ResourceType) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) IClientInformationProvider(logisticspipes.interfaces.IClientInformationProvider) InventoryProperty(network.rs485.logisticspipes.property.InventoryProperty) ImmutableList(com.google.common.collect.ImmutableList) IRequestItems(logisticspipes.interfaces.routing.IRequestItems) ProviderModuleGuiProvider(logisticspipes.network.guis.module.inpipe.ProviderModuleGuiProvider) IModuleWatchReciver(logisticspipes.interfaces.IModuleWatchReciver) Nonnull(javax.annotation.Nonnull) Iterator(java.util.Iterator) IHUDModuleRenderer(logisticspipes.interfaces.IHUDModuleRenderer) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) EnumFacing(net.minecraft.util.EnumFacing) LogisticsPromise(logisticspipes.routing.LogisticsPromise) ItemSendMode(logisticspipes.pipes.basic.CoreRoutedPipe.ItemSendMode) RequestTree(logisticspipes.request.RequestTree) HUDProviderModule(logisticspipes.gui.hud.modules.HUDProviderModule) HUDStartModuleWatchingPacket(logisticspipes.network.packets.hud.HUDStartModuleWatchingPacket) IResource(logisticspipes.request.resources.IResource) ModuleInventory(logisticspipes.network.packets.module.ModuleInventory) TreeMap(java.util.TreeMap) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ILegacyActiveModule(logisticspipes.interfaces.ILegacyActiveModule) TileEntity(net.minecraft.tileentity.TileEntity) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) EnumFacing(net.minecraft.util.EnumFacing) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) IRouter(logisticspipes.routing.IRouter) SinkReply(logisticspipes.utils.SinkReply) ItemStack(net.minecraft.item.ItemStack) Pair(logisticspipes.utils.tuples.Pair)

Aggregations

WorldCoordinatesWrapper (network.rs485.logisticspipes.world.WorldCoordinatesWrapper)16 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)13 IFilter (logisticspipes.interfaces.routing.IFilter)12 TileEntity (net.minecraft.tileentity.TileEntity)12 Pair (logisticspipes.utils.tuples.Pair)11 List (java.util.List)10 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)10 MainProxy (logisticspipes.proxy.MainProxy)10 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)10 ItemStack (net.minecraft.item.ItemStack)10 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)10 Map (java.util.Map)9 PacketHandler (logisticspipes.network.PacketHandler)9 EntityPlayer (net.minecraft.entity.player.EntityPlayer)9 LinkedList (java.util.LinkedList)8 Collectors (java.util.stream.Collectors)8 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)8 PlayerCollectionList (logisticspipes.utils.PlayerCollectionList)8 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)8 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)8