From 0b52eeda2b4890cccc06b73610a3b262bf053f26 Mon Sep 17 00:00:00 2001 From: LatvianModder Date: Sat, 7 Sep 2024 18:29:05 +0300 Subject: [PATCH] Added slot to item highlight, added better error capture for generated assets --- .../mods/kubejs/client/ClientAssetPacks.java | 9 +++++++++ .../mods/kubejs/client/ModelGenerator.java | 2 ++ .../kubejs/kubedex/KubedexPayloadHandler.java | 17 +++++++++++++---- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main/java/dev/latvian/mods/kubejs/client/ClientAssetPacks.java b/src/main/java/dev/latvian/mods/kubejs/client/ClientAssetPacks.java index be774be63..b5af73384 100644 --- a/src/main/java/dev/latvian/mods/kubejs/client/ClientAssetPacks.java +++ b/src/main/java/dev/latvian/mods/kubejs/client/ClientAssetPacks.java @@ -37,6 +37,15 @@ public ClientAssetPacks() { } public List inject(List original) { + try { + return inject0(original); + } catch (Throwable ex) { + ConsoleJS.CLIENT.error("Error while generating client assets", ex); + return original; + } + } + + private List inject0(List original) { var packs = new ArrayList<>(original); var filePacks = new ArrayList(); diff --git a/src/main/java/dev/latvian/mods/kubejs/client/ModelGenerator.java b/src/main/java/dev/latvian/mods/kubejs/client/ModelGenerator.java index c332b0b74..8fdf764fd 100644 --- a/src/main/java/dev/latvian/mods/kubejs/client/ModelGenerator.java +++ b/src/main/java/dev/latvian/mods/kubejs/client/ModelGenerator.java @@ -4,6 +4,7 @@ import com.google.gson.JsonObject; import dev.latvian.mods.kubejs.bindings.AABBWrapper; import dev.latvian.mods.kubejs.bindings.DirectionWrapper; +import dev.latvian.mods.rhino.util.HideFromJS; import net.minecraft.core.Direction; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.phys.AABB; @@ -169,6 +170,7 @@ public void parent(@Nullable ResourceLocation s) { parent = s; } + @HideFromJS public void texture(String name, String texture) { textures.put(name, texture); } diff --git a/src/main/java/dev/latvian/mods/kubejs/kubedex/KubedexPayloadHandler.java b/src/main/java/dev/latvian/mods/kubejs/kubedex/KubedexPayloadHandler.java index c62e72324..d60663b21 100644 --- a/src/main/java/dev/latvian/mods/kubejs/kubedex/KubedexPayloadHandler.java +++ b/src/main/java/dev/latvian/mods/kubejs/kubedex/KubedexPayloadHandler.java @@ -30,6 +30,9 @@ import java.util.stream.Stream; public class KubedexPayloadHandler { + public record SlotItem(ItemStack item, int slot) { + } + private static ListTag sortedTagList(Stream> stream) { return stream .map(TagKey::location) @@ -132,14 +135,18 @@ public static void entity(ServerPlayer player, int entityId, int flags) { } public static void inventory(ServerPlayer player, List slots, List stacks, int flags) { - var allStacks = new LinkedHashSet<>(stacks); + var allStacks = new LinkedHashSet(); + + for (var s : stacks) { + allStacks.add(new SlotItem(s, -1)); + } for (int s : slots) { if (s >= 0 && s < player.getInventory().getContainerSize()) { var item = player.getInventory().getItem(s); if (!item.isEmpty()) { - allStacks.add(item); + allStacks.add(new SlotItem(item, s)); } } } @@ -147,7 +154,7 @@ public static void inventory(ServerPlayer player, List slots, List stacks, int flags) { + public static void itemStacks(ServerPlayer player, Collection stacks, int flags) { var ops = player.server.registryAccess().createSerializationContext(NbtOps.INSTANCE); var payload = new CompoundTag(); @@ -155,12 +162,14 @@ public static void itemStacks(ServerPlayer player, Collection stacks, var payloadItems = new ListTag(); - for (var stack : stacks) { + for (var slotStack : stacks) { + var stack = slotStack.item; var tag = new OrderedCompoundTag(); tag.putString("string", stack.kjs$toItemString0(ops)); tag.put("item", ItemStack.CODEC.encodeStart(ops, stack).result().get()); tag.put("name", ComponentSerialization.FLAT_CODEC.encodeStart(ops, stack.getHoverName()).getOrThrow()); tag.putString("icon", stack.kjs$getWebIconURL(ops, 64).toString()); + tag.putInt("slot", slotStack.slot); var patch = stack.getComponentsPatch();