Search in sources :

Example 1 with ModuleVeinMiningUnit

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);
}
Also used : FloatingLong(mekanism.api.math.FloatingLong) IEnergyContainer(mekanism.api.energy.IEnergyContainer) BlockState(net.minecraft.block.BlockState) BlockBounding(mekanism.common.block.BlockBounding) ModuleVeinMiningUnit(mekanism.common.content.gear.mekatool.ModuleVeinMiningUnit) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World)

Aggregations

IEnergyContainer (mekanism.api.energy.IEnergyContainer)1 FloatingLong (mekanism.api.math.FloatingLong)1 BlockBounding (mekanism.common.block.BlockBounding)1 ModuleVeinMiningUnit (mekanism.common.content.gear.mekatool.ModuleVeinMiningUnit)1 BlockState (net.minecraft.block.BlockState)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1