From 75de3bbc46300c64b083c11746e98c9a0b4e87d5 Mon Sep 17 00:00:00 2001 From: Reason <28310208+Reasonlesss@users.noreply.github.com> Date: Sat, 28 Jun 2025 14:12:30 +0100 Subject: [PATCH] action dump crash fix --- .../codeclient/dev/menu/SlotGhostManager.java | 45 ++++++------ .../codeclient/dev/overlay/ChestPeeker.java | 10 +-- .../hypercube/actiondump/Argument.java | 35 ++++++--- .../codeclient/hypercube/actiondump/Icon.java | 71 +++++++------------ 4 files changed, 78 insertions(+), 83 deletions(-) diff --git a/src/main/java/dev/dfonline/codeclient/dev/menu/SlotGhostManager.java b/src/main/java/dev/dfonline/codeclient/dev/menu/SlotGhostManager.java index d8ae8651..cc137cc6 100644 --- a/src/main/java/dev/dfonline/codeclient/dev/menu/SlotGhostManager.java +++ b/src/main/java/dev/dfonline/codeclient/dev/menu/SlotGhostManager.java @@ -20,12 +20,13 @@ import net.minecraft.client.render.RenderLayer; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.screen.slot.Slot; -import net.minecraft.text.Text; import net.minecraft.util.hit.BlockHitResult; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.List; public class SlotGhostManager extends Feature { private Action action; @@ -84,10 +85,10 @@ public void render(DrawContext context, int mouseX, int mouseY, int x, int y, fl @Nullable public Argument getArgument(Slot slot) { - var args = new ArrayList(); + List args = new ArrayList<>(); - for (var group : action.icon.getArgGroups()) { - var pos = group.getPossibilities(); + for (Icon.ArgumentGroup group : action.icon.getArgGroups()) { + List pos = group.getPossibilities(); args.addAll(pos.get((int) (time / 30F) % pos.size()).arguments()); } @@ -97,27 +98,21 @@ public Argument getArgument(Slot slot) { } public void drawSlot(DrawContext context, Slot slot) { - try { - if (!(CodeClient.MC.currentScreen instanceof GenericContainerScreen || CodeClient.MC.currentScreen instanceof CustomChestMenu)) { - action = null; - } - if (badAction() || slot.inventory instanceof PlayerInventory) - return; - if (slot.hasStack()) return; - var arg = getArgument(slot); - if (arg == null) return; - Icon.Type type = Icon.Type.valueOf(arg.type); - ItemStack itemStack = type.getIcon(); - if (itemStack.isEmpty()) return; -// itemStack.setCount(slot.id); - context.fill(slot.x, slot.y, slot.x + 16, slot.y + 16, arg.optional ? 0x50__90_90_ff : 0x30__ff_00_00); - context.drawItem(itemStack, slot.x, slot.y); - context.drawStackOverlay(CodeClient.MC.textRenderer, itemStack, slot.x, slot.y); -// context.drawText(CodeClient.MC.textRenderer, Text.literal(arg.type),slot.x,slot.y,0xFFFFFF00,true); - context.fill(RenderLayer.getGuiGhostRecipeOverlay(), slot.x, slot.y, slot.x + 16, slot.y + 16, 0x40ffffff); - } catch (Exception e) { - context.drawText(CodeClient.MC.textRenderer, Text.literal("Error."), slot.x, slot.y, 0xFF0000, true); + if (!(CodeClient.MC.currentScreen instanceof GenericContainerScreen || CodeClient.MC.currentScreen instanceof CustomChestMenu)) { + action = null; } + if (badAction() || slot.inventory instanceof PlayerInventory) + return; + if (slot.hasStack()) return; + Argument arg = getArgument(slot); + if (arg == null) return; + ItemStack itemStack = arg.getItem(); + + if (itemStack.isEmpty()) return; + context.fill(slot.x, slot.y, slot.x + 16, slot.y + 16, arg.optional ? 0x50__90_90_ff : 0x30__ff_00_00); + context.drawItem(itemStack, slot.x, slot.y); + context.drawStackOverlay(CodeClient.MC.textRenderer, itemStack, slot.x, slot.y); + context.fill(RenderLayer.getGuiGhostRecipeOverlay(), slot.x, slot.y, slot.x + 16, slot.y + 16, 0x40ffffff); } @Override @Nullable @@ -125,7 +120,7 @@ public ItemStack getHoverStack(Slot slot) { if (badAction() || slot.inventory instanceof PlayerInventory) return null; if (slot.hasStack()) return null; - var arg = getArgument(slot); + Argument arg = getArgument(slot); if (arg == null) return null; return arg.getItem(); } diff --git a/src/main/java/dev/dfonline/codeclient/dev/overlay/ChestPeeker.java b/src/main/java/dev/dfonline/codeclient/dev/overlay/ChestPeeker.java index 22e97403..8262d245 100644 --- a/src/main/java/dev/dfonline/codeclient/dev/overlay/ChestPeeker.java +++ b/src/main/java/dev/dfonline/codeclient/dev/overlay/ChestPeeker.java @@ -150,11 +150,10 @@ public List getOverlayText() { text.append(item.getCount() + "x "); text.append(item.getName()); } else { + JsonObject object = JsonParser.parseString(varItem).getAsJsonObject(); try { - JsonObject object = JsonParser.parseString(varItem).getAsJsonObject(); Type type = Type.valueOf(object.get("id").getAsString()); JsonObject data = object.get("data").getAsJsonObject(); - // JsonArray lore = data.get("display").getAsJsonObject().get("Lore").getAsJsonArray(); text.append(Text.literal(type.name.toUpperCase()).fillStyle(Style.EMPTY.withColor(type.color)).append(" ")); if (type == Type.var) { Scope scope = Scope.valueOf(data.get("scope").getAsString()); @@ -202,8 +201,11 @@ public List getOverlayText() { text.append(Text.literal(data.get("option").getAsString()).formatted(Formatting.AQUA)); } if (type == Type.hint) continue; - } catch (Exception ignored) { - continue; + } catch (IllegalArgumentException ignored) { + text.append(Text.literal(object.get("id").getAsString().toUpperCase()) + .styled(style -> style.withColor(TextColor.fromRgb(0x808080))) + .append(" ")); + text.append(item.getName()); } } texts.add(text); diff --git a/src/main/java/dev/dfonline/codeclient/hypercube/actiondump/Argument.java b/src/main/java/dev/dfonline/codeclient/hypercube/actiondump/Argument.java index 50ca1011..7c5db771 100644 --- a/src/main/java/dev/dfonline/codeclient/hypercube/actiondump/Argument.java +++ b/src/main/java/dev/dfonline/codeclient/hypercube/actiondump/Argument.java @@ -1,15 +1,19 @@ package dev.dfonline.codeclient.hypercube.actiondump; +import com.ibm.icu.text.CaseMap; import dev.dfonline.codeclient.Utility; import dev.dfonline.codeclient.data.DFItem; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.text.MutableText; import net.minecraft.text.Text; +import net.minecraft.text.TextColor; import net.minecraft.util.Formatting; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.Objects; public class Argument { @@ -30,9 +34,10 @@ public Icon.Type getType() { } public ItemStack getItem() { - Icon.Type icon = getType(); - if(icon == null) return ItemStack.EMPTY; - var item = icon.getIcon(); + Icon.Type type = getType(); + ItemStack item = type == null + ? Items.GRAY_DYE.getDefaultStack() + : type.getIcon(); DFItem dfItem = DFItem.of(item); // First line is item name, others are lore @@ -50,10 +55,22 @@ public List getLore() { int i = 0; if (this.text != null) addToLore(lore, this.text); if (this.description != null) for (String line : this.description) { - Icon.Type type = Icon.Type.valueOf(this.type); + MutableText text = Text.empty().formatted(Formatting.GRAY).styled(s -> s.withItalic(false)); + MutableText typeText; + + try { + Icon.Type type = Icon.Type.valueOf(this.type); + typeText = Text.literal(type.display).setStyle(Text.empty().getStyle().withColor(type.color).withItalic(false)); + } catch (IllegalArgumentException e) { + // Show a grayed out version of the name. + String properCase = CaseMap.Title.toTitle().apply(Locale.ENGLISH, null, this.type.replaceAll("_", " ")); + typeText = Text.literal(properCase).setStyle(Text.empty().getStyle() + .withColor(TextColor.fromRgb(0x808080)) + .withItalic(false)); + } + if (i == 0) { - MutableText text = Text.empty().formatted(Formatting.GRAY).styled(s -> s.withItalic(false)); - MutableText typeText = Text.literal(type.display).setStyle(Text.empty().getStyle().withColor(type.color).withItalic(false)); + if (this.plural) typeText.append("(s)"); text.append(typeText); if (this.optional) { @@ -80,10 +97,12 @@ public List getLore() { public boolean isOr() { return text != null && text.endsWith("OR"); } + public boolean isSplitter() { - return Objects.equals(text,""); + return Objects.equals(text, ""); } private void addToLore(ArrayList lore, String text) { lore.add(Utility.textFromString(text)); - }} \ No newline at end of file + } +} \ No newline at end of file diff --git a/src/main/java/dev/dfonline/codeclient/hypercube/actiondump/Icon.java b/src/main/java/dev/dfonline/codeclient/hypercube/actiondump/Icon.java index f5c432f0..d6550c47 100644 --- a/src/main/java/dev/dfonline/codeclient/hypercube/actiondump/Icon.java +++ b/src/main/java/dev/dfonline/codeclient/hypercube/actiondump/Icon.java @@ -1,5 +1,6 @@ package dev.dfonline.codeclient.hypercube.actiondump; +import com.ibm.icu.text.CaseMap; import dev.dfonline.codeclient.Utility; import dev.dfonline.codeclient.data.DFItem; import dev.dfonline.codeclient.data.ItemData; @@ -19,10 +20,12 @@ import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; import net.minecraft.util.Util; +import org.apache.commons.lang3.text.WordUtils; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; +import java.util.Locale; public class Icon { private static final TextColor GOLD = TextColor.fromFormatting(Formatting.GOLD); @@ -78,33 +81,7 @@ public ItemStack getItem() { addToLore(lore, "Chest Parameters:"); boolean hasOptional = false; for (Argument arg : arguments) { - int i = 0; - if (arg.text != null) addToLore(lore, arg.text); - if (arg.description != null && description.length != 0) for (String line : arg.description) { - Type type = Type.valueOf(arg.type); - if (i == 0) { - MutableText text = Text.empty().formatted(Formatting.GRAY).styled(s -> s.withItalic(false)); - MutableText typeText = Text.literal(type.display).setStyle(Text.empty().getStyle().withColor(type.color).withItalic(false)); - if (arg.plural) typeText.append("(s)"); - text.append(typeText); - if (arg.optional) { - text.append(Text.literal("*").formatted(Formatting.WHITE)); - hasOptional = true; - } - text.append(Text.literal(" - ").formatted(Formatting.DARK_GRAY)); - text.append(Utility.textFromString(line).formatted(Formatting.GRAY)); - lore.add(text); - } else lore.add(Utility.textFromString(line).formatted(Formatting.GRAY)); - i++; - } - if (arg.notes != null) for (String[] lines : arg.notes) { - i = 0; - if (lines != null) for (String line : lines) { - if (i == 0) addToLore(lore, "§9⏵ §7" + line); - else addToLore(lore, "§7" + line); - i++; - } - } + lore.addAll(arg.getLore()); } if (tags != null && tags != 0) { lore.add(Text.literal("# ").formatted(Formatting.DARK_AQUA).styled(s -> s.withItalic(false)).append(Text.literal(tags + " Tag" + (tags != 1 ? "s" : "")).formatted(Formatting.GRAY))); @@ -149,17 +126,16 @@ public ItemStack getItem() { if (cancelledAutomatically) addToLore(lore, "§4∅ §cCancelled automatically"); else addToLore(lore, "§4∅ §cCancellable"); } - if(requireTokens) { - addToLore(lore,""); + if (requireTokens) { + addToLore(lore, ""); lore.add(Text.literal("Unlock with Tokens").withColor(0xffd42a)); } - if(requiredRank != null) { - if(requireTokens) { + if (requiredRank != null) { + if (requireTokens) { lore.add(Text.literal("OR").withColor(0xff55aa)); lore.add(Text.literal("Unlock with " + requiredRank.name).withColor(requiredRank.color.getRgb())); - } - else { - addToLore(lore,""); + } else { + addToLore(lore, ""); lore.add(Text.literal(requiredRank.name + " Exclusive").setStyle(Style.EMPTY.withColor(requiredRank.color.getRgb()).withItalic(false))); } } @@ -185,8 +161,8 @@ private void addToLore(ArrayList lore, String text) { public List getArgGroups() { var groups = new ArrayList(); var group = new ArrayList(); - for(var arg: arguments) { - if(!arg.isSplitter()) group.add(arg); + for (var arg : arguments) { + if (!arg.isSplitter()) group.add(arg); else { groups.add(new ArgumentGroup(group)); group = new ArrayList<>(); @@ -200,6 +176,7 @@ public enum Type { TEXT(TextColor.fromFormatting(Formatting.AQUA), "String", Items.STRING, dev.dfonline.codeclient.hypercube.item.Text::new), COMPONENT(TextColor.fromRgb(0x7fd42a), "Styled Text", Items.BOOK, Component::new), NUMBER(TextColor.fromFormatting(Formatting.RED), "Number", Items.SLIME_BALL, Number::new), + BYTE(TextColor.fromFormatting(Formatting.RED), "Byte", Items.SLIME_BALL, Number::new), LOCATION(TextColor.fromFormatting(Formatting.GREEN), "Location", Items.PAPER, Location::new), VECTOR(TextColor.fromRgb(0x2AFFAA), "Vector", Items.PRISMARINE_SHARD, Vector::new), SOUND(TextColor.fromFormatting(Formatting.BLUE), "Sound", Items.NAUTILUS_SHELL, Sound::new), @@ -216,18 +193,19 @@ public enum Type { BLOCK_TAG(TextColor.fromFormatting(Formatting.AQUA), "Block Tag", Items.CHAIN_COMMAND_BLOCK, dev.dfonline.codeclient.hypercube.item.Text::new), LIST(TextColor.fromFormatting(Formatting.DARK_GREEN), "List", Items.SKULL_BANNER_PATTERN), // Ender chest or empty banner pattern DICT(TextColor.fromRgb(0x55AAFF), "Dictionary", Items.KNOWLEDGE_BOOK), // Knowledge book or chest minecart - NONE(TextColor.fromRgb(0x808080), "None", Items.AIR), + NONE(TextColor.fromRgb(0x808080), "None", Items.AIR) ; public final TextColor color; public final String display; private final ItemStack icon; - @Nullable public final Icon.Type.getVarItem getVarItem; + @Nullable + public final Icon.Type.getVarItem getVarItem; Type(TextColor color, String display, Item icon) { this.color = color; this.display = display; - var item = icon.getDefaultStack(); + ItemStack item = icon.getDefaultStack(); this.icon = item; getVarItem = null; } @@ -249,14 +227,15 @@ public ItemStack getIcon() { } public enum RequiredRank { - Noble("Noble",TextColor.fromRgb(0x7fff7f)), - Emperor("Emperor",TextColor.fromRgb(0x55aaff)), - Mythic("Mythic",TextColor.fromRgb(0xd42ad4)), - Overlord("Overlord",TextColor.fromFormatting(Formatting.RED)), - Dev("",TextColor.fromRgb(0)); + Noble("Noble", TextColor.fromRgb(0x7fff7f)), + Emperor("Emperor", TextColor.fromRgb(0x55aaff)), + Mythic("Mythic", TextColor.fromRgb(0xd42ad4)), + Overlord("Overlord", TextColor.fromFormatting(Formatting.RED)), + Dev("", TextColor.fromRgb(0)); public final String name; public final TextColor color; + RequiredRank(String name, TextColor color) { this.name = name; this.color = color; @@ -267,8 +246,8 @@ public record ArgumentGroup(List arguments) { public List getPossibilities() { var groups = new ArrayList(); var group = new ArrayList(); - for(var arg: arguments) { - if(!arg.isOr()) group.add(arg); + for (var arg : arguments) { + if (!arg.isOr()) group.add(arg); else { groups.add(new ArgumentPossibilities(group)); group = new ArrayList<>();