Search in sources :

Example 41 with ForgeDirection

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

the class LogisticsTileGenericPipe method initialize.

public void initialize(CoreUnroutedPipe pipe) {
    blockType = getBlockType();
    if (pipe == null) {
        LogisticsPipes.log.log(Level.WARN, "Pipe failed to initialize at {0},{1},{2}, deleting", xCoord, yCoord, zCoord);
        worldObj.setBlockToAir(xCoord, yCoord, zCoord);
        return;
    }
    this.pipe = pipe;
    for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
        TileEntity tile = getTile(o);
        if (tile instanceof LogisticsTileGenericPipe) {
            ((LogisticsTileGenericPipe) tile).scheduleNeighborChange();
        }
        SimpleServiceLocator.buildCraftProxy.notifyOfChange(this, tile, o);
    }
    bindPipe();
    computeConnections();
    scheduleRenderUpdate();
    if (pipe.needsInit()) {
        pipe.initialize();
    }
    initialized = true;
}
Also used : LogisticsSolidTileEntity(logisticspipes.blocks.LogisticsSolidTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 42 with ForgeDirection

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

the class LogisticsTileGenericPipe method computeConnections.

private void computeConnections() {
    TileBuffer[] cache = getTileCache();
    if (cache == null) {
        return;
    }
    boolean[] pipeTDConnectionsBufferOld = pipeTDConnectionsBuffer.clone();
    for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
        TileBuffer t = cache[side.ordinal()];
        t.refresh();
        pipeConnectionsBuffer[side.ordinal()] = canPipeConnect(t.getTile(), side);
        if (pipeConnectionsBuffer[side.ordinal()]) {
            pipeBCConnectionsBuffer[side.ordinal()] = SimpleServiceLocator.buildCraftProxy.isTileGenericPipe(t.getTile());
            pipeTDConnectionsBuffer[side.ordinal()] = SimpleServiceLocator.thermalDynamicsProxy.isItemDuct(t.getTile());
        } else {
            pipeBCConnectionsBuffer[side.ordinal()] = false;
            pipeTDConnectionsBuffer[side.ordinal()] = false;
        }
    }
    if (!Arrays.equals(pipeTDConnectionsBufferOld, pipeTDConnectionsBuffer)) {
        tdPart.connectionsChanged();
    }
}
Also used : TileBuffer(logisticspipes.utils.TileBuffer) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 43 with ForgeDirection

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

the class FluidRoutedPipe method endReached.

public boolean endReached(LPTravelingItemServer arrivingItem, TileEntity tile) {
    if (canInsertToTanks() && MainProxy.isServer(getWorld())) {
        getCacheHolder().trigger(CacheTypes.Inventory);
        if (arrivingItem.getItemIdentifierStack() == null || !(arrivingItem.getItemIdentifierStack().getItem().isFluidContainer())) {
            return false;
        }
        if (getRouter().getSimpleID() != arrivingItem.getDestination()) {
            return false;
        }
        int filled = 0;
        FluidStack liquid = SimpleServiceLocator.logisticsFluidManager.getFluidFromContainer(arrivingItem.getItemIdentifierStack());
        if (isConnectableTank(tile, arrivingItem.output, false)) {
            List<Pair<TileEntity, ForgeDirection>> adjTanks = getAdjacentTanks(false);
            //Try to put liquid into all adjacent tanks.
            for (Pair<TileEntity, ForgeDirection> pair : adjTanks) {
                IFluidHandler tank = (IFluidHandler) pair.getValue1();
                ForgeDirection dir = pair.getValue2();
                filled = tank.fill(dir.getOpposite(), liquid.copy(), true);
                liquid.amount -= filled;
                if (liquid.amount != 0) {
                    continue;
                }
                return true;
            }
            //Try inserting the liquid into the pipe side tank
            filled = ((PipeFluidTransportLogistics) transport).sideTanks[arrivingItem.output.ordinal()].fill(liquid, true);
            if (filled == liquid.amount) {
                return true;
            }
            liquid.amount -= filled;
        }
        //Try inserting the liquid into the pipe internal tank
        filled = ((PipeFluidTransportLogistics) transport).internalTank.fill(liquid, true);
        if (filled == liquid.amount) {
            return true;
        }
        //If liquids still exist,
        liquid.amount -= filled;
        //TODO: FIX THIS
        if (this instanceof IRequireReliableFluidTransport) {
            ((IRequireReliableFluidTransport) this).liquidNotInserted(FluidIdentifier.get(liquid), liquid.amount);
        }
        IRoutedItem routedItem = SimpleServiceLocator.routedItemHelper.createNewTravelItem(SimpleServiceLocator.logisticsFluidManager.getFluidContainer(liquid));
        Pair<Integer, Integer> replies = SimpleServiceLocator.logisticsFluidManager.getBestReply(liquid, getRouter(), routedItem.getJamList());
        int dest = replies.getValue1();
        routedItem.setDestination(dest);
        routedItem.setTransportMode(TransportMode.Passive);
        this.queueRoutedItem(routedItem, arrivingItem.output.getOpposite());
        return true;
    }
    return false;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) PipeFluidTransportLogistics(logisticspipes.transport.PipeFluidTransportLogistics) IRequireReliableFluidTransport(logisticspipes.interfaces.routing.IRequireReliableFluidTransport) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) TileEntity(net.minecraft.tileentity.TileEntity) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Pair(logisticspipes.utils.tuples.Pair)

Example 44 with ForgeDirection

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

the class PipeFluidBasic method sinkAmount.

