Tak Shun Fong

5AZRQ3

Kodari AI
KodariNov 15 at 2:18 am 1

What would you like me to do with 5AZRQ3?

Tak Shun Fong

Take the code I pasted in "donut smp stuff" and set up the full Fabric 1.21.4 project structure around it (move it to src/main/java/com/takshun/donutahpopup/DonutAhPopupClient.java, create build.gradle, gradle.properties, and src/main/resources/fabric.mod.json), and make sure it compiles cleanly.

Kodari AI
KodariNov 15 at 2:19 am 1

The file donut smp stuff contains only // New file; the code isn’t present in the project. Please paste it here so I can set up the Fabric 1.21.4 project and address any compilation issues.

Tak Shun Fong
📎 1 file 11,280 chars
📄
pasted-code-1794709210300.txt
txt 235 lines
▶
package com.takshun.donutahpopup;

import com.mojang.brigadier.arguments.StringArgumentType;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.RenderTickCounter;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DonutAhPopupClient implements ClientModInitializer {

    private static final List ACTIVE_POPUPS = new ArrayList<>();
    private static final long POPUP_DURATION_MS = 5500L; // 5.5 seconds on screen

    // Matches common DonutSMP & AuctionHouse sale chat patterns:
    // Pattern 1: " bought your  for $" or " purchased your  for $"
    private static final Pattern BOUGHT_YOUR_PATTERN = Pattern.compile(
            "(?i)(?:\[.*?\]\s*)?([A-Za-z0-9_\.]{2,20})\s+(?:just\s+)?(?:bought|purchased)\s+your\s+(.+?)\s+for\s+\$?([0-9][0-9,\.]*[kKmMbBtT]?)"
    );

    // Pattern 2: "You sold  for $" or "Your auction of  sold for $"
    private static final Pattern SOLD_FOR_PATTERN = Pattern.compile(
            "(?i)(?:you\s+sold|your\s+(?:item|listing|auction)\s+(.+?)\s+sold)\s*(?:(.+?)\s+)?for\s+\$?([0-9][0-9,\.]*[kKmMbBtT]?)"
    );

    // Fallback price extractor if message clearly says auction/ah sold
    private static final Pattern PRICE_PATTERN = Pattern.compile(
            "\$([0-9][0-9,\.]*[kKmMbBtT]?)"
    );

    @Override
    public void onInitializeClient() {
        // 1. Listen for incoming server/system messages (where DonutSMP sends AH alerts)
        ClientReceiveMessageEvents.GAME.register((message, overlay) -> {
            if (!overlay) {
                checkChatMessage(message.getString());
            }
        });

        // 2. Listen for chat messages just in case the server routes AH messages via standard chat
        ClientReceiveMessageEvents.CHAT.register((message, signedMessage, sender, params, receptionTimestamp) -> {
            checkChatMessage(message.getString());
        });

        // 3. Register HUD Renderer to draw our animated popup card at the top-center of the screen
        HudRenderCallback.EVENT.register(this::renderPopupHud);

        // 4. Register "/ahpopuptest" command so you can test the popup anytime in-game!
        ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
            dispatcher.register(ClientCommandManager.literal("ahpopuptest")
                    .executes(context -> {
                        triggerSalePopup("Netherite Sword", "2.5M", "DrDonut");
                        context.getSource().sendFeedback(
                                Text.literal("[AH Popup] ").formatted(Formatting.GOLD)
                                        .append(Text.literal("Triggered a test Auction House sale popup!").formatted(Formatting.GREEN))
                        );
                        return 1;
                    })
                    .then(ClientCommandManager.argument("price", StringArgumentType.word())
                            .executes(context -> {
                                String price = StringArgumentType.getString(context, "price");
                                triggerSalePopup("1x Spawner", price, "TakShun3");
                                return 1;
                            })
                    )
            );
        });
    }

    private void checkChatMessage(String rawText) {
        if (rawText == null || rawText.isEmpty()) return;

        // Strip legacy Minecraft formatting codes (§a, §6, etc.)
        String clean = rawText.replaceAll("§[0-9a-fk-orA-FK-OR]", "").trim();
        String lower = clean.toLowerCase();

        // Check Pattern 1: " bought your  for $"
        Matcher m1 = BOUGHT_YOUR_PATTERN.matcher(clean);
        if (m1.find()) {
            String buyer = m1.group(1).trim();
            String item = m1.group(2).trim();
            String price = m1.group(3).trim();
            triggerSalePopup(item, price, buyer);
            return;
        }

        // Check Pattern 2: "You sold  for $"
        Matcher m2 = SOLD_FOR_PATTERN.matcher(clean);
        if (m2.find()) {
            String item = m2.group(1) != null ? m2.group(1).trim() : (m2.group(2) != null ? m2.group(2).trim() : "Auction Item");
            String price = m2.group(3).trim();
            triggerSalePopup(item, price, "Buyer");
            return;
        }

        // Fallback check for custom DonutSMP AH sale formatting
        if ((lower.contains("auction") || lower.contains("[ah]") || lower.contains("bought your") || lower.contains("sold your"))
                && (lower.contains("sold") || lower.contains("bought") || lower.contains("purchased"))) {
            Matcher priceMatcher = PRICE_PATTERN.matcher(clean);
            if (priceMatcher.find()) {
                String price = priceMatcher.group(1).trim();
                triggerSalePopup("Auction Listing", price, "DonutSMP AH");
            }
        }
    }

    public static void triggerSalePopup(String itemName, String rawPrice, String buyerName) {
        String formattedPrice = rawPrice.startsWith("$") ? rawPrice : "$" + rawPrice;
        synchronized (ACTIVE_POPUPS) {
            ACTIVE_POPUPS.add(0, new SaleNotification(itemName, formattedPrice, buyerName, System.currentTimeMillis()));
            if (ACTIVE_POPUPS.size() > 3) {
                ACTIVE_POPUPS.remove(ACTIVE_POPUPS.size() - 1);
            }
        }

        // Play a celebratory chime sound locally on the client
        MinecraftClient client = MinecraftClient.getInstance();
        if (client.player != null) {
            client.player.playSound(SoundEvents.ENTITY_PLAYER_LEVELUP, 0.85f, 1.25f);
            client.player.playSound(SoundEvents.BLOCK_AMETHYST_BLOCK_CHIME, 1.0f, 1.1f);
        }
    }

    private void renderPopupHud(DrawContext context, RenderTickCounter tickCounter) {
        MinecraftClient client = MinecraftClient.getInstance();
        if (client.player == null || client.options.hudHidden) return;

        long now = System.currentTimeMillis();
        TextRenderer font = client.textRenderer;
        int screenWidth = context.getScaledWindowWidth();

        synchronized (ACTIVE_POPUPS) {
            Iterator iterator = ACTIVE_POPUPS.iterator();
            int index = 0;

            while (iterator.hasNext()) {
                SaleNotification popup = iterator.next();
                long elapsed = now - popup.startTime;

                if (elapsed > POPUP_DURATION_MS) {
                    iterator.remove();
                    continue;
                }

                // Calculate smooth slide-in (first 350ms) and slide-out (last 450ms) animation
                float progress = 1.0f;
                if (elapsed < 350L) {
                    float t = elapsed / 350.0f;
                    progress = 1.0f - (float) Math.pow(1.0f - t, 3); // Cubic ease-out
                } else if (elapsed > POPUP_DURATION_MS - 450L) {
                    float t = (POPUP_DURATION_MS - elapsed) / 450.0f;
                    progress = Math.max(0.0f, t);
                }

                String headerText = "★ AUCTION HOUSE SOLD! ★";
                String priceText = "+" + popup.price;
                String detailText = popup.item + (popup.buyer.isEmpty() ? "" : " • Buyer: " + popup.buyer);

                int headerW = font.getWidth(headerText);
                int priceW = font.getWidth(priceText) * 2; // Rendered at 2x scale
                int detailW = font.getWidth(detailText);

                int boxWidth = Math.max(190, Math.max(headerW, Math.max(priceW, detailW)) + 28);
                int boxHeight = 52;

                int x = (screenWidth - boxWidth) / 2;
                int targetY = 14 + (index * (boxHeight + 8));
                int y = (int) (-boxHeight + (targetY + boxHeight) * progress);

                // Colors (ARGB): Dark obsidian card with gold & emerald accents
                int bgColor = 0xE614141F;       // Deep translucent slate
                int goldBorder = 0xFFFFAA00;    // Gold border
                int emeraldBar = 0xFF55FF55;    // Bright emerald green

                // Draw background card
                context.fill(x, y, x + boxWidth, y + boxHeight, bgColor);

                // Draw 1px gold border around the card
                context.fill(x, y, x + boxWidth, y + 1, goldBorder);                 // Top
                context.fill(x, y + boxHeight - 1, x + boxWidth, y + boxHeight, goldBorder); // Bottom
                context.fill(x, y, x + 1, y + boxHeight, goldBorder);                 // Left
                context.fill(x + boxWidth - 1, y, x + boxWidth, y + boxHeight, goldBorder); // Right

                // Draw animated countdown progress bar along the bottom edge
                float timeRemainingRatio = 1.0f - ((float) elapsed / POPUP_DURATION_MS);
                int barWidth = (int) ((boxWidth - 4) * timeRemainingRatio);
                context.fill(x + 2, y + boxHeight - 3, x + 2 + barWidth, y + boxHeight - 1, emeraldBar);

                // 1. Header text (Gold)
                context.drawTextWithShadow(font, headerText, x + (boxWidth - headerW) / 2, y + 6, 0xFFFFD700);

                // 2. Big Sold Price (1.5x scale in bright Emerald Green)
                context.getMatrices().push();
                float scale = 1.5f;
                context.getMatrices().scale(scale, scale, 1.0f);
                int scaledPriceX = (int) ((x + (boxWidth - font.getWidth(priceText) * scale) / 2.0f) / scale);
                int scaledPriceY = (int) ((y + 18) / scale);
                context.drawTextWithShadow(font, priceText, scaledPriceX, scaledPriceY, 0xFF55FF55);
                context.getMatrices().pop();

                // 3. Item & Buyer details (Soft gray/white)
                context.drawTextWithShadow(font, detailText, x + (boxWidth - detailW) / 2, y + 36, 0xFFDDDDDD);

                index++;
            }
        }
    }

    private static class SaleNotification {
        final String item;
        final String price;
        final String buyer;
        final long startTime;

        SaleNotification(String item, String price, String buyer, long startTime) {
            this.item = item;
            this.price = price;
            this.buyer = buyer;
            this.startTime = startTime;
        }
    }
}
Kodari AI
KodariNov 15 at 2:23 am 2
  • Set up the Fabric client project and dependencies.

  • Preserve the popup behavior while fixing the pasted Java escapes and any version-specific API issues.

