Fluid Regulator code optimization

This commit is contained in:
Blood-Asp 2016-10-26 17:08:28 +02:00 committed by Technus
parent 971e770219
commit 508c229340
2 changed files with 120 additions and 113 deletions

View file

@ -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;
@ -203,7 +204,7 @@ public class GT_MetaPipeEntity_Fluid extends MetaPipeEntity {
continue;
}
}
}
}
FluidTankInfo[] tInfo = tTileEntity.getTankInfo(ForgeDirection.getOrientation(tSide).getOpposite());
if (tInfo != null && tInfo.length > 0) {
if (tTileEntity instanceof ICoverable && ((ICoverable) tTileEntity).getCoverBehaviorAtSide(GT_Utility.getOppositeSide(tSide)).alwaysLookConnected(GT_Utility.getOppositeSide(tSide), ((ICoverable) tTileEntity).getCoverIDAtSide(GT_Utility.getOppositeSide(tSide)), ((ICoverable) tTileEntity).getCoverDataAtSide(GT_Utility.getOppositeSide(tSide)), ((ICoverable) tTileEntity))) {
@ -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);
}
}
}
}
}

View file

@ -9,130 +9,123 @@ import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
public class GT_Cover_FluidRegulator
extends GT_CoverBehavior {
public final int mTransferRate;
public class GT_Cover_FluidRegulator extends GT_CoverBehavior {
public final int mTransferRate;
public GT_Cover_FluidRegulator(int aTransferRate) {
this.mTransferRate = aTransferRate;
}
public GT_Cover_FluidRegulator(int aTransferRate) {
this.mTransferRate = aTransferRate;
}
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;
if (aCoverVariable > 0) {
FluidStack tLiquid = tTank1.drain(ForgeDirection.UNKNOWN, aCoverVariable, false);
if (tLiquid != null) {
tLiquid = tLiquid.copy();
tLiquid.amount = tTank2.fill(ForgeDirection.getOrientation(aSide).getOpposite(), 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);
tTank2.fill(ForgeDirection.getOrientation(aSide).getOpposite(), tTank1.drain(ForgeDirection.UNKNOWN, tLiquid.amount, true), true);
}
} else {
tTank2.fill(ForgeDirection.getOrientation(aSide).getOpposite(), tTank1.drain(ForgeDirection.UNKNOWN, tLiquid.amount, true), true);
}
}
}
} 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 doCoverThings(byte aSide, byte aInputRedstone, int aCoverID, int aCoverVariable, ICoverable aTileEntity,
long aTimer) {
if (aCoverVariable == 0) {
return aCoverVariable;
}
if ((aTileEntity instanceof IFluidHandler)) {
IFluidHandler tTank1;
IFluidHandler tTank2;
if (aCoverVariable > 0) {
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);
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);
tTank2.fill(ForgeDirection.getOrientation(aSide).getOpposite(), tTank1.drain(ForgeDirection.UNKNOWN, tLiquid.amount, true), true);
}
} else {
tTank2.fill(ForgeDirection.getOrientation(aSide).getOpposite(), tTank1.drain(ForgeDirection.UNKNOWN, 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) {
if (GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ)[0] >= 0.5F) {
aCoverVariable += 16;
} else {
aCoverVariable -= 16;
}
if (aCoverVariable > mTransferRate) {
aCoverVariable = mTransferRate;
}
if (aCoverVariable < (0 - mTransferRate)) {
aCoverVariable = (0 - mTransferRate);
}
GT_Utility.sendChatToPlayer(aPlayer, "Pump speed: " + aCoverVariable + "L/tick " + aCoverVariable * 20 + "L/sec");
return aCoverVariable;
}
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 {
aCoverVariable -= 16;
}
if (aCoverVariable > mTransferRate) {
aCoverVariable = mTransferRate;
}
if (aCoverVariable < (0 - mTransferRate)) {
aCoverVariable = (0 - mTransferRate);
}
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) {
if (GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ)[0] >= 0.5F) {
aCoverVariable++;
} else {
aCoverVariable--;
}
if (aCoverVariable > mTransferRate) {
aCoverVariable = mTransferRate;
}
if (aCoverVariable < (0 - mTransferRate)) {
aCoverVariable = (0 - mTransferRate);
}
GT_Utility.sendChatToPlayer(aPlayer, "Pump speed: " + aCoverVariable + "L/tick " + aCoverVariable * 20 + "L/sec");
aTileEntity.setCoverDataAtSide(aSide, aCoverVariable);
return true;
}
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 {
aCoverVariable--;
}
if (aCoverVariable > mTransferRate) {
aCoverVariable = mTransferRate;
}
if (aCoverVariable < (0 - mTransferRate)) {
aCoverVariable = (0 - mTransferRate);
}
GT_Utility.sendChatToPlayer(aPlayer,
"Pump speed: " + aCoverVariable + "L/tick " + aCoverVariable * 20 + "L/sec");
aTileEntity.setCoverDataAtSide(aSide, aCoverVariable);
return true;
}
public boolean letsRedstoneGoIn(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) {
return true;
}
public boolean letsRedstoneGoIn(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) {
return true;
}
public boolean letsRedstoneGoOut(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) {
return true;
}
public boolean letsRedstoneGoOut(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) {
return true;
}
public boolean letsEnergyIn(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) {
return true;
}
public boolean letsEnergyIn(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) {
return true;
}
public boolean letsEnergyOut(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) {
return true;
}
public boolean letsEnergyOut(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) {
return true;
}
public boolean letsItemsIn(byte aSide, int aCoverID, int aCoverVariable, int aSlot, ICoverable aTileEntity) {
return true;
}
public boolean letsItemsIn(byte aSide, int aCoverID, int aCoverVariable, int aSlot, ICoverable aTileEntity) {
return true;
}
public boolean letsItemsOut(byte aSide, int aCoverID, int aCoverVariable, int aSlot, ICoverable aTileEntity) {
return true;
}
public boolean letsItemsOut(byte aSide, int aCoverID, int aCoverVariable, int aSlot, ICoverable aTileEntity) {
return true;
}
public boolean letsFluidIn(byte aSide, int aCoverID, int aCoverVariable, Fluid aFluid, ICoverable aTileEntity) {
return false;
}
public boolean letsFluidIn(byte aSide, int aCoverID, int aCoverVariable, Fluid aFluid, ICoverable aTileEntity) {
return false;
}
public boolean letsFluidOut(byte aSide, int aCoverID, int aCoverVariable, Fluid aFluid, ICoverable aTileEntity) {
return aFluid == null;
}
public boolean letsFluidOut(byte aSide, int aCoverID, int aCoverVariable, Fluid aFluid, ICoverable aTileEntity) {
return false;
}
public boolean alwaysLookConnected(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) {
return true;
}
public boolean alwaysLookConnected(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) {
return true;
}
public int getTickRate(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) {
return 1;
}
public int getTickRate(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) {
return 1;
}
}