use of mekanism.common.content.gear.mekatool.ModuleVeinMiningUnit in project Mekanism by mekanism.
the class ItemMekaTool method onBlockStartBreak.
@Override
public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, PlayerEntity player) {
if (player.level.isClientSide || player.isCreative()) {
return super.onBlockStartBreak(stack, pos, player);
}
IEnergyContainer energyContainer = StorageUtils.getEnergyContainer(stack, 0);
if (energyContainer != null) {
World world = player.level;
BlockState state = world.getBlockState(pos);
boolean silk = isModuleEnabled(stack, MekanismModules.SILK_TOUCH_UNIT);
FloatingLong energyRequired = getDestroyEnergy(stack, state.getDestroySpeed(world, pos), silk);
if (energyContainer.extract(energyRequired, Action.SIMULATE, AutomationType.MANUAL).greaterOrEqual(energyRequired)) {
IModule<ModuleVeinMiningUnit> veinMiningUnit = getModule(stack, MekanismModules.VEIN_MINING_UNIT);
// Even though we now handle breaking bounding blocks properly, don't allow vein mining them
if (veinMiningUnit != null && veinMiningUnit.isEnabled() && !(state.getBlock() instanceof BlockBounding)) {
boolean isOre = state.is(MekanismTags.Blocks.ATOMIC_DISASSEMBLER_ORE);
// If it is extended or should be treated as an ore
if (isOre || veinMiningUnit.getCustomInstance().isExtended()) {
// Don't include bonus energy required by efficiency modules when calculating energy of vein mining targets
FloatingLong baseDestroyEnergy = getDestroyEnergy(silk);
Set<BlockPos> found = ModuleVeinMiningUnit.findPositions(state, pos, world, isOre ? -1 : veinMiningUnit.getCustomInstance().getExcavationRange());
MekanismUtils.veinMineArea(energyContainer, world, pos, (ServerPlayerEntity) player, stack, this, found, isModuleEnabled(stack, MekanismModules.SHEARING_UNIT), hardness -> getDestroyEnergy(baseDestroyEnergy, hardness), distance -> 0.5 * Math.pow(distance, isOre ? 1.5 : 2), state);
}
}
}
}
return super.onBlockStartBreak(stack, pos, player);
}
Aggregations