poliskipoland434343

can you make me a mod that show other players saturation hearts and even inventory above the head

Kodari AI
KodariJun 1 at 12:47 pm 38
SaturationDisplay
A Fabric 1.21.11 mod that displays other players' saturation level as hearts floating above their heads, along with a visual inventory grid showing their held and equipped items. Saturation hearts use a distinct color to differentiate from health. The inventory display shows the player's hotbar, armor slots, and offhand. Both displays are visible to nearby players in the world.

Let me read the necessary docs before writing any code.

SaturationDisplay
A Fabric 1.21.11 mod that shows other players' saturation as golden hearts and their equipped items (armor, mainhand, offhand) floating above their head. Data is synced from the server every 10 ticks to nearby players within 32 blocks. Hearts and item icons are rendered in 3D world space as billboarded overlays, making it easy to glance at allies' food status and gear during gameplay.

Plan:

  1. PlayerDataPayload — 8-field CustomPayload (uuid, saturation, 6 item stacks)

  2. SaturationDisplay — ModInitializer, registers packet + server tick sender

  3. PlayerDataCache — thread-safe client side UUID → display data map

  4. PlayerOverlayRenderer — WorldRenderEvents.AFTER_ENTITIES billboard renderer

  5. SaturationDisplayClient — ClientModInitializer, wires receiver + renderer

  6. Build files + fabric.mod.json

Here’s what the mod does and how each piece fits together:

Data flow:

  • Every 10 ticks, the server collects each player’s saturation level + 6 equipment slots and sends a PlayerDataPayload to all nearby players (within 32 blocks)

  • On the client, received payloads are cached in PlayerDataCache keyed by UUID

  • On disconnect, the cache is cleared

Rendering (WorldRenderEvents.AFTER_ENTITIES):

  • For each other player in the world with cached data, a billboard transform is applied (translate to head position + camera rotation + scale)

  • Hearts row — 10 ♥/♡ characters drawn with the text renderer: filled hearts are gold (0xFFAA00), empty are dark gray. Count = ceil(saturation / 2)

  • Items row (below hearts) — each non-empty slot (helmet → chestplate → leggings → boots → mainhand → offhand) rendered as a GUI-mode item icon; a -1/-1 counter-scale flips them right-side up within the billboard

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
the director
Code
10 402
src/main/java/com/saturationdisplay/SaturationDisplay.java
package com.saturationdisplay;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.PlayerLookup;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;

public class SaturationDisplay implements ModInitializer {

    public static final String MOD_ID = "saturationdisplay";

    @Override
    public void onInitialize() {
        PayloadTypeRegistry.playS2C().register(PlayerDataPayload.ID, PlayerDataPayload.CODEC);
        ServerTickEvents.END_SERVER_TICK.register(this::onServerTick);
    }

    private void onServerTick(MinecraftServer server) {
        if (server.getTicks() % 10 != 0) return;

        for (ServerWorld world : server.getWorlds()) {
            for (ServerPlayerEntity target : world.getPlayers()) {
                var inv = target.getInventory();
                var payload = new PlayerDataPayload(
                    target.getUuid(),
                    target.getHungerManager().getSaturationLevel(),
                    inv.getArmorStack(3),
                    inv.getArmorStack(2),
                    inv.getArmorStack(1),
                    inv.getArmorStack(0),
                    target.getMainHandStack(),
                    target.getOffHandStack()
                );

                for (ServerPlayerEntity watcher : PlayerLookup.around(world, target.getPos(), 32.0)) {
                    if (!watcher.equals(target)) {
                        ServerPlayNetworking.send(watcher, payload);
                    }
                }
            }
        }
    }
}