Skip to content

Commit caf58da

Browse files
committed
Remove capturing lambda's from vein and blast mining calculations
1 parent 2f4c4b6 commit caf58da

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

src/main/java/mekanism/common/item/gear/ItemAtomicDisassembler.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,11 @@ public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, Player player) {
174174
if (energyContainer.extract(energyRequired, Action.SIMULATE, AutomationType.MANUAL).greaterOrEqual(energyRequired)) {
175175
// Only allow mining things that are considered an ore
176176
if (ModuleVeinMiningUnit.canVeinBlock(state) && state.is(MekanismTags.Blocks.ATOMIC_DISASSEMBLER_ORE)) {
177-
Object2IntMap<BlockPos> found = ModuleVeinMiningUnit.findPositions(world, Map.of(pos, state), 0, Reference2BooleanMaps.singleton(state.getBlock(), true));
178-
MekanismUtils.veinMineArea(energyContainer, energyRequired, world, pos, (ServerPlayer) player, stack, this, found, hardness -> FloatingLong.ZERO,
179-
(hardness, distance, bs) -> getDestroyEnergy(baseDestroyEnergy, hardness).multiply(0.5 * Math.pow(distance, 1.5)));
177+
Object2IntMap<BlockPos> found = ModuleVeinMiningUnit.findPositions(world, Map.of(pos, state), 0,
178+
Reference2BooleanMaps.singleton(state.getBlock(), true));
179+
MekanismUtils.veinMineArea(energyContainer, energyRequired, FloatingLong.ZERO, baseDestroyEnergy, world, pos, (ServerPlayer) player, stack,
180+
this, found, (base, hardness) -> FloatingLong.ZERO,
181+
(base, hardness, distance, bs) -> getDestroyEnergy(base, hardness).multiply(0.5 * Math.pow(distance, 1.5)));
180182
}
181183
}
182184
}
@@ -187,7 +189,7 @@ private FloatingLong getDestroyEnergy(ItemStack itemStack, float hardness) {
187189
return getDestroyEnergy(getDestroyEnergy(itemStack), hardness);
188190
}
189191

190-
private FloatingLong getDestroyEnergy(FloatingLong baseDestroyEnergy, float hardness) {
192+
private static FloatingLong getDestroyEnergy(FloatingLong baseDestroyEnergy, float hardness) {
191193
return hardness == 0 ? baseDestroyEnergy.divide(2) : baseDestroyEnergy;
192194
}
193195

src/main/java/mekanism/common/item/gear/ItemMekaTool.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,9 @@ public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, Player player) {
309309
if (!veinedBlocks.isEmpty()) {
310310
//Don't include bonus energy required by efficiency modules when calculating energy of vein mining targets
311311
FloatingLong baseDestroyEnergy = getDestroyEnergy(silk);
312-
MekanismUtils.veinMineArea(energyContainer, energyRequired, world, pos, (ServerPlayer) player, stack, this, veinedBlocks,
313-
hardness -> getDestroyEnergy(modDestroyEnergy, hardness),
314-
(hardness, distance, bs) -> getDestroyEnergy(baseDestroyEnergy, hardness).multiply(0.5 * Math.pow(distance, oreTracker.getBoolean(bs.getBlock()) ? 1.5 : 2)));
312+
MekanismUtils.veinMineArea(energyContainer, energyRequired, modDestroyEnergy, baseDestroyEnergy, world, pos, (ServerPlayer) player, stack, this, veinedBlocks,
313+
ItemMekaTool::getDestroyEnergy, (base, hardness, distance, bs) -> getDestroyEnergy(base, hardness)
314+
.multiply(0.5 * Math.pow(distance, bs.is(MekanismTags.Blocks.ATOMIC_DISASSEMBLER_ORE) ? 1.5 : 2)));
315315
}
316316
}
317317
}
@@ -322,17 +322,17 @@ private static FloatingLong getDestroyEnergy(boolean silk) {
322322
return silk ? MekanismConfig.gear.mekaToolEnergyUsageSilk.get() : MekanismConfig.gear.mekaToolEnergyUsage.get();
323323
}
324324

