CrazyPlay Mister
📎 1 file 3,859 chars
📄
pasted-code-1790845466861.txt
txt 151 lines
▶
Create a complete Minecraft Fabric mod for Minecraft 1.21.11 using Java 21.

Mod name ExtraCLine
Author ExtraDev

MAIN FEATURE
Add a floating custom text line above a player's head.

Command
cline text

Example
cline &b&lCrystal &fPvP

The text must appear directly above the player's head, follow them smoothly while walking, jumping, sneaking, flying, swimming, teleporting and changing dimensions, and stay separate from the normal Minecraft username.

COLORS
Support Minecraft legacy `&` colorformatting codes
&0-&9, &a-&f, &k, &l, &m, &n, &o, &r

Example
cline &b&lCrystal &fPvP

CLEAR
Add
cline clear

This completely removes the player's CLine. `clear` must be treated as a special subcommand.

If `cline` has no arguments, show
Usage cline text

MULTIPLAYER
This is extremely important.

The CLine must work correctly between multiple Fabric clients.

If Player A uses
cline &b&lHello

and Player B uses
cline &cGood Luck

Player A must see Good Luck above Player B, and Player B must see Hello above Player A.

Every player must see the correct CLine above the correct player.

CLine data must NOT be client-only. The server must synchronize it using Fabric networking.

Use player UUIDs, not usernames.

NETWORKING
When a player joins
- Load their saved CLine.
- Send their CLine to relevant clients.
- Send existing players' CLines to the new player.

When a player changes or clears their CLine, update all relevant clients immediately.

When a player disconnects, remove their CLine from other clients.

When players become visiblerelevant again, their CLine must appear correctly.

Do not create duplicate renderers.

PERSISTENCE
Save each player's CLine using their UUID so it survives reconnects and server restarts.

Do not save data every tick.

RENDERING
Use an efficient FabricMinecraft-native rendering solution appropriate for 1.21.11.

Prefer a client-side renderer synchronized through Fabric networking if practical. Do not create unnecessary entities for every player.

Do not use expensive repeating tasks for every player every tick.

The CLine should
- Have no background.
- Be centered.
- Look like clean Minecraft text.
- Not replace the normal username.
- Have configurable heightoffset.
- Optionally support text shadow.

CONFIG
Create a simple config containing at least

text-height = 0.65
shadow = false
max-length = 64

PERMISSIONS
Support the permission
extracline.use

Do NOT use Bukkit permissions. If no permission API is installed, allow the mod to work normally or use a Fabric-compatible permission system.

TAB COMPLETION
Add tab completion for `cline clear`.

CLEANUP
Properly remove CLine rendering when
- Player disconnects.
- Player clears their CLine.
- Player changes their CLine.
- Player becomes irrelevantunloaded.
- Clientserver shuts down.

IMPORTANT
This MUST be a Fabric mod, NOT a BukkitPaperSpigot plugin.

Do NOT use
- Bukkit
- Spigot
- Paper
- plugin.yml
- Bukkit APIs
- Paper APIs

Use Fabric API, Fabric networking, Minecraft 1.21.11 APIs and Java 21.

PROJECT
Provide the complete Gradle project including
- build.gradle
- gradle.properties
- settings.gradle
- fabric.mod.json
- All Java source files
- Resources
- Clientserver code
- Networking
- Commands
- Persistence
- Rendering
- Config

The project must build with

.gradlew build

Do not provide pseudocode, TODOs, placeholder methods, fake APIs or missing classes.

Make sure all APIs and mappings are correct for Minecraft 1.21.11.

FINAL RESULT
`cline &b&lCrystal PvP` displays Crystal PvP above the player's head, with correct colors, and other players using the mod can see it too.

`cline clear` removes it for everyone.

Again FABRIC MOD, Minecraft 1.21.11, Java 21. NOT a plugin.
Kodari AI
KodariOct 1 at 9:20 am 5
ExtraCLine
ExtraCLine is a Fabric mod for Minecraft 1.21.11 that adds a customizable floating text line above player heads. Players use the /cline command with legacy color codes to set their display text, which synchronizes across all clients via Fabric networking using UUIDs. The mod features server-side persistence, configurable height offset and shadow settings, permission support, tab completion, and efficient client-side rendering without creating entities. It handles player join, disconnect, visibility changes, and dimension transitions smoothly while maintaining clean, centered text that doesn't replace usernames.
  1. Set up the 1.21.11 Fabric/Java 21 project structure and metadata.

  2. Implement server-side commands, UUID persistence, permission-aware access, and tracking-based synchronization.

  3. Add client config, legacy-color parsing, rendering, and disconnect/world cleanup.

