Search in sources :

Example 31 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection 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 32 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.

the class RequestRoutingLasersPacket method processPacket.

@Override
public void processPacket(EntityPlayer player) {
    LogisticsTileGenericPipe tile = this.getPipe(player.worldObj);
    if (tile == null) {
        return;
    }
    if (tile.pipe instanceof CoreRoutedPipe) {
        IRouter router = ((CoreRoutedPipe) tile.pipe).getRouter();
        //this is here to allow players to manually trigger a network-wide LSA update
        router.forceLsaUpdate();
        List<List<ExitRoute>> exits = router.getRouteTable();
        HashMap<ForgeDirection, ArrayList<ExitRoute>> routers = new HashMap<>();
        for (List<ExitRoute> exit : exits) {
            if (exit == null) {
                continue;
            }
            for (ExitRoute e : exit) {
                if (!routers.containsKey(e.exitOrientation)) {
                    routers.put(e.exitOrientation, new ArrayList<>());
                }
                if (!routers.get(e.exitOrientation).contains(e)) {
                    routers.get(e.exitOrientation).add(e);
                }
            }
        }
        ArrayList<LaserData> lasers = new ArrayList<>();
        firstPipe = true;
        for (final ForgeDirection dir : routers.keySet()) {
            if (dir == ForgeDirection.UNKNOWN) {
                continue;
            }
            handleRouteInDirection(tile, dir, routers.get(dir), lasers, EnumSet.allOf(PipeRoutingConnectionType.class), new Log() {

                @Override
                void log(String log) {
                    if (LPConstants.DEBUG) {
                        System.out.println(dir.name() + ": " + log);
                    }
                }
            });
        }
        lasers = compressLasers(lasers);
        MainProxy.sendPacketToPlayer(PacketHandler.getPacket(RoutingLaserPacket.class).setLasers(lasers), player);
    }
}
Also used : PipeRoutingConnectionType(logisticspipes.routing.PipeRoutingConnectionType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) IRouter(logisticspipes.routing.IRouter) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) LaserData(logisticspipes.routing.LaserData) ExitRoute(logisticspipes.routing.ExitRoute)

Example 33 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.

the class PipeItemsProviderLogistics method sendStack.

private int sendStack(ItemIdentifierStack stack, int maxCount, int destination, IAdditionalTargetInformation info) {
    ItemIdentifier item = stack.getItem();
    WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(container);
    //@formatter:off
    Iterator<Pair<IInventoryUtil, ForgeDirection>> iterator = worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).filter(adjacent -> !SimpleServiceLocator.pipeInformationManager.isItemPipe(adjacent.tileEntity)).map(adjacent -> new Pair<>(getAdaptedInventoryUtil(adjacent), adjacent.direction)).iterator();
    while (iterator.hasNext()) {
        Pair<IInventoryUtil, ForgeDirection> next = iterator.next();
        int available = next.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.getRouterUnsafe(destination, false);
        if (dRtr == null) {
            _orderManager.sendFailed();
            return 0;
        }
        SinkReply reply = LogisticsManager.canSink(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) {
                    _orderManager.deferSend();
                    return 0;
                }
                defersend = true;
            }
        }
        if (!canUseEnergy(wanted * neededEnergy())) {
            return -1;
        }
        ItemStack removed = next.getValue1().getMultipleItems(item, wanted);
        if (removed == null || removed.stackSize == 0) {
            continue;
        }
        int sent = removed.stackSize;
        useEnergy(sent * neededEnergy());
        IRoutedItem routedItem = SimpleServiceLocator.routedItemHelper.createNewTravelItem(removed);
        routedItem.setDestination(destination);
        routedItem.setTransportMode(TransportMode.Active);
        routedItem.setAdditionalTargetInformation(info);
        super.queueRoutedItem(routedItem, next.getValue2());
        _orderManager.sendSuccessfull(sent, defersend, routedItem);
        return sent;
    }
    _orderManager.sendFailed();
    return 0;
}
Also used : IRouter(logisticspipes.routing.IRouter) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) Textures(logisticspipes.textures.Textures) Item(net.minecraft.item.Item) LogisticsPipes(logisticspipes.LogisticsPipes) ProviderPipeInclude(logisticspipes.network.packets.modules.ProviderPipeInclude) Particles(logisticspipes.pipefxhandlers.Particles) ChestContent(logisticspipes.network.packets.hud.ChestContent) MainProxy(logisticspipes.proxy.MainProxy) IHeadUpDisplayRenderer(logisticspipes.interfaces.IHeadUpDisplayRenderer) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) HUDStartWatchingPacket(logisticspipes.network.packets.hud.HUDStartWatchingPacket) SinkReply(logisticspipes.utils.SinkReply) SidedInventoryMinecraftAdapter(logisticspipes.utils.SidedInventoryMinecraftAdapter) Map(java.util.Map) ModuleProvider(logisticspipes.modules.ModuleProvider) IAdditionalTargetInformation(logisticspipes.interfaces.routing.IAdditionalTargetInformation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IChangeListener(logisticspipes.interfaces.IChangeListener) HUDStopWatchingPacket(logisticspipes.network.packets.hud.HUDStopWatchingPacket) IProvideItems(logisticspipes.interfaces.routing.IProvideItems) ConnectionPipeType(logisticspipes.routing.pathfinder.IPipeInformationProvider.ConnectionPipeType) Collection(java.util.Collection) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) LogisticsManager(logisticspipes.logistics.LogisticsManager) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) Set(java.util.Set) PacketHandler(logisticspipes.network.PacketHandler) RequestTreeNode(logisticspipes.request.RequestTreeNode) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) DictResource(logisticspipes.request.resources.DictResource) Collectors(java.util.stream.Collectors) TransportMode(logisticspipes.logisticspipes.IRoutedItem.TransportMode) List(java.util.List) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) IChestContentReceiver(logisticspipes.interfaces.IChestContentReceiver) IFilter(logisticspipes.interfaces.routing.IFilter) OrdererManagerContent(logisticspipes.network.packets.orderer.OrdererManagerContent) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Pair(logisticspipes.utils.tuples.Pair) Entry(java.util.Map.Entry) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) GuiIDs(logisticspipes.network.GuiIDs) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) ItemResource(logisticspipes.request.resources.ItemResource) LogisticsOrder(logisticspipes.routing.order.LogisticsOrder) HashMap(java.util.HashMap) HUDProvider(logisticspipes.gui.hud.HUDProvider) ResourceType(logisticspipes.routing.order.IOrderInfoProvider.ResourceType) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) IRequestItems(logisticspipes.interfaces.routing.IRequestItems) IHeadUpDisplayRendererProvider(logisticspipes.interfaces.IHeadUpDisplayRendererProvider) ExtractionMode(logisticspipes.logisticspipes.ExtractionMode) LogisticsItemOrderManager(logisticspipes.routing.order.LogisticsItemOrderManager) LinkedList(java.util.LinkedList) Iterator(java.util.Iterator) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) LogisticsPromise(logisticspipes.routing.LogisticsPromise) TextureType(logisticspipes.textures.Textures.TextureType) RequestTree(logisticspipes.request.RequestTree) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity) IResource(logisticspipes.request.resources.IResource) TreeMap(java.util.TreeMap) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ProviderPipeMode(logisticspipes.network.packets.modules.ProviderPipeMode) IInventory(net.minecraft.inventory.IInventory) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) IOrderManagerContentReceiver(logisticspipes.interfaces.IOrderManagerContentReceiver) IInventory(net.minecraft.inventory.IInventory) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) IRouter(logisticspipes.routing.IRouter) SinkReply(logisticspipes.utils.SinkReply) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) ItemStack(net.minecraft.item.ItemStack) Pair(logisticspipes.utils.tuples.Pair)

