Skip to content

Commit 11173b0

Browse files
committed
saved templates improvements (code palette entry) and why logging every command?
1 parent 7df36ac commit 11173b0

File tree

5 files changed

+47
-12
lines changed

5 files changed

+47
-12
lines changed

src/main/java/dev/dfonline/codeclient/CodeClient.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ public static <T extends PacketListener> boolean onSendPacket(Packet<T> packet)
116116
if(BuildPhaser.onPacket(packet)) return true;
117117
Event.onSendPacket(packet);
118118
String name = packet.getClass().getName().replace("net.minecraft.network.packet.c2s.play.","");
119-
if(packet instanceof CommandExecutionC2SPacket commandExecutionC2SPacket) {
120-
LOGGER.info(commandExecutionC2SPacket.command());
121-
}
122119
// LOGGER.info(name);
123120
return false;
124121
}

src/main/java/dev/dfonline/codeclient/Commands.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ else if(!Files.isDirectory(currentPath)) {
340340
return -2;
341341
}
342342
})));
343-
dispatcher.register(literal("save").then(argument("path", StringArgumentType.greedyString()).suggests(Commands::suggestTemplates).executes(context -> {
343+
dispatcher.register(literal("save").then(argument("path", StringArgumentType.greedyString()).suggests(Commands::suggestDirectories).executes(context -> {
344344
String data = Utility.templateDataItem(CodeClient.MC.player.getMainHandStack());
345345
if(data == null) {
346346
Utility.sendMessage("You need to hold a template to save.",ChatType.FAIL);
@@ -389,7 +389,7 @@ else if(!Files.isDirectory(currentPath)) {
389389
try {
390390
byte[] data = Files.readAllBytes(path);
391391
ItemStack template = Utility.makeTemplate(new String(Base64.getEncoder().encode(data)));
392-
template.setCustomName(Text.empty().formatted(Formatting.RED).append("Saved Template").append(Text.literal(" » ").formatted(Formatting.DARK_RED, Formatting.BOLD)).append(String.valueOf(path.getFileName())));
392+
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))));
393393
CodeClient.MC.player.giveItemStack(template);
394394
Utility.sendInventory();
395395
}

src/main/java/dev/dfonline/codeclient/dev/menu/DevInventory/DevInventoryGroup.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
package dev.dfonline.codeclient.dev.menu.DevInventory;
22

3+
import dev.dfonline.codeclient.FileManager;
4+
import dev.dfonline.codeclient.Utility;
35
import dev.dfonline.codeclient.hypercube.actiondump.*;
46
import net.minecraft.item.ItemStack;
57
import net.minecraft.item.Items;
68
import net.minecraft.nbt.NbtHelper;
79
import net.minecraft.text.Text;
10+
import net.minecraft.util.Formatting;
811

12+
import java.io.IOException;
13+
import java.nio.file.Files;
14+
import java.nio.file.Path;
915
import java.util.ArrayList;
16+
import java.util.Base64;
1017
import java.util.List;
1118

1219
public class DevInventoryGroup {
@@ -111,7 +118,7 @@ public int getDisplayY(int originY, int menuHeight) {
111118
public static final DevInventoryGroup POTIONS = new DevInventoryGroup("potion", "Potions", Items.DRAGON_BREATH.getDefaultStack(), false);
112119
public static final DevInventoryGroup GAME_VALUES = new DevInventoryGroup("game_value", "Game Values", Items.NAME_TAG.getDefaultStack(), false);
113120
public static final DevInventoryGroup OTHERS = new DevInventoryGroup("others", "Other Items", Items.IRON_INGOT.getDefaultStack(), false).disableSearch();
114-
public static final DevInventoryGroup CODE_VAULT = new DevInventoryGroup("code_vault", "Code Vault", Items.ENDER_CHEST.getDefaultStack(), false);
121+
public static final DevInventoryGroup SAVED_TEMPLATES = new DevInventoryGroup("saved_templates", "Saved Templates", Items.ENDER_CHEST.getDefaultStack(), false);
115122
public static final DevInventoryGroup INVENTORY = new DevInventoryGroup("inventory", "Inventory", Items.CHEST.getDefaultStack(), false).disableSearch();
116123

117124
interface ItemsProvider {
@@ -211,6 +218,18 @@ private DevInventoryGroup useCategory(Searchable[] categoryValues) {
211218
POTIONS.useCategory(actionDump.potions);
212219
PARTICLES.useCategory(actionDump.particles);
213220

221+
SAVED_TEMPLATES.setItemsProvider(query -> {
222+
ArrayList<Searchable> items = new ArrayList<>();
223+
if(query == null) query = "";
224+
query = query.toLowerCase();
225+
for (Searchable template: readTemplates(FileManager.templatesPath())) {
226+
for (String term : template.getTerms()) if(term.toLowerCase().contains(query)) {
227+
items.add(template);
228+
break;
229+
}
230+
}
231+
return items;
232+
});
214233
SEARCH.setItemsProvider(query -> {
215234
ArrayList<Searchable> items = new ArrayList<>();
216235
if(query == null) query = "";
@@ -246,4 +265,26 @@ private DevInventoryGroup useCategory(Searchable[] categoryValues) {
246265
catch (Exception ignored) {
247266
}
248267
}
268+
269+
static private ArrayList<Searchable> readTemplates(Path path) {
270+
return readTemplates(path,path);
271+
}
272+
static private ArrayList<Searchable> readTemplates(Path path, Path root) {
273+
var list = new ArrayList<Searchable>();
274+
try {
275+
var dir = Files.list(path);
276+
for (var file : dir.toList()) {
277+
if(Files.isDirectory(file)) list.addAll(readTemplates(file,root));
278+
if(file.getFileName().toString().endsWith(".dft")) {
279+
byte[] data = Files.readAllBytes(file);
280+
ItemStack template = Utility.makeTemplate(new String(Base64.getEncoder().encode(data)));
281+
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))));
282+
list.add(new Searchable.StaticSearchable(template));
283+
}
284+
}
285+
dir.close();
286+
} catch (IOException ignored) {
287+
}
288+
return list;
289+
}
249290
}

src/main/java/dev/dfonline/codeclient/dev/menu/DevInventory/DevInventoryScreen.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
282282
Integer hoveredGroup = getGroupFromMouse(mouseX,mouseY);
283283
if(hoveredGroup != null) {
284284
DevInventoryGroup group = GROUPS[hoveredGroup];
285-
if(group != CODE_VAULT || GROUPS[selectedTab] == CODE_VAULT) context.drawTooltip(textRenderer, GROUPS[hoveredGroup].getName(), mouseX, mouseY);
285+
context.drawTooltip(textRenderer, GROUPS[hoveredGroup].getName(), mouseX, mouseY);
286286
}
287287

288288
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
364364
for(DevInventoryGroup group : DevInventoryGroup.GROUPS) {
365365
RenderSystem.setShader(GameRenderer::getPositionTexProgram);
366366
RenderSystem.setShaderTexture(0, TEXTURE);
367-
if (group.getIndex() != selectedTab && group != CODE_VAULT) {
368-
this.renderTabIcon(context, group);
369-
}
367+
this.renderTabIcon(context, group);
370368
}
371369

372370
RenderSystem.setShader(GameRenderer::getPositionTexProgram);

src/main/java/dev/dfonline/codeclient/hypercube/actiondump/Searchable.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import net.minecraft.item.ItemStack;
44

5-
import java.util.ArrayList;
65
import java.util.List;
76

87
public interface Searchable {
@@ -14,7 +13,7 @@ class StaticSearchable implements Searchable {
1413
private final ItemStack item;
1514

1615
public StaticSearchable(ItemStack item) {
17-
this.terms = new ArrayList<>();
16+
this.terms = List.of(item.getName().getString());
1817
this.item = item;
1918
}
2019

0 commit comments

Comments
 (0)