Created the ExtraCLine Fabric 1.21.11 project with server-synchronized, UUID-based CLine data and world-save persistence. It supports both cline <text> and cline text <text>, plus cline clear; clients render formatted text above loaded players and clear it on unload or disconnect.

The config file is created at config/extracline.properties with text-height, shadow, and max-length defaults. Vanilla’s permission predicate is checked for the extracline.use permission atom, with default access when the source uses the vanilla leveled predicate.

CrazyPlay Mister

זה לא שם את השורה מעל השם ובשרתים זה לא עובד

Kodari AI
KodariOct 1 at 9:36 am 3
  1. עוגן את השורה למיקום תג השם של השחקן והוסף את היסט הגובה פעם אחת בלבד.

  2. תקן את סנכרון ה־tracking כך שהשורה תישלח ללקוח שמתחיל לעקוב אחרי השחקן.

תיקנתי את עוגן הרינדור: השורה ממוקמת עכשיו ביחס לתג השם של השחקן, עם היסט הגובה מההגדרות, במקום להסתמך רק על גובה המודל.

כדי שזה יעבוד בשרת, צריך להתקין ExtraCLine וגם Fabric API בשרת Fabric ובכל לקוח. השרת מטפל בפקודה ובסנכרון; בשרת Vanilla, Paper או שרת שבו המוד לא מותקן, הפקודה והסנכרון לא יהיו זמינים. רכיב הסנכרון בקוד כבר שולח את הנתונים ללקוחות הרלוונטיים.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
10 544
src/main/java/com/extradev/extracline/ExtraCLine.java
package com.extradev.extracline;

import com.mojang.brigadier.arguments.StringArgumentType;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.networking.v1.EntityTrackingEvents;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.command.permission.LeveledPermissionPredicate;
import net.minecraft.command.permission.Permission;
import net.minecraft.command.permission.PermissionPredicate;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.WorldSavePath;
import net.minecraft.entity.Entity;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ExtraCLine implements ModInitializer {
    public static final String MOD_ID = "extracline";
    public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

    private static final Permission.Atom USE_PERMISSION = Permission.Atom.of(Identifier.of(MOD_ID, "use"));
    private static final Map<UUID, String> LINES = new HashMap<>();
    private static Path saveFile;
    private static boolean dirty;

    @Override
    public void onInitialize() {
        CLineConfig.load();
        PayloadTypeRegistry.playS2C().register(CLinePayload.ID, CLinePayload.CODEC);

        ServerLifecycleEvents.SERVER_STARTED.register(ExtraCLine::loadData);
        ServerLifecycleEvents.SERVER_STOPPING.register(ExtraCLine::saveAndClearData);
        ServerPlayConnectionEvents.JOIN.register(ExtraCLine::onJoin);
        ServerPlayConnectionEvents.DISCONNECT.register(ExtraCLine::onDisconnect);
        EntityTrackingEvents.START_TRACKING.register(ExtraCLine::onStartTracking);
        CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(
                CommandManager.literal("cline")
                        .requires(ExtraCLine::hasUsePermission)
                        .executes(context -> showUsage(context.getSource()))
                        .then(CommandManager.literal("clear")
                                .executes(context -> clearLine(context.getSource())))
                        .then(CommandManager.literal("text")
                                .executes(context -> showUsage(context.getSource()))
                                .then(CommandManager.argument("text", StringArgumentType.greedyString())
                                        .executes(context -> setLine(context.getSource(), StringArgumentType.getString(context, "text")))))
                        .then(CommandManager.argument("text", StringArgumentType.greedyString())
                                .executes(context -> setLine(context.getSource(), StringArgumentType.getString(context, "text"))))
        ));
    }

    private static boolean hasUsePermission(ServerCommandSource source) {
        PermissionPredicate permissions = source.getPermissions();
        return permissions.hasPermission(USE_PERMISSION) || permissions instanceof LeveledPermissionPredicate;
    }

    private static int showUsage(ServerCommandSource source) {
        source.sendFeedback(() -> Text.literal("Usage cline text"), false);
        return 1;
    }

    private static int setLine(ServerCommandSource source, String text) {
        ServerPlayerEntity player = source.getPlayer();
        if (player == null) {
            source.sendError(Text.literal("Only players can set a CLine."));
            return 0;
        }
        if (text.length() > CLineConfig.maxLength()) {
            source.sendError(Text.literal("CLine is too long (maximum " + CLineConfig.maxLength() + " characters)."));
            return 0;
        }

        UUID playerId = player.getUuid();
        String previous = LINES.put(playerId, text);
        if (!text.equals(previous)) {
            dirty = true;
            saveData();
        }
        broadcast(source.getServer(), new CLinePayload(playerId, text), null);
        source.sendFeedback(() -> Text.literal("CLine updated."), false);
        return 1;
    }

    private static int clearLine(ServerCommandSource source) {
        ServerPlayerEntity player = source.getPlayer();
        if (player == null) {
            source.sendError(Text.literal("Only players can clear a CLine."));
            return 0;
        }

        UUID playerId = player.getUuid();
        if (LINES.remove(playerId) != null) {
            dirty = true;
            saveData();
        }
        broadcast(source.getServer(), new CLinePayload(playerId, ""), null);
        source.sendFeedback(() -> Text.literal("CLine cleared."), false);
        return 1;
    }

    private static void loadData(MinecraftServer server) {
        LINES.clear();
        dirty = false;
        saveFile = server.getSavePath(WorldSavePath.ROOT).resolve("extracline-data.txt");
        if (Files.notExists(saveFile)) {
            return;
        }

        try {
            for (String row : Files.readAllLines(saveFile, StandardCharsets.UTF_8)) {
                int separator = row.indexOf('\t');
                if (separator < 0) {
                    continue;
                }
                try {
                    UUID playerId = UUID.fromString(row.substring(0, separator));
                    String text = new String(Base64.getDecoder().decode(row.substring(separator + 1)), StandardCharsets.UTF_8);
                    if (!text.isEmpty()) {
                        LINES.put(playerId, text);
                    }
                } catch (IllegalArgumentException ignored) {
                }
            }
        } catch (IOException exception) {
            LOGGER.error("Could not load saved CLines", exception);
        }
    }

    private static void saveAndClearData(MinecraftServer server) {
        saveData();
        LINES.clear();
        saveFile = null;
        dirty = false;
    }

    private static void saveData() {
        if (!dirty || saveFile == null) {
            return;
        }

        List<String> rows = new ArrayList<>(LINES.size());
        for (Map.Entry<UUID, String> entry : LINES.entrySet()) {
            String encoded = Base64.getEncoder().encodeToString(entry.getValue().getBytes(StandardCharsets.UTF_8));
            rows.add(entry.getKey() + "\t" + encoded);
        }
        try {
            Files.createDirectories(saveFile.getParent());
            Files.write(saveFile, rows, StandardCharsets.UTF_8);
            dirty = false;
        } catch (IOException exception) {
            LOGGER.error("Could not save CLines", exception);
        }
    }

    private static void onJoin(net.minecraft.server.network.ServerPlayNetworkHandler handler,
                               net.fabricmc.fabric.api.networking.v1.PacketSender sender,
                               MinecraftServer server) {
        ServerPlayerEntity joiningPlayer = handler.getPlayer();
        UUID joiningId = joiningPlayer.getUuid();
        String joiningText = LINES.getOrDefault(joiningId, "");

        for (ServerPlayerEntity onlinePlayer : server.getPlayerManager().getPlayerList()) {
            ServerPlayNetworking.send(joiningPlayer,
                    new CLinePayload(onlinePlayer.getUuid(), LINES.getOrDefault(onlinePlayer.getUuid(), "")));
            if (!onlinePlayer.getUuid().equals(joiningId)) {
                ServerPlayNetworking.send(onlinePlayer, new CLinePayload(joiningId, joiningText));
            }
        }
    }

    private static void onDisconnect(net.minecraft.server.network.ServerPlayNetworkHandler handler, MinecraftServer server) {
        UUID playerId = handler.getPlayer().getUuid();
        broadcast(server, new CLinePayload(playerId, ""), playerId);
    }

    private static void onStartTracking(Entity trackedEntity, ServerPlayerEntity trackingPlayer) {
        if (trackedEntity instanceof ServerPlayerEntity trackedPlayer) {
            ServerPlayNetworking.send(trackingPlayer,
                    new CLinePayload(trackedPlayer.getUuid(), LINES.getOrDefault(trackedPlayer.getUuid(), "")));
        }
    }