Миша Ломов
📎 1 file 4,310 chars
📄
pasted-code-1794813849096.txt
txt 120 lines
▶
Task: Build a client-side Fabric mod for Minecraft 1.21.4 (Java 21). Use the reference code below verbatim — do not rewrite, do not "improve", do not add features. Your job is to place these files in the correct project structure and compile them into a .jar.

If you cannot use the code as-is, fall back to the behavior description that follows the code.

Behavior summary (for fallback): On command send, rewrite /an102–/an199 → /an101, /an202–/an299 → /an201, /an302–/an399 → /an301, /an502–/an599 → /an501, preserving arguments after the command. Do not touch /an101, /an201, /an301, /an501 or numbers outside those ranges. Client-side only, no GUI, silent replacement.

Reference files:

gradle.properties

properties
minecraft_version=1.21.4
yarn_mappings=1.21.4+build.8
loader_version=0.16.10
fabric_version=0.112.0+1.21.4
mod_version=1.0.0
maven_group=ru.anreplace
archives_base_name=ancommand-replace
settings.gradle

groovy
pluginManagement {
    repositories {
        maven { url 'https://maven.fabricmc.net/' }
        mavenCentral()
        gradlePluginPortal()
    }
}
rootProject.name = 'ancommand-replace'
build.gradle

groovy
plugins {
    id 'fabric-loom' version '1.8-SNAPSHOT'
    id 'java'
}
version = project.mod_version
group = project.maven_group
base { archivesName = project.archives_base_name }
repositories {
    maven { url 'https://maven.fabricmc.net/' }
    mavenCentral()
}
dependencies {
    minecraft "com.mojang:minecraft:${project.minecraft_version}"
    mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
    modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
    modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
}
processResources {
    inputs.property 'version', project.version
    filesMatching('fabric.mod.json') { expand 'version': project.version }
}
tasks.withType(JavaCompile).configureEach {
    it.options.release = 21
    it.options.encoding = 'UTF-8'
}
java {
    sourceCompatibility = JavaVersion.VERSION_21
    targetCompatibility = JavaVersion.VERSION_21
}
src/main/resources/fabric.mod.json

json
{
  "schemaVersion": 1,
  "id": "ancommand-replace",
  "version": "${version}",
  "name": "AN Command Replace",
  "description": "Auto-rewrite /an102-199 -> /an101, /an202-299 -> /an201, /an302-399 -> /an301, /an502-599 -> /an501",
  "environment": "client",
  "entrypoints": { "client": ["ru.anreplace.AnReplaceClient"] },
  "depends": {
    "fabricloader": ">=0.16.9",
    "minecraft": "~1.21.4",
    "fabric-api": "*",
    "java": ">=21"
  }
}
src/main/java/ru/anreplace/AnReplaceClient.java

java
package ru.anreplace;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.message.v1.ClientSendMessageEvents;
import net.minecraft.client.MinecraftClient;

public class AnReplaceClient implements ClientModInitializer {
    @Override
    public void onInitializeClient() {
        ClientSendMessageEvents.ALLOW_COMMAND.register(AnReplaceClient::onCommand);
    }

    private static boolean onCommand(String command) {
        String replaced = replace(command);
        if (replaced == null) return true;
        MinecraftClient client = MinecraftClient.getInstance();
        if (client.player != null) {
            client.player.networkHandler.sendCommand(replaced);
        }
        return false;
    }

    static String replace(String command) {
        int space = command.indexOf(' ');
        String name = (space == -1) ? command : command.substring(0, space);
        String tail = (space == -1) ? "" : command.substring(space);
        if (name.length() < 4 || !name.startsWith("an")) return null;
        String digits = name.substring(2);
        for (char c : digits.toCharArray()) if (!Character.isDigit(c)) return null;
        final int n;
        try { n = Integer.parseInt(digits); } catch (NumberFormatException e) { return null; }
        int hi = n / 100, lo = n % 100;
        if (lo < 2) return null;
        if (hi != 1 && hi != 2 && hi != 3 && hi != 5) return null;
        return "an" + (hi * 100 + 1) + tail;
    }
}
Build command: ./gradlew build with JDK 21. Output must be build/libs/ancommand-replace-1.0.0.jar.
Kodari AI
KodariMon at 7:27 am 1
AnCommandReplace
Client-side Fabric mod for Minecraft 1.21.4 that silently rewrites chat commands on send. When a player types /an102 through /an199, it converts to /an101; /an202-/an299 to /an201; /an302-/an399 to /an301; and /an502-/an599 to /an501. Preserves all arguments after the command name. Commands already in canonical form (/an101, /an201, /an301, /an501) or outside specified ranges remain untouched. Uses ClientSendMessageEvents.ALLOW_COMMAND to intercept and replace commands before network transmission, with no GUI or user-visible feedback.
  • Create the Gradle project files and Fabric metadata for Minecraft 1.21.4.

  • Verify the referenced Fabric and Minecraft signatures against the mounted 1.21.4 source.

  • Add the client initializer using the supplied behavior and code.

Created the Fabric 1.21.4 project with the supplied command-replacement code. Compile in Kodari by clicking Compile in the desktop top bar, or ⋮ → Compile Project on phone, then Compile in the dialog. The expected jar is build/libs/ancommand-replace-1.0.0.jar; download it from the successful build or the chat’s download button.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
5 96
src/main/java/ru/anreplace/AnReplaceClient.java
package ru.anreplace;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.message.v1.ClientSendMessageEvents;
import net.minecraft.client.MinecraftClient;

public class AnReplaceClient implements ClientModInitializer {
    @Override
    public void onInitializeClient() {
        ClientSendMessageEvents.ALLOW_COMMAND.register(AnReplaceClient::onCommand);
    }

    private static boolean onCommand(String command) {
        String replaced = replace(command);
        if (replaced == null) return true;
        MinecraftClient client = MinecraftClient.getInstance();
        if (client.player != null) {
            client.player.networkHandler.sendCommand(replaced);
        }
        return false;
    }

    static String replace(String command) {
        int space = command.indexOf(' ');
        String name = (space == -1) ? command : command.substring(0, space);
        String tail = (space == -1) ? "" : command.substring(space);
        if (name.length() < 4 || !name.startsWith("an")) return null;
        String digits = name.substring(2);
        for (char c : digits.toCharArray()) if (!Character.isDigit(c)) return null;
        final int n;
        try { n = Integer.parseInt(digits); } catch (NumberFormatException e) { return null; }
        int hi = n / 100, lo = n % 100;
        if (lo < 2) return null;
        if (hi != 1 && hi != 2 && hi != 3 && hi != 5) return null;
        return "an" + (hi * 100 + 1) + tail;
    }
}