325-
public FloatingLong getDestroyEnergy(ItemStack itemStack, float hardness, boolean silk) {
325+
public static FloatingLong getDestroyEnergy(ItemStack itemStack, float hardness, boolean silk) {
326326
return getDestroyEnergy(getDestroyEnergy(itemStack, silk), hardness);
327327
}
328328

329329
private static FloatingLong getDestroyEnergy(FloatingLong baseDestroyEnergy, float hardness) {
330330
return hardness == 0 ? baseDestroyEnergy.divide(2) : baseDestroyEnergy;
331331
}
332332

333-
private FloatingLong getDestroyEnergy(ItemStack itemStack, boolean silk) {
333+
private static FloatingLong getDestroyEnergy(ItemStack itemStack, boolean silk) {
334334
FloatingLong destroyEnergy = getDestroyEnergy(silk);
335-
IModule<ModuleExcavationEscalationUnit> module = getEnabledModule(itemStack, MekanismModules.EXCAVATION_ESCALATION_UNIT);
335+
IModule<ModuleExcavationEscalationUnit> module = IModuleHelper.INSTANCE.getIfEnabled(itemStack, MekanismModules.EXCAVATION_ESCALATION_UNIT);
336336
float efficiency = module == null ? MekanismConfig.gear.mekaToolBaseEfficiency.get() : module.getCustomInstance().getEfficiency();
337337
return destroyEnergy.multiply(efficiency);
338338
}

src/main/java/mekanism/common/util/MekanismUtils.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,9 @@ public static Map<FluidType, FluidInDetails> getFluidsIn(Player player, double d
721721
return fluidsIn;
722722
}
723723

724-
public static void veinMineArea(IEnergyContainer energyContainer, FloatingLong energyRequired, Level world, BlockPos pos, ServerPlayer player, ItemStack stack, Item usedTool,
725-
Object2IntMap<BlockPos> found, BlastEnergyFunction blastEnergy, VeinEnergyFunction veinEnergy) {
724+
public static void veinMineArea(IEnergyContainer energyContainer, FloatingLong energyRequired, FloatingLong baseBlastEnergy, FloatingLong baseVeinEnergy,
725+
Level world, BlockPos pos, ServerPlayer player, ItemStack stack, Item usedTool, Object2IntMap<BlockPos> found, BlastEnergyFunction blastEnergy,
726+
VeinEnergyFunction veinEnergy) {
726727
FloatingLong energyUsed = FloatingLong.ZERO;
727728
FloatingLong energyAvailable = energyContainer.getEnergy();
728729
//Subtract from our available energy the amount that we will require to break the target block
@@ -741,7 +742,7 @@ public static void veinMineArea(IEnergyContainer energyContainer, FloatingLong e
741742
continue;
742743
}
743744
int distance = foundEntry.getIntValue();
744-
FloatingLong destroyEnergy = distance == 0 ? blastEnergy.calc(hardness) : veinEnergy.calc(hardness, distance, targetState);
745+
FloatingLong destroyEnergy = distance == 0 ? blastEnergy.calc(baseBlastEnergy, hardness) : veinEnergy.calc(baseVeinEnergy, hardness, distance, targetState);
745746
if (energyUsed.add(destroyEnergy).greaterThan(energyAvailable)) {
746747
//If we don't have energy to break the block continue
747748
//Note: We do not break as given the energy scales with hardness, so it is possible we still have energy to break another block
@@ -824,12 +825,12 @@ public double getMaxHeight() {
824825
@FunctionalInterface
825826
public interface BlastEnergyFunction {
826827

827-
FloatingLong calc(float hardness);
828+
FloatingLong calc(FloatingLong baseBlastEnergy, float hardness);
828829
}
829830

830831
@FunctionalInterface
831832
public interface VeinEnergyFunction {
832833

833-
FloatingLong calc(float hardness, int distance, BlockState state);
834+
FloatingLong calc(FloatingLong baseVeinEnergy, float hardness, int distance, BlockState state);
834835
}
835836
}

0 commit comments

Comments
 (0)