Search in sources :

Example 11 with IAirHandler

use of me.desht.pneumaticcraft.api.tileentity.IAirHandler in project pnc-repressurized by TeamPneumatic.

the class AirHandler method getConnectedPneumatics.

/**
 * Retrieves a list of all the connecting pneumatics. It takes sides in account.
 *
 * @return a list of face->air-handler pairs
 */
@Override
public List<Pair<EnumFacing, IAirHandler>> getConnectedPneumatics() {
    List<Pair<EnumFacing, IAirHandler>> teList = new ArrayList<>();
    for (IAirHandler specialConnection : specialConnectedHandlers) {
        teList.add(new ImmutablePair<>(null, specialConnection));
    }
    for (EnumFacing direction : EnumFacing.VALUES) {
        TileEntity te = getTileCache()[direction.ordinal()].getTileEntity();
        IPneumaticMachine machine = ModInteractionUtils.getInstance().getMachine(te);
        if (machine != null && parentPneumatic.getAirHandler(direction) == this && machine.getAirHandler(direction.getOpposite()) != null) {
            teList.add(new ImmutablePair<>(direction, machine.getAirHandler(direction.getOpposite())));
        }
    }
    if (airListener != null)
        airListener.addConnectedPneumatics(teList);
    return teList;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IAirHandler(me.desht.pneumaticcraft.api.tileentity.IAirHandler) IPneumaticMachine(me.desht.pneumaticcraft.api.tileentity.IPneumaticMachine) EnumFacing(net.minecraft.util.EnumFacing) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair)

Example 12 with IAirHandler

use of me.desht.pneumaticcraft.api.tileentity.IAirHandler in project pnc-repressurized by TeamPneumatic.

the class AirHandler method disperseAir.

private void disperseAir(List<Pair<EnumFacing, IAirHandler>> teList) {
    boolean shouldRepeat;
    List<Pair<Integer, Integer>> dispersion = new ArrayList<>();
    do {
        shouldRepeat = false;
        // Add up every volume and air.
        int totalVolume = getVolume();
        int totalAir = air;
        for (Pair<EnumFacing, IAirHandler> entry : teList) {
            IAirHandler airHandler = entry.getValue();
            totalVolume += airHandler.getVolume();
            totalAir += airHandler.getAir();
        }
        // Only go push based, ignore any machines that have a higher pressure than this block.
        Iterator<Pair<EnumFacing, IAirHandler>> iterator = teList.iterator();
        while (iterator.hasNext()) {
            Pair<EnumFacing, IAirHandler> entry = iterator.next();
            IAirHandler airHandler = entry.getValue();
            // Calculate the total air the machine is going to get.
            int totalMachineAir = (int) ((long) totalAir * airHandler.getVolume() / totalVolume);
            int airDispersed = totalMachineAir - airHandler.getAir();
            if (airDispersed < 0) {
                iterator.remove();
                shouldRepeat = true;
                dispersion.clear();
                break;
            } else {
                dispersion.add(new MutablePair<>(getMaxDispersion(entry.getKey()), airDispersed));
            }
        }
    } while (shouldRepeat);
    int toBeDivided = 0;
    int receivers = dispersion.size();
    for (Pair<Integer, Integer> disp : dispersion) {
        if (disp.getValue() > disp.getKey()) {
            // Any air that wants to go to a neighbor, but can't (because of regulator module) gives back its air.
            toBeDivided += disp.getValue() - disp.getKey();
            disp.setValue(disp.getKey());
            receivers--;
        }
    }
    while (toBeDivided >= receivers && receivers > 0) {
        // try to give every receiver an equal part of the to be divided air.
        int dividedValue = toBeDivided / receivers;
        for (Pair<Integer, Integer> disp : dispersion) {
            int maxTransfer = disp.getKey() - disp.getValue();
            if (maxTransfer > 0) {
                if (maxTransfer <= dividedValue) {
                    // next step this receiver won't be able to receive any air.
                    receivers--;
                }
                // cap it at the max it can have.
                int transfered = Math.min(dividedValue, maxTransfer);
                disp.setValue(disp.getValue() + transfered);
                toBeDivided -= transfered;
            } else {
                receivers--;
            }
        }
    }
    for (int i = 0; i < teList.size(); i++) {
        IAirHandler neighbor = teList.get(i).getValue();
        int transferedAir = dispersion.get(i).getValue();
        onAirDispersion(teList.get(i).getKey(), transferedAir);
        neighbor.addAir(transferedAir);
        addAir(-transferedAir);
    }
}
Also used : IAirHandler(me.desht.pneumaticcraft.api.tileentity.IAirHandler) EnumFacing(net.minecraft.util.EnumFacing) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair)

Example 13 with IAirHandler

