Skip to content

Commit 490a37f

Browse files
committed
Balance annihilation plane enchantment energy cost (#8590)
The current implementation had two problems: Enchanting an annihilation plane with any level of efficiency (and nothing else) would reduce the required energy to zero due to multiplying with the 0 in levelSum directly. Enchanting an annihilation plane with unbreaking would increase the energy cost by a factor of 8 per level of unbreaking, but only leading to an average saving of 50% (lv1), 33% (lv2), or 25% (lv3), effectively increasing the average cost rather than reducing it. Fixes #8188 --------- Co-authored-by: Sebastian Hartte <shartte@users.noreply.github.com> (cherry picked from commit 68e2b82) (cherry picked from commit 8aa0c6b)
1 parent 22bc441 commit 490a37f

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

src/main/java/appeng/parts/automation/ItemPickupStrategy.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,20 +254,22 @@ protected float calculateEnergyUsage(ServerLevel level, BlockPos pos, List<ItemS
254254

255255
if (enchantments != null) {
256256
var efficiencyFactor = 1f;
257-
var efficiencyLevel = 0;
258-
if (enchantments.containsKey(Enchantments.BLOCK_EFFICIENCY)) {
257+
var efficiencyLevel = enchantments.getOrDefault(Enchantments.BLOCK_EFFICIENCY, 0);
258+
if (efficiencyLevel > 0) {
259259
// Reduce total energy usage incurred by other enchantments by 15% per Efficiency level.
260-
efficiencyLevel = enchantments.get(Enchantments.BLOCK_EFFICIENCY);
261260
efficiencyFactor *= Math.pow(0.85, efficiencyLevel);
262261
}
263-
if (enchantments.containsKey(Enchantments.UNBREAKING)) {
262+
var unbreakingLevel = enchantments.getOrDefault(Enchantments.UNBREAKING, 0);
263+
if (unbreakingLevel > 0) {
264264
// Give plane only a (100 / (level + 1))% chance to use energy.
265265
// This is similar to vanilla Unbreaking behaviour for tools.
266-
int randomNumber = level.getRandom().nextInt(enchantments.get(Enchantments.UNBREAKING) + 1);
266+
int randomNumber = level.getRandom().nextInt(unbreakingLevel + 1);
267267
useEnergy = randomNumber == 0;
268268
}
269-
var levelSum = enchantments.values().stream().reduce(0, Integer::sum) - efficiencyLevel;
270-
requiredEnergy *= 8 * levelSum * efficiencyFactor;
269+
// Increase energy usage 8x for each *other* enchantment that might affect the pickup.
270+
// Ignore efficiency & unbreaking since we did account for them here explicitly.
271+
var levelSum = enchantments.values().stream().reduce(0, Integer::sum) - efficiencyLevel - unbreakingLevel;
272+
requiredEnergy *= (levelSum > 0 ? 8 * levelSum : 1) * efficiencyFactor;
271273
}
272274

273275
return useEnergy ? requiredEnergy : 0;

0 commit comments

Comments
 (0)