Flare GG

a pickaxe mine 3 by 3 area

Kodari AI
KodariNov 13 at 1:15 am 13
AreaMiningPickaxe
Adds a custom pickaxe tool that mines a 3x3 area when breaking blocks. The mod registers a new pickaxe item with enhanced mining capability, allowing players to harvest a 3x3 grid of blocks simultaneously. Includes custom tool tier, durability handling, and proper block-breaking logic that respects game rules such as silk touch and fortune enchantments. The 3x3 mining area is centered on the targeted block and works in all directions, providing an efficient mining experience for players seeking faster resource gathering.
  • Add a diamond-tier pickaxe that mines a 3×3 plane facing the player.

  • Preserve normal drops, durability, and block-protection checks.

  • Make it craftable and available in the tools creative tab.

Added the Area Pickaxe, which mines a 3×3 area and uses durability for each block.

Craft it with three diamonds across the top row, a diamond pickaxe in the center, and a stick beneath it.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
9 161
src/main/java/com/kodari/areaminer/AreaMiner.java
package com.kodari.areaminer;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ToolMaterial;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.bus.api.EventPriority;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent;
import net.neoforged.neoforge.event.level.block.BreakBlockEvent;
import net.neoforged.neoforge.registries.DeferredItem;
import net.neoforged.neoforge.registries.DeferredRegister;

@Mod(AreaMiner.MOD_ID)
@EventBusSubscriber(modid = AreaMiner.MOD_ID)
public final class AreaMiner {
    public static final String MOD_ID = "area_miner";
    private static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(MOD_ID);
    private static final DeferredItem<Item> AREA_PICKAXE = ITEMS.registerItem(
            "area_pickaxe", Item::new, properties -> properties.pickaxe(ToolMaterial.DIAMOND, 1.0F, -2.8F));
    private static boolean miningNeighbors;

    public AreaMiner(IEventBus modBus) {
        ITEMS.register(modBus);
    }

    @SubscribeEvent
    public static void addToCreativeTab(BuildCreativeModeTabContentsEvent event) {
        if (event.getTabKey().equals(CreativeModeTabs.TOOLS_AND_UTILITIES)) {
            event.accept(AREA_PICKAXE.get());
        }
    }

    @SubscribeEvent(priority = EventPriority.LOWEST)
    public static void mineArea(BreakBlockEvent event) {
        if (miningNeighbors || !(event.getPlayer() instanceof ServerPlayer player)
                || !(event.getLevel() instanceof ServerLevel level)) {
            return;
        }
        ItemStack tool = player.getMainHandItem();
        if (tool.getItem() != AREA_PICKAXE.get() || tool.getDestroySpeed(event.getState()) <= 1.0F) {
            return;
        }

        Direction.Axis axis = player.getNearestViewDirection().getAxis();
        BlockPos origin = event.getPos();
        miningNeighbors = true;
        try {
            for (int a = -1; a <= 1; a++) {
                for (int b = -1; b <= 1; b++) {
                    if (a == 0 && b == 0) continue;
                    if (player.getMainHandItem().getItem() != AREA_PICKAXE.get()) return;
                    BlockPos pos = switch (axis) {
                        case X -> origin.offset(0, a, b);
                        case Y -> origin.offset(a, 0, b);
                        case Z -> origin.offset(a, b, 0);
                    };
                    BlockState state = level.getBlockState(pos);
                    if (!state.isAir() && tool.getDestroySpeed(state) > 1.0F
                            && state.getDestroyProgress(player, level, pos) > 0.0F
                            && !level.getServer().isUnderSpawnProtection(level, pos, player)
                            && level.mayInteract(player, pos)) {
                        player.gameMode.destroyBlock(pos);
                    }
                }
            }
        } finally {
            miningNeighbors = false;
        }
    }
}