Skip to content

Commit

Permalink
Always clamp current power when changing max power (AppliedEnergistic…
Browse files Browse the repository at this point in the history
…s#7443)

If the new max power was lower than the current power, the clamping took
only place if the new max power was larger than the default max power,
i.e. it worked for any energy card but the last one.

Fixes AppliedEnergistics#7431

There is a potential for refactoring here, depending on whether the 3
functions setAEMaxPowerMultiplier, setAEMaxPower, and resetAEMaxPower
are considered to be a stable API or not. I chose to not refactor for
compatibility reasons. Deciding if that is the way to go is up to a
reviewer in my opinion.

Be advised that this is my first time coding for any Minecraft mod, but
the change should be small enough for a starter task.
  • Loading branch information
Mithi83 authored Nov 10, 2023
1 parent e6a49c3 commit bbc6f72
Showing 1 changed file with 2 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,14 @@ protected final void setAEMaxPower(ItemStack stack, double maxPower) {
*/
protected final void setAEMaxPowerMultiplier(ItemStack stack, int multiplier) {
multiplier = Mth.clamp(multiplier, 1, 100);
if (multiplier == 1) {
resetAEMaxPower(stack);
} else {
setAEMaxPower(stack, multiplier * powerCapacity.getAsDouble());
}
setAEMaxPower(stack, multiplier * powerCapacity.getAsDouble());
}

/**
* Clears any custom maximum power from the given stack.
*/
protected final void resetAEMaxPower(ItemStack stack) {
stack.removeTagKey(MAX_POWER_NBT_KEY);
setAEMaxPower(stack, powerCapacity.getAsDouble());
}

@Override
Expand Down

0 comments on commit bbc6f72

Please sign in to comment.