Fix: Fluid pipes transfer capacity (#1378)
* Fix: Fluid pipes transfer capacity * Fix: Not all GT machines return fluid tank info
This commit is contained in:
parent
2cea339c9b
commit
cc40637087
1 changed files with 94 additions and 27 deletions
|
@ -265,8 +265,9 @@ public class GT_MetaPipeEntity_Fluid extends MetaPipeEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mLastReceivedFrom == oLastReceivedFrom) {
|
if (mLastReceivedFrom == oLastReceivedFrom) {
|
||||||
ConcurrentHashMap<IFluidHandler, ForgeDirection> tTanks = new ConcurrentHashMap<IFluidHandler, ForgeDirection>();
|
ArrayList<IFluidHandler> tTanksList = 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, uSide = 0, i = 0, j = (byte) aBaseMetaTileEntity.getRandomNumber(6); i < 6; i++) {
|
||||||
tSide = (byte) ((i + j) % 6);
|
tSide = (byte) ((i + j) % 6);
|
||||||
uSide = GT_Utility.getOppositeSide(tSide);
|
uSide = GT_Utility.getOppositeSide(tSide);
|
||||||
|
@ -279,38 +280,104 @@ public class GT_MetaPipeEntity_Fluid extends MetaPipeEntity {
|
||||||
case 0:
|
case 0:
|
||||||
disconnect(tSide); break;
|
disconnect(tSide); break;
|
||||||
case 2:
|
case 2:
|
||||||
if ((mLastReceivedFrom & (1 << tSide)) == 0)
|
if ((mLastReceivedFrom & (1 << tSide)) == 0) {
|
||||||
tTanks.put(tTank, ForgeDirection.getOrientation(tSide).getOpposite()); break;
|
tTanksList.add(tTank);
|
||||||
}
|
tDirectionsList.add(ForgeDirection.getOrientation(tSide).getOpposite());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (GT_Mod.gregtechproxy.gt6Pipe) mCheckConnections = false;
|
if (GT_Mod.gregtechproxy.gt6Pipe) mCheckConnections = false;
|
||||||
|
|
||||||
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 && mFluids[index].amount > 0) {
|
||||||
int tAmount = Math.max(1, Math.min(mCapacity * 10, mFluids[index].amount / 2)), tSuccessfulTankAmount = 0;
|
int tAmount = Math.max(1, Math.min(mCapacity * 10, mFluids[index].amount));
|
||||||
|
|
||||||
for (Entry<IFluidHandler, ForgeDirection> tEntry : tTanks.entrySet())
|
List<Integer> tTankAmounts = new ArrayList<Integer>();
|
||||||
if (tEntry.getKey().fill(tEntry.getValue(), drainFromIndex(tAmount, false, index), false) > 0)
|
int totalFreeAmount = 0;
|
||||||
tSuccessfulTankAmount++;
|
int totalOverAmount = 0;
|
||||||
|
|
||||||
if (tSuccessfulTankAmount > 0) {
|
// Calculating of amounts by fullness of consumers
|
||||||
if (tAmount >= tSuccessfulTankAmount) {
|
for (int tankIndex = 0; tankIndex < tTanksList.size(); tankIndex++) {
|
||||||
tAmount /= tSuccessfulTankAmount;
|
IFluidHandler tTileEntity = tTanksList.get(tankIndex);
|
||||||
for (Entry<IFluidHandler, ForgeDirection> tTileEntity : tTanks.entrySet()) {
|
ForgeDirection dir = tDirectionsList.get(tankIndex);
|
||||||
if (mFluids[index] == null || mFluids[index].amount <= 0) break;
|
FluidTankInfo[] tTankInfoList = tTileEntity.getTankInfo(dir.getOpposite());
|
||||||
int tFilledAmount = tTileEntity.getKey().fill(tTileEntity.getValue(), drain(tAmount, false), false);
|
tTankAmounts.add(0);
|
||||||
if (tFilledAmount > 0)
|
|
||||||
tTileEntity.getKey().fill(tTileEntity.getValue(), drainFromIndex(tFilledAmount, true, index), true);
|
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 {
|
} else {
|
||||||
for (Entry<IFluidHandler, ForgeDirection> tTileEntity : tTanks.entrySet()) {
|
tTankAmounts.set(tankIndex, mCapacity * 20);
|
||||||
if (mFluids[index] == null || mFluids[index].amount <= 0) break;
|
}
|
||||||
int tFilledAmount = tTileEntity.getKey().fill(tTileEntity.getValue(), drainFromIndex(mFluids[index].amount, false, index), false);
|
|
||||||
if (tFilledAmount > 0)
|
totalFreeAmount += tTankAmounts.get(tankIndex);
|
||||||
tTileEntity.getKey().fill(tTileEntity.getValue(), drainFromIndex(tFilledAmount, true, index), true);
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
for (int tFillIndex = 0; tFillIndex < tTanksList.size(); tFillIndex++) {
|
||||||
|
if (tFilledTanksCnt >= tTanksList.size() || tRemainingAmount <= 0) break;
|
||||||
|
|
||||||
|
for (int tankIndex = 0; tankIndex < tTanksList.size(); tankIndex++) {
|
||||||
|
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) {
|
||||||
|
tTileEntity.fill(tDir, 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue