Fluid Regulator code optimization
This commit is contained in:
parent
2d5c40ef8f
commit
4a8a0ab576
2 changed files with 120 additions and 113 deletions
|
@ -2,6 +2,7 @@ package gregtech.api.metatileentity.implementations;
|
|||
|
||||
import gregtech.api.GregTech_API;
|
||||
import gregtech.api.enums.Dyes;
|
||||
import gregtech.api.enums.ItemList;
|
||||
import gregtech.api.enums.Materials;
|
||||
import gregtech.api.enums.OrePrefixes;
|
||||
import gregtech.api.enums.SubTag;
|
||||
|
@ -217,9 +218,22 @@ public class GT_MetaPipeEntity_Fluid extends MetaPipeEntity {
|
|||
if (((1 << tSide) & mLastReceivedFrom) == 0)
|
||||
tTanks.put(tTileEntity, ForgeDirection.getOrientation(tSide).getOpposite());
|
||||
}
|
||||
|
||||
if (aBaseMetaTileEntity.getCoverBehaviorAtSide(tSide).alwaysLookConnected(tSide, aBaseMetaTileEntity.getCoverIDAtSide(tSide), aBaseMetaTileEntity.getCoverDataAtSide(tSide), aBaseMetaTileEntity)) {
|
||||
mConnections |= (1 << tSide);
|
||||
}
|
||||
}else if(tInfo != null && tInfo.length == 0){
|
||||
IGregTechTileEntity tSideTile = aBaseMetaTileEntity.getIGregTechTileEntityAtSide(tSide);
|
||||
if(tSideTile!=null){
|
||||
ItemStack tCover = tSideTile.getCoverItemAtSide(GT_Utility.getOppositeSide(tSide));
|
||||
if (tCover!=null &&(GT_Utility.areStacksEqual(tCover, ItemList.FluidRegulator_LV.get(1, new Object[]{},true)) ||
|
||||
GT_Utility.areStacksEqual(tCover, ItemList.FluidRegulator_MV.get(1, new Object[]{},true)) ||
|
||||
GT_Utility.areStacksEqual(tCover, ItemList.FluidRegulator_HV.get(1, new Object[]{},true)) ||
|
||||
GT_Utility.areStacksEqual(tCover, ItemList.FluidRegulator_EV.get(1, new Object[]{},true)) ||
|
||||
GT_Utility.areStacksEqual(tCover, ItemList.FluidRegulator_IV.get(1, new Object[]{},true)))) {
|
||||
mConnections |= (1 << tSide);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,24 +9,30 @@ import net.minecraftforge.fluids.Fluid;
|
|||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
public class GT_Cover_FluidRegulator
|
||||
extends GT_CoverBehavior {
|
||||
public class GT_Cover_FluidRegulator extends GT_CoverBehavior {
|
||||
public final int mTransferRate;
|
||||
|
||||
public GT_Cover_FluidRegulator(int aTransferRate) {
|
||||
this.mTransferRate = aTransferRate;
|
||||
}
|
||||
|
||||
public int doCoverThings(byte aSide, byte aInputRedstone, int aCoverID, int aCoverVariable, ICoverable aTileEntity, long aTimer) {
|
||||
public int doCoverThings(byte aSide, byte aInputRedstone, int aCoverID, int aCoverVariable, ICoverable aTileEntity,
|
||||
long aTimer) {
|
||||
if (aCoverVariable == 0) {
|
||||
return aCoverVariable;
|
||||
}
|
||||
if ((aTileEntity instanceof IFluidHandler)) {
|
||||
IFluidHandler tTank2 = aTileEntity.getITankContainerAtSide(aSide);
|
||||
if (tTank2 != null) {
|
||||
IFluidHandler tTank1 = (IFluidHandler) aTileEntity;
|
||||
IFluidHandler tTank1;
|
||||
IFluidHandler tTank2;
|
||||
if (aCoverVariable > 0) {
|
||||
FluidStack tLiquid = tTank1.drain(ForgeDirection.UNKNOWN, aCoverVariable, false);
|
||||
tTank2 = aTileEntity.getITankContainerAtSide(aSide);
|
||||
tTank1 = (IFluidHandler) aTileEntity;
|
||||
} else {
|
||||
tTank1 = aTileEntity.getITankContainerAtSide(aSide);
|
||||
tTank2 = (IFluidHandler) aTileEntity;
|
||||
}
|
||||
if (tTank1 != null && tTank2 != null) {
|
||||
FluidStack tLiquid = tTank1.drain(ForgeDirection.UNKNOWN, Math.abs(aCoverVariable), false);
|
||||
if (tLiquid != null) {
|
||||
tLiquid = tLiquid.copy();
|
||||
tLiquid.amount = tTank2.fill(ForgeDirection.getOrientation(aSide).getOpposite(), tLiquid, false);
|
||||
|
@ -41,29 +47,13 @@ public class GT_Cover_FluidRegulator
|
|||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
FluidStack tLiquid = tTank2.drain(ForgeDirection.getOrientation(aSide).getOpposite(), Math.abs(aCoverVariable), false);
|
||||
if (tLiquid != null) {
|
||||
tLiquid = tLiquid.copy();
|
||||
tLiquid.amount = tTank1.fill(ForgeDirection.UNKNOWN, tLiquid, false);
|
||||
if (tLiquid.amount > 0) {
|
||||
if (aTileEntity.getUniversalEnergyCapacity() >= Math.min(1, tLiquid.amount / 10)) {
|
||||
if (aTileEntity.isUniversalEnergyStored(Math.min(1, tLiquid.amount / 10))) {
|
||||
aTileEntity.decreaseStoredEnergyUnits(Math.min(1, tLiquid.amount / 10), true);
|
||||
tTank1.fill(ForgeDirection.UNKNOWN, tTank2.drain(ForgeDirection.getOrientation(aSide).getOpposite(), tLiquid.amount, true), true);
|
||||
}
|
||||
} else {
|
||||
tTank1.fill(ForgeDirection.UNKNOWN, tTank2.drain(ForgeDirection.getOrientation(aSide).getOpposite(), tLiquid.amount, true), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return aCoverVariable;
|
||||
}
|
||||
|
||||
public int onCoverScrewdriverclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) {
|
||||
public int onCoverScrewdriverclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity,
|
||||
EntityPlayer aPlayer, float aX, float aY, float aZ) {
|
||||
if (GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ)[0] >= 0.5F) {
|
||||
aCoverVariable += 16;
|
||||
} else {
|
||||
|
@ -75,11 +65,13 @@ public class GT_Cover_FluidRegulator
|
|||
if (aCoverVariable < (0 - mTransferRate)) {
|
||||
aCoverVariable = (0 - mTransferRate);
|
||||
}
|
||||
GT_Utility.sendChatToPlayer(aPlayer, "Pump speed: " + aCoverVariable + "L/tick " + aCoverVariable * 20 + "L/sec");
|
||||
GT_Utility.sendChatToPlayer(aPlayer,
|
||||
"Pump speed: " + aCoverVariable + "L/tick " + aCoverVariable * 20 + "L/sec");
|
||||
return aCoverVariable;
|
||||
}
|
||||
|
||||
public boolean onCoverRightclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) {
|
||||
public boolean onCoverRightclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity,
|
||||
EntityPlayer aPlayer, float aX, float aY, float aZ) {
|
||||
if (GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ)[0] >= 0.5F) {
|
||||
aCoverVariable++;
|
||||
} else {
|
||||
|
@ -91,7 +83,8 @@ public class GT_Cover_FluidRegulator
|
|||
if (aCoverVariable < (0 - mTransferRate)) {
|
||||
aCoverVariable = (0 - mTransferRate);
|
||||
}
|
||||
GT_Utility.sendChatToPlayer(aPlayer, "Pump speed: " + aCoverVariable + "L/tick " + aCoverVariable * 20 + "L/sec");
|
||||
GT_Utility.sendChatToPlayer(aPlayer,
|
||||
"Pump speed: " + aCoverVariable + "L/tick " + aCoverVariable * 20 + "L/sec");
|
||||
aTileEntity.setCoverDataAtSide(aSide, aCoverVariable);
|
||||
return true;
|
||||
}
|
||||
|
@ -125,7 +118,7 @@ public class GT_Cover_FluidRegulator
|
|||
}
|
||||
|
||||
public boolean letsFluidOut(byte aSide, int aCoverID, int aCoverVariable, Fluid aFluid, ICoverable aTileEntity) {
|
||||
return aFluid == null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean alwaysLookConnected(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) {
|
||||
|
|
Loading…
Reference in a new issue