hgjpwp

wygeneruj mi moda do minecraft ktory jak wykryje ze kilof ma ponizej 30 uzyc przerywa kopanie klika w kowadło naprawia kilof diamentami odklada diamenty i kilof na pierwotne miejsce i idzie kopać dalej, dodaj tez opcje auto-mine ktora po prostu trzyma lewy przycisk i dziala razem z tym pierwszym co napislaem. czyli kopie kilof ma ponizej trzydziestu uzyc auto mine sie chwilowo wyłącza, bot naprawia kilof auto mine sie włącza i kopie dalej powtarzajac proces

Kodari AI
KodariOct 11 at 12:51 pm 2
AutoMineRepairBot
Minecraft Fabric mod that adds an auto-mine feature holding left mouse button continuously. When pickaxe durability drops below 30 uses remaining, mining pauses automatically, bot navigates to anvil, repairs pickaxe using diamonds from inventory, returns to original position, and resumes mining. Fully automated repair cycle with seamless integration between mining and repair states.
  1. Dodam klientowy auto-mine na skrócie klawiszowym.

  2. Przy mniej niż 30 użyciach zatrzymam kopanie, automatycznie użyję pobliskiego kowadła z diamentami, przywrócę przedmioty do ich slotów i wznowię kopanie.

  3. Utworzę kompletny szkielet moda Fabric 1.21.11; naprawa zakłada diamentowy kilof oraz kowadło i diamenty w zasięgu/inwentarzu.

Gotowy mod Diamond Auto Repair:

  • Naciśnij M, aby włączyć lub wyłączyć auto-mine.

  • Gdy trzymany diamentowy kilof spadnie poniżej 30 pozostałych użyć, kopanie się zatrzyma.

  • Mod użyje pobliskiego kowadła i diamentów z ekwipunku, a następnie odłoży kilof oraz niewykorzystane diamenty na ich pierwotne miejsca i wznowi kopanie.

Potrzebne jest kowadło w pobliżu oraz diamenty w ekwipunku. Mod nie podchodzi do kowadła ani go nie stawia — czeka, aż znajdzie się ono w zasięgu. Nie dodaje nowych przedmiotów, więc nie wymaga receptur ani dodatkowych sposobów zdobywania. Na serwerach sprawdź, czy używanie auto-mine jest dozwolone.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
6 385
src/client/java/com/kodari/diamondautorepair/DiamondAutoRepairClient.java
package com.kodari.diamondautorepair;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.screen.AnvilScreenHandler;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;

import org.lwjgl.glfw.GLFW;

public final class DiamondAutoRepairClient implements ClientModInitializer {
    private static final String MOD_ID = "diamond_autorepair";
    private static final int REPAIR_THRESHOLD = 30;
    private static final int ANVIL_SEARCH_RADIUS = 4;
    private static final int ANVIL_SEARCH_VERTICAL_RADIUS = 2;

    private KeyBinding autoMineKey;
    private boolean autoMineEnabled;
    private RepairState repairState = RepairState.IDLE;
    private int toolInventorySlot = -1;
    private int diamondInventorySlot = -1;
    private int waitTicks;
    private int resourceSearchCooldown;

    @Override
    public void onInitializeClient() {
        autoMineKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
                "key.diamond_autorepair.toggle_auto_mine",
                GLFW.GLFW_KEY_M,
                KeyBinding.Category.create(Identifier.of(MOD_ID, "general"))
        ));
        ClientTickEvents.END_CLIENT_TICK.register(this::onEndClientTick);
    }

    private void onEndClientTick(MinecraftClient client) {
        while (autoMineKey.wasPressed()) {
            autoMineEnabled = !autoMineEnabled;
            if (!autoMineEnabled && repairState == RepairState.WAITING_FOR_RESOURCES) {
                resetRepair();
            }
        }

        if (client.player == null || client.world == null || client.interactionManager == null) {
            client.options.attackKey.setPressed(false);
            return;
        }

        if (repairState == RepairState.IDLE && autoMineEnabled) {
            ItemStack heldStack = client.player.getInventory().getSelectedStack();
            if (heldStack.isOf(Items.DIAMOND_PICKAXE)
                    && heldStack.getMaxDamage() - heldStack.getDamage() < REPAIR_THRESHOLD) {
                toolInventorySlot = client.player.getInventory().getSelectedSlot();
                repairState = RepairState.WAITING_FOR_RESOURCES;
            }
        }

        if (repairState == RepairState.IDLE) {
            client.options.attackKey.setPressed(autoMineEnabled && client.currentScreen == null);
            return;
        }

        client.options.attackKey.setPressed(false);
        advanceRepair(client);
    }

    private void advanceRepair(MinecraftClient client) {
        switch (repairState) {
            case IDLE -> {
            }
            case WAITING_FOR_RESOURCES -> waitForResources(client);
            case WAITING_FOR_ANVIL_SCREEN -> waitForAnvilScreen(client);
            case PICK_UP_TOOL -> {
                clickSlot(client, inventoryToHandlerSlot(toolInventorySlot));
                repairState = RepairState.PLACE_TOOL;
            }
            case PLACE_TOOL -> {
                clickSlot(client, AnvilScreenHandler.INPUT_1_ID);
                repairState = RepairState.PICK_UP_DIAMONDS;
            }
            case PICK_UP_DIAMONDS -> {
                clickSlot(client, inventoryToHandlerSlot(diamondInventorySlot));
                repairState = RepairState.PLACE_DIAMONDS;
            }
            case PLACE_DIAMONDS -> {
                clickSlot(client, AnvilScreenHandler.INPUT_2_ID);
                waitTicks = 0;
                repairState = RepairState.WAITING_FOR_OUTPUT;
            }
            case WAITING_FOR_OUTPUT -> waitForOutput(client);
            case TAKE_OUTPUT -> {
                clickSlot(client, AnvilScreenHandler.OUTPUT_ID);
                repairState = RepairState.RETURN_TOOL;
            }
            case RETURN_TOOL -> {
                clickSlot(client, inventoryToHandlerSlot(toolInventorySlot));
                repairState = RepairState.RETURN_REMAINING_DIAMONDS;
            }
            case RETURN_REMAINING_DIAMONDS -> {
                if (anvilHandler(client).getSlot(AnvilScreenHandler.INPUT_2_ID).hasStack()) {
                    clickSlot(client, AnvilScreenHandler.INPUT_2_ID);
                    repairState = RepairState.RESTORE_DIAMONDS;
                } else {
                    repairState = RepairState.CLOSE_ANVIL;
                }
            }
            case RESTORE_DIAMONDS -> {
                clickSlot(client, inventoryToHandlerSlot(diamondInventorySlot));
                repairState = RepairState.CLOSE_ANVIL;
            }
            case RECOVER_TOOL_FROM_INPUT -> {
                if (anvilHandler(client).getSlot(AnvilScreenHandler.INPUT_1_ID).hasStack()) {
                    clickSlot(client, AnvilScreenHandler.INPUT_1_ID);
                    repairState = RepairState.RECOVER_TOOL_TO_INVENTORY;
                } else {
                    repairState = RepairState.RECOVER_DIAMONDS_FROM_INPUT;
                }
            }
            case RECOVER_TOOL_TO_INVENTORY -> {
                clickSlot(client, inventoryToHandlerSlot(toolInventorySlot));
                repairState = RepairState.RECOVER_DIAMONDS_FROM_INPUT;
            }
            case RECOVER_DIAMONDS_FROM_INPUT -> {
                if (anvilHandler(client).getSlot(AnvilScreenHandler.INPUT_2_ID).hasStack()) {
                    clickSlot(client, AnvilScreenHandler.INPUT_2_ID);
                    repairState = RepairState.RECOVER_DIAMONDS_TO_INVENTORY;
                } else {
                    repairState = RepairState.CLOSE_ANVIL;
                }
            }
            case RECOVER_DIAMONDS_TO_INVENTORY -> {
                clickSlot(client, inventoryToHandlerSlot(diamondInventorySlot));
                repairState = RepairState.CLOSE_ANVIL;
            }
            case CLOSE_ANVIL -> {
                if (client.player.currentScreenHandler instanceof AnvilScreenHandler) {
                    client.player.closeHandledScreen();
                }
                resetRepair();
            }
        }
    }

    private void waitForResources(MinecraftClient client) {
        if (!autoMineEnabled) {
            resetRepair();
            return;
        }

        PlayerInventory inventory = client.player.getInventory();
        if (toolInventorySlot < 0
                || !inventory.getStack(toolInventorySlot).isOf(Items.DIAMOND_PICKAXE)) {
            resetRepair();
            return;
        }

        if (client.currentScreen != null || resourceSearchCooldown > 0) {
            resourceSearchCooldown--;
            return;
        }
        resourceSearchCooldown = 10;

        int diamondSlot = findDiamondSlot(inventory, toolInventorySlot);
        BlockPos anvilPos = findNearbyAnvil(client);
        if (diamondSlot < 0 || anvilPos == null) {
            return;
        }

        diamondInventorySlot = diamondSlot;
        BlockHitResult hitResult = new BlockHitResult(anvilPos.toCenterPos(), Direction.UP, anvilPos, false);
        client.interactionManager.interactBlock(client.player, Hand.MAIN_HAND, hitResult);
        waitTicks = 0;
        repairState = RepairState.WAITING_FOR_ANVIL_SCREEN;
    }

    private void waitForAnvilScreen(MinecraftClient client) {
        if (client.player.currentScreenHandler instanceof AnvilScreenHandler) {
            repairState = RepairState.PICK_UP_TOOL;
            return;
        }

        if (++waitTicks > 40) {
            waitTicks = 0;
            repairState = RepairState.WAITING_FOR_RESOURCES;
        }
    }

    private void waitForOutput(MinecraftClient client) {
        if (!(client.player.currentScreenHandler instanceof AnvilScreenHandler handler)) {