Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Power rebalance #8258

Draft
wants to merge 21 commits into
base: 1.21.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6e89dcc
initial test numbers
thiakil Sep 15, 2024
a6dd001
make heat gen numbers work adequately
thiakil Sep 15, 2024
79176a8
biofuel recalculation
thiakil Sep 15, 2024
ca2021b
biofuel recalculation
thiakil Sep 17, 2024
c7160c8
make GBG able to fully burn hydrogen produced by one Separator
thiakil Sep 22, 2024
235eb91
make separator only use special behavior if processing hydrogen. All …
thiakil Sep 22, 2024
0b4764f
remove outdated todo
thiakil Sep 23, 2024
03494e8
scale only the separator by operations cost
thiakil Sep 23, 2024
4199613
trial machine buffers based on max usage per full operation or 4 tick…
thiakil Sep 23, 2024
6ea79a9
ensure uncapped energy containers dont return less than 0 for getNeeded
thiakil Sep 23, 2024
b0701e3
make biofuel base recipes manual again
thiakil Sep 27, 2024
d54ec9f
remove compat biofuel recipes from compostable, most should be covere…
thiakil Sep 27, 2024
dd0b08d
rewrite Gas Generator consumption, remove generators' max output rest…
thiakil Sep 28, 2024
9c16c1e
fix bad bio recipes
thiakil Sep 28, 2024
d81875a
lang for bio fuel per item config
thiakil Sep 28, 2024
5f6767b
GBG numbers
thiakil Sep 28, 2024
581302f
dont display empty decimals from unit conversions
thiakil Oct 1, 2024
8a14c09
use multiblock method to get turbine generation rate
thiakil Oct 1, 2024
26a5ce8
move max floaw calculation to a method and remove dupes
thiakil Oct 1, 2024
3d5d295
tweak turbine generation amounts
thiakil Nov 16, 2024
b67dc1e
Merge branch '1.21.x' into power-rebalance
thiakil Nov 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.function.Consumer;
import java.util.function.IntSupplier;
import java.util.function.LongSupplier;
import mekanism.api.MekanismAPI;
import mekanism.api.chemical.Chemical;
import mekanism.api.math.MathUtils;
import mekanism.api.providers.IChemicalProvider;
Expand All @@ -13,6 +12,7 @@
import mekanism.api.text.EnumColor;
import mekanism.api.text.ITooltipHelper;
import net.minecraft.network.chat.Component;
import org.jetbrains.annotations.Range;