Set up the Fabric 1.21.4 client project and corrected the pasted regex escapes. Use /ahpopuptest in-game to preview the popup.

Compilation hasn’t been verified in this session.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
5 253
src/main/java/com/takshun/donutahpopup/DonutAhPopupClient.java
package com.takshun.donutahpopup;

import com.mojang.brigadier.arguments.StringArgumentType;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.RenderTickCounter;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DonutAhPopupClient implements ClientModInitializer {
    private static final List<SaleNotification> ACTIVE_POPUPS = new ArrayList<>();
    private static final long POPUP_DURATION_MS = 5500L;
    private static final Pattern BOUGHT_YOUR_PATTERN = Pattern.compile(
            "(?i)(?:\\[.*?\\]\\s*)?([A-Za-z0-9_.]{2,20})\\s+(?:just\\s+)?(?:bought|purchased)\\s+your\\s+(.+?)\\s+for\\s+\\$?([0-9][0-9,.]*[kKmMbBtT]?)"
    );
    private static final Pattern SOLD_FOR_PATTERN = Pattern.compile(
            "(?i)(?:you\\s+sold|your\\s+(?:item|listing|auction)\\s+(.+?)\\s+sold)\\s*(?:(.+?)\\s+)?for\\s+\\$?([0-9][0-9,.]*[kKmMbBtT]?)"
    );
    private static final Pattern PRICE_PATTERN = Pattern.compile("\\$([0-9][0-9,.]*[kKmMbBtT]?)");

    @Override
    public void onInitializeClient() {
        ClientReceiveMessageEvents.GAME.register((message, overlay) -> {
            if (!overlay) {
                checkChatMessage(message.getString());
            }
        });
        ClientReceiveMessageEvents.CHAT.register((message, signedMessage, sender, params, receptionTimestamp) ->
                checkChatMessage(message.getString()));
        HudRenderCallback.EVENT.register(this::renderPopupHud);
        ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
            dispatcher.register(ClientCommandManager.literal("ahpopuptest")
                    .executes(context -> {
                        triggerSalePopup("Netherite Sword", "2.5M", "DrDonut");
                        context.getSource().sendFeedback(
                                Text.literal("[AH Popup] ").formatted(Formatting.GOLD)
                                        .append(Text.literal("Triggered a test Auction House sale popup!").formatted(Formatting.GREEN))
                        );
                        return 1;
                    })
                    .then(ClientCommandManager.argument("price", StringArgumentType.word())
                            .executes(context -> {
                                String price = StringArgumentType.getString(context, "price");
                                triggerSalePopup("1x Spawner", price, "TakShun3");
                                return 1;
                            })));
        });
    }

    private void checkChatMessage(String rawText) {
        if (rawText == null || rawText.isEmpty()) return;
        String clean = rawText.replaceAll("§[0-9a-fk-orA-FK-OR]", "").trim();
        String lower = clean.toLowerCase(java.util.Locale.ROOT);

        Matcher m1 = BOUGHT_YOUR_PATTERN.matcher(clean);
        if (m1.find()) {
            triggerSalePopup(m1.group(2).trim(), m1.group(3).trim(), m1.group(1).trim());
            return;
        }
        Matcher m2 = SOLD_FOR_PATTERN.matcher(clean);
        if (m2.find()) {
            String item = m2.group(1) != null ? m2.group(1).trim() : (m2.group(2) != null ? m2.group(2).trim() : "Auction Item");
            triggerSalePopup(item, m2.group(3).trim(), "Buyer");
            return;
        }
        if ((lower.contains("auction") || lower.contains("[ah]") || lower.contains("bought your") || lower.contains("sold your"))
                && (lower.contains("sold") || lower.contains("bought") || lower.contains("purchased"))) {
            Matcher priceMatcher = PRICE_PATTERN.matcher(clean);
            if (priceMatcher.find()) {
                triggerSalePopup("Auction Listing", priceMatcher.group(1).trim(), "DonutSMP AH");
            }
        }
    }

    public static void triggerSalePopup(String itemName, String rawPrice, String buyerName) {
        String formattedPrice = rawPrice.startsWith("$") ? rawPrice : "$" + rawPrice;
        synchronized (ACTIVE_POPUPS) {
            ACTIVE_POPUPS.add(0, new SaleNotification(itemName, formattedPrice, buyerName, System.currentTimeMillis()));
            if (ACTIVE_POPUPS.size() > 3) {
                ACTIVE_POPUPS.remove(ACTIVE_POPUPS.size() - 1);
            }
        }
        MinecraftClient client = MinecraftClient.getInstance();
        if (client.player != null) {
            client.player.playSound(SoundEvents.ENTITY_PLAYER_LEVELUP, 0.85f, 1.25f);
            client.player.playSound(SoundEvents.BLOCK_AMETHYST_BLOCK_CHIME, 1.0f, 1.1f);
        }
    }

    private void renderPopupHud(DrawContext context, RenderTickCounter tickCounter) {
        MinecraftClient client = MinecraftClient.getInstance();
        if (client.player == null || client.options.hudHidden) return;

        long now = System.currentTimeMillis();
        TextRenderer font = client.textRenderer;
        int screenWidth = context.getScaledWindowWidth();
        synchronized (ACTIVE_POPUPS) {
            Iterator<SaleNotification> iterator = ACTIVE_POPUPS.iterator();
            int index = 0;
            while (iterator.hasNext()) {
                SaleNotification popup = iterator.next();
                long elapsed = now - popup.startTime;
                if (elapsed > POPUP_DURATION_MS) {
                    iterator.remove();
                    continue;
                }
                float progress = 1.0f;
                if (elapsed < 350L) {
                    float t = elapsed / 350.0f;
                    progress = 1.0f - (float) Math.pow(1.0f - t, 3);
                } else if (elapsed > POPUP_DURATION_MS - 450L) {
                    float t = (POPUP_DURATION_MS - elapsed) / 450.0f;
                    progress = Math.max(0.0f, t);
                }

                String headerText = "★ AUCTION HOUSE SOLD! ★";
                String priceText = "+" + popup.price;
                String detailText = popup.item + (popup.buyer.isEmpty() ? "" : " • Buyer: " + popup.buyer);
                int headerW = font.getWidth(headerText);
                int priceW = font.getWidth(priceText) * 2;
                int detailW = font.getWidth(detailText);
                int boxWidth = Math.max(190, Math.max(headerW, Math.max(priceW, detailW)) + 28);
                int boxHeight = 52;
                int x = (screenWidth - boxWidth) / 2;
                int targetY = 14 + (index * (boxHeight + 8));
                int y = (int) (-boxHeight + (targetY + boxHeight) * progress);

                int bgColor = 0xE614141F;
                int goldBorder = 0xFFFFAA00;
                int emeraldBar = 0xFF55FF55;
                context.fill(x, y, x + boxWidth, y + boxHeight, bgColor);
                context.fill(x, y, x + boxWidth, y + 1, goldBorder);
                context.fill(x, y + boxHeight - 1, x + boxWidth, y + boxHeight, goldBorder);
                context.fill(x, y, x + 1, y + boxHeight, goldBorder);
                context.fill(x + boxWidth - 1, y, x + boxWidth, y + boxHeight, goldBorder);
                float timeRemainingRatio = 1.0f - ((float) elapsed / POPUP_DURATION_MS);
                int barWidth = (int) ((boxWidth - 4) * timeRemainingRatio);
                context.fill(x + 2, y + boxHeight - 3, x + 2 + barWidth, y + boxHeight - 1, emeraldBar);
                context.drawTextWithShadow(font, headerText, x + (boxWidth - headerW) / 2, y + 6, 0xFFFFD700);
                context.getMatrices().push();
                float scale = 1.5f;
                context.getMatrices().scale(scale, scale, 1.0f);
                int scaledPriceX = (int) ((x + (boxWidth - font.getWidth(priceText) * scale) / 2.0f) / scale);
                int scaledPriceY = (int) ((y + 18) / scale);
                context.drawTextWithShadow(font, priceText, scaledPriceX, scaledPriceY, 0xFF55FF55);
                context.getMatrices().pop();
                context.drawTextWithShadow(font, detailText, x + (boxWidth - detailW) / 2, y + 36, 0xFFDDDDDD);
                index++;
            }
        }
    }

    private static class SaleNotification {
        final String item;
        final String price;
        final String buyer;
        final long startTime;

        SaleNotification(String item, String price, String buyer, long startTime) {
            this.item = item;
            this.price = price;
            this.buyer = buyer;
            this.startTime = startTime;
        }
    }
}