* Fixed #1406 * Rewritten pipes logic, now it less complex and more optimized. Fixed bug when pipes sometimes cant insert steam into steam machines.
This commit is contained in:
parent
fcdb80b886
commit
b397abae97
1 changed files with 43 additions and 110 deletions
|
@ -8,7 +8,6 @@ import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
|
||||||
import gregtech.api.interfaces.tileentity.ICoverable;
|
import gregtech.api.interfaces.tileentity.ICoverable;
|
||||||
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
|
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
|
||||||
import gregtech.api.metatileentity.BaseMetaPipeEntity;
|
import gregtech.api.metatileentity.BaseMetaPipeEntity;
|
||||||
import gregtech.api.metatileentity.BaseTileEntity;
|
|
||||||
import gregtech.api.metatileentity.MetaPipeEntity;
|
import gregtech.api.metatileentity.MetaPipeEntity;
|
||||||
import gregtech.api.objects.GT_RenderedTexture;
|
import gregtech.api.objects.GT_RenderedTexture;
|
||||||
import gregtech.api.objects.XSTR;
|
import gregtech.api.objects.XSTR;
|
||||||
|
@ -27,11 +26,10 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import net.minecraftforge.fluids.FluidTankInfo;
|
import net.minecraftforge.fluids.FluidTankInfo;
|
||||||
import net.minecraftforge.fluids.IFluidHandler;
|
import net.minecraftforge.fluids.IFluidHandler;
|
||||||
|
import org.apache.commons.lang3.tuple.MutableTriple;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
import static gregtech.api.enums.GT_Values.D1;
|
import static gregtech.api.enums.GT_Values.D1;
|
||||||
|
|
||||||
|
@ -229,7 +227,8 @@ public class GT_MetaPipeEntity_Fluid extends MetaPipeEntity {
|
||||||
mLastReceivedFrom = 0;
|
mLastReceivedFrom = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (FluidStack tFluid : mFluids) {
|
for (int i = 0; i < mFluids.length; i++) {
|
||||||
|
FluidStack tFluid = mFluids[i];
|
||||||
if (tFluid != null && tFluid.amount > 0) {
|
if (tFluid != null && tFluid.amount > 0) {
|
||||||
int tTemperature = tFluid.getFluid().getTemperature(tFluid);
|
int tTemperature = tFluid.getFluid().getTemperature(tFluid);
|
||||||
if (tTemperature > mHeatResistance) {
|
if (tTemperature > mHeatResistance) {
|
||||||
|
@ -259,18 +258,16 @@ public class GT_MetaPipeEntity_Fluid extends MetaPipeEntity {
|
||||||
if (D1) e.printStackTrace(GT_Log.err);
|
if (D1) e.printStackTrace(GT_Log.err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tFluid.amount <= 0) tFluid = null;
|
if (tFluid.amount <= 0) mFluids[i] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mLastReceivedFrom == oLastReceivedFrom) {
|
if (mLastReceivedFrom == oLastReceivedFrom) {
|
||||||
ArrayList<IFluidHandler> tTanksList = new ArrayList<>();
|
List<MutableTriple<IFluidHandler, ForgeDirection, Integer>> tanksList = new ArrayList<>();
|
||||||
ArrayList<ForgeDirection> tDirectionsList = new ArrayList<>();
|
|
||||||
|
|
||||||
for (byte tSide = 0, uSide = 0, i = 0, j = (byte) aBaseMetaTileEntity.getRandomNumber(6); i < 6; i++) {
|
for (byte tSide = 0; tSide < 6; tSide++) {
|
||||||
tSide = (byte) ((i + j) % 6);
|
byte uSide = GT_Utility.getOppositeSide(tSide);
|
||||||
uSide = GT_Utility.getOppositeSide(tSide);
|
|
||||||
IFluidHandler tTank = aBaseMetaTileEntity.getITankContainerAtSide(tSide);
|
IFluidHandler tTank = aBaseMetaTileEntity.getITankContainerAtSide(tSide);
|
||||||
ICoverable tBaseMetaTileEntity = tTank instanceof ICoverable ? (ICoverable) tTank : null;
|
ICoverable tBaseMetaTileEntity = tTank instanceof ICoverable ? (ICoverable) tTank : null;
|
||||||
if (mCheckConnections || isConnectedAtSide(tSide)
|
if (mCheckConnections || isConnectedAtSide(tSide)
|
||||||
|
@ -278,11 +275,11 @@ public class GT_MetaPipeEntity_Fluid extends MetaPipeEntity {
|
||||||
|| (tBaseMetaTileEntity != null && tBaseMetaTileEntity.getCoverBehaviorAtSide(uSide).alwaysLookConnected(uSide, tBaseMetaTileEntity.getCoverIDAtSide(uSide), tBaseMetaTileEntity.getCoverDataAtSide(uSide), tBaseMetaTileEntity))) {
|
|| (tBaseMetaTileEntity != null && tBaseMetaTileEntity.getCoverBehaviorAtSide(uSide).alwaysLookConnected(uSide, tBaseMetaTileEntity.getCoverIDAtSide(uSide), tBaseMetaTileEntity.getCoverDataAtSide(uSide), tBaseMetaTileEntity))) {
|
||||||
switch (connect(tSide)) {
|
switch (connect(tSide)) {
|
||||||
case 0:
|
case 0:
|
||||||
disconnect(tSide); break;
|
disconnect(tSide);
|
||||||
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if ((mLastReceivedFrom & (1 << tSide)) == 0) {
|
if ((mLastReceivedFrom & (1 << tSide)) == 0) {
|
||||||
tTanksList.add(tTank);
|
tanksList.add(new MutableTriple<>(tTank, ForgeDirection.getOrientation(uSide), 0));
|
||||||
tDirectionsList.add(ForgeDirection.getOrientation(tSide).getOpposite());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -291,94 +288,29 @@ public class GT_MetaPipeEntity_Fluid extends MetaPipeEntity {
|
||||||
|
|
||||||
for (int i = 0, j = aBaseMetaTileEntity.getRandomNumber(mPipeAmount); i < mPipeAmount; i++) {
|
for (int i = 0, j = aBaseMetaTileEntity.getRandomNumber(mPipeAmount); i < mPipeAmount; i++) {
|
||||||
int index = (i + j) % mPipeAmount;
|
int index = (i + j) % mPipeAmount;
|
||||||
if (mFluids[index] != null && mFluids[index].amount > 0) {
|
if (mFluids[index] == null) {
|
||||||
int tAmount = Math.max(1, Math.min(mCapacity * 10, mFluids[index].amount));
|
continue;
|
||||||
|
}
|
||||||
List<Integer> tTankAmounts = new ArrayList<Integer>();
|
double amount = Math.max(1, Math.min(mCapacity * 10, mFluids[index].amount));
|
||||||
int totalFreeAmount = 0;
|
FluidStack s = mFluids[index].copy();
|
||||||
int totalOverAmount = 0;
|
s.amount = Integer.MAX_VALUE;
|
||||||
|
double totalFreeAmount = 0;
|
||||||
|
|
||||||
// Calculating of amounts by fullness of consumers
|
// Calculating of amounts by fullness of consumers
|
||||||
for (int tankIndex = 0; tankIndex < tTanksList.size(); tankIndex++) {
|
for (MutableTriple<IFluidHandler, ForgeDirection, Integer> tank : tanksList) {
|
||||||
IFluidHandler tTileEntity = tTanksList.get(tankIndex);
|
tank.right = tank.left.fill(tank.middle, s, false);
|
||||||
ForgeDirection dir = tDirectionsList.get(tankIndex);
|
totalFreeAmount += tank.right;
|
||||||
FluidTankInfo[] tTankInfoList = tTileEntity.getTankInfo(dir.getOpposite());
|
|
||||||
tTankAmounts.add(0);
|
|
||||||
|
|
||||||
FluidTankInfo successfulTankInfo = null;
|
|
||||||
for (FluidTankInfo tankInfo : tTankInfoList) {
|
|
||||||
// Empty tank
|
|
||||||
if (successfulTankInfo == null && tankInfo.fluid == null)
|
|
||||||
successfulTankInfo = tankInfo;
|
|
||||||
// Tank with equal fluid
|
|
||||||
if (tankInfo.fluid == null || !tankInfo.fluid.isFluidEqual(mFluids[index])) continue;
|
|
||||||
successfulTankInfo = tankInfo;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if (successfulTankInfo != null) {
|
|
||||||
tTankAmounts.set(tankIndex, (successfulTankInfo.fluid != null)
|
|
||||||
? successfulTankInfo.capacity - successfulTankInfo.fluid.amount
|
|
||||||
: successfulTankInfo.capacity);
|
|
||||||
} else {
|
|
||||||
tTankAmounts.set(tankIndex, mCapacity * 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
totalFreeAmount += tTankAmounts.get(tankIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Accounting of proportions
|
|
||||||
if (totalFreeAmount > tAmount) {
|
|
||||||
for (int tankIndex = 0; tankIndex < tTanksList.size(); tankIndex++) {
|
|
||||||
double tankAmount = (double)tTankAmounts.get(tankIndex);
|
|
||||||
tTankAmounts.set(tankIndex, (int)Math.floor(tankAmount * tAmount / totalFreeAmount));
|
|
||||||
totalOverAmount += tTankAmounts.get(tankIndex);
|
|
||||||
}
|
|
||||||
totalOverAmount = tAmount - totalOverAmount;
|
|
||||||
} else {
|
|
||||||
tAmount = totalFreeAmount;
|
|
||||||
}
|
|
||||||
|
|
||||||
int tOverAmount = totalOverAmount;
|
|
||||||
int tRemainingAmount = tAmount;
|
|
||||||
int tFilledTanksCnt = 0;
|
|
||||||
|
|
||||||
// Filling and amount correction
|
// Filling and amount correction
|
||||||
for (int tFillIndex = 0; tFillIndex < tTanksList.size(); tFillIndex++) {
|
for (MutableTriple<IFluidHandler, ForgeDirection, Integer> tank : tanksList) {
|
||||||
if (tFilledTanksCnt >= tTanksList.size() || tRemainingAmount <= 0) break;
|
if (totalFreeAmount > amount) {
|
||||||
|
tank.right = (int) Math.floor(tank.right * amount / totalFreeAmount);
|
||||||
|
}
|
||||||
|
if (tank.right <= 0) continue;
|
||||||
|
|
||||||
for (int tankIndex = 0; tankIndex < tTanksList.size(); tankIndex++) {
|
int tFilledAmount = tank.left.fill(tank.middle, drainFromIndex(tank.right, false, index), false);
|
||||||
int tankAmount = tTankAmounts.get(tankIndex);
|
|
||||||
if (tankAmount < 0) continue;
|
|
||||||
|
|
||||||
IFluidHandler tTileEntity = tTanksList.get(tankIndex);
|
|
||||||
ForgeDirection tDir = tDirectionsList.get(tankIndex);
|
|
||||||
|
|
||||||
int tFilledAmount = tTileEntity.fill(tDir, drainFromIndex(tankAmount, false, index), false);
|
|
||||||
if (tFilledAmount > 0) {
|
if (tFilledAmount > 0) {
|
||||||
tTileEntity.fill(tDir, drainFromIndex(tFilledAmount, true, index), true);
|
tank.left.fill(tank.middle, drainFromIndex(tFilledAmount, true, index), true);
|
||||||
}
|
|
||||||
tRemainingAmount -= tFilledAmount;
|
|
||||||
|
|
||||||
if (tFilledAmount < tankAmount) {
|
|
||||||
tFilledTanksCnt++;
|
|
||||||
tOverAmount += tankAmount - tFilledAmount;
|
|
||||||
tTankAmounts.set(tankIndex, -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unused amount will be transferred to the rest
|
|
||||||
if (tFilledTanksCnt < tTanksList.size()) {
|
|
||||||
totalOverAmount = tOverAmount;
|
|
||||||
tOverAmount = tOverAmount / (tTanksList.size() - tFilledTanksCnt);
|
|
||||||
|
|
||||||
for (int tankIndex = 0; tankIndex < tTanksList.size(); tankIndex++) {
|
|
||||||
int tankAmount = tTankAmounts.get(tankIndex);
|
|
||||||
if (tankAmount < 0) continue;
|
|
||||||
|
|
||||||
tTankAmounts.set(tankIndex, tankAmount + tOverAmount);
|
|
||||||
}
|
|
||||||
tOverAmount = totalOverAmount - tOverAmount * (tTanksList.size() - tFilledTanksCnt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -387,7 +319,8 @@ public class GT_MetaPipeEntity_Fluid extends MetaPipeEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
oLastReceivedFrom = mLastReceivedFrom;
|
oLastReceivedFrom = mLastReceivedFrom;
|
||||||
}else if(aBaseMetaTileEntity.isClientSide() && GT_Client.changeDetected==4) aBaseMetaTileEntity.issueTextureUpdate();
|
} else if (aBaseMetaTileEntity.isClientSide() && GT_Client.changeDetected == 4)
|
||||||
|
aBaseMetaTileEntity.issueTextureUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue