Skip to content
This repository has been archived by the owner on May 25, 2024. It is now read-only.

Commit

Permalink
Only tick the tank once per second, adjust the output to match
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenraven committed May 7, 2024
1 parent ae3733d commit c22843c
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/main/java/goodgenerator/blocks/tileEntity/YottaFluidTank.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public class YottaFluidTank extends GT_MetaTileEntity_TooltipMultiBlockBase_EM
protected IStructureDefinition<YottaFluidTank> multiDefinition = null;
protected final ArrayList<YOTTAHatch> mYottaHatch = new ArrayList<>();

private static final BigInteger ONE_HUNDRED = BigInteger.valueOf(100);
private static final BigInteger FIVE = BigInteger.valueOf(5);

/** Tank capacity */
public BigInteger mStorage = BigInteger.ZERO;
/** Amount of fluid millibuckets currently in the tank */
Expand All @@ -87,6 +90,7 @@ public class YottaFluidTank extends GT_MetaTileEntity_TooltipMultiBlockBase_EM
protected final String YOTTANK_MID = mName + "mid";
protected final String YOTTANK_TOP = mName + "top";
protected final NumberFormatMUI numberFormat = new NumberFormatMUI();
private int workTickCounter = 0;

private static final BigInteger MAX_INT_BIGINT = BigInteger.valueOf(Integer.MAX_VALUE);

Expand Down Expand Up @@ -168,7 +172,7 @@ public boolean getIsVoidExcessEnabled() {

/**
* Attempts to remove {@code amount} of fluid from the tank if possible, does not do partial removals.
*
*
* @param amount The millibucket amount of the fluid to remove
* @return True if successfully removed amount, false if no fluid was removed.
*/
Expand All @@ -185,7 +189,7 @@ public boolean reduceFluid(long amount) {
/**
* Attempts to put {@code amount} of fluid into the tank if possible, fails if there's not enough space for all of
* it.
*
*
* @param amount The millibucket amount of the fluid to insert
* @return True if successfully added the given amount of fluid to the tank, false if failed.
*/
Expand Down Expand Up @@ -357,8 +361,6 @@ public String[] getInfoData() {
+ EnumChatFormatting.RESET) };
}

static final BigInteger ONE_HUNDRED = BigInteger.valueOf(100);

private String getPercent() {
if (mStorage.signum() == 0) return "0";
return mStorageCurrent.multiply(ONE_HUNDRED).divide(mStorage).toString();
Expand Down Expand Up @@ -401,6 +403,12 @@ public BigInteger calStorage(int meta) {
public boolean onRunningTick(ItemStack aStack) {
super.onRunningTick(aStack);
if (this.getBaseMetaTileEntity().isServerSide()) {
++workTickCounter;
if (workTickCounter < 20) {
return true;
}
workTickCounter = 0;

List<FluidStack> tStore = getStoredFluids();
for (FluidStack tFluid : tStore) {
if (tFluid == null) continue;
Expand Down Expand Up @@ -435,8 +443,8 @@ public boolean onRunningTick(ItemStack aStack) {
}

if (StringUtils.isNotEmpty(mFluidName)) {
int outputAmount = mStorageCurrent.divide(ONE_HUNDRED).min(MAX_INT_BIGINT).max(BigInteger.ONE)
.intValueExact();
// Try to drain 1% of the tank per tick, so 20% per second aka 1/5
int outputAmount = mStorageCurrent.divide(FIVE).min(MAX_INT_BIGINT).max(BigInteger.ONE).intValueExact();
final int originalOutputAmount = outputAmount;

final FluidStack fluidToOutput = FluidRegistry.getFluidStack(mFluidName, outputAmount);
Expand Down

0 comments on commit c22843c

Please sign in to comment.