Skip to content

Commit

Permalink
Added slot to item highlight, added better error capture for generate…
Browse files Browse the repository at this point in the history
…d assets
  • Loading branch information
LatvianModder committed Sep 7, 2024
1 parent b561674 commit 0b52eed
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ public ClientAssetPacks() {
}

public List<PackResources> inject(List<PackResources> original) {
try {
return inject0(original);
} catch (Throwable ex) {
ConsoleJS.CLIENT.error("Error while generating client assets", ex);
return original;
}
}

private List<PackResources> inject0(List<PackResources> original) {
var packs = new ArrayList<>(original);

var filePacks = new ArrayList<PackResources>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -169,6 +170,7 @@ public void parent(@Nullable ResourceLocation s) {
parent = s;
}

@HideFromJS
public void texture(String name, String texture) {
textures.put(name, texture);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
import java.util.stream.Stream;

public class KubedexPayloadHandler {
public record SlotItem(ItemStack item, int slot) {
}

private static ListTag sortedTagList(Stream<? extends TagKey<?>> stream) {
return stream
.map(TagKey::location)
Expand Down Expand Up @@ -132,35 +135,41 @@ public static void entity(ServerPlayer player, int entityId, int flags) {
}

public static void inventory(ServerPlayer player, List<Integer> slots, List<ItemStack> stacks, int flags) {
var allStacks = new LinkedHashSet<>(stacks);
var allStacks = new LinkedHashSet<SlotItem>();

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));
}
}
}

itemStacks(player, allStacks, flags);
}

public static void itemStacks(ServerPlayer player, Collection<ItemStack> stacks, int flags) {
public static void itemStacks(ServerPlayer player, Collection<SlotItem> stacks, int flags) {
var ops = player.server.registryAccess().createSerializationContext(NbtOps.INSTANCE);

var payload = new CompoundTag();
payload.put("flags", flags(flags));

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();

Expand Down

0 comments on commit 0b52eed

Please sign in to comment.