use of me.desht.pneumaticcraft.api.tileentity.IAirHandler in project pnc-repressurized by TeamPneumatic.

the class GuiVacuumPump method addPressureStatInfo.

@Override
protected void addPressureStatInfo(List<String> pressureStatText) {
    IAirHandler inputHandler = te.getAirHandler(te.getInputSide());
    IAirHandler vacuumHandler = te.getAirHandler(te.getVacuumSide());
    pressureStatText.add("\u00a77Current Input Pressure:");
    pressureStatText.add("\u00a70" + PneumaticCraftUtils.roundNumberTo(inputHandler.getPressure(), 1) + " bar.");
    pressureStatText.add("\u00a77Current Input Air:");
    pressureStatText.add("\u00a70" + (inputHandler.getAir() + inputHandler.getVolume()) + " mL.");
    pressureStatText.add("\u00a77Current Vacuum Pressure:");
    pressureStatText.add("\u00a70" + PneumaticCraftUtils.roundNumberTo(vacuumHandler.getPressure(), 1) + " bar.");
    pressureStatText.add("\u00a77Current Vacuum Air:");
    pressureStatText.add("\u00a70" + (vacuumHandler.getAir() + vacuumHandler.getVolume()) + " mL.");
    pressureStatText.add("\u00a77Volume:");
    pressureStatText.add("\u00a70" + (double) Math.round(PneumaticValues.VOLUME_VACUUM_PUMP) + " mL.");
    int volumeLeft = inputHandler.getVolume() - PneumaticValues.VOLUME_VACUUM_PUMP;
    if (volumeLeft > 0) {
        pressureStatText.add("\u00a70" + volumeLeft + " mL. (Volume Upgrades)");
        pressureStatText.add("\u00a70--------+");
        pressureStatText.add("\u00a70" + inputHandler.getVolume() + " mL.");
    }
    if (te.turning) {
        pressureStatText.add("\u00a77Currently sucking at:");
        pressureStatText.add("\u00a70" + (double) Math.round(PneumaticValues.PRODUCTION_VACUUM_PUMP * te.getSpeedMultiplierFromUpgrades()) + " mL/tick.");
    }
}
Also used : IAirHandler(me.desht.pneumaticcraft.api.tileentity.IAirHandler)

Example 14 with IAirHandler

use of me.desht.pneumaticcraft.api.tileentity.IAirHandler in project pnc-repressurized by TeamPneumatic.

the class TileEntityPressureTube method update.

@Override
public void update() {
    super.update();
    for (TubeModule module : modules) {
        if (module != null) {
            module.shouldDrop = true;
            module.update();
        }
    }
    List<Pair<EnumFacing, IAirHandler>> teList = getAirHandler(null).getConnectedPneumatics();
    boolean hasModules = false;
    for (TubeModule module : modules) {
        if (module != null) {
            hasModules = true;
            break;
        }
    }
    if (!hasModules && teList.size() == 1 && !getWorld().isRemote) {
        for (Pair<EnumFacing, IAirHandler> entry : teList) {
            if (entry.getKey() != null && modules[entry.getKey().getOpposite().ordinal()] == null && isConnectedTo(entry.getKey().getOpposite()))
                getAirHandler(null).airLeak(entry.getKey().getOpposite());
        }
    }
}
Also used : IAirHandler(me.desht.pneumaticcraft.api.tileentity.IAirHandler) EnumFacing(net.minecraft.util.EnumFacing) TubeModule(me.desht.pneumaticcraft.common.block.tubes.TubeModule) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

IAirHandler (me.desht.pneumaticcraft.api.tileentity.IAirHandler)14 EnumFacing (net.minecraft.util.EnumFacing)6 Pair (org.apache.commons.lang3.tuple.Pair)6 TileEntity (net.minecraft.tileentity.TileEntity)3 IPneumaticMachine (me.desht.pneumaticcraft.api.tileentity.IPneumaticMachine)2 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)2 MutablePair (org.apache.commons.lang3.tuple.MutablePair)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 IPressurizable (me.desht.pneumaticcraft.api.item.IPressurizable)1 TubeModule (me.desht.pneumaticcraft.common.block.tubes.TubeModule)1 PacketDescriptionPacketRequest (me.desht.pneumaticcraft.common.network.PacketDescriptionPacketRequest)1 LuaConstant (me.desht.pneumaticcraft.common.thirdparty.computercraft.LuaConstant)1 LuaMethod (me.desht.pneumaticcraft.common.thirdparty.computercraft.LuaMethod)1 TileEntityPneumaticBase (me.desht.pneumaticcraft.common.tileentity.TileEntityPneumaticBase)1 ItemStack (net.minecraft.item.ItemStack)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1 IItemHandler (net.minecraftforge.items.IItemHandler)1