Search in sources :

Example 46 with ForgeDirection

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

the class PipeFluidProvider method getAvailableFluids.

@Override
public Map<FluidIdentifier, Integer> getAvailableFluids() {
    Map<FluidIdentifier, Integer> map = new HashMap<>();
    for (Pair<TileEntity, ForgeDirection> pair : getAdjacentTanks(false)) {
        boolean fallback = true;
        if (SimpleServiceLocator.specialTankHandler.hasHandlerFor(pair.getValue1())) {
            ISpecialTankHandler handler = SimpleServiceLocator.specialTankHandler.getTankHandlerFor(pair.getValue1());
            if (handler instanceof ISpecialTankAccessHandler) {
                fallback = false;
                Map<FluidIdentifier, Long> tmp = ((ISpecialTankAccessHandler) handler).getAvailableLiquid(pair.getValue1());
                for (Entry<FluidIdentifier, Long> entry : tmp.entrySet()) {
                    if (map.containsKey(entry.getKey())) {
                        long addition = ((long) map.get(entry.getKey())) + entry.getValue();
                        map.put(entry.getKey(), addition > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) addition);
                    } else {
                        map.put(entry.getKey(), entry.getValue() > Integer.MAX_VALUE ? Integer.MAX_VALUE : entry.getValue().intValue());
                    }
                }
            }
        }
        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) {
                        FluidIdentifier ident = FluidIdentifier.get(liquid);
                        if (((IFluidHandler) pair.getValue1()).canDrain(pair.getValue2().getOpposite(), liquid.getFluid())) {
                            if (((IFluidHandler) pair.getValue1()).drain(pair.getValue2().getOpposite(), 1, false) != null) {
                                if (map.containsKey(ident)) {
                                    long addition = ((long) map.get(ident)) + tank.fluid.amount;
                                    map.put(ident, addition > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) addition);
                                } else {
                                    map.put(ident, tank.fluid.amount);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    Map<FluidIdentifier, Integer> result = new HashMap<>();
    //Reduce what has been reserved, add.
    for (Entry<FluidIdentifier, Integer> fluid : map.entrySet()) {
        int remaining = fluid.getValue() - getFluidOrderManager().totalFluidsCountInOrders(fluid.getKey());
        if (remaining < 1) {
            continue;
        }
        result.put(fluid.getKey(), remaining);
    }
    return result;
}
Also used : ISpecialTankHandler(logisticspipes.interfaces.ISpecialTankHandler) FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) HashMap(java.util.HashMap) FluidStack(net.minecraftforge.fluids.FluidStack) ISpecialTankAccessHandler(logisticspipes.interfaces.ISpecialTankAccessHandler) FluidIdentifier(logisticspipes.utils.FluidIdentifier) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) TileEntity(net.minecraft.tileentity.TileEntity) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 47 with ForgeDirection

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

the class PipeItemsInvSysConnector method inventoryConnected.

private boolean inventoryConnected() {
    for (int i = 0; i < 6; i++) {
        ForgeDirection dir = ForgeDirection.values()[i];
        DoubleCoordinates p = CoordinateUtils.add(new DoubleCoordinates(this), dir);
        TileEntity tile = p.getTileEntity(getWorld());
        if (tile instanceof IInventory && this.container.canPipeConnect(tile, dir)) {
            return true;
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 48 with ForgeDirection

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

the class LPBCTileGenericPipe method updateEntity_LP.

@Override
@SneakyThrows({ NoSuchFieldException.class, SecurityException.class, IllegalArgumentException.class, IllegalAccessException.class, NoSuchMethodException.class, InvocationTargetException.class })
public void updateEntity_LP() {
    //Make sure we still have the same TE values
    xCoord = lpPipe.xCoord;
    yCoord = lpPipe.yCoord;
    zCoord = lpPipe.zCoord;
    if (attachPluggables) {
        attachPluggables = false;
        // Attach callback
        PipePluggable[] pluggables = ReflectionHelper.getPrivateField(PipePluggable[].class, SideProperties.class, "pluggables", sideProperties);
        for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
            if (pluggables[i] != null) {
                pipe.eventBus.registerHandler(pluggables[i]);
                pluggables[i].onAttachedPipe(this, ForgeDirection.getOrientation(i));
            }
        }
        notifyBlockChanged();
    }
    if (!BlockGenericPipe.isValid(pipe)) {
        return;
    }
    pipe.updateEntity();
    boolean recheckThisPipe = false;
    for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
        PipePluggable p = getPipePluggable(direction);
        if (p != null) {
            p.update(this, direction);
            //Check Gate for ActionChanges
            if (p instanceof GatePluggable && lpPipe.isRoutingPipe()) {
                if (!activeActions.containsKey(direction)) {
                    activeActions.put(direction, new ArrayList<>());
                }
                if (!listEquals(activeActions.get(direction), pipe.gates[direction.ordinal()].activeActions)) {
                    activeActions.get(direction).clear();
                    activeActions.get(direction).addAll(pipe.gates[direction.ordinal()].activeActions);
                    lpPipe.getRoutingPipe().triggerConnectionCheck();
                    recheckThisPipe = true;
                }
            } else if (activeActions.containsKey(direction)) {
                activeActions.remove(direction);
            }
            if (p instanceof RobotStationPluggable) {
                if (((RobotStationPluggable) p).getStation() != null && ((RobotStationPluggable) p).getStation().robotTaking() != null && ((RobotStationPluggable) p).getStation().robotTaking().getBoard() instanceof LogisticsRoutingBoardRobot) {
                    ((RobotStationPluggable) p).getStation().robotTaking().getBoard().cycle();
                }
            }
        }
    }
    if (recheckThisPipe) {
        LPRobotConnectionControl.instance.checkAll(worldObj);
    }
    if (worldObj.isRemote) {
        if (resyncGateExpansions) {
            ReflectionHelper.invokePrivateMethod(Object.class, TileGenericPipe.class, this, "syncGateExpansions", new Class[] {}, new Object[] {});
        }
        return;
    }
    if (blockNeighborChange) {
        //ReflectionHelper.invokePrivateMethod(Object.class, TileGenericPipe.class, this, "computeConnections", new Class[]{}, new Object[]{});
        pipe.onNeighborBlockChange(0);
        blockNeighborChange = false;
        refreshRenderState = true;
    }
    if (refreshRenderState) {
        refreshRenderState();
        refreshRenderState = false;
    }
}
Also used : RobotStationPluggable(buildcraft.robotics.RobotStationPluggable) LogisticsRoutingBoardRobot(logisticspipes.proxy.buildcraft.robots.boards.LogisticsRoutingBoardRobot) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) GatePluggable(buildcraft.transport.gates.GatePluggable) SneakyThrows(lombok.SneakyThrows)

Example 49 with ForgeDirection

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

the class EnderIOHyperCubeConnection method getConnections.

@Override
public List<TileEntity> getConnections(TileEntity tile) {
    boolean onlyOnePipe = false;
    for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
        DoubleCoordinates p = CoordinateUtils.add(new DoubleCoordinates(tile), direction);
        TileEntity canidate = p.getTileEntity(tile.getWorldObj());
        if (canidate instanceof LogisticsTileGenericPipe && MainProxy.checkPipesConnections(tile, canidate, direction)) {
            if (onlyOnePipe) {
                onlyOnePipe = false;
                break;
            } else {
                onlyOnePipe = true;
            }
        }
    }
    if (!onlyOnePipe || !SimpleServiceLocator.enderIOProxy.isSendAndReceive(tile)) {
        return new ArrayList<>(0);
    }
    List<? extends TileEntity> connections = SimpleServiceLocator.enderIOProxy.getConnectedHyperCubes(tile);
    List<TileEntity> list = new ArrayList<>();
    for (TileEntity connected : connections) {
        if (!SimpleServiceLocator.enderIOProxy.isSendAndReceive(connected)) {
            continue;
        }
        LogisticsTileGenericPipe pipe = null;
        for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
            DoubleCoordinates p = CoordinateUtils.add(new DoubleCoordinates(connected), direction);
            TileEntity canidate = p.getTileEntity(tile.getWorldObj());
            if (canidate instanceof LogisticsTileGenericPipe && MainProxy.checkPipesConnections(connected, canidate, direction)) {
                if (pipe != null) {
                    pipe = null;
                    break;
                } else {
                    pipe = (LogisticsTileGenericPipe) canidate;
                }
            }
        }
        if (pipe != null && pipe.pipe instanceof CoreRoutedPipe) {
            list.add(pipe);
        }
    }
    if (list.size() == 1) {
        return list;
    } else {
        return new ArrayList<>(0);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) ArrayList(java.util.ArrayList) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 50 with ForgeDirection

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

the class ItemAmountPipeSign method spread.

private void spread(Map<ItemIdentifier, Integer> availableItems, BitSet set) {
    // Improve performance by updating a wall of Amount pipe signs all at once
    IRouter router = pipe.getRouter();
    if (set.get(router.getSimpleID()))
        return;
    set.set(router.getSimpleID());
    for (ExitRoute exit : router.getIRoutersByCost()) {
        // Only when the signs are in one wall. To not spread to far.
        if (exit.distanceToDestination > 2)
            break;
        if (!exit.filters.isEmpty())
            continue;
        if (set.get(exit.destination.getSimpleID()))
            continue;
        if (exit.connectionDetails.contains(PipeRoutingConnectionType.canRequestFrom) && exit.connectionDetails.contains(PipeRoutingConnectionType.canRouteTo)) {
            CoreRoutedPipe cachedPipe = exit.destination.getCachedPipe();
            if (cachedPipe != null) {
                List<Pair<ForgeDirection, IPipeSign>> pipeSigns = cachedPipe.getPipeSigns();
                pipeSigns.stream().filter(signPair -> signPair != null && signPair.getValue2() instanceof ItemAmountPipeSign).forEach(signPair -> ((ItemAmountPipeSign) signPair.getValue2()).updateStats(availableItems, set));
            }
        }
    }
}
Also used : IRouter(logisticspipes.routing.IRouter) Item(net.minecraft.item.Item) MainProxy(logisticspipes.proxy.MainProxy) StringUtils(logisticspipes.utils.string.StringUtils) ItemStack(net.minecraft.item.ItemStack) Map(java.util.Map) LogisticsRenderPipe(logisticspipes.renderer.LogisticsRenderPipe) GL11(org.lwjgl.opengl.GL11) ItemAmountSignUpdatePacket(logisticspipes.network.packets.pipe.ItemAmountSignUpdatePacket) ModernPacket(logisticspipes.network.abstractpackets.ModernPacket) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NewGuiHandler(logisticspipes.network.NewGuiHandler) PipeRoutingConnectionType(logisticspipes.routing.PipeRoutingConnectionType) Side(cpw.mods.fml.relauncher.Side) ItemAmountSignGui(logisticspipes.network.guis.item.ItemAmountSignGui) SideOnly(cpw.mods.fml.relauncher.SideOnly) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) PacketHandler(logisticspipes.network.PacketHandler) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ExitRoute(logisticspipes.routing.ExitRoute) ServerRouter(logisticspipes.routing.ServerRouter) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) ISimpleInventoryEventHandler(logisticspipes.utils.ISimpleInventoryEventHandler) List(java.util.List) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) FontRenderer(net.minecraft.client.gui.FontRenderer) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Pair(logisticspipes.utils.tuples.Pair) IInventory(net.minecraft.inventory.IInventory) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) Data(lombok.Data) BitSet(java.util.BitSet) IRouter(logisticspipes.routing.IRouter) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ExitRoute(logisticspipes.routing.ExitRoute) Pair(logisticspipes.utils.tuples.Pair)

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