@Override
public int sinkAmount(FluidStack stack) {
    if (!guiOpenedBy.isEmpty()) {
        //Don't sink when the gui is open
        return 0;
    }
    FluidIdentifier ident = FluidIdentifier.get(stack);
    if (filterInv.getStackInSlot(0) == null) {
        return 0;
    }
    if (!ident.equals(FluidIdentifier.get(filterInv.getIDStackInSlot(0).getItem()))) {
        return 0;
    }
    int onTheWay = this.countOnRoute(ident);
    int freeSpace = -onTheWay;
    for (Pair<TileEntity, ForgeDirection> pair : getAdjacentTanks(true)) {
        FluidTank tank = ((PipeFluidTransportLogistics) transport).sideTanks[pair.getValue2().ordinal()];
        freeSpace += ident.getFreeSpaceInsideTank((IFluidHandler) pair.getValue1(), pair.getValue2().getOpposite());
        freeSpace += ident.getFreeSpaceInsideTank(tank);
        if (freeSpace >= stack.amount) {
            return stack.amount;
        }
    }
    return freeSpace;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidTank(net.minecraftforge.fluids.FluidTank) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) FluidIdentifier(logisticspipes.utils.FluidIdentifier) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 45 with ForgeDirection

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

the class PipeFluidProvider method enabledUpdateEntity.

@Override
public void enabledUpdateEntity() {
    super.enabledUpdateEntity();
    if (!getFluidOrderManager().hasOrders(ResourceType.PROVIDER) || !isNthTick(6)) {
        return;
    }
    LogisticsFluidOrder order = getFluidOrderManager().peekAtTopRequest(ResourceType.PROVIDER);
    int amountToSend, attemptedAmount;
    amountToSend = attemptedAmount = Math.min(order.getAmount(), 5000);
    for (Pair<TileEntity, ForgeDirection> pair : getAdjacentTanks(false)) {
        if (amountToSend <= 0) {
            break;
        }
        boolean fallback = true;
        if (SimpleServiceLocator.specialTankHandler.hasHandlerFor(pair.getValue1())) {
            ISpecialTankHandler handler = SimpleServiceLocator.specialTankHandler.getTankHandlerFor(pair.getValue1());
            if (handler instanceof ISpecialTankAccessHandler) {
                fallback = false;
                FluidStack drained = ((ISpecialTankAccessHandler) handler).drainFrom(pair.getValue1(), order.getFluid(), amountToSend, false);
                if (drained != null && drained.amount > 0 && order.getFluid().equals(FluidIdentifier.get(drained))) {
                    drained = ((ISpecialTankAccessHandler) handler).drainFrom(pair.getValue1(), order.getFluid(), amountToSend, true);
                    int amount = drained.amount;
                    amountToSend -= amount;
                    ItemIdentifierStack stack = SimpleServiceLocator.logisticsFluidManager.getFluidContainer(drained);
                    IRoutedItem item = SimpleServiceLocator.routedItemHelper.createNewTravelItem(stack);
                    item.setDestination(order.getRouter().getSimpleID());
                    item.setTransportMode(TransportMode.Active);
                    this.queueRoutedItem(item, pair.getValue2());
                    getFluidOrderManager().sendSuccessfull(amount, false, item);
                    if (amountToSend <= 0) {
                        break;
                    }
                }
            }
        }
        if (fallback) {
            FluidTankInfo[] tanks = ((IFluidHandler) pair.getValue1()).getTankInfo(pair.getValue2().getOpposite());
            if (tanks != null) {
                for (FluidTankInfo tank : tanks) {
                    if (tank == null) {
                        continue;
                    }
                    FluidStack liquid;
                    if ((liquid = tank.fluid) != null && liquid.getFluidID() != 0) {
                        if (order.getFluid().equals(FluidIdentifier.get(liquid))) {
                            int amount = Math.min(liquid.amount, amountToSend);
                            FluidStack drained = ((IFluidHandler) pair.getValue1()).drain(pair.getValue2().getOpposite(), amount, false);
                            if (drained != null && drained.amount > 0 && order.getFluid().equals(FluidIdentifier.get(drained))) {
                                drained = ((IFluidHandler) pair.getValue1()).drain(pair.getValue2().getOpposite(), amount, true);
                                while (drained.amount < amountToSend) {
                                    FluidStack addition = ((IFluidHandler) pair.getValue1()).drain(pair.getValue2().getOpposite(), amountToSend - drained.amount, false);
                                    if (addition != null && addition.amount > 0 && order.getFluid().equals(FluidIdentifier.get(addition))) {
                                        addition = ((IFluidHandler) pair.getValue1()).drain(pair.getValue2().getOpposite(), amountToSend - drained.amount, true);
                                        drained.amount += addition.amount;
                                    } else {
                                        break;
                                    }
                                }
                                amount = drained.amount;
                                amountToSend -= amount;
                                ItemIdentifierStack stack = SimpleServiceLocator.logisticsFluidManager.getFluidContainer(drained);
                                IRoutedItem item = SimpleServiceLocator.routedItemHelper.createNewTravelItem(stack);
                                item.setDestination(order.getRouter().getSimpleID());
                                item.setTransportMode(TransportMode.Active);
                                this.queueRoutedItem(item, pair.getValue2());
                                getFluidOrderManager().sendSuccessfull(amount, false, item);
                                if (amountToSend <= 0) {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (amountToSend >= attemptedAmount) {
        getFluidOrderManager().sendFailed();
    }
}
Also used : ISpecialTankHandler(logisticspipes.interfaces.ISpecialTankHandler) FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) FluidStack(net.minecraftforge.fluids.FluidStack) LogisticsFluidOrder(logisticspipes.routing.order.LogisticsFluidOrder) ISpecialTankAccessHandler(logisticspipes.interfaces.ISpecialTankAccessHandler) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) TileEntity(net.minecraft.tileentity.TileEntity) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack)

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