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;
}
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);
}
}
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.");
}
}
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());
}
}
}
Aggregations