From a77f94276626ea344330e729a61f72672cc454f5 Mon Sep 17 00:00:00 2001 From: direwolf20 <39863894+Direwolf20-MC@users.noreply.github.com> Date: Sun, 4 Aug 2024 14:07:52 -0400 Subject: [PATCH] Bring Back NBT Filter as Data Filter --- .../4cf32af2ec4a8dd31b9375f1443e6ccfbff638ab | 4 +- .../resources/assets/laserio/lang/en_us.json | 10 +-- .../client/screens/FilterNBTScreen.java | 87 +++++++++++-------- .../common/containers/FilterNBTContainer.java | 17 ++-- .../common/items/filters/BaseFilter.java | 2 + .../common/items/filters/FilterNBT.java | 58 ++----------- .../common/items/filters/FilterTag.java | 31 ------- .../network/handler/PacketOpenFilter.java | 12 +-- .../handler/PacketUpdateFilterTag.java | 7 +- .../datagen/LaserIOLanguageProvider.java | 10 +-- .../laserio/util/BaseCardCache.java | 11 +-- 11 files changed, 98 insertions(+), 151 deletions(-) diff --git a/src/generated/resources/.cache/4cf32af2ec4a8dd31b9375f1443e6ccfbff638ab b/src/generated/resources/.cache/4cf32af2ec4a8dd31b9375f1443e6ccfbff638ab index 1eabdc01..bc5ddc55 100644 --- a/src/generated/resources/.cache/4cf32af2ec4a8dd31b9375f1443e6ccfbff638ab +++ b/src/generated/resources/.cache/4cf32af2ec4a8dd31b9375f1443e6ccfbff638ab @@ -1,2 +1,2 @@ -// 1.21 2024-07-24T22:27:48.0729142 Languages: en_us for mod: laserio -9858c55ab597f0b1e24ce2bbada665158cfc3e9d assets/laserio/lang/en_us.json +// 1.21 2024-08-04T13:44:14.7251544 Languages: en_us for mod: laserio +85b7b822654083ab1c8be08c584bb15e38a364a0 assets/laserio/lang/en_us.json diff --git a/src/generated/resources/assets/laserio/lang/en_us.json b/src/generated/resources/assets/laserio/lang/en_us.json index 5f8cde97..99210ce5 100644 --- a/src/generated/resources/assets/laserio/lang/en_us.json +++ b/src/generated/resources/assets/laserio/lang/en_us.json @@ -12,7 +12,7 @@ "item.laserio.filter_basic": "Basic Filter", "item.laserio.filter_count": "Counting Filter", "item.laserio.filter_mod": "Mod Filter", - "item.laserio.filter_nbt": "NBT Filter", + "item.laserio.filter_nbt": "Data Filter", "item.laserio.filter_tag": "Tag Filter", "item.laserio.laser_wrench": "Laser Wrench", "item.laserio.logic_chip": "Logic Chip", @@ -38,7 +38,7 @@ "laserio.tooltip.item.card.sneaky.SOUTH": "South", "laserio.tooltip.item.card.sneaky.UP": "Up", "laserio.tooltip.item.card.sneaky.WEST": "West", - "laserio.tooltip.item.filter.nbt": "Match NBT: ", + "laserio.tooltip.item.filter.nbt": "Match Data: ", "laserio.tooltip.item.filter.nbt.allow": "True", "laserio.tooltip.item.filter.nbt.deny": "False", "laserio.tooltip.item.filter.type": "Type: ", @@ -52,7 +52,7 @@ "screen.laserio.apply": "Apply", "screen.laserio.blue": "Blue", "screen.laserio.channel": "Channel: ", - "screen.laserio.comparenbt": "NBT", + "screen.laserio.comparenbt": "Data", "screen.laserio.default": "Default", "screen.laserio.denylist": "Deny", "screen.laserio.down": "Down", @@ -71,8 +71,8 @@ "screen.laserio.insert": "Insert", "screen.laserio.lasernode": "Laser Node", "screen.laserio.low": "Low", - "screen.laserio.nbtfalse": "Ignore NBT", - "screen.laserio.nbttrue": "Match NBT", + "screen.laserio.nbtfalse": "Ignore Data", + "screen.laserio.nbttrue": "Match Data", "screen.laserio.north": "North", "screen.laserio.or": "Or", "screen.laserio.output": "Output", diff --git a/src/main/java/com/direwolf20/laserio/client/screens/FilterNBTScreen.java b/src/main/java/com/direwolf20/laserio/client/screens/FilterNBTScreen.java index a3229f37..0920232f 100644 --- a/src/main/java/com/direwolf20/laserio/client/screens/FilterNBTScreen.java +++ b/src/main/java/com/direwolf20/laserio/client/screens/FilterNBTScreen.java @@ -13,25 +13,25 @@ import com.mojang.blaze3d.platform.InputConstants; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.Util; +import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.Tag; +import net.minecraft.core.component.DataComponentType; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; import net.neoforged.neoforge.network.PacketDistributor; import java.awt.*; -import java.util.ArrayList; -import java.util.Comparator; import java.util.List; -import java.util.Locale; +import java.util.*; public class FilterNBTScreen extends AbstractContainerScreen { private final ResourceLocation GUI = ResourceLocation.fromNamespaceAndPath(LaserIO.MODID, "textures/gui/filtertag.png"); @@ -61,7 +61,6 @@ public FilterNBTScreen(FilterNBTContainer container, Inventory inv, Component na @Override public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { - //this.renderBackground(guiGraphics); super.render(guiGraphics, mouseX, mouseY, partialTicks); this.renderTooltip(guiGraphics, mouseX, mouseY); if (MiscTools.inBounds(getGuiLeft() + 5, getGuiTop() + 10, 16, 16, mouseX, mouseY)) { @@ -112,48 +111,30 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partia overSlot = -1; for (String tag : displayTags) { - matrixStack.pushPose(); - matrixStack.scale(0.75f, 0.75f, 0.75f); int fontColor = stackInSlotTags.contains(tag) ? Color.BLUE.getRGB() : Color.DARK_GRAY.getRGB(); - guiGraphics.drawString(font, tag, availableItemsstartX / 0.75f + 16, tagStartY / 0.75f, fontColor, false); - matrixStack.popPose(); + renderScrollingString(guiGraphics, font, Component.literal(tag), availableItemsstartX, tagStartY, availableItemsstartX + 152, fontColor); if (MiscTools.inBounds(availableItemsstartX, tagStartY - 2, 160, 8, mouseX, mouseY)) { overSlot = slot; color = -2130706433;// : 0xFF5B5B5B; - - matrixStack.pushPose(); - RenderSystem.disableDepthTest(); - RenderSystem.colorMask(true, true, true, false); guiGraphics.fillGradient(availableItemsstartX - 1, tagStartY - 2, availableItemsstartX + 160, tagStartY + 8, color, color); - //Tag tempTag = stackInSlot.getOrCreateTag().get(displayTags.get(overSlot)); - Tag tempTag = new CompoundTag(); - if (tempTag != null) { //Todo Revisit - //String tooltip = Objects.requireNonNull(stackInSlot.getOrCreateTag().get(displayTags.get(overSlot))).toString(); - String tooltip = ""; - if (tooltip.length() > 60) tooltip = tooltip.substring(0, 60) + "..."; - guiGraphics.renderTooltip(font, Component.literal(tooltip), mouseX, mouseY); + String tagValue = getTagValueFor(displayTags.get(overSlot)); + if (!tagValue.isEmpty()) { + if (tagValue.length() > 60) tagValue = tagValue.substring(0, 60) + "..."; + guiGraphics.renderTooltip(font, Component.literal(tagValue), mouseX, mouseY); + guiGraphics.flush(); //Not sure why this is necessary, but it is! } - RenderSystem.colorMask(true, true, true, true); - matrixStack.popPose(); } if (slot == selectedSlot) { color = 0xFFFF0000; - matrixStack.pushPose(); - RenderSystem.disableDepthTest(); - RenderSystem.colorMask(true, true, true, false); - int x1 = availableItemsstartX + 160; int y1 = tagStartY + 10; guiGraphics.hLine(availableItemsstartX - 2, x1 - 0, tagStartY - 2, color); guiGraphics.hLine(availableItemsstartX - 2, x1 - 0, y1 - 3, color); guiGraphics.vLine(availableItemsstartX - 2, tagStartY - 2, y1 - 2, color); guiGraphics.vLine(x1 - 0, tagStartY - 2, y1 - 2, color); - - RenderSystem.colorMask(true, true, true, true); - matrixStack.popPose(); } tagStartY += 10; @@ -161,15 +142,51 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partia } } + protected static void renderScrollingString(GuiGraphics graphics, Font fontRenderer, Component text, int xStart, int yStart, int xEnd, int textColor) { + int textWidth = fontRenderer.width(text); + int yEnd = yStart + fontRenderer.lineHeight; + int maxRenderWidth = xEnd - xStart; + + if (textWidth > maxRenderWidth) { + int textOverflow = textWidth - maxRenderWidth; + double currentTime = (double) Util.getMillis() / 1000.0D; + double scrollDuration = Math.max((double) textOverflow * 0.5D, 3.0D); + double oscillation = Math.sin((Math.PI / 2D) * Math.cos((Math.PI * 2D) * currentTime / scrollDuration)) / 2.0D + 0.5D; + double scrollOffset = Mth.lerp(oscillation, 0.0D, (double) textOverflow); + + graphics.enableScissor(xStart, yStart, xEnd, yEnd); + graphics.drawString(fontRenderer, text, xStart - (int) scrollOffset, yStart, textColor, false); + graphics.disableScissor(); + } else { + graphics.drawString(fontRenderer, text, xStart, yStart, textColor, false); + } + } + protected void populateStackInSlotTags() { stackInSlotTags = new ArrayList<>(); ItemStack stackInSlot = container.handler.getStackInSlot(0); - /*if (!stackInSlot.isEmpty()) {//Todo Revisit - stackInSlot.getOrCreateTag().getAllKeys().forEach(t -> { - if (!stackInSlotTags.contains(t) && !tags.contains(t)) - stackInSlotTags.add(t); + if (!stackInSlot.isEmpty()) { + stackInSlot.getComponentsPatch().entrySet().forEach(t -> { + if (!stackInSlotTags.contains(t.getKey().toString()) && !tags.contains(t.getKey().toString())) + stackInSlotTags.add(t.getKey().toString()); }); - }*/ + } + } + + protected String getTagValueFor(String name) { + ItemStack stackInSlot = container.handler.getStackInSlot(0); + if (!stackInSlot.isEmpty()) { + for (Map.Entry, Optional> entry : stackInSlot.getComponentsPatch().entrySet()) { + if (entry.getKey().toString().equals(name)) { + // Check if the value is present and return its string representation + Optional value = entry.getValue(); + if (value.isPresent()) { + return value.get().toString(); + } + } + } + } + return ""; } @Override diff --git a/src/main/java/com/direwolf20/laserio/common/containers/FilterNBTContainer.java b/src/main/java/com/direwolf20/laserio/common/containers/FilterNBTContainer.java index 4e9c23bd..7bfd27ac 100644 --- a/src/main/java/com/direwolf20/laserio/common/containers/FilterNBTContainer.java +++ b/src/main/java/com/direwolf20/laserio/common/containers/FilterNBTContainer.java @@ -1,8 +1,10 @@ package com.direwolf20.laserio.common.containers; import com.direwolf20.laserio.common.blockentities.LaserNodeBE; +import com.direwolf20.laserio.common.containers.customhandler.CardItemHandler; import com.direwolf20.laserio.common.containers.customhandler.FilterBasicHandler; import com.direwolf20.laserio.common.containers.customslot.FilterBasicSlot; +import com.direwolf20.laserio.common.items.cards.BaseCard; import com.direwolf20.laserio.setup.Registration; import net.minecraft.core.BlockPos; import net.minecraft.network.RegistryFriendlyByteBuf; @@ -29,15 +31,14 @@ public class FilterNBTContainer extends AbstractContainerMenu { public BlockPos sourceContainer = BlockPos.ZERO; public FilterNBTContainer(int windowId, Inventory playerInventory, Player player, RegistryFriendlyByteBuf extraData) { - this(windowId, playerInventory, player, new FilterBasicHandler(SLOTS, ItemStack.EMPTY), ItemStack.EMPTY); - filterItem = ItemStack.OPTIONAL_STREAM_CODEC.decode(extraData); + this(windowId, playerInventory, player, ItemStack.OPTIONAL_STREAM_CODEC.decode(extraData)); this.sourceCard = ItemStack.OPTIONAL_STREAM_CODEC.decode(extraData); } - public FilterNBTContainer(int windowId, Inventory playerInventory, Player player, FilterBasicHandler handler, ItemStack filterItem) { + public FilterNBTContainer(int windowId, Inventory playerInventory, Player player, ItemStack filterItem) { super(Registration.FilterNBT_Container.get(), windowId); playerEntity = player; - this.handler = handler; + this.handler = new FilterBasicHandler(SLOTS, filterItem); this.playerInventory = new InvWrapper(playerInventory); this.filterItem = filterItem; if (handler != null) @@ -46,8 +47,8 @@ public FilterNBTContainer(int windowId, Inventory playerInventory, Player player layoutPlayerInventorySlots(8, 172); } - public FilterNBTContainer(int windowId, Inventory playerInventory, Player player, FilterBasicHandler handler, BlockPos sourcePos, ItemStack filterItem, ItemStack sourceCard) { - this(windowId, playerInventory, player, handler, filterItem); + public FilterNBTContainer(int windowId, Inventory playerInventory, Player player, BlockPos sourcePos, ItemStack filterItem, ItemStack sourceCard) { + this(windowId, playerInventory, player, filterItem); this.sourceContainer = sourcePos; this.sourceCard = sourceCard; } @@ -121,6 +122,10 @@ public void removed(Player playerIn) { Level world = playerIn.level(); if (!world.isClientSide) { handler.setStackInSlot(0, ItemStack.EMPTY); //Clear the current slot + if (sourceCard != null && !sourceCard.isEmpty()) { + CardItemHandler cardItemHandler = BaseCard.getInventory(sourceCard); + cardItemHandler.setStackInSlot(0, filterItem); + } if (!sourceContainer.equals(BlockPos.ZERO)) { BlockEntity blockEntity = world.getBlockEntity(sourceContainer); if (blockEntity instanceof LaserNodeBE) diff --git a/src/main/java/com/direwolf20/laserio/common/items/filters/BaseFilter.java b/src/main/java/com/direwolf20/laserio/common/items/filters/BaseFilter.java index c685e4cd..30fcec5a 100644 --- a/src/main/java/com/direwolf20/laserio/common/items/filters/BaseFilter.java +++ b/src/main/java/com/direwolf20/laserio/common/items/filters/BaseFilter.java @@ -84,6 +84,8 @@ public static boolean setAllowList(ItemStack stack, boolean allowList) { } public static boolean getCompareNBT(ItemStack stack) { + if (stack.getItem() instanceof FilterNBT) + return stack.getOrDefault(LaserIODataComponents.FILTER_COMPARE, true); return stack.getOrDefault(LaserIODataComponents.FILTER_COMPARE, false); } diff --git a/src/main/java/com/direwolf20/laserio/common/items/filters/FilterNBT.java b/src/main/java/com/direwolf20/laserio/common/items/filters/FilterNBT.java index fd52d05d..ffd231b9 100644 --- a/src/main/java/com/direwolf20/laserio/common/items/filters/FilterNBT.java +++ b/src/main/java/com/direwolf20/laserio/common/items/filters/FilterNBT.java @@ -3,6 +3,7 @@ import com.direwolf20.laserio.common.containers.FilterBasicContainer; import com.direwolf20.laserio.common.containers.FilterNBTContainer; import com.direwolf20.laserio.common.containers.customhandler.FilterBasicHandler; +import com.direwolf20.laserio.setup.LaserIODataComponents; import net.minecraft.network.chat.Component; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; @@ -12,6 +13,9 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; +import java.util.ArrayList; +import java.util.List; + public class FilterNBT extends BaseFilter { public FilterNBT() { super(); @@ -22,11 +26,9 @@ public InteractionResultHolder use(Level level, Player player, Intera ItemStack itemstack = player.getItemInHand(hand); if (level.isClientSide()) return new InteractionResultHolder<>(InteractionResult.PASS, itemstack); - FilterBasicHandler handler = getInventory(itemstack); player.openMenu(new SimpleMenuProvider( - (windowId, playerInventory, playerEntity) -> new FilterNBTContainer(windowId, playerInventory, player, handler, itemstack), Component.translatable("")), (buf -> { + (windowId, playerInventory, playerEntity) -> new FilterNBTContainer(windowId, playerInventory, player, itemstack), Component.translatable("")), (buf -> { ItemStack.OPTIONAL_STREAM_CODEC.encode(buf, itemstack); - ItemStack.OPTIONAL_STREAM_CODEC.encode(buf, ItemStack.EMPTY); })); return new InteractionResultHolder<>(InteractionResult.PASS, itemstack); @@ -37,55 +39,11 @@ public static FilterBasicHandler getInventory(ItemStack stack) { return handler; } - //TODO Re-Implement - /*public static FilterBasicHandler setInventory(ItemStack stack, FilterBasicHandler handler) { - stack.getOrCreateTag().put("inv", handler.serializeNBT()); - return handler; - }*/ - - /*public static void addTag(ItemStack card, String tag) { - List tags = getTags(card); - if (!tags.contains(tag)) { - tags.add(tag); - CompoundTag compound = card.getOrCreateTag(); - compound.put("tags", MiscTools.stringListToNBT(tags)); - } - } - - public static void removeTag(ItemStack card, String tag) { - List tags = getTags(card); - if (tags.contains(tag)) { - tags.remove(tag); - CompoundTag compound = card.getOrCreateTag(); - compound.put("tags", MiscTools.stringListToNBT(tags)); - } - } - - public static void clearTags(ItemStack card) { - List tags = new ArrayList(); - CompoundTag compound = card.getOrCreateTag(); - compound.put("tags", MiscTools.stringListToNBT(tags)); - } - public static void setTags(ItemStack card, List tagsIn) { - CompoundTag compound = card.getOrCreateTag(); - compound.put("tags", MiscTools.stringListToNBT(tagsIn)); - } - - public static void setTags(ItemStack card, CompoundTag tagsTag) { - CompoundTag compound = card.getOrCreateTag(); - compound.put("tags", tagsTag.getList("tags", Tag.TAG_COMPOUND)); + card.set(LaserIODataComponents.FILTER_TAG_TAGS, tagsIn); } public static List getTags(ItemStack card) { - List tags = new ArrayList(); - CompoundTag compound = card.getOrCreateTag(); - if (compound.contains("tags")) { - ListTag listNBT = compound.getList("tags", Tag.TAG_COMPOUND); - tags = new ArrayList<>(MiscTools.NBTToStringList(listNBT)); - } else { - compound.put("tags", MiscTools.stringListToNBT(tags)); - } - return tags; - }*/ + return card.getOrDefault(LaserIODataComponents.FILTER_TAG_TAGS, new ArrayList<>()); + } } diff --git a/src/main/java/com/direwolf20/laserio/common/items/filters/FilterTag.java b/src/main/java/com/direwolf20/laserio/common/items/filters/FilterTag.java index 765d8ce7..bba7cb95 100644 --- a/src/main/java/com/direwolf20/laserio/common/items/filters/FilterTag.java +++ b/src/main/java/com/direwolf20/laserio/common/items/filters/FilterTag.java @@ -42,37 +42,6 @@ public static FilterBasicHandler getInventory(ItemStack stack) { return handler; } - /*public static FilterBasicHandler setInventory(ItemStack stack, FilterBasicHandler handler) { - stack.getOrCreateTag().put("inv", handler.serializeNBT()); - return handler; - }*/ - - /*public static void addTag(ItemStack card, String tag) { - List tags = getTags(card); - if (!tags.contains(tag)) { - tags.add(tag); - CompoundTag compound = card.getOrCreateTag(); - compound.put("tags", MiscTools.stringListToNBT(tags)); - } - } - - public static void removeTag(ItemStack card, String tag) { - List tags = getTags(card); - if (tags.contains(tag)) { - tags.remove(tag); - CompoundTag compound = card.getOrCreateTag(); - compound.put("tags", MiscTools.stringListToNBT(tags)); - } - } - - public static void clearTags(ItemStack card) { - List tags = new ArrayList(); - CompoundTag compound = card.getOrCreateTag(); - compound.put("tags", MiscTools.stringListToNBT(tags)); - }*/ - - - public static void setTags(ItemStack card, List tagsIn) { card.set(LaserIODataComponents.FILTER_TAG_TAGS, tagsIn); } diff --git a/src/main/java/com/direwolf20/laserio/common/network/handler/PacketOpenFilter.java b/src/main/java/com/direwolf20/laserio/common/network/handler/PacketOpenFilter.java index a3dc6c95..3a24bd78 100644 --- a/src/main/java/com/direwolf20/laserio/common/network/handler/PacketOpenFilter.java +++ b/src/main/java/com/direwolf20/laserio/common/network/handler/PacketOpenFilter.java @@ -1,9 +1,6 @@ package com.direwolf20.laserio.common.network.handler; -import com.direwolf20.laserio.common.containers.CardItemContainer; -import com.direwolf20.laserio.common.containers.FilterBasicContainer; -import com.direwolf20.laserio.common.containers.FilterCountContainer; -import com.direwolf20.laserio.common.containers.FilterTagContainer; +import com.direwolf20.laserio.common.containers.*; import com.direwolf20.laserio.common.items.filters.FilterBasic; import com.direwolf20.laserio.common.items.filters.FilterCount; import com.direwolf20.laserio.common.items.filters.FilterNBT; @@ -93,11 +90,9 @@ public AbstractContainerMenu createMenu(int windowId, Inventory playerInventory, }; sender.openMenu(containerProvider, (buf -> { ItemStack.OPTIONAL_STREAM_CODEC.encode(buf, filterItem); - ItemStack.OPTIONAL_STREAM_CODEC.encode(buf, ItemStack.EMPTY); })); } if (filterItem.getItem() instanceof FilterNBT) { - /*FilterBasicHandler handler = FilterBasic.getInventory(filterItem); MenuProvider containerProvider = new MenuProvider() { @Override public Component getDisplayName() { @@ -111,13 +106,12 @@ public boolean shouldTriggerClientSideContainerClosingOnOpen() { @Override public AbstractContainerMenu createMenu(int windowId, Inventory playerInventory, Player playerEntity) { - return new FilterNBTContainer(windowId, playerInventory, sender, handler, sourcePos, filterItem, cardItem); + return new FilterNBTContainer(windowId, playerInventory, sender, sourcePos, filterItem, cardItem); } }; sender.openMenu(containerProvider, (buf -> { ItemStack.OPTIONAL_STREAM_CODEC.encode(buf, filterItem); - ItemStack.OPTIONAL_STREAM_CODEC.encode(buf, ItemStack.EMPTY); - }));*/ + })); } } diff --git a/src/main/java/com/direwolf20/laserio/common/network/handler/PacketUpdateFilterTag.java b/src/main/java/com/direwolf20/laserio/common/network/handler/PacketUpdateFilterTag.java index a0a47afc..5031204e 100644 --- a/src/main/java/com/direwolf20/laserio/common/network/handler/PacketUpdateFilterTag.java +++ b/src/main/java/com/direwolf20/laserio/common/network/handler/PacketUpdateFilterTag.java @@ -1,6 +1,8 @@ package com.direwolf20.laserio.common.network.handler; +import com.direwolf20.laserio.common.containers.FilterNBTContainer; import com.direwolf20.laserio.common.containers.FilterTagContainer; +import com.direwolf20.laserio.common.items.filters.FilterNBT; import com.direwolf20.laserio.common.items.filters.FilterTag; import com.direwolf20.laserio.common.network.data.UpdateFilterTagPayload; import net.minecraft.world.entity.player.Player; @@ -28,12 +30,11 @@ public void handle(final UpdateFilterTagPayload payload, final IPayloadContext c FilterTag.setAllowList(stack, payload.allowList()); FilterTag.setTags(stack, payload.tags()); } - //TODO Re-Implement - /*if (container instanceof FilterNBTContainer) { + if (container instanceof FilterNBTContainer) { ItemStack stack = ((FilterNBTContainer) container).filterItem; FilterNBT.setAllowList(stack, payload.allowList()); FilterNBT.setTags(stack, payload.tags()); - }*/ + } }); } } diff --git a/src/main/java/com/direwolf20/laserio/datagen/LaserIOLanguageProvider.java b/src/main/java/com/direwolf20/laserio/datagen/LaserIOLanguageProvider.java index 74f85a44..bce02a9b 100644 --- a/src/main/java/com/direwolf20/laserio/datagen/LaserIOLanguageProvider.java +++ b/src/main/java/com/direwolf20/laserio/datagen/LaserIOLanguageProvider.java @@ -29,7 +29,7 @@ protected void addTranslations() { add(Registration.Filter_Count.get(), "Counting Filter"); add(Registration.Filter_Tag.get(), "Tag Filter"); add(Registration.Filter_Mod.get(), "Mod Filter"); - add(Registration.Filter_NBT.get(), "NBT Filter"); + add(Registration.Filter_NBT.get(), "Data Filter"); add(Registration.Logic_Chip.get(), "Logic Chip"); add(Registration.Logic_Chip_Raw.get(), "Raw Logic Chip"); add(Registration.Overclocker_Card.get(), "Card Overclocker"); @@ -51,7 +51,7 @@ protected void addTranslations() { add("screen.laserio.and", "And"); add("screen.laserio.or", "Or"); add("screen.laserio.allowlist", "Allow"); - add("screen.laserio.comparenbt", "NBT"); + add("screen.laserio.comparenbt", "Data"); add("screen.laserio.lasernode", "Laser Node"); add("screen.laserio.energylimit", "Energy Limit (%)"); @@ -87,8 +87,8 @@ protected void addTranslations() { add("screen.laserio.hideparticles", "Hide Particles"); add("screen.laserio.denylist", "Deny"); - add("screen.laserio.nbttrue", "Match NBT"); - add("screen.laserio.nbtfalse", "Ignore NBT"); + add("screen.laserio.nbttrue", "Match Data"); + add("screen.laserio.nbtfalse", "Ignore Data"); add("message.laserio.wrenchrange", "Connection exceeds maximum range of %d"); @@ -115,7 +115,7 @@ protected void addTranslations() { add("laserio.tooltip.item.filter.type", "Type: "); add("laserio.tooltip.item.filter.type.allow", "Allow"); add("laserio.tooltip.item.filter.type.deny", "Deny"); - add("laserio.tooltip.item.filter.nbt", "Match NBT: "); + add("laserio.tooltip.item.filter.nbt", "Match Data: "); add("laserio.tooltip.item.filter.nbt.allow", "True"); add("laserio.tooltip.item.filter.nbt.deny", "False"); diff --git a/src/main/java/com/direwolf20/laserio/util/BaseCardCache.java b/src/main/java/com/direwolf20/laserio/util/BaseCardCache.java index 5554ebfc..7c799ff7 100644 --- a/src/main/java/com/direwolf20/laserio/util/BaseCardCache.java +++ b/src/main/java/com/direwolf20/laserio/util/BaseCardCache.java @@ -9,6 +9,7 @@ import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import net.minecraft.core.Direction; +import net.minecraft.core.component.DataComponentType; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.tags.TagKey; import net.minecraft.world.item.ItemStack; @@ -206,7 +207,7 @@ public List getFilterTags() { public List getFilterNBTs() { List filterNBTs = new ArrayList<>(); if (filterCard.getItem() instanceof FilterNBT) { - filterNBTs = FilterTag.getTags(filterCard); + filterNBTs = FilterNBT.getTags(filterCard); } return filterNBTs; } @@ -230,14 +231,14 @@ public boolean isStackValidForCard(ItemStack testStack) { return isAllowList; } } - } /*else if (filterCard.getItem() instanceof FilterNBT) { //TODO Review FilterNBT Filter - for (String tag : testStack.getOrCreateTag().getAllKeys()) { - if (filterNBTs.contains(tag)) { + } else if (filterCard.getItem() instanceof FilterNBT) { + for (Map.Entry, Optional> entry : testStack.getComponentsPatch().entrySet()) { + if (filterNBTs.contains(entry.getKey().toString())) { filterCache.put(key, isAllowList); return isAllowList; } } - }*/ else { + } else { for (ItemStack stack : filteredItems) { if (key.equals(new ItemStackKey(stack, isCompareNBT))) { filterCache.put(key, isAllowList);