Example 34 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.

the class CoreRoutedPipe method updateEntity.

@Override
public final void updateEntity() {
    debug.tick();
    spawnParticleTick();
    if (stillNeedReplace) {
        stillNeedReplace = false;
        getWorld().notifyBlockChange(getX(), getY(), getZ(), getWorld().getBlock(getX(), getY(), getZ()));
        /* TravelingItems are just held by a pipe, they don't need to know their world
			 * for(Triplet<IRoutedItem, ForgeDirection, ItemSendMode> item : _sendQueue) {
				//assign world to any entityitem we created in readfromnbt
				item.getValue1().getTravelingItem().setWorld(getWorld());
			}*/
        //first tick just create a router and do nothing.
        firstInitialiseTick();
        return;
    }
    if (repeatFor > 0) {
        if (delayTo < System.currentTimeMillis()) {
            delayTo = System.currentTimeMillis() + 200;
            repeatFor--;
            getWorld().markBlockForUpdate(getX(), getY(), getZ());
        }
    }
    // remove old items _inTransit -- these should have arrived, but have probably been lost instead. In either case, it will allow a re-send so that another attempt to re-fill the inventory can be made.
    while (_inTransitToMe.peek() != null && _inTransitToMe.peek().getTickToTimeOut() <= 0) {
        final ItemRoutingInformation p = _inTransitToMe.poll();
        if (LPConstants.DEBUG) {
            LogisticsPipes.log.info("Timed Out: " + p.getItem().getFriendlyName() + " (" + p.hashCode() + ")");
        }
        debug.log("Timed Out: " + p.getItem().getFriendlyName() + " (" + p.hashCode() + ")");
    }
    //update router before ticking logic/transport
    getRouter().update(getWorld().getTotalWorldTime() % Configs.LOGISTICS_DETECTION_FREQUENCY == _delayOffset || _initialInit || recheckConnections, this);
    recheckConnections = false;
    getOriginalUpgradeManager().securityTick();
    super.updateEntity();
    if (isNthTick(200)) {
        getCacheHolder().trigger(null);
    }
    // from BaseRoutingLogic
    if (--throttleTimeLeft <= 0) {
        throttledUpdateEntity();
        throttleTimeLeft = throttleTime;
    }
    ignoreDisableUpdateEntity();
    _initialInit = false;
    if (!_sendQueue.isEmpty()) {
        if (getItemSendMode() == ItemSendMode.Normal) {
            Triplet<IRoutedItem, ForgeDirection, ItemSendMode> itemToSend = _sendQueue.getFirst();
            sendRoutedItem(itemToSend.getValue1(), itemToSend.getValue2());
            _sendQueue.removeFirst();
            for (int i = 0; i < 16 && !_sendQueue.isEmpty() && _sendQueue.getFirst().getValue3() == ItemSendMode.Fast; i++) {
                if (!_sendQueue.isEmpty()) {
                    itemToSend = _sendQueue.getFirst();
                    sendRoutedItem(itemToSend.getValue1(), itemToSend.getValue2());
                    _sendQueue.removeFirst();
                }
            }
            sendQueueChanged(false);
        } else if (getItemSendMode() == ItemSendMode.Fast) {
            for (int i = 0; i < 16; i++) {
                if (!_sendQueue.isEmpty()) {
                    Triplet<IRoutedItem, ForgeDirection, ItemSendMode> itemToSend = _sendQueue.getFirst();
                    sendRoutedItem(itemToSend.getValue1(), itemToSend.getValue2());
                    _sendQueue.removeFirst();
                }
            }
            sendQueueChanged(false);
        } else if (getItemSendMode() == null) {
            throw new UnsupportedOperationException("getItemSendMode() can't return null. " + this.getClass().getName());
        } else {
            throw new UnsupportedOperationException("getItemSendMode() returned unhandled value. " + getItemSendMode().name() + " in " + this.getClass().getName());
        }
    }
    if (MainProxy.isClient(getWorld())) {
        return;
    }
    checkTexturePowered();
    if (!isEnabled()) {
        return;
    }
    enabledUpdateEntity();
    if (getLogisticsModule() == null) {
        return;
    }
    getLogisticsModule().tick();
}
Also used : ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) Triplet(logisticspipes.utils.tuples.Triplet) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 35 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.

