diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java b/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java index 2cb54d5cb..83cbf4762 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java @@ -79,7 +79,7 @@ public class CommonEvents { boolean changed = false; boolean isVoid = ((Sack) invStack.getItem()).isVoid; - FilterSettings filter = new FilterSettings(4, false, false); + FilterSettings filter = new FilterSettings(4, false, false, false, false); filter.readFromNBT(invStack.getOrCreateTag(), "Filter"); if (isVoid) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/SackContainer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/SackContainer.java index c77602023..f29f79923 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/SackContainer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/SackContainer.java @@ -32,7 +32,7 @@ import java.util.UUID; public class SackContainer extends AbstractContainerMenu implements IButtonReactor { - public final FilterSettings filter = new FilterSettings(4, false,false); + public final FilterSettings filter = new FilterSettings(4, false,false, false, false); private final ItemStackHandlerAA bagInventory; private final Inventory inventory; public boolean autoInsert; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/VoidSackContainer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/VoidSackContainer.java index b5e3966e0..f18838fee 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/VoidSackContainer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/VoidSackContainer.java @@ -19,7 +19,7 @@ import net.minecraft.world.item.ItemStack; import javax.annotation.Nonnull; public class VoidSackContainer extends AbstractContainerMenu implements IButtonReactor { - public final FilterSettings filter = new FilterSettings(4, false,false); + public final FilterSettings filter = new FilterSettings(4, false,false, false, false); private final ItemStackHandlerAA bagInventory; private final Inventory inventory; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/FilterSettingsGui.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/FilterSettingsGui.java index d94d5dcde..f96945ce9 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/FilterSettingsGui.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/FilterSettingsGui.java @@ -32,6 +32,8 @@ public class FilterSettingsGui { public Button whitelistButton; public Button modButton; + public Button damageButton; + public Button nbtButton; public FilterSettingsGui(FilterSettings settings, int x, int y, boolean vertical, Consumer buttonConsumer, Consumer clickConsumer, int idOffset) { this.theSettings = settings; @@ -42,10 +44,12 @@ public class FilterSettingsGui { }) .bounds(x, y, 16, 12).build(); buttonConsumer.accept(this.whitelistButton); + if (vertical) y += 14; else x += 18; + this.modButton = Button.builder(Component.literal("MO"), $ -> { theSettings.respectMod = !theSettings.respectMod; clickConsumer.accept(idOffset + 1); @@ -53,17 +57,33 @@ public class FilterSettingsGui { .bounds(x, y, 16, 12).build(); buttonConsumer.accept(this.modButton); + if (vertical) + y += 14; + else + x += 18; + + this.damageButton = Button.builder(Component.literal("DM"), $ -> { + theSettings.matchDamage = !theSettings.matchDamage; + clickConsumer.accept(idOffset + 2); + }) + .bounds(x, y, 16, 12).build(); + buttonConsumer.accept(this.damageButton); + + if (vertical) + y += 14; + else + x += 18; + + this.nbtButton = Button.builder(Component.literal("DA"), $ -> { + theSettings.matchNBT = !theSettings.matchNBT; + clickConsumer.accept(idOffset + 2); + }) + .bounds(x, y, 16, 12).build(); + buttonConsumer.accept(this.nbtButton); + this.tick(); } -/* public void buttonClicked(int id) { - CompoundTag data = new CompoundTag(); - data.putInt("ButtonID", id); - data.putInt("PlayerID", Minecraft.getInstance().player.getId()); - data.putString("WorldID", Minecraft.getInstance().level.dimension().location().toString()); - PacketDistributor.SERVER.noArg().send(new PacketClientToServer(data, PacketHandler.GUI_BUTTON_TO_CONTAINER_HANDLER)); - }*/ - public void tick() { this.whitelistButton.setMessage(Component.literal("WH").withStyle(this.theSettings.isWhitelist ? ChatFormatting.DARK_GREEN @@ -71,6 +91,12 @@ public class FilterSettingsGui { this.modButton.setMessage(Component.literal("MO").withStyle(this.theSettings.respectMod ? ChatFormatting.DARK_GREEN : ChatFormatting.RED)); + this.damageButton.setMessage(Component.literal("DM").withStyle(this.theSettings.matchDamage + ? ChatFormatting.DARK_GREEN + : ChatFormatting.RED)); + this.nbtButton.setMessage(Component.literal("DA").withStyle(this.theSettings.matchNBT + ? ChatFormatting.DARK_GREEN + : ChatFormatting.RED)); } public void drawHover(GuiGraphics guiGraphics, int mouseX, int mouseY) { @@ -78,16 +104,22 @@ public class FilterSettingsGui { List list = new ArrayList<>(); if (this.whitelistButton.isMouseOver(mouseX, mouseY)) { list.add((this.theSettings.isWhitelist - ? Component.translatable("info." + ActuallyAdditions.MODID + ".gui.whitelist") - : Component.translatable("info." + ActuallyAdditions.MODID + ".gui.blacklist")).withStyle(ChatFormatting.BOLD)); - list.add(Component.translatable("info." + ActuallyAdditions.MODID + ".gui.whitelistInfo")); + ? Component.translatable("info.actuallyadditions.gui.whitelist") + : Component.translatable("info.actuallyadditions.gui.blacklist")).withStyle(ChatFormatting.BOLD)); + list.add(Component.translatable("info.actuallyadditions.gui.whitelistInfo")); } else if (this.modButton.isMouseOver(mouseX, mouseY)) { list.add((this.theSettings.respectMod - ? Component.translatable("info." + ActuallyAdditions.MODID + ".gui.respectMod") - : Component.translatable("info." + ActuallyAdditions.MODID + ".gui.ignoreMod")).withStyle(ChatFormatting.BOLD)); - list.add(Component.translatable("info." + ActuallyAdditions.MODID + ".gui.respectModInfo")); - - + ? Component.translatable("info.actuallyadditions.gui.respectMod") + : Component.translatable("info.actuallyadditions.gui.ignoreMod")).withStyle(ChatFormatting.BOLD)); + list.add(Component.translatable("info.actuallyadditions.gui.respectModInfo")); + } else if (this.modButton.isMouseOver(mouseX, mouseY)) { + list.add((this.theSettings.matchDamage + ? Component.translatable("info.actuallyadditions.gui.respectDamage") + : Component.translatable("info.actuallyadditions.gui.ignoreDamage")).withStyle(ChatFormatting.BOLD)); + } else if (this.modButton.isMouseOver(mouseX, mouseY)) { + list.add((this.theSettings.matchNBT + ? Component.translatable("info.actuallyadditions.gui.respectNBT") + : Component.translatable("info.actuallyadditions.gui.ignoreNBT")).withStyle(ChatFormatting.BOLD)); } //TODO tooltips still jank if (!list.isEmpty()) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/FilterSettings.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/FilterSettings.java index 4b8c44483..d489f34bc 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/FilterSettings.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/FilterSettings.java @@ -25,15 +25,21 @@ public class FilterSettings { public final ItemStackHandlerAA filterInventory; public boolean isWhitelist; public boolean respectMod; + public boolean matchDamage; + public boolean matchNBT; private boolean lastWhitelist; private boolean lastRespectMod; + private boolean lastMatchDamage; + private boolean lastMatchNBT; public enum Buttons { WHITELIST, - MOD + MOD, + DAMAGE, + NBT } - public FilterSettings(int slots, boolean defaultWhitelist, boolean defaultRespectMod) { + public FilterSettings(int slots, boolean defaultWhitelist, boolean defaultRespectMod, boolean defaultMatchDamage, boolean defaultMatchNBT) { this.filterInventory = new ItemStackHandlerAA(slots) { @Override protected void onContentsChanged(int slot) { @@ -44,11 +50,13 @@ public class FilterSettings { this.isWhitelist = defaultWhitelist; this.respectMod = defaultRespectMod; + this.matchDamage = defaultMatchDamage; + this.matchNBT = defaultMatchNBT; } public void onContentsChanged() {} - public static boolean check(ItemStack stack, ItemStackHandlerAA filter, boolean whitelist, boolean mod) { + public static boolean check(ItemStack stack, ItemStackHandlerAA filter, boolean whitelist, boolean mod, boolean damage, boolean nbt) { if (!stack.isEmpty()) { for (int i = 0; i < filter.getSlots(); i++) { ItemStack slot = filter.getStackInSlot(i); @@ -59,7 +67,7 @@ public class FilterSettings { DrillItem.loadSlotsFromNBT(inv, slot); for (int k = 0; k < inv.getSlots(); k++) { ItemStack filterSlot = inv.getStackInSlot(k); - if (!filterSlot.isEmpty() && areEqualEnough(filterSlot, stack, mod)) { + if (!filterSlot.isEmpty() && areEqualEnough(filterSlot, stack, mod, damage, nbt)) { return whitelist; } } @@ -75,7 +83,7 @@ public class FilterSettings { } } } - else if (areEqualEnough(slot, stack, mod)) { + else if (areEqualEnough(slot, stack, mod, damage, nbt)) { return whitelist; } } @@ -84,20 +92,31 @@ public class FilterSettings { return !whitelist; } - private static boolean areEqualEnough(ItemStack first, ItemStack second, boolean mod) { - Item firstItem = first.getItem(); - Item secondItem = second.getItem(); - if (mod && BuiltInRegistries.ITEM.getKey(firstItem).getNamespace().equals(BuiltInRegistries.ITEM.getKey(secondItem).getNamespace())) { + private static boolean areEqualEnough(ItemStack first, ItemStack second, boolean mod, boolean damage, boolean nbt) { + if (mod && checkMod(first, second) && checkDamage(first, second, damage)) { return true; } + return checkItem(first, second, nbt) && checkDamage(first, second, damage); + } - return firstItem == secondItem; + public static boolean checkDamage(ItemStack first, ItemStack second, boolean damage) { + return !damage || first.getDamageValue() == second.getDamageValue(); + } + + public static boolean checkItem(ItemStack first, ItemStack second, boolean nbt) { + return nbt? ItemStack.isSameItemSameTags(first, second) : ItemStack.isSameItem(first, second); + } + + public static boolean checkMod(ItemStack first, ItemStack second) { + return BuiltInRegistries.ITEM.getKey(first.getItem()).getNamespace().equals(BuiltInRegistries.ITEM.getKey(second.getItem()).getNamespace()); } public void writeToNBT(CompoundTag tag, String name) { CompoundTag compound = new CompoundTag(); compound.putBoolean("Whitelist", this.isWhitelist); compound.putBoolean("Mod", this.respectMod); + compound.putBoolean("Damage", this.matchDamage); + compound.putBoolean("NBT", this.matchNBT); compound.put("Items", filterInventory.serializeNBT()); tag.put(name, compound); } @@ -106,16 +125,20 @@ public class FilterSettings { CompoundTag compound = tag.getCompound(name); this.isWhitelist = compound.getBoolean("Whitelist"); this.respectMod = compound.getBoolean("Mod"); + this.matchDamage = compound.getBoolean("Damage"); + this.matchNBT = compound.getBoolean("NBT"); this.filterInventory.deserializeNBT(compound.getCompound("Items")); } public boolean needsUpdateSend() { - return this.lastWhitelist != this.isWhitelist || this.lastRespectMod != this.respectMod; + return this.lastWhitelist != this.isWhitelist || this.lastRespectMod != this.respectMod || this.lastMatchDamage != this.matchDamage || this.lastMatchNBT != this.matchNBT; } public void updateLasts() { this.lastWhitelist = this.isWhitelist; this.lastRespectMod = this.respectMod; + this.lastMatchDamage = this.matchDamage; + this.lastMatchNBT = this.matchNBT; } public void onButtonPressed(int id) { @@ -123,11 +146,15 @@ public class FilterSettings { this.isWhitelist = !this.isWhitelist; } else if (id == Buttons.MOD.ordinal()) { this.respectMod = !this.respectMod; + } else if (id == Buttons.DAMAGE.ordinal()) { + this.matchDamage = !this.matchDamage; + } else if (id == Buttons.NBT.ordinal()) { + this.matchNBT = !this.matchNBT; } } public boolean check(ItemStack stack) { - return !this.needsCheck() || check(stack, this.filterInventory, this.isWhitelist, this.respectMod); + return !this.needsCheck() || check(stack, this.filterInventory, this.isWhitelist, this.respectMod, this.matchDamage, this.matchNBT); } public boolean needsCheck() { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItemAdvanced.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItemAdvanced.java index 7acbee5ec..09057671c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItemAdvanced.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItemAdvanced.java @@ -35,8 +35,8 @@ import java.util.Optional; public class TileEntityLaserRelayItemAdvanced extends TileEntityLaserRelayItem implements IButtonReactor, MenuProvider { - public FilterSettings leftFilter = new FilterSettings(12, true, false); - public FilterSettings rightFilter = new FilterSettings(12, true, false); + public FilterSettings leftFilter = new FilterSettings(12, true, false, false, false); + public FilterSettings rightFilter = new FilterSettings(12, true, false, false, false); public TileEntityLaserRelayItemAdvanced(BlockPos pos, BlockState state) { super(ActuallyBlocks.LASER_RELAY_ITEM_ADVANCED.getTileEntityType(), pos, state); @@ -118,7 +118,7 @@ public class TileEntityLaserRelayItemAdvanced extends TileEntityLaserRelayItem i ItemStack copy = stack.copy(); copy.setCount(1); - if (!FilterSettings.check(copy, usedSettings.filterInventory, true, usedSettings.respectMod)) { + if (!FilterSettings.check(copy, usedSettings.filterInventory, true, usedSettings.respectMod, usedSettings.matchDamage, usedSettings.matchNBT)) { for (int k = 0; k < usedSettings.filterInventory.getSlots(); k++) { ItemStack slot = usedSettings.filterInventory.getStackInSlot(k); if (!slot.isEmpty()) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityRangedCollector.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityRangedCollector.java index bcba022a5..eb3f6eda5 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityRangedCollector.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityRangedCollector.java @@ -39,7 +39,7 @@ import java.util.List; public class TileEntityRangedCollector extends TileEntityInventoryBase implements IButtonReactor, MenuProvider { public static final int RANGE = 6; - public FilterSettings filter = new FilterSettings(12, true, false); + public FilterSettings filter = new FilterSettings(12, true, false, false, false); public TileEntityRangedCollector(BlockPos pos, BlockState state) { super(ActuallyBlocks.RANGED_COLLECTOR.getTileEntityType(), pos, state, 6); diff --git a/src/main/resources/assets/actuallyadditions/lang/en_us.json b/src/main/resources/assets/actuallyadditions/lang/en_us.json index 9e7ba3000..3cf35ab2c 100644 --- a/src/main/resources/assets/actuallyadditions/lang/en_us.json +++ b/src/main/resources/assets/actuallyadditions/lang/en_us.json @@ -466,18 +466,13 @@ "info.actuallyadditions.gui.whitelist": "Whitelist", "info.actuallyadditions.gui.blacklist": "Blacklist", "info.actuallyadditions.gui.whitelistInfo": "To let all items through, an empty blacklist can be used, to let no items through, an empty whitelist can be used. To configure certain items, place them or configured Item Filters in the slots.", - "info.actuallyadditions.gui.respectMeta": "Respecting Metadata", - "info.actuallyadditions.gui.ignoreMeta": "Ignoring Metadata", - "info.actuallyadditions.gui.respectNBT": "Respecting NBT", - "info.actuallyadditions.gui.ignoreNBT": "Ignoring NBT", + "info.actuallyadditions.gui.respectDamage": "Respecting Damage", + "info.actuallyadditions.gui.ignoreDamage": "Ignoring Damage", + "info.actuallyadditions.gui.respectNBT": "Respecting NBT Data", + "info.actuallyadditions.gui.ignoreNBT": "Ignoring NBT Data", "info.actuallyadditions.gui.ignoreMod": "Mod Mode Off", "info.actuallyadditions.gui.respectMod": "Mod Mode On", "info.actuallyadditions.gui.respectModInfo": "If this is enabled, the filter will compare the mods items come from §cinstead of comparing the items themselves§r. This can be useful for storage systems with mod-based chests. Can also be combined with the other options, but that normally isn't very useful.", - "info.actuallyadditions.gui.ignoreOredict": "Ignoring OreDictionary", - "info.actuallyadditions.gui.respectOredictSoft": "Soft Respecting OreDictionary", - "info.actuallyadditions.gui.respectOredictHard": "Hard Respecting OreDictionary", - "info.actuallyadditions.gui.respectOredictInfo.one": "The item being passed only has to contain §2only one§r of the OreDictionary tags of the item in the filter.", - "info.actuallyadditions.gui.respectOredictInfo.all": "The item being passed has to contain §2all§r of the OreDictionary tags of the item in the filter.", "info.actuallyadditions.gui.autosplititems.on": "Auto-Split Items On", "info.actuallyadditions.gui.autosplititems.off": "Auto-Split Items Off", "info.actuallyadditions.gui.inbound": "INBOUND",