@@ -93,10 +93,10 @@ public class ItemMekaTool extends ItemEnergized implements IRadialModuleContaine
9393
9494 public ItemMekaTool (Properties properties ) {
9595 super (IModuleHelper .INSTANCE .applyModuleContainerProperties (properties .rarity (Rarity .EPIC ).setNoRepair ()
96- .component (DataComponents .TOOL , new Tool (List .of (
97- Tool .Rule .deniesDrops (MekanismTags .Blocks .INCORRECT_FOR_MEKA_TOOL ),
98- new Tool .Rule (new AnyHolderSet <>(BuiltInRegistries .BLOCK .asLookup ()), Optional .empty (), Optional .of (true ))
99- ), 1 , 0 ))
96+ .component (DataComponents .TOOL , new Tool (List .of (
97+ Tool .Rule .deniesDrops (MekanismTags .Blocks .INCORRECT_FOR_MEKA_TOOL ),
98+ new Tool .Rule (new AnyHolderSet <>(BuiltInRegistries .BLOCK .asLookup ()), Optional .empty (), Optional .of (true ))
99+ ), 1 , 0 ))
100100 ));
101101 }
102102
@@ -249,11 +249,31 @@ public float getDestroySpeed(@NotNull ItemStack stack, @NotNull BlockState state
249249 }
250250
251251 @ Override
252- public boolean mineBlock (@ NotNull ItemStack stack , @ NotNull Level world , @ NotNull BlockState state , @ NotNull BlockPos pos , @ NotNull LivingEntity entityliving ) {
252+ public boolean mineBlock (@ NotNull ItemStack stack , @ NotNull Level world , @ NotNull BlockState state , @ NotNull BlockPos pos , @ NotNull LivingEntity entity ) {
253253 IEnergyContainer energyContainer = StorageUtils .getEnergyContainer (stack , 0 );
254254 if (energyContainer != null ) {
255- FloatingLong energyRequired = getDestroyEnergy (stack , state .getDestroySpeed (world , pos ), isModuleEnabled (stack , MekanismModules .SILK_TOUCH_UNIT ));
255+ boolean silk = isModuleEnabled (stack , MekanismModules .SILK_TOUCH_UNIT );
256+ FloatingLong modDestroyEnergy = getDestroyEnergy (stack , silk );
257+ FloatingLong energyRequired = getDestroyEnergy (modDestroyEnergy , state .getDestroySpeed (world , pos ));
256258 energyContainer .extract (energyRequired , Action .EXECUTE , AutomationType .MANUAL );
259+ //AOE/vein mining handling
260+ if (!world .isClientSide && entity instanceof ServerPlayer player && !player .isCreative () &&
261+ energyContainer .extract (energyRequired , Action .SIMULATE , AutomationType .MANUAL ).greaterOrEqual (energyRequired )) {
262+ Map <BlockPos , BlockState > blocks = getBlastedBlocks (world , player , stack , pos , state );
263+ blocks = blocks .isEmpty () && ModuleVeinMiningUnit .canVeinBlock (state ) ? Map .of (pos , state ) : blocks ;
264+
265+ Reference2BooleanMap <Block > oreTracker = blocks .values ().stream ().collect (Collectors .toMap (BlockStateBase ::getBlock ,
266+ bs -> bs .is (MekanismTags .Blocks .ATOMIC_DISASSEMBLER_ORE ), (l , r ) -> l , Reference2BooleanArrayMap ::new ));
267+
268+ Object2IntMap <BlockPos > veinedBlocks = getVeinedBlocks (world , stack , blocks , oreTracker );
269+ if (!veinedBlocks .isEmpty ()) {
270+ //Don't include bonus energy required by efficiency modules when calculating energy of vein mining targets
271+ FloatingLong baseDestroyEnergy = getDestroyEnergy (silk );
272+ MekanismUtils .veinMineArea (energyContainer , energyRequired , modDestroyEnergy , baseDestroyEnergy , world , pos , player , stack , this , veinedBlocks ,
273+ ItemMekaTool ::getDestroyEnergy , (base , hardness , distance , bs ) -> getDestroyEnergy (base , hardness )
274+ .multiply (0.5 * Math .pow (distance , bs .is (MekanismTags .Blocks .ATOMIC_DISASSEMBLER_ORE ) ? 1.5 : 2 )));
275+ }
276+ }
257277 }
258278 return true ;
259279 }
@@ -302,38 +322,6 @@ private Object2IntMap<BlockPos> getVeinedBlocks(Level world, ItemStack stack, Ma
302322 return blocks .entrySet ().stream ().collect (Collectors .toMap (Entry ::getKey , be -> 0 , (l , r ) -> l , Object2IntArrayMap ::new ));
303323 }
304324
305- @ Override
306- public boolean onBlockStartBreak (ItemStack stack , BlockPos pos , Player player ) {
307- if (player .level ().isClientSide || player .isCreative ()) {
308- return super .onBlockStartBreak (stack , pos , player );
309- }
310- IEnergyContainer energyContainer = StorageUtils .getEnergyContainer (stack , 0 );
311- if (energyContainer != null ) {
312- Level world = player .level ();
313- BlockState state = world .getBlockState (pos );
314- boolean silk = isModuleEnabled (stack , MekanismModules .SILK_TOUCH_UNIT );
315- FloatingLong modDestroyEnergy = getDestroyEnergy (stack , silk );
316- FloatingLong energyRequired = getDestroyEnergy (modDestroyEnergy , state .getDestroySpeed (world , pos ));
317- if (energyContainer .extract (energyRequired , Action .SIMULATE , AutomationType .MANUAL ).greaterOrEqual (energyRequired )) {
318- Map <BlockPos , BlockState > blocks = getBlastedBlocks (world , player , stack , pos , state );
319- blocks = blocks .isEmpty () && ModuleVeinMiningUnit .canVeinBlock (state ) ? Map .of (pos , state ) : blocks ;
320-
321- Reference2BooleanMap <Block > oreTracker = blocks .values ().stream ().collect (Collectors .toMap (BlockStateBase ::getBlock ,
322- bs -> bs .is (MekanismTags .Blocks .ATOMIC_DISASSEMBLER_ORE ), (l , r ) -> l , Reference2BooleanArrayMap ::new ));
323-
324- Object2IntMap <BlockPos > veinedBlocks = getVeinedBlocks (world , stack , blocks , oreTracker );
325- if (!veinedBlocks .isEmpty ()) {
326- //Don't include bonus energy required by efficiency modules when calculating energy of vein mining targets
327- FloatingLong baseDestroyEnergy = getDestroyEnergy (silk );
328- MekanismUtils .veinMineArea (energyContainer , energyRequired , modDestroyEnergy , baseDestroyEnergy , world , pos , (ServerPlayer ) player , stack , this , veinedBlocks ,
329- ItemMekaTool ::getDestroyEnergy , (base , hardness , distance , bs ) -> getDestroyEnergy (base , hardness )
330- .multiply (0.5 * Math .pow (distance , bs .is (MekanismTags .Blocks .ATOMIC_DISASSEMBLER_ORE ) ? 1.5 : 2 )));
331- }
332- }
333- }
334- return super .onBlockStartBreak (stack , pos , player );
335- }
336-
337325 private static FloatingLong getDestroyEnergy (boolean silk ) {
338326 return silk ? MekanismConfig .gear .mekaToolEnergyUsageSilk .get () : MekanismConfig .gear .mekaToolEnergyUsage .get ();
339327 }
0 commit comments