the class CoreRoutedPipe method readFromNBT.

@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
    super.readFromNBT(nbttagcompound);
    synchronized (routerIdLock) {
        routerId = nbttagcompound.getString("routerId");
    }
    stat_lifetime_sent = nbttagcompound.getLong("stat_lifetime_sent");
    stat_lifetime_recieved = nbttagcompound.getLong("stat_lifetime_recieved");
    stat_lifetime_relayed = nbttagcompound.getLong("stat_lifetime_relayed");
    if (getLogisticsModule() != null) {
        getLogisticsModule().readFromNBT(nbttagcompound);
    }
    upgradeManager.readFromNBT(nbttagcompound.getCompoundTag("upgradeManager"));
    powerHandler.readFromNBT(nbttagcompound.getCompoundTag("powerHandler"));
    _sendQueue.clear();
    NBTTagList sendqueue = nbttagcompound.getTagList("sendqueue", nbttagcompound.getId());
    for (int i = 0; i < sendqueue.tagCount(); i++) {
        NBTTagCompound tagentry = sendqueue.getCompoundTagAt(i);
        NBTTagCompound tagentityitem = tagentry.getCompoundTag("entityitem");
        LPTravelingItemServer item = new LPTravelingItemServer(tagentityitem);
        ForgeDirection from = ForgeDirection.values()[tagentry.getByte("from")];
        ItemSendMode mode = ItemSendMode.values()[tagentry.getByte("mode")];
        _sendQueue.add(new Triplet<>(item, from, mode));
    }
    for (int i = 0; i < 6; i++) {
        if (nbttagcompound.getBoolean("PipeSign_" + i)) {
            int type = nbttagcompound.getInteger("PipeSign_" + i + "_type");
            Class<? extends IPipeSign> typeClass = ItemPipeSignCreator.signTypes.get(type);
            try {
                signItem[i] = typeClass.newInstance();
                signItem[i].init(this, ForgeDirection.getOrientation(i));
                signItem[i].readFromNBT(nbttagcompound.getCompoundTag("PipeSign_" + i + "_tags"));
            } catch (InstantiationException | IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) LPTravelingItemServer(logisticspipes.transport.LPTravelingItem.LPTravelingItemServer)

Aggregations

ForgeDirection (net.minecraftforge.common.util.ForgeDirection)242 TileEntity (net.minecraft.tileentity.TileEntity)80 ItemStack (net.minecraft.item.ItemStack)47 ArrayList (java.util.ArrayList)29 Block (net.minecraft.block.Block)28 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)24 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)21 IInventory (net.minecraft.inventory.IInventory)19 FluidStack (net.minecraftforge.fluids.FluidStack)18 SideOnly (cpw.mods.fml.relauncher.SideOnly)17 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)17 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)17 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)16 HashMap (java.util.HashMap)12 Pair (logisticspipes.utils.tuples.Pair)11 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)10 World (net.minecraft.world.World)10 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)9 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)9 List (java.util.List)8