/**
* @since 10.7.0 Previously was GasAttributes
Expand Down Expand Up @@ -194,65 +194,57 @@ public Chemical getCooledChemical() {
}

/**
* Defines a fuel which can be processed by a Gas-Burning Generator to produce energy. Fuels have two primary values: 'burn ticks', defining how many ticks one mB of
* fuel can be burned for before being depleted, and 'energyDensity', defining how much energy is stored in one mB of fuel.
* Defines a fuel which can be processed by a Gas-Burning Generator to produce energy.
* Fuels have two primary values:
* - 'max burn per tick', defining how many mB per tick can be burnt (max amount burned when tank is full)
* - 'energy density', defining how much energy is stored in one mB of fuel.
*
* @author aidancbrady
*/
public static class Fuel extends ChemicalAttribute {

private final IntSupplier burnTicks;
private final IntSupplier maxBurnPerTick;
private final LongSupplier energyDensity;

/**
* @param burnTicks The number of ticks one mB of fuel can be burned for before being depleted; must be greater than zero.
* @param energyDensity The energy density in one mB of fuel; must be greater than zero.
* @param maxBurnPerTick how many mB per tick can be burnt; must be greater than zero.
* @param energyDensity The energy density in one mB of fuel; must be greater than zero.
*
* @since 10.4.0
* @since 10.7.8
*/
public Fuel(int burnTicks, long energyDensity) {
if (burnTicks <= 0) {
throw new IllegalArgumentException("Fuel attributes must burn for at least one tick! Burn Ticks: " + burnTicks);
public Fuel(int maxBurnPerTick, long energyDensity) {
if (maxBurnPerTick <= 0) {
throw new IllegalArgumentException("Fuel attributes must be able to burn at least 1 per tick. maxBurnPerTick: " + maxBurnPerTick);
} else if (energyDensity <= 0) {
throw new IllegalArgumentException("Fuel attributes must have an energy density greater than zero!");
} else if (energyDensity / burnTicks == 0L) {
throw new IllegalArgumentException("Energy density per tick must be greater than zero! (integer division)");
}
this.burnTicks = () -> burnTicks;
this.maxBurnPerTick = () -> maxBurnPerTick;
this.energyDensity = () -> energyDensity;
}

/**
* @param burnTicks Supplier for the number of ticks one mB of fuel can be burned for before being depleted. The supplier should return values greater than
* zero.
* @param energyDensity Supplier for the energy density of one mB of fuel. The supplier should return values be greater than zero.
* @param maxBurnPerTick Supplier for how many mB per tick can be burnt. The supplier should return values greater than zero.
* @param energyDensity Supplier for the energy density of one mB of fuel. The supplier should return values be greater than zero.
*/
public Fuel(IntSupplier burnTicks, LongSupplier energyDensity) {
this.burnTicks = burnTicks;
public Fuel(IntSupplier maxBurnPerTick, LongSupplier energyDensity) {
this.maxBurnPerTick = maxBurnPerTick;
this.energyDensity = energyDensity;
}

/**
* Gets the number of ticks this fuel burns for.
*/
public int getBurnTicks() {
return burnTicks.getAsInt();
@Range(from = 1, to = Integer.MAX_VALUE)
public int getMaxBurnPerTick() {
return Math.max(maxBurnPerTick.getAsInt(), 1);
}

/**
* Gets the amount of energy produced per tick of this fuel.
*/
public long getEnergyPerTick() {
int ticks = getBurnTicks();
//If we have less than one tick, the density is invalid
if (ticks < 1) {
MekanismAPI.logger.warn("Invalid tick count ({}) for Fuel attribute, this number should be at least 1.", ticks);
return 0;
} else if (ticks == 1) {
//Single tick, no division necessary
return energyDensity.getAsLong();
}
return energyDensity.getAsLong() / ticks;
@Range(from = 1, to = Integer.MAX_VALUE)
public long getEnergyDensity() {
return Math.max(energyDensity.getAsLong(), 1);
}

@Override
Expand All @@ -265,9 +257,15 @@ public List<Component> addTooltipText(List<Component> list) {
@Override
public void collectTooltips(Consumer<Component> adder) {
ITooltipHelper tooltipHelper = ITooltipHelper.INSTANCE;
adder.accept(APILang.CHEMICAL_ATTRIBUTE_FUEL_BURN_TICKS.translateColored(EnumColor.GRAY, EnumColor.INDIGO, tooltipHelper.getFormattedNumber(getBurnTicks())));
adder.accept(APILang.CHEMICAL_ATTRIBUTE_FUEL_MAX_BURN.translateColored(EnumColor.GRAY, EnumColor.INDIGO, tooltipHelper.getFluidDisplay(getMaxBurnPerTick(), true)));
adder.accept(APILang.CHEMICAL_ATTRIBUTE_FUEL_ENERGY_DENSITY.translateColored(EnumColor.GRAY, EnumColor.INDIGO,
tooltipHelper.getEnergyPerMBDisplayShort(energyDensity.getAsLong())));
adder.accept(APILang.CHEMICAL_ATTRIBUTE_FUEL_ENERGY_MAX_TOTAL.translateColored(EnumColor.GRAY, EnumColor.INDIGO,
tooltipHelper.getEnergyDisplay(getMaxJoulesPerTick(), true)));
}

public long getMaxJoulesPerTick() {
return getMaxBurnPerTick() * energyDensity.getAsLong();
}
}
}
2 changes: 1 addition & 1 deletion src/api/java/mekanism/api/energy/IEnergyContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ default void setEmpty() {
*/
@Range(from = 0, to = Long.MAX_VALUE)
default long getNeeded() {
return getMaxEnergy() - getEnergy();
return Math.max(0L, getMaxEnergy() - getEnergy());
}

@Override
Expand Down
26 changes: 19 additions & 7 deletions src/api/java/mekanism/api/recipes/cache/CachedRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ public abstract class CachedRecipe<RECIPE extends MekanismRecipe<?>> {
private IntConsumer operatingTicksChanged = ticks -> {
};

/**
* Whether multiple operations multiply the power usage.
* Currently only used for Hydrogen separating.
*/
private boolean multipleOperationsCost = false;

/**
* @param recipe Recipe.
* @param recheckAllErrors Returns {@code true} if processing should be continued even if an error is hit in order to gather all the errors. It is recommended to not
Expand Down Expand Up @@ -252,6 +258,15 @@ public CachedRecipe<RECIPE> setPostProcessOperations(Consumer<OperationTracker>
return this;
}

/**
* Sets whether the calculated operations increase the energy cost subtracted from the container.
* Currently only used for Hydrogen Separation.
*/
public CachedRecipe<RECIPE> setOperationsCost(boolean value) {
this.multipleOperationsCost = value;
return this;
}

/**
* Sets the callback that run when the set of known {@link RecipeError}s of this {@link CachedRecipe} changes.
*
Expand Down Expand Up @@ -320,7 +335,7 @@ public void process() {
postProcessOperations.accept(tracker);
//If we should continue checking try to cap the max at the max amount we have for energy that we didn't cap it at earlier
// Note: We don't have to always try and cap it as if we shouldn't continue checking that means we are already stopped.
if (tracker.shouldContinueChecking() && tracker.capAtMaxForEnergy()) {
if (tracker.shouldContinueChecking() && (multipleOperationsCost && tracker.capAtMaxForEnergy())) {
//If we lowered the maximum number of operations due to our available energy, then we add an error that we don't have
// enough energy to run at our maximum rate
tracker.addError(RecipeError.NOT_ENOUGH_ENERGY_REDUCED_RATE);
Expand Down Expand Up @@ -404,13 +419,10 @@ protected void resetCache() {
*/
protected void useEnergy(int operations) {
long energy = perTickEnergy.getAsLong();
if (operations == 1) {
//While floating long will short circuit any calculations if multiplied by one given we require making a copy to ensure we don't
// modify the source value, if we do the check here manually as well, then we can skip creating unnecessary objects
useEnergy.accept(energy);
} else {
useEnergy.accept(energy * operations);
if (this.multipleOperationsCost) {
energy = energy * operations;
}
useEnergy.accept(energy);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/api/java/mekanism/api/text/APILang.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ public enum APILang implements ILangEntry {
CHEMICAL_ATTRIBUTE_RADIATION("chemical", "attribute.radiation"),
CHEMICAL_ATTRIBUTE_COOLANT_EFFICIENCY("chemical", "attribute.coolant.efficiency"),
CHEMICAL_ATTRIBUTE_COOLANT_ENTHALPY("chemical", "attribute.coolant.heat_capacity"),
CHEMICAL_ATTRIBUTE_FUEL_BURN_TICKS("chemical", "attribute.fuel.burn_ticks"),
CHEMICAL_ATTRIBUTE_FUEL_MAX_BURN("chemical", "attribute.fuel.max_burn"),
CHEMICAL_ATTRIBUTE_FUEL_ENERGY_DENSITY("chemical", "attribute.fuel.energy_density"),
CHEMICAL_ATTRIBUTE_FUEL_ENERGY_MAX_TOTAL("chemical", "attribute.fuel.energy_max_total"),
//Security
PUBLIC("security", "public"),
TRUSTED("security", "trusted"),
Expand Down
4 changes: 4 additions & 0 deletions src/api/java/mekanism/api/text/ITooltipHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ public interface ITooltipHelper {
String getFormattedNumber(long number);

Component getPercent(double ratio);

Component getEnergyDisplay(long joules, boolean perTick);

Component getFluidDisplay(long joules, boolean perTick);
}
Loading