diff --git a/src/main/java/dev/dfonline/codeclient/CodeClient.java b/src/main/java/dev/dfonline/codeclient/CodeClient.java index e59dd57f..debbeb8a 100644 --- a/src/main/java/dev/dfonline/codeclient/CodeClient.java +++ b/src/main/java/dev/dfonline/codeclient/CodeClient.java @@ -116,9 +116,6 @@ public static boolean onSendPacket(Packet packet) if(BuildPhaser.onPacket(packet)) return true; Event.onSendPacket(packet); String name = packet.getClass().getName().replace("net.minecraft.network.packet.c2s.play.",""); - if(packet instanceof CommandExecutionC2SPacket commandExecutionC2SPacket) { - LOGGER.info(commandExecutionC2SPacket.command()); - } // LOGGER.info(name); return false; } diff --git a/src/main/java/dev/dfonline/codeclient/Commands.java b/src/main/java/dev/dfonline/codeclient/Commands.java index 053458e4..811ac478 100644 --- a/src/main/java/dev/dfonline/codeclient/Commands.java +++ b/src/main/java/dev/dfonline/codeclient/Commands.java @@ -340,7 +340,7 @@ else if(!Files.isDirectory(currentPath)) { return -2; } }))); - dispatcher.register(literal("save").then(argument("path", StringArgumentType.greedyString()).suggests(Commands::suggestTemplates).executes(context -> { + dispatcher.register(literal("save").then(argument("path", StringArgumentType.greedyString()).suggests(Commands::suggestDirectories).executes(context -> { String data = Utility.templateDataItem(CodeClient.MC.player.getMainHandStack()); if(data == null) { Utility.sendMessage("You need to hold a template to save.",ChatType.FAIL); @@ -389,7 +389,7 @@ else if(!Files.isDirectory(currentPath)) { try { byte[] data = Files.readAllBytes(path); ItemStack template = Utility.makeTemplate(new String(Base64.getEncoder().encode(data))); - template.setCustomName(Text.empty().formatted(Formatting.RED).append("Saved Template").append(Text.literal(" » ").formatted(Formatting.DARK_RED, Formatting.BOLD)).append(String.valueOf(path.getFileName()))); + template.setCustomName(Text.empty().formatted(Formatting.RED).append("Saved Template").append(Text.literal(" » ").formatted(Formatting.DARK_RED, Formatting.BOLD)).append(String.valueOf(FileManager.templatesPath().relativize(path)))); CodeClient.MC.player.giveItemStack(template); Utility.sendInventory(); } diff --git a/src/main/java/dev/dfonline/codeclient/dev/menu/DevInventory/DevInventoryGroup.java b/src/main/java/dev/dfonline/codeclient/dev/menu/DevInventory/DevInventoryGroup.java index d34b0360..ac4e325a 100644 --- a/src/main/java/dev/dfonline/codeclient/dev/menu/DevInventory/DevInventoryGroup.java +++ b/src/main/java/dev/dfonline/codeclient/dev/menu/DevInventory/DevInventoryGroup.java @@ -1,12 +1,19 @@ package dev.dfonline.codeclient.dev.menu.DevInventory; +import dev.dfonline.codeclient.FileManager; +import dev.dfonline.codeclient.Utility; import dev.dfonline.codeclient.hypercube.actiondump.*; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.nbt.NbtHelper; import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; +import java.util.Base64; import java.util.List; public class DevInventoryGroup { @@ -111,7 +118,7 @@ public int getDisplayY(int originY, int menuHeight) { public static final DevInventoryGroup POTIONS = new DevInventoryGroup("potion", "Potions", Items.DRAGON_BREATH.getDefaultStack(), false); public static final DevInventoryGroup GAME_VALUES = new DevInventoryGroup("game_value", "Game Values", Items.NAME_TAG.getDefaultStack(), false); public static final DevInventoryGroup OTHERS = new DevInventoryGroup("others", "Other Items", Items.IRON_INGOT.getDefaultStack(), false).disableSearch(); - public static final DevInventoryGroup CODE_VAULT = new DevInventoryGroup("code_vault", "Code Vault", Items.ENDER_CHEST.getDefaultStack(), false); + public static final DevInventoryGroup SAVED_TEMPLATES = new DevInventoryGroup("saved_templates", "Saved Templates", Items.ENDER_CHEST.getDefaultStack(), false); public static final DevInventoryGroup INVENTORY = new DevInventoryGroup("inventory", "Inventory", Items.CHEST.getDefaultStack(), false).disableSearch(); interface ItemsProvider { @@ -211,6 +218,18 @@ private DevInventoryGroup useCategory(Searchable[] categoryValues) { POTIONS.useCategory(actionDump.potions); PARTICLES.useCategory(actionDump.particles); + SAVED_TEMPLATES.setItemsProvider(query -> { + ArrayList items = new ArrayList<>(); + if(query == null) query = ""; + query = query.toLowerCase(); + for (Searchable template: readTemplates(FileManager.templatesPath())) { + for (String term : template.getTerms()) if(term.toLowerCase().contains(query)) { + items.add(template); + break; + } + } + return items; + }); SEARCH.setItemsProvider(query -> { ArrayList items = new ArrayList<>(); if(query == null) query = ""; @@ -246,4 +265,26 @@ private DevInventoryGroup useCategory(Searchable[] categoryValues) { catch (Exception ignored) { } } + + static private ArrayList readTemplates(Path path) { + return readTemplates(path,path); + } + static private ArrayList readTemplates(Path path, Path root) { + var list = new ArrayList(); + try { + var dir = Files.list(path); + for (var file : dir.toList()) { + if(Files.isDirectory(file)) list.addAll(readTemplates(file,root)); + if(file.getFileName().toString().endsWith(".dft")) { + byte[] data = Files.readAllBytes(file); + ItemStack template = Utility.makeTemplate(new String(Base64.getEncoder().encode(data))); + template.setCustomName(Text.empty().formatted(Formatting.RED).append("Saved Template").append(Text.literal(" » ").formatted(Formatting.DARK_RED, Formatting.BOLD)).append(String.valueOf(root.relativize(file)))); + list.add(new Searchable.StaticSearchable(template)); + } + } + dir.close(); + } catch (IOException ignored) { + } + return list; + } } diff --git a/src/main/java/dev/dfonline/codeclient/dev/menu/DevInventory/DevInventoryScreen.java b/src/main/java/dev/dfonline/codeclient/dev/menu/DevInventory/DevInventoryScreen.java index 043cf149..25f14fa3 100644 --- a/src/main/java/dev/dfonline/codeclient/dev/menu/DevInventory/DevInventoryScreen.java +++ b/src/main/java/dev/dfonline/codeclient/dev/menu/DevInventory/DevInventoryScreen.java @@ -282,7 +282,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { Integer hoveredGroup = getGroupFromMouse(mouseX,mouseY); if(hoveredGroup != null) { DevInventoryGroup group = GROUPS[hoveredGroup]; - if(group != CODE_VAULT || GROUPS[selectedTab] == CODE_VAULT) context.drawTooltip(textRenderer, GROUPS[hoveredGroup].getName(), mouseX, mouseY); + context.drawTooltip(textRenderer, GROUPS[hoveredGroup].getName(), mouseX, mouseY); } if (this.deleteItemSlot != null && this.isPointWithinBounds(this.deleteItemSlot.x, this.deleteItemSlot.y, 16, 16, mouseX, mouseY)) { @@ -364,9 +364,7 @@ protected void drawBackground(DrawContext context, float delta, int mouseX, int for(DevInventoryGroup group : DevInventoryGroup.GROUPS) { RenderSystem.setShader(GameRenderer::getPositionTexProgram); RenderSystem.setShaderTexture(0, TEXTURE); - if (group.getIndex() != selectedTab && group != CODE_VAULT) { - this.renderTabIcon(context, group); - } + this.renderTabIcon(context, group); } RenderSystem.setShader(GameRenderer::getPositionTexProgram); diff --git a/src/main/java/dev/dfonline/codeclient/hypercube/actiondump/Searchable.java b/src/main/java/dev/dfonline/codeclient/hypercube/actiondump/Searchable.java index 655711d7..c36996f9 100644 --- a/src/main/java/dev/dfonline/codeclient/hypercube/actiondump/Searchable.java +++ b/src/main/java/dev/dfonline/codeclient/hypercube/actiondump/Searchable.java @@ -2,7 +2,6 @@ import net.minecraft.item.ItemStack; -import java.util.ArrayList; import java.util.List; public interface Searchable { @@ -14,7 +13,7 @@ class StaticSearchable implements Searchable { private final ItemStack item; public StaticSearchable(ItemStack item) { - this.terms = new ArrayList<>(); + this.terms = List.of(item.getName().getString()); this.item = item; }