furo2v

Create a server-side mod that works as a universal command available for anyone that works like this:

  1. /trader. This opens a INVENTORY GUI that shows 2 options: Emerald to Gold conversion button (This opens a bordered gray-stained glass INVENTORY GUI with a confirm button below and the other slot left empty, depends on how much the emeralds put inside those slot, player will get the corresponding gold amount (1:1 ratio)), the other option is Enchanted Golden Apple purchase which cost 64 emeralds block for 1 Enchanted Golden Apple.
Kodari AI
KodariJun 8 at 9:33 am 28
TraderMod
A server-side Fabric mod adding a /trader command that opens a GUI shop. Features two options: an Emerald-to-Gold converter (1:1 ratio with a bordered gray glass UI and confirm button) and an Enchanted Golden Apple shop (costs 64 emerald blocks each). Universal command available to all players.

Plan:

  • build.gradle + gradle.properties + settings.gradle — project setup

  • fabric.mod.json + tradermod.mixins.json — mod metadata

  • TraderMod.java — init + /trader command

  • TraderMainHandler.java — main menu GUI (2 option buttons, glass filler)

  • EmeraldConverterHandler.java — bordered glass GUI, input slot + confirm

Here’s what was built:


/trader — Main Menu

A 3-row chest GUI with gray glass filler and two buttons:

  • Slot 11 — Emerald → Gold Converter (emerald icon, opens the converter GUI)

  • Slot 15 — Enchanted Golden Apple (EGA icon, costs 64 Emerald Blocks, instant purchase)


Emerald → Gold Converter GUI

A bordered 3-row chest with gray glass everywhere except:

  • Slot 13 (center row) — empty input slot, accepts only emeralds

  • Slot 22 (below, center) — lime ✔ Confirm button

Clicking confirm converts however many emeralds are in the input slot at a 1:1 ratio into gold ingots. Any leftovers are returned to the player on close.


EGA Shop

Clicking the EGA button in the main menu checks the player’s inventory for 64 Emerald Blocks, removes them, and gives 1 Enchanted Golden Apple with actionbar feedback. Player is notified if they’re short on funds.

furo2v

The compilation failed with this error:

code
Compilation failed with 2 error(s):

ERROR in src/main/java/com/example/tradermod/TraderMainHandler.java at line 69: cannot find symbol
            serverPlayer.getServer().execute(() -> EmeraldConverterHandler.open(serverPlayer));
                        ^
  symbol: method getServer()
  location: variable serverPlayer of type ServerPlayerEntity

ERROR in   src/main/java/com/example/tradermod/TraderMainHandler.java at line 69: cannot find symbol
              serverPlayer.getServer().execute(() -> EmeraldConverterHandler.open(serverPlayer));
                          ^
  symbol: method getServer()
  location: variable serverPlayer of type ServerPlayerEntity


=== COMPILATION ERROR ANALYSIS ===

MISSING METHODS:
  - getServer()
ACTION: Check method names and signatures

FILES TO INVESTIGATE:
  - src/main/java/com/example/tradermod/TraderMainHandler.java
  -   src/main/java/com/example/tradermod/TraderMainHandler.java

Please fix this error by creating a new artifact with the corrected code.

Kodari AI
KodariJun 8 at 9:36 am 3

ServerPlayerEntity has a public server field directly — no getter needed.

Fixed — serverPlayer.getServer() → serverPlayer.server (direct field access, Yarn mappings for 1.21.11).

furo2v

The compilation failed with this error:

code
Compilation failed with 2 error(s):

ERROR in src/main/java/com/example/tradermod/TraderMainHandler.java at line 69: server has private access in ServerPlayerEntity
            serverPlayer.server.execute(() -> EmeraldConverterHandler.open(serverPlayer));
                        ^

ERROR in   src/main/java/com/example/tradermod/TraderMainHandler.java at line 69: server has private access in ServerPlayerEntity
              serverPlayer.server.execute(() -> EmeraldConverterHandler.open(serverPlayer));
                          ^


=== COMPILATION ERROR ANALYSIS ===

FILES TO INVESTIGATE:
  - src/main/java/com/example/tradermod/TraderMainHandler.java
  -   src/main/java/com/example/tradermod/TraderMainHandler.java

Please fix this error by creating a new artifact with the corrected code.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
8 401
src/main/java/com/example/tradermod/TraderMod.java
package com.example.tradermod;

import com.mojang.brigadier.Command;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;

public class TraderMod implements ModInitializer {

    public static final String MOD_ID = "tradermod";

    @Override
    public void onInitialize() {
        CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) ->
            dispatcher.register(CommandManager.literal("trader")
                .executes(context -> {
                    ServerPlayerEntity player = context.getSource().getPlayer();
                    if (player == null) {
                        context.getSource().sendError(Text.literal("Only players can use this command."));
                        return 0;
                    }
                    TraderMainHandler.open(player);
                    return Command.SINGLE_SUCCESS;
                })
            )
        );
    }
}