Arhaan Karim
📎 1 file 4,099 chars
📄
pasted-code-1793440790418.txt
txt 98 lines
▶
Build a completely NEW Minecraft Java Edition Fabric mod from scratch. Do not modify or depend on any existing project code.

## Project Name
BananaSMP Bone Automation

## Objective
Create a mod that automates purchasing 36 stacks of Bones from the BananaSMP shop and then uses my existing Drop All button in my inventory.

## My Setup
- Minecraft Java Edition on PC.
- Fabric mod loader.
- Server: BananaSMP.
- I already have a Drop All button, but it appears ONLY in my inventory, not in the shop.
- The `/shop` command must be typed manually by me.

Before choosing Minecraft and Fabric dependency versions, verify which versions are supported. Keep the Minecraft version configurable where possible.

## Required Workflow

### Step 1: Detect the Shop
- Wait for me to type `/shop` manually.
- Detect when the shop GUI opens.
- Do not send chat commands automatically.

### Step 2: Navigate to Bones
- Identify the Mob Drops category.
- Click the correct Mob Drops item.
- Wait for the next menu to load.
- Identify and select Bones.
- Never blindly click guessed slots or screen coordinates.

### Step 3: Select Quantity
- Wait for the Bones purchase menu to load.
- Identify the chest button used to increase the purchase quantity.
- Use the correct controls to select exactly 36 stacks.
- Verify the displayed quantity before purchasing.
- If the quantity cannot be verified, stop safely.

### Step 4: Purchase
- Confirm the purchase only after verifying the selected quantity.
- Wait for the purchase to complete.
- Handle the shop closing or remaining open correctly.

### Step 5: Open Inventory
- Open my Minecraft inventory after the purchase.
- Wait until the inventory GUI is fully loaded.
- Locate my existing Drop All button.

### Step 6: Use Drop All
- Click the existing Drop All button ONLY when it is visible in my inventory.
- Do not search for or click this button in the shop GUI.
- Do not create a replacement Drop All button.
- If the button cannot be identified, stop and display a useful error message.

## Technical Requirements

1. Create a complete, buildable Fabric mod project from scratch.
2. Include the necessary Gradle files, Fabric metadata, Java source files, and configuration.
3. Use appropriate Minecraft client APIs to detect screen transitions and container state.
4. Prefer container-slot identification over hardcoded screen coordinates.
5. Use a state-machine design with separate states for:
   - Waiting for the shop
   - Selecting Mob Drops
   - Selecting Bones
   - Setting quantity
   - Confirming purchase
   - Opening inventory
   - Finding Drop All
   - Completing the workflow
   - Error handling
6. Add appropriate delays and checks between GUI interactions.
7. Add a configurable emergency stop key.
8. Prevent duplicate purchases and repeated Drop All clicks.
9. Print clear progress messages in the Minecraft log.
10. Never click arbitrary buttons when the expected menu is missing.
11. Keep all automation client-side unless a server-side component is genuinely necessary.
12. Do not claim that the mod works until the project has been built and tested.

## Important Unknowns

Do not invent BananaSMP's exact GUI layout or assume that the Drop All button is a standard Minecraft button.

If the server's GUI does not expose enough information to identify an item or button reliably, implement a safe configuration mechanism and explain what screenshots or slot information are needed to finish the setup.

## Deliverables

Provide:
- The complete project folder structure.
- All source files with complete code.
- Build and installation instructions.
- The generated JAR file if the build environment supports it.
- Instructions for configuring the GUI slots and testing safely.

The final workflow must be:

I manually type `/shop` → the mod selects Mob Drops → selects Bones → sets 36 stacks → purchases the Bones → opens my inventory → clicks my existing Drop All button.

Build this as a new project, not as an edit to an existing project.
Kodari AI
KodariOct 31 at 10:17 am 6
BoneShopAutomation
A client-side Fabric mod for Minecraft that automates purchasing 36 stacks of bones from the BananaSMP shop and then triggers the player's existing Drop All inventory button. The mod uses a state-machine design to wait for the player to manually open the shop via /shop, then navigates through the shop GUI by identifying container slots for Mob Drops and Bones categories, selects the exact quantity of 36 stacks via the chest quantity button, verifies the displayed amount before confirming purchase, and finally opens the inventory to locate and click the existing Drop All button. Includes configurable emergency stop key, safe error handling with clear log messages, and prevents duplicate purchases or clicks. All automation is client-side with no server modifications required.
  1. Build the Fabric 26.2 project and its configurable, fail-closed GUI automation state machine.

  2. Include setup instructions and explain the GUI details needed to configure safe slot/name detection.

Created the new BananaSMP Bone Automation Fabric project for Minecraft 26.2. It waits for you to open /shop manually, then uses a fail-closed state machine to identify menu entries, verify a displayed quantity of 36 stacks, confirm the purchase once, open inventory, and look for the existing Drop All button. It does not send commands or guess slots or coordinates.

Project files: settings.gradle, gradle.properties, build.gradle, src/main/resources/fabric.mod.json, src/main/resources/assets/bananasmp_bone_automation/lang/en_us.json, and client sources under src/client/java/com/kodari/bananasmpboneautomation/client/.

Configure before purchasing: On first launch it creates config/bananasmp-bone-automation.properties. The quantity-increase and purchase labels are intentionally blank; set them, and verify the title/name filters against BananaSMP’s actual menus. The mod logs menu titles and populated slot labels to help identify them. The quantity display must reliably indicate stacks—otherwise it stops without purchasing. For a shop that stays open after purchase, configure a visible completion title or message.

The Drop All check is deliberately limited to a uniquely labeled, visible vanilla Button on the vanilla player inventory screen. If the existing button uses a different GUI implementation, the mod stops instead of clicking an uncertain control. Screenshots of the shop, quantity menu, purchase result, and inventory—plus the logged titles and slot labels—are needed to finish configuring the server-specific details.

Minecraft 26.2, Fabric Loader 0.19.3, Fabric API 0.158.0+26.2, Loom 1.17, and Java 25 are set in the project. I have not built or tested this against BananaSMP, and no JAR has been generated. To build and download it in Kodari: click Compile (phone: ⋮ → Compile Project), click Compile in the window, then click Download when it succeeds. Install Fabric Loader and Fabric API for 26.2, put the downloaded JAR in your Minecraft mods folder, and launch the Fabric profile.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
README.md
settings.gradle
Code
8 789
src/client/java/com/kodari/bananasmpboneautomation/client/BananaAutomationClient.java
package com.kodari.bananasmpboneautomation.client;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keymapping.v1.KeyMappingHelper;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
import net.minecraft.client.input.MouseButtonEvent;
import net.minecraft.client.input.MouseButtonInfo;
import net.minecraft.client.multiplayer.MultiPlayerGameMode;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ContainerInput;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.ItemLore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.regex.Matcher;

public final class BananaAutomationClient implements ClientModInitializer {
	private static final Logger LOGGER = LoggerFactory.getLogger("bananasmp_bone_automation");
	private static final int TARGET_STACKS = 36;
	private static final int START_KEY = 85;
	private static final int EMERGENCY_STOP_KEY = 88;

	private KeyMapping startKey;
	private KeyMapping emergencyStopKey;
	private AutomationConfig config;
	private State state = State.WAITING_FOR_SHOP;
	private boolean enabled = true;
	private boolean quantityUpdatePending;
	private boolean purchaseSent;
	private boolean inventoryCloseRequested;
	private boolean inventoryOpenRequested;
	private boolean loggedBonesMenu;
	private int quantityBeforeClick;
	private long tick;
	private long stateStartedAt;
	private long lastActionAt;
	private Screen lastObservedScreen;

	@Override
	public void onInitializeClient() {
		try {
			config = AutomationConfig.load();
		} catch (IOException | IllegalArgumentException exception) {
			enabled = false;
			state = State.ERROR;
			LOGGER.error("Could not load {}. Automation is disabled; correct the config and restart.", AutomationConfig.PATH, exception);
		}

		startKey = KeyMappingHelper.registerKeyMapping(new KeyMapping(
				"key.bananasmp_bone_automation.start", START_KEY, KeyMapping.Category.MISC));
		emergencyStopKey = KeyMappingHelper.registerKeyMapping(new KeyMapping(
				"key.bananasmp_bone_automation.stop", EMERGENCY_STOP_KEY, KeyMapping.Category.MISC));

		if (config != null) {
			LOGGER.info("BananaSMP Bone Automation loaded. Config: {}. Waiting for you to open the shop.", AutomationConfig.PATH);
		}
		ClientTickEvents.END_CLIENT_TICK.register(this::tickClient);
	}

	private void tickClient(Minecraft client) {
		tick++;
		if (emergencyStopKey.consumeClick()) {
			enabled = false;
			state = State.WAITING_FOR_SHOP;
			LOGGER.warn("Emergency stop pressed; automation is disarmed.");
			message(client.player, "Emergency stop: automation disarmed. Use the arm/restart key to resume.");
			return;
		}

		if (startKey.consumeClick()) {
			if (!enabled || state == State.ERROR || state == State.COMPLETED) {
				resetRun();
				enabled = true;
				LOGGER.info("Automation armed; waiting for the shop GUI you open manually.");
				message(client.player, "Automation armed; open the shop manually when ready.");
			} else {
				LOGGER.info("Automation is already active; the current run was not restarted.");
			}
		}

		if (!enabled || config == null) {
			return;
		}

		Screen screen = client.gui.screen();
		observeScreen(screen);
		if (client.player == null || client.gameMode == null) {
			return;
		}

		switch (state) {
			case WAITING_FOR_SHOP -> waitForShop(screen);
			case SELECTING_MOB_DROPS -> selectMobDrops(client, screen);
			case SELECTING_BONES -> selectBones(client, screen);
			case SETTING_QUANTITY -> setQuantity(client, screen);
			case CONFIRMING_PURCHASE -> confirmPurchase(client, screen);
			case OPENING_INVENTORY -> openInventory(client, screen);
			case FINDING_DROP_ALL -> findDropAll(client, screen);
			case COMPLETED, ERROR -> {
			}
		}
	}

	private void waitForShop(Screen screen) {
		if (screen != null && containsIgnoreCase(screen.getTitle().getString(), config.shopTitle)) {
			transition(State.SELECTING_MOB_DROPS, "Shop GUI detected.");
		}
	}

	private void selectMobDrops(Minecraft client, Screen screen) {
		if (!awaitTitle(client, screen, config.shopTitle, "the shop menu")) {
			return;
		}
		AbstractContainerScreen<?> container = (AbstractContainerScreen<?>) screen;
		logContainer("shop", container);
		int slot = findUniqueSlot(client, container, config.mobDropsItem, config.mobDropsSlot, "Mob Drops category");
		if (slot < 0 || !clickContainerSlot(client, container, slot)) {
			return;
		}
		transition(State.SELECTING_BONES, "Selected the uniquely identified Mob Drops entry; waiting for its menu.");
	}

	private void selectBones(Minecraft client, Screen screen) {
		if (!awaitTitle(client, screen, config.mobDropsTitle, "the Mob Drops menu")) {
			return;
		}
		AbstractContainerScreen<?> container = (AbstractContainerScreen<?>) screen;
		logContainer("Mob Drops", container);
		int slot = findUniqueSlot(client, container, config.bonesItem, config.bonesSlot, "Bones entry");
		if (slot < 0 || !clickContainerSlot(client, container, slot)) {
			return;
		}
		loggedBonesMenu = false;
		transition(State.SETTING_QUANTITY, "Selected the uniquely identified Bones entry; waiting for the purchase menu.");
	}

	private void setQuantity(Minecraft client, Screen screen) {
		if (!awaitTitle(client, screen, config.bonesMenuTitle, "the Bones purchase menu")) {
			return;
		}
		AbstractContainerScreen<?> container = (AbstractContainerScreen<?>) screen;
		if (!loggedBonesMenu) {
			logContainer("Bones purchase", container);
			loggedBonesMenu = true;
		}

		int quantity = readQuantity(container);
		if (quantity == -2) {
			fail(client, "More than one distinct stack quantity is visible. Refusing to purchase; configure quantity_text_regex to match exactly one quantity.");
			return;
		}
		if (quantity == -1) {
			if (tick - stateStartedAt > 20) {
				fail(client, "Could not verify the selected stack quantity in the Bones menu. Refusing to purchase; configure quantity_text_regex from the menu's visible text.");
			}
			return;
		}
		if (quantity > TARGET_STACKS) {
			fail(client, "The Bones menu already shows " + quantity + " stacks, above the required 36. Refusing to purchase.");
			return;
		}

		if (quantityUpdatePending) {
			if (quantity == quantityBeforeClick) {
				if (tick - lastActionAt > config.quantityResponseTimeoutTicks) {
					fail(client, "The quantity did not change after one increment click. Stopped without repeating the click.");
				}
				return;
			}
			if (quantity != quantityBeforeClick + 1) {
				fail(client, "One quantity click changed the displayed value by more than one stack. Stopped to avoid an incorrect purchase.");
				return;
			}
			quantityUpdatePending = false;
			lastActionAt = tick;
			LOGGER.info("Verified the shop quantity changed to {} of {} stacks.", quantity, TARGET_STACKS);
		}

		if (quantity == TARGET_STACKS) {
			transition(State.CONFIRMING_PURCHASE, "Verified exactly 36 stacks; purchase confirmation is next.");
			return;
		}