Hunter XD

make me an mc mod for 26.3, Excavation mod, which just a single enchantment with just level no level ups like silktouch. and it can be put on pickaxe shovel axe or hoe. its a strong enchant and it its basically veinminer but not op, just 3 by 3 block breaking. can only get from looting or villagers

Kodari AI
KodariOct 24 at 9:30 am 3
ExcavationEnchant
Adds a single "Excavation" enchantment obtainable only through loot or villager trading, never from enchanting tables. Applicable to pickaxes, shovels, axes, and hoes. When mining a block, it simultaneously breaks the surrounding 3x3 area in the same plane, functioning as a balanced vein-miner alternative. The enchantment has only one level, similar to Silk Touch, and cannot be upgraded. Designed for Minecraft Fabric 26.3, the mod registers the custom enchantment, integrates with existing loot tables and villager trade pools, and hooks into block-breaking logic to trigger the area excavation effect without being overpowered.
  1. Add the Excavation enchantment and its single-level, tool-compatible definition.

  2. Make it obtainable through loot and villager trades, not the enchanting table.

  3. Implement bounded 3×3 excavation that preserves normal block drops and avoids recursive breaking.

Created the Fabric 26.3 Excavation mod. Excavation is a single-level enchantment for pickaxes, shovels, axes, and hoes. It mines matching blocks in a 3×3 plane, using normal player-breaking behavior and tool durability.

It’s available through randomized loot and villager trades, and excluded from enchanting tables. In survival, look for it in loot or trade with villagers.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
9 182
src/main/java/com/kodari/excavation/ExcavationMod.java
package com.kodari.excavation;

import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.Set;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.phys.Vec3;

public class ExcavationMod implements ModInitializer {
	public static final String MOD_ID = "excavation";
	private static final ResourceKey<Enchantment> EXCAVATION = ResourceKey.create(
			Registries.ENCHANTMENT,
			Identifier.fromNamespaceAndPath(MOD_ID, "excavation")
	);
	private static final Set<ServerPlayer> EXCAVATING = Collections.newSetFromMap(new IdentityHashMap<>());

	@Override
	public void onInitialize() {
		PlayerBlockBreakEvents.AFTER.register(ExcavationMod::onBlockBreak);
	}

	private static void onBlockBreak(Level level, Player player, BlockPos pos, BlockState state, net.minecraft.world.level.block.entity.BlockEntity blockEntity) {
		if (!(level instanceof ServerLevel) || !(player instanceof ServerPlayer serverPlayer) || EXCAVATING.contains(serverPlayer)) {
			return;
		}

		ItemStack tool = serverPlayer.getMainHandItem();
		if (!isSupportedTool(tool)) {
			return;
		}

		Holder<Enchantment> enchantment = level.registryAccess().lookupOrThrow(Registries.ENCHANTMENT).getOrThrow(EXCAVATION);
		if (EnchantmentHelper.getItemEnchantmentLevel(enchantment, tool) < 1 || !EXCAVATING.add(serverPlayer)) {
			return;
		}

		try {
			Vec3 look = player.getLookAngle();
			boolean horizontalPlane = Math.abs(look.y) >= Math.abs(look.x) && Math.abs(look.y) >= Math.abs(look.z);
			boolean xNormalPlane = !horizontalPlane && Math.abs(look.x) >= Math.abs(look.z);

			for (int first = -1; first <= 1; first++) {
				for (int second = -1; second <= 1; second++) {
					if (first == 0 && second == 0) {
						continue;
					}

					if (serverPlayer.getMainHandItem() != tool) {
						return;
					}

					BlockPos target = horizontalPlane
							? pos.offset(first, 0, second)
							: xNormalPlane ? pos.offset(0, first, second) : pos.offset(first, second, 0);
					BlockState targetState = level.getBlockState(target);
					if (!targetState.isAir() && targetState.getBlock() == state.getBlock()) {
						serverPlayer.gameMode.destroyBlock(target);
					}
				}
			}
		} finally {
			EXCAVATING.remove(serverPlayer);
		}
	}

	private static boolean isSupportedTool(ItemStack stack) {
		return stack.typeHolder().is(ItemTags.PICKAXES)
				|| stack.typeHolder().is(ItemTags.SHOVELS)
				|| stack.typeHolder().is(ItemTags.AXES)
				|| stack.typeHolder().is(ItemTags.HOES);
	}
}