diff --git a/src/main/java/de/ellpeck/prettypipes/Registry.java b/src/main/java/de/ellpeck/prettypipes/Registry.java index 7dbfd57..59ec0ba 100644 --- a/src/main/java/de/ellpeck/prettypipes/Registry.java +++ b/src/main/java/de/ellpeck/prettypipes/Registry.java @@ -3,7 +3,7 @@ package de.ellpeck.prettypipes; import de.ellpeck.prettypipes.entities.PipeFrameEntity; import de.ellpeck.prettypipes.entities.PipeFrameRenderer; import de.ellpeck.prettypipes.items.*; -import de.ellpeck.prettypipes.misc.ItemEqualityType; +import de.ellpeck.prettypipes.misc.ItemEquality; import de.ellpeck.prettypipes.network.PipeNetwork; import de.ellpeck.prettypipes.packets.PacketHandler; import de.ellpeck.prettypipes.pipe.IPipeConnectable; @@ -26,6 +26,9 @@ import de.ellpeck.prettypipes.pipe.modules.filter.FilterIncreaseModuleItem; import de.ellpeck.prettypipes.pipe.modules.insertion.FilterModuleContainer; import de.ellpeck.prettypipes.pipe.modules.insertion.FilterModuleGui; import de.ellpeck.prettypipes.pipe.modules.insertion.FilterModuleItem; +import de.ellpeck.prettypipes.pipe.modules.modifier.FilterModifierModuleContainer; +import de.ellpeck.prettypipes.pipe.modules.modifier.FilterModifierModuleGui; +import de.ellpeck.prettypipes.pipe.modules.modifier.FilterModifierModuleItem; import de.ellpeck.prettypipes.pipe.modules.retrieval.RetrievalModuleContainer; import de.ellpeck.prettypipes.pipe.modules.retrieval.RetrievalModuleGui; import de.ellpeck.prettypipes.pipe.modules.retrieval.RetrievalModuleItem; @@ -122,6 +125,7 @@ public final class Registry { public static ContainerType stackSizeModuleContainer; public static ContainerType filterIncreaseModuleContainer; public static ContainerType craftingModuleContainer; + public static ContainerType filterModifierModuleContainer; @SubscribeEvent public static void registerBlocks(RegistryEvent.Register event) { @@ -148,7 +152,7 @@ public final class Registry { registry.registerAll(createTieredModule("high_priority_module", HighPriorityModuleItem::new)); registry.registerAll(createTieredModule("retrieval_module", RetrievalModuleItem::new)); registry.register(new StackSizeModuleItem("stack_size_module")); - registry.registerAll(Arrays.stream(ItemEqualityType.values()).map(t -> new FilterModifierModuleItem(t.name().toLowerCase(Locale.ROOT) + "_filter_modifier", t)).toArray(Item[]::new)); + registry.registerAll(Arrays.stream(ItemEquality.Type.values()).map(t -> new FilterModifierModuleItem(t.name().toLowerCase(Locale.ROOT) + "_filter_modifier", t)).toArray(Item[]::new)); registry.register(new RedstoneModuleItem("redstone_module")); registry.register(new FilterIncreaseModuleItem("filter_increase_modifier")); registry.registerAll(createTieredModule("crafting_module", CraftingModuleItem::new)); @@ -188,7 +192,8 @@ public final class Registry { retrievalModuleContainer = createPipeContainer("retrieval_module"), stackSizeModuleContainer = createPipeContainer("stack_size_module"), filterIncreaseModuleContainer = createPipeContainer("filter_increase_module"), - craftingModuleContainer = createPipeContainer("crafting_module") + craftingModuleContainer = createPipeContainer("crafting_module"), + filterModifierModuleContainer = createPipeContainer("filter_modifier_module") ); } @@ -230,6 +235,7 @@ public final class Registry { ScreenManager.registerFactory(stackSizeModuleContainer, StackSizeModuleGui::new); ScreenManager.registerFactory(filterIncreaseModuleContainer, FilterIncreaseModuleGui::new); ScreenManager.registerFactory(craftingModuleContainer, CraftingModuleGui::new); + ScreenManager.registerFactory(filterModifierModuleContainer, FilterModifierModuleGui::new); } } diff --git a/src/main/java/de/ellpeck/prettypipes/compat/jei/CraftingModuleTransferHandler.java b/src/main/java/de/ellpeck/prettypipes/compat/jei/CraftingModuleTransferHandler.java index 85299b6..41c7f4a 100644 --- a/src/main/java/de/ellpeck/prettypipes/compat/jei/CraftingModuleTransferHandler.java +++ b/src/main/java/de/ellpeck/prettypipes/compat/jei/CraftingModuleTransferHandler.java @@ -1,6 +1,6 @@ package de.ellpeck.prettypipes.compat.jei; -import de.ellpeck.prettypipes.misc.ItemEqualityType; +import de.ellpeck.prettypipes.misc.ItemEquality; import de.ellpeck.prettypipes.packets.PacketCraftingModuleTransfer; import de.ellpeck.prettypipes.packets.PacketHandler; import de.ellpeck.prettypipes.pipe.modules.craft.CraftingModuleContainer; @@ -35,7 +35,7 @@ public class CraftingModuleTransferHandler implements IRecipeTransferHandler toAdd = entry.getValue().isInput() ? inputs : outputs; for (ItemStack stack : toAdd) { - if (ItemEqualityType.compareItems(stack, remain)) { + if (ItemEquality.compareItems(stack, remain)) { int fits = Math.min(stack.getMaxStackSize() - stack.getCount(), remain.getCount()); stack.grow(fits); remain.shrink(fits); diff --git a/src/main/java/de/ellpeck/prettypipes/misc/EquatableItemStack.java b/src/main/java/de/ellpeck/prettypipes/misc/EquatableItemStack.java index db606cc..2e5289a 100644 --- a/src/main/java/de/ellpeck/prettypipes/misc/EquatableItemStack.java +++ b/src/main/java/de/ellpeck/prettypipes/misc/EquatableItemStack.java @@ -8,9 +8,9 @@ import java.util.Objects; public class EquatableItemStack { public final ItemStack stack; - public final ItemEqualityType[] equalityTypes; + public final ItemEquality[] equalityTypes; - public EquatableItemStack(ItemStack stack, ItemEqualityType... equalityTypes) { + public EquatableItemStack(ItemStack stack, ItemEquality... equalityTypes) { this.stack = stack; this.equalityTypes = equalityTypes; } @@ -18,7 +18,7 @@ public class EquatableItemStack { public boolean equals(Object o) { if (o instanceof EquatableItemStack) { EquatableItemStack other = (EquatableItemStack) o; - return Arrays.equals(this.equalityTypes, other.equalityTypes) && ItemEqualityType.compareItems(this.stack, other.stack, this.equalityTypes); + return Arrays.equals(this.equalityTypes, other.equalityTypes) && ItemEquality.compareItems(this.stack, other.stack, this.equalityTypes); } return false; } diff --git a/src/main/java/de/ellpeck/prettypipes/misc/ItemEquality.java b/src/main/java/de/ellpeck/prettypipes/misc/ItemEquality.java new file mode 100644 index 0000000..1944769 --- /dev/null +++ b/src/main/java/de/ellpeck/prettypipes/misc/ItemEquality.java @@ -0,0 +1,58 @@ +package de.ellpeck.prettypipes.misc; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; + +import java.util.function.BiFunction; +import java.util.function.Supplier; + +public class ItemEquality { + + public static final ItemEquality DAMAGE = new ItemEquality((stack, filter) -> stack.getDamage() == filter.getDamage(), false, Type.DAMAGE); + public static final ItemEquality NBT = new ItemEquality(ItemStack::areItemStackTagsEqual, false, Type.NBT); + public static final ItemEquality MOD = new ItemEquality((stack, filter) -> stack.getItem().getCreatorModId(stack).equals(filter.getItem().getCreatorModId(filter)), true, Type.MOD); + + public final Type type; + private final BiFunction filter; + private final boolean ignoreItemEquality; + + ItemEquality(BiFunction filter, boolean ignoreItemEquality, Type type) { + this.filter = filter; + this.ignoreItemEquality = ignoreItemEquality; + this.type = type; + } + + public static ItemEquality tag(ResourceLocation tag) { + return new ItemEquality((stack, filter) -> stack.getItem().getTags().contains(tag), true, Type.TAG); + } + + public static boolean compareItems(ItemStack stack, ItemStack filter, ItemEquality... types) { + boolean equal = ItemStack.areItemsEqual(stack, filter); + if (types.length <= 0) + return equal; + for (ItemEquality type : types) { + if (!type.ignoreItemEquality && !equal) + return false; + if (!type.filter.apply(stack, filter)) + return false; + } + return true; + } + + public enum Type { + DAMAGE(() -> ItemEquality.DAMAGE), + NBT(() -> ItemEquality.NBT), + MOD(() -> ItemEquality.MOD), + TAG(null); + + private final Supplier defaultInstance; + + Type(Supplier defaultInstance) { + this.defaultInstance = defaultInstance; + } + + public ItemEquality getDefaultInstance() { + return this.defaultInstance.get(); + } + } +} diff --git a/src/main/java/de/ellpeck/prettypipes/misc/ItemEqualityType.java b/src/main/java/de/ellpeck/prettypipes/misc/ItemEqualityType.java deleted file mode 100644 index 4d40313..0000000 --- a/src/main/java/de/ellpeck/prettypipes/misc/ItemEqualityType.java +++ /dev/null @@ -1,43 +0,0 @@ -package de.ellpeck.prettypipes.misc; - -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; - -import java.util.Arrays; -import java.util.Set; -import java.util.function.BiFunction; - -public enum ItemEqualityType { - - DAMAGE((stack, filter) -> stack.getDamage() == filter.getDamage(), false), - NBT(ItemStack::areItemStackTagsEqual, false), - TAG((stack, filter) -> { - Set stackTags = stack.getItem().getTags(); - Set filterTags = filter.getItem().getTags(); - if (filterTags.isEmpty()) - return false; - return stackTags.containsAll(filterTags); - }, true), - MOD((stack, filter) -> stack.getItem().getCreatorModId(stack).equals(filter.getItem().getCreatorModId(filter)), true); - - public final BiFunction filter; - public final boolean ignoreItemEquality; - - ItemEqualityType(BiFunction filter, boolean ignoreItemEquality) { - this.filter = filter; - this.ignoreItemEquality = ignoreItemEquality; - } - - public static boolean compareItems(ItemStack stack, ItemStack filter, ItemEqualityType... types) { - boolean equal = ItemStack.areItemsEqual(stack, filter); - if (types.length <= 0) - return equal; - for (ItemEqualityType type : types) { - if (!type.ignoreItemEquality && !equal) - return false; - if (!type.filter.apply(stack, filter)) - return false; - } - return true; - } -} diff --git a/src/main/java/de/ellpeck/prettypipes/misc/ItemFilter.java b/src/main/java/de/ellpeck/prettypipes/misc/ItemFilter.java index d1ecbc6..53ef1b0 100644 --- a/src/main/java/de/ellpeck/prettypipes/misc/ItemFilter.java +++ b/src/main/java/de/ellpeck/prettypipes/misc/ItemFilter.java @@ -4,7 +4,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import de.ellpeck.prettypipes.PrettyPipes; import de.ellpeck.prettypipes.packets.PacketButton; import de.ellpeck.prettypipes.pipe.PipeTileEntity; -import de.ellpeck.prettypipes.pipe.modules.FilterModifierModuleItem; +import de.ellpeck.prettypipes.pipe.modules.modifier.FilterModifierModuleItem; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.Widget; import net.minecraft.client.gui.widget.button.Button; @@ -19,7 +19,6 @@ import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.items.ItemStackHandler; -import org.apache.commons.lang3.tuple.Pair; import java.util.ArrayList; import java.util.List; @@ -106,14 +105,14 @@ public class ItemFilter extends ItemStackHandler { } private boolean isFiltered(ItemStack stack) { - ItemEqualityType[] types = getEqualityTypes(this.pipe); + ItemEquality[] types = getEqualityTypes(this.pipe); // also check if any filter increase modules have the item we need for (ItemStackHandler handler : this.pipe.getFilters()) { for (int i = 0; i < handler.getSlots(); i++) { ItemStack filter = handler.getStackInSlot(i); if (filter.isEmpty()) continue; - if (ItemEqualityType.compareItems(stack, filter, types)) + if (ItemEquality.compareItems(stack, filter, types)) return true; } } @@ -147,12 +146,11 @@ public class ItemFilter extends ItemStackHandler { this.modified = true; } - public static ItemEqualityType[] getEqualityTypes(PipeTileEntity pipe) { + public static ItemEquality[] getEqualityTypes(PipeTileEntity pipe) { return pipe.streamModules() - .map(Pair::getRight) - .filter(m -> m instanceof FilterModifierModuleItem) - .map(m -> ((FilterModifierModuleItem) m).type) - .toArray(ItemEqualityType[]::new); + .filter(m -> m.getRight() instanceof FilterModifierModuleItem) + .map(m -> ((FilterModifierModuleItem) m.getRight()).getEqualityType(m.getLeft())) + .toArray(ItemEquality[]::new); } public interface IFilteredContainer { diff --git a/src/main/java/de/ellpeck/prettypipes/network/NetworkLocation.java b/src/main/java/de/ellpeck/prettypipes/network/NetworkLocation.java index ce03709..dc1ba02 100644 --- a/src/main/java/de/ellpeck/prettypipes/network/NetworkLocation.java +++ b/src/main/java/de/ellpeck/prettypipes/network/NetworkLocation.java @@ -1,6 +1,6 @@ package de.ellpeck.prettypipes.network; -import de.ellpeck.prettypipes.misc.ItemEqualityType; +import de.ellpeck.prettypipes.misc.ItemEquality; import de.ellpeck.prettypipes.pipe.PipeTileEntity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; @@ -33,19 +33,19 @@ public class NetworkLocation implements INBTSerializable { this.deserializeNBT(nbt); } - public List getStackSlots(World world, ItemStack stack, ItemEqualityType... equalityTypes) { + public List getStackSlots(World world, ItemStack stack, ItemEquality... equalityTypes) { if (this.isEmpty(world)) return Collections.emptyList(); return this.getItems(world).entrySet().stream() - .filter(kv -> ItemEqualityType.compareItems(kv.getValue(), stack, equalityTypes) && this.canExtract(world, kv.getKey())) + .filter(kv -> ItemEquality.compareItems(kv.getValue(), stack, equalityTypes) && this.canExtract(world, kv.getKey())) .map(Map.Entry::getKey).collect(Collectors.toList()); } - public int getItemAmount(World world, ItemStack stack, ItemEqualityType... equalityTypes) { + public int getItemAmount(World world, ItemStack stack, ItemEquality... equalityTypes) { if (this.isEmpty(world)) return 0; return this.getItems(world).entrySet().stream() - .filter(kv -> ItemEqualityType.compareItems(stack, kv.getValue(), equalityTypes) && this.canExtract(world, kv.getKey())) + .filter(kv -> ItemEquality.compareItems(stack, kv.getValue(), equalityTypes) && this.canExtract(world, kv.getKey())) .mapToInt(kv -> kv.getValue().getCount()).sum(); } diff --git a/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java b/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java index 8d804a7..ac02cd9 100644 --- a/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java +++ b/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java @@ -6,7 +6,7 @@ import com.google.common.collect.Streams; import de.ellpeck.prettypipes.PrettyPipes; import de.ellpeck.prettypipes.Registry; import de.ellpeck.prettypipes.Utility; -import de.ellpeck.prettypipes.misc.ItemEqualityType; +import de.ellpeck.prettypipes.misc.ItemEquality; import de.ellpeck.prettypipes.packets.PacketHandler; import de.ellpeck.prettypipes.packets.PacketItemEnterPipe; import de.ellpeck.prettypipes.pipe.IPipeItem; @@ -185,7 +185,7 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL return true; } - public ItemStack requestItem(BlockPos destPipe, BlockPos destInventory, ItemStack stack, ItemEqualityType... equalityTypes) { + public ItemStack requestItem(BlockPos destPipe, BlockPos destInventory, ItemStack stack, ItemEquality... equalityTypes) { ItemStack remain = stack.copy(); // check existing items for (NetworkLocation location : this.getOrderedNetworkItems(destPipe)) { @@ -197,9 +197,9 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL return this.requestCraftedItem(destPipe, null, remain, new Stack<>(), equalityTypes); } - public ItemStack requestCraftedItem(BlockPos destPipe, Consumer unavailableConsumer, ItemStack stack, Stack dependencyChain, ItemEqualityType... equalityTypes) { + public ItemStack requestCraftedItem(BlockPos destPipe, Consumer unavailableConsumer, ItemStack stack, Stack dependencyChain, ItemEquality... equalityTypes) { for (Pair craftable : this.getAllCraftables(destPipe)) { - if (!ItemEqualityType.compareItems(stack, craftable.getRight(), equalityTypes)) + if (!ItemEquality.compareItems(stack, craftable.getRight(), equalityTypes)) continue; PipeTileEntity pipe = this.getPipe(craftable.getLeft()); if (pipe == null) @@ -211,11 +211,11 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL return stack; } - public ItemStack requestExistingItem(NetworkLocation location, BlockPos destPipe, BlockPos destInventory, NetworkLock ignoredLock, ItemStack stack, ItemEqualityType... equalityTypes) { + public ItemStack requestExistingItem(NetworkLocation location, BlockPos destPipe, BlockPos destInventory, NetworkLock ignoredLock, ItemStack stack, ItemEquality... equalityTypes) { return this.requestExistingItem(location, destPipe, destInventory, ignoredLock, PipeItem::new, stack, equalityTypes); } - public ItemStack requestExistingItem(NetworkLocation location, BlockPos destPipe, BlockPos destInventory, NetworkLock ignoredLock, BiFunction itemSupplier, ItemStack stack, ItemEqualityType... equalityTypes) { + public ItemStack requestExistingItem(NetworkLocation location, BlockPos destPipe, BlockPos destInventory, NetworkLock ignoredLock, BiFunction itemSupplier, ItemStack stack, ItemEquality... equalityTypes) { if (location.getPos().equals(destInventory)) return stack; // make sure we don't pull any locked items @@ -253,7 +253,7 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL return tile; } - public List> getCurrentlyCrafting(BlockPos node, ItemEqualityType... equalityTypes) { + public List> getCurrentlyCrafting(BlockPos node, ItemEquality... equalityTypes) { this.startProfile("get_currently_crafting"); List> items = new ArrayList<>(); Iterator craftingPipes = this.getAllCraftables(node).stream().map(c -> this.getPipe(c.getLeft())).distinct().iterator(); @@ -264,7 +264,7 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL ItemStack stack = request.getRight(); // add up all the items that should go to the same location Optional> existing = items.stream() - .filter(s -> s.getLeft().equals(dest) && ItemEqualityType.compareItems(s.getRight(), stack, equalityTypes)) + .filter(s -> s.getLeft().equals(dest) && ItemEquality.compareItems(s.getRight(), stack, equalityTypes)) .findFirst(); if (existing.isPresent()) { existing.get().getRight().grow(stack.getCount()); @@ -277,9 +277,9 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL return items; } - public int getCurrentlyCraftingAmount(BlockPos destNode, ItemStack stack, ItemEqualityType... equalityTypes) { + public int getCurrentlyCraftingAmount(BlockPos destNode, ItemStack stack, ItemEquality... equalityTypes) { return this.getCurrentlyCrafting(destNode).stream() - .filter(p -> p.getLeft().equals(destNode) && ItemEqualityType.compareItems(p.getRight(), stack, equalityTypes)) + .filter(p -> p.getLeft().equals(destNode) && ItemEquality.compareItems(p.getRight(), stack, equalityTypes)) .mapToInt(p -> p.getRight().getCount()).sum(); } @@ -299,10 +299,10 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL return craftables; } - public int getCraftableAmount(BlockPos node, Consumer unavailableConsumer, ItemStack stack, Stack dependencyChain, ItemEqualityType... equalityTypes) { + public int getCraftableAmount(BlockPos node, Consumer unavailableConsumer, ItemStack stack, Stack dependencyChain, ItemEquality... equalityTypes) { int total = 0; for (Pair pair : this.getAllCraftables(node)) { - if (!ItemEqualityType.compareItems(pair.getRight(), stack, equalityTypes)) + if (!ItemEquality.compareItems(pair.getRight(), stack, equalityTypes)) continue; if (!this.world.isBlockLoaded(pair.getLeft())) continue; @@ -352,9 +352,9 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL return this.networkLocks.get(pos); } - public int getLockedAmount(BlockPos pos, ItemStack stack, NetworkLock ignoredLock, ItemEqualityType... equalityTypes) { + public int getLockedAmount(BlockPos pos, ItemStack stack, NetworkLock ignoredLock, ItemEquality... equalityTypes) { return this.getNetworkLocks(pos).stream() - .filter(l -> !l.equals(ignoredLock) && ItemEqualityType.compareItems(l.stack, stack, equalityTypes)) + .filter(l -> !l.equals(ignoredLock) && ItemEquality.compareItems(l.stack, stack, equalityTypes)) .mapToInt(l -> l.stack.getCount()).sum(); } @@ -481,9 +481,9 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL return ret; } - public int getItemsOnTheWay(BlockPos goalInv, ItemStack type, ItemEqualityType... equalityTypes) { + public int getItemsOnTheWay(BlockPos goalInv, ItemStack type, ItemEquality... equalityTypes) { return this.getPipeItemsOnTheWay(goalInv) - .filter(i -> type == null || ItemEqualityType.compareItems(i.getContent(), type, equalityTypes)) + .filter(i -> type == null || ItemEquality.compareItems(i.getContent(), type, equalityTypes)) .mapToInt(i -> i.getItemsOnTheWay(goalInv)).sum(); } diff --git a/src/main/java/de/ellpeck/prettypipes/packets/PacketButton.java b/src/main/java/de/ellpeck/prettypipes/packets/PacketButton.java index a716132..477ca23 100644 --- a/src/main/java/de/ellpeck/prettypipes/packets/PacketButton.java +++ b/src/main/java/de/ellpeck/prettypipes/packets/PacketButton.java @@ -1,12 +1,13 @@ package de.ellpeck.prettypipes.packets; -import de.ellpeck.prettypipes.PrettyPipes; import de.ellpeck.prettypipes.Utility; import de.ellpeck.prettypipes.items.IModule; import de.ellpeck.prettypipes.misc.ItemFilter; import de.ellpeck.prettypipes.misc.ItemFilter.IFilteredContainer; import de.ellpeck.prettypipes.pipe.PipeTileEntity; import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; +import de.ellpeck.prettypipes.pipe.modules.modifier.FilterModifierModuleContainer; +import de.ellpeck.prettypipes.pipe.modules.modifier.FilterModifierModuleItem; import de.ellpeck.prettypipes.pipe.modules.stacksize.StackSizeModuleItem; import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity; import de.ellpeck.prettypipes.terminal.ItemTerminalTileEntity; @@ -118,6 +119,10 @@ public class PacketButton { CANCEL_CRAFTING((pos, data, player) -> { ItemTerminalTileEntity tile = Utility.getTileEntity(ItemTerminalTileEntity.class, player.world, pos); tile.cancelCrafting(); + }), + TAG_FILTER((pos, data, player) -> { + FilterModifierModuleContainer container = (FilterModifierModuleContainer) player.openContainer; + FilterModifierModuleItem.setFilterTag(container.moduleStack, container.getTags().get(data[0])); }); public final TriConsumer action; diff --git a/src/main/java/de/ellpeck/prettypipes/packets/PacketCraftingModuleTransfer.java b/src/main/java/de/ellpeck/prettypipes/packets/PacketCraftingModuleTransfer.java index b768591..dd04468 100644 --- a/src/main/java/de/ellpeck/prettypipes/packets/PacketCraftingModuleTransfer.java +++ b/src/main/java/de/ellpeck/prettypipes/packets/PacketCraftingModuleTransfer.java @@ -1,30 +1,15 @@ package de.ellpeck.prettypipes.packets; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.ListMultimap; -import de.ellpeck.prettypipes.Utility; -import de.ellpeck.prettypipes.misc.FilterSlot; -import de.ellpeck.prettypipes.misc.ItemEqualityType; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; import de.ellpeck.prettypipes.pipe.modules.craft.CraftingModuleContainer; -import de.ellpeck.prettypipes.pipe.modules.craft.CraftingModuleItem; -import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity; -import de.ellpeck.prettypipes.terminal.ItemTerminalTileEntity; -import net.minecraft.client.Minecraft; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.container.Slot; import net.minecraft.item.ItemStack; import net.minecraft.network.PacketBuffer; -import net.minecraft.util.math.BlockPos; import net.minecraftforge.fml.network.NetworkEvent; -import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.items.ItemStackHandler; import java.util.ArrayList; import java.util.List; -import java.util.Map; -import java.util.function.Consumer; import java.util.function.Supplier; public class PacketCraftingModuleTransfer { diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java b/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java index 01d2818..2e66c97 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java @@ -4,7 +4,7 @@ import de.ellpeck.prettypipes.PrettyPipes; import de.ellpeck.prettypipes.Registry; import de.ellpeck.prettypipes.Utility; import de.ellpeck.prettypipes.items.IModule; -import de.ellpeck.prettypipes.misc.ItemEqualityType; +import de.ellpeck.prettypipes.misc.ItemEquality; import de.ellpeck.prettypipes.misc.ItemFilter; import de.ellpeck.prettypipes.network.NetworkLock; import de.ellpeck.prettypipes.network.PipeNetwork; @@ -314,7 +314,7 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide while (modules.hasNext()) { Pair module = modules.next(); // make sure we don't factor in recursive dependencies like ingot -> block -> ingot etc. - if (dependencyChain.stream().noneMatch(d -> ItemEqualityType.compareItems(module.getLeft(), d, ItemEqualityType.NBT))) { + if (dependencyChain.stream().noneMatch(d -> ItemEquality.compareItems(module.getLeft(), d, ItemEquality.NBT))) { int amount = module.getRight().getCraftableAmount(module.getLeft(), this, unavailableConsumer, stack, dependencyChain); if (amount > 0) total += amount; diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/FilterModifierModuleItem.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/FilterModifierModuleItem.java deleted file mode 100644 index 28a27cf..0000000 --- a/src/main/java/de/ellpeck/prettypipes/pipe/modules/FilterModifierModuleItem.java +++ /dev/null @@ -1,42 +0,0 @@ -package de.ellpeck.prettypipes.pipe.modules; - -import de.ellpeck.prettypipes.items.IModule; -import de.ellpeck.prettypipes.items.ModuleItem; -import de.ellpeck.prettypipes.misc.ItemEqualityType; -import de.ellpeck.prettypipes.pipe.PipeTileEntity; -import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.world.World; - -import javax.annotation.Nullable; -import java.util.List; -import java.util.Set; -import java.util.function.BiFunction; - -public class FilterModifierModuleItem extends ModuleItem { - - public final ItemEqualityType type; - - public FilterModifierModuleItem(String name, ItemEqualityType type) { - super(name); - this.type = type; - this.setRegistryName(name); - } - - @Override - public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) { - return other != this; - } - - @Override - public boolean hasContainer(ItemStack module, PipeTileEntity tile) { - return false; - } - - @Override - public void addInformation(ItemStack stack, @Nullable World worldIn, List tooltip, ITooltipFlag flagIn) { - super.addInformation(stack, worldIn, tooltip, flagIn); - } -} diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/craft/CraftingModuleItem.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/craft/CraftingModuleItem.java index 8750856..8eed4bd 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/modules/craft/CraftingModuleItem.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/craft/CraftingModuleItem.java @@ -4,7 +4,7 @@ import de.ellpeck.prettypipes.Registry; import de.ellpeck.prettypipes.items.IModule; import de.ellpeck.prettypipes.items.ModuleItem; import de.ellpeck.prettypipes.items.ModuleTier; -import de.ellpeck.prettypipes.misc.ItemEqualityType; +import de.ellpeck.prettypipes.misc.ItemEquality; import de.ellpeck.prettypipes.misc.ItemFilter; import de.ellpeck.prettypipes.network.NetworkLocation; import de.ellpeck.prettypipes.network.NetworkLock; @@ -74,7 +74,7 @@ public class CraftingModuleItem extends ModuleItem { if (!tile.craftIngredientRequests.isEmpty()) { network.startProfile("crafting_ingredients"); NetworkLock request = tile.craftIngredientRequests.peek(); - ItemEqualityType[] equalityTypes = ItemFilter.getEqualityTypes(tile); + ItemEquality[] equalityTypes = ItemFilter.getEqualityTypes(tile); Pair dest = tile.getAvailableDestination(request.stack, true, true); if (dest != null) { ItemStack requestRemain = network.requestExistingItem(request.location, tile.getPos(), dest.getLeft(), request, dest.getRight(), equalityTypes); @@ -96,7 +96,7 @@ public class CraftingModuleItem extends ModuleItem { if (!tile.craftResultRequests.isEmpty()) { network.startProfile("crafting_results"); List items = network.getOrderedNetworkItems(tile.getPos()); - ItemEqualityType[] equalityTypes = ItemFilter.getEqualityTypes(tile); + ItemEquality[] equalityTypes = ItemFilter.getEqualityTypes(tile); for (Pair request : tile.craftResultRequests) { ItemStack remain = request.getRight().copy(); PipeTileEntity destPipe = network.getPipe(request.getLeft()); @@ -140,14 +140,14 @@ public class CraftingModuleItem extends ModuleItem { public int getCraftableAmount(ItemStack module, PipeTileEntity tile, Consumer unavailableConsumer, ItemStack stack, Stack dependencyChain) { PipeNetwork network = PipeNetwork.get(tile.getWorld()); List items = network.getOrderedNetworkItems(tile.getPos()); - ItemEqualityType[] equalityTypes = ItemFilter.getEqualityTypes(tile); + ItemEquality[] equalityTypes = ItemFilter.getEqualityTypes(tile); ItemStackHandler input = this.getInput(module); int craftable = 0; ItemStackHandler output = this.getOutput(module); for (int i = 0; i < output.getSlots(); i++) { ItemStack out = output.getStackInSlot(i); - if (!out.isEmpty() && ItemEqualityType.compareItems(out, stack, equalityTypes)) { + if (!out.isEmpty() && ItemEquality.compareItems(out, stack, equalityTypes)) { // figure out how many crafting operations we can actually do with the input items we have in the network int availableCrafts = CraftingTerminalTileEntity.getAvailableCrafts(tile, input.getSlots(), input::getStackInSlot, k -> true, s -> items, unavailableConsumer, addDependency(dependencyChain, module), equalityTypes); if (availableCrafts > 0) @@ -167,7 +167,7 @@ public class CraftingModuleItem extends ModuleItem { PipeNetwork network = PipeNetwork.get(tile.getWorld()); List items = network.getOrderedNetworkItems(tile.getPos()); - ItemEqualityType[] equalityTypes = ItemFilter.getEqualityTypes(tile); + ItemEquality[] equalityTypes = ItemFilter.getEqualityTypes(tile); int resultAmount = this.getResultAmountPerCraft(module, stack, equalityTypes); int requiredCrafts = MathHelper.ceil(stack.getCount() / (float) resultAmount); int toCraft = Math.min(craftableAmount, requiredCrafts); @@ -215,12 +215,12 @@ public class CraftingModuleItem extends ModuleItem { tag.put("output", output.serializeNBT()); } - private int getResultAmountPerCraft(ItemStack module, ItemStack stack, ItemEqualityType... equalityTypes) { + private int getResultAmountPerCraft(ItemStack module, ItemStack stack, ItemEquality... equalityTypes) { ItemStackHandler output = this.getOutput(module); int resultAmount = 0; for (int i = 0; i < output.getSlots(); i++) { ItemStack out = output.getStackInSlot(i); - if (ItemEqualityType.compareItems(stack, out, equalityTypes)) + if (ItemEquality.compareItems(stack, out, equalityTypes)) resultAmount += out.getCount(); } return resultAmount; diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/modifier/FilterModifierModuleContainer.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/modifier/FilterModifierModuleContainer.java new file mode 100644 index 0000000..eb5e6cb --- /dev/null +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/modifier/FilterModifierModuleContainer.java @@ -0,0 +1,38 @@ +package de.ellpeck.prettypipes.pipe.modules.modifier; + +import de.ellpeck.prettypipes.misc.ItemFilter; +import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.container.ContainerType; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; + +import javax.annotation.Nullable; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +public class FilterModifierModuleContainer extends AbstractPipeContainer { + + public FilterModifierModuleContainer(@Nullable ContainerType type, int id, PlayerEntity player, BlockPos pos, int moduleIndex) { + super(type, id, player, pos, moduleIndex); + } + + public List getTags() { + Set unsortedTags = new HashSet<>(); + for (ItemFilter filter : this.tile.getFilters()) { + for (int i = 0; i < filter.getSlots(); i++) { + ItemStack stack = filter.getStackInSlot(i); + unsortedTags.addAll(stack.getItem().getTags()); + } + } + return unsortedTags.stream().sorted().collect(Collectors.toList()); + } + + @Override + protected void addSlots() { + + } +} diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/modifier/FilterModifierModuleGui.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/modifier/FilterModifierModuleGui.java new file mode 100644 index 0000000..77cc505 --- /dev/null +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/modifier/FilterModifierModuleGui.java @@ -0,0 +1,138 @@ +package de.ellpeck.prettypipes.pipe.modules.modifier; + +import com.mojang.blaze3d.matrix.MatrixStack; +import de.ellpeck.prettypipes.packets.PacketButton; +import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui; +import net.minecraft.client.audio.SimpleSound; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.SoundEvents; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextFormatting; + +import java.util.ArrayList; +import java.util.List; + +public class FilterModifierModuleGui extends AbstractPipeGui { + private int scrollOffset; + private boolean isScrolling; + private List tags; + private final List tagButtons = new ArrayList<>(); + + public FilterModifierModuleGui(FilterModifierModuleContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) { + super(screenContainer, inv, titleIn); + } + + @Override + protected void drawGuiContainerBackgroundLayer(MatrixStack matrix, float partialTicks, int mouseX, int mouseY) { + super.drawGuiContainerBackgroundLayer(matrix, partialTicks, mouseX, mouseY); + this.blit(matrix, this.guiLeft + 7, this.guiTop + 32 + 15, 0, 196, 162, 60); + + for (Tag tag : this.tagButtons) + tag.draw(matrix, mouseX, mouseY); + + if (this.tags.size() >= 6) { + float percentage = this.scrollOffset / (float) (this.tags.size() - 5); + this.blit(matrix, this.guiLeft + 156, this.guiTop + 32 + 16 + (int) (percentage * (58 - 15)), 232, 241, 12, 15); + } else { + this.blit(matrix, this.guiLeft + 156, this.guiTop + 32 + 16, 244, 241, 12, 15); + } + } + + @Override + protected void init() { + super.init(); + this.tags = this.container.getTags(); + this.updateWidgets(); + } + + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + for (Tag tag : this.tagButtons) { + if (tag.onClicked(mouseX, mouseY, button)) + return true; + } + if (button == 0 && mouseX >= this.guiLeft + 156 && this.guiTop + mouseY >= 32 + 16 && mouseX < this.guiLeft + 156 + 12 && mouseY < this.guiTop + 32 + 16 + 58) { + this.isScrolling = true; + return true; + } + return super.mouseClicked(mouseX, mouseY, button); + } + + @Override + public boolean mouseReleased(double mouseX, double mouseY, int button) { + if (button == 0) + this.isScrolling = false; + return super.mouseReleased(mouseX, mouseY, button); + } + + @Override + public boolean mouseDragged(double mouseX, double mouseY, int i, double j, double k) { + if (this.isScrolling) { + float percentage = MathHelper.clamp(((float) mouseY - (this.guiTop + 32 + 18)) / (58 - 15), 0, 1); + int offset = (int) (percentage * (float) (this.tags.size() - 5)); + if (offset != this.scrollOffset) { + this.scrollOffset = offset; + this.updateWidgets(); + } + return true; + } + return super.mouseDragged(mouseX, mouseY, i, j, k); + } + + @Override + public boolean mouseScrolled(double x, double y, double scroll) { + if (this.tags.size() >= 6) { + int offset = MathHelper.clamp(this.scrollOffset - (int) Math.signum(scroll), 0, this.tags.size() - 5); + if (offset != this.scrollOffset) { + this.scrollOffset = offset; + this.updateWidgets(); + } + } + return true; + } + + private void updateWidgets() { + this.tagButtons.clear(); + for (int i = 0; i < 5; i++) { + if (i >= this.tags.size()) + break; + this.tagButtons.add(new Tag(this.tags.get(this.scrollOffset + i), this.guiLeft + 10, this.guiTop + 32 + 17 + i * 12)); + } + } + + private class Tag { + + private final ResourceLocation tag; + private final int x; + private final int y; + + public Tag(ResourceLocation tag, int x, int y) { + this.tag = tag; + this.x = x; + this.y = y; + } + + private void draw(MatrixStack matrix, double mouseX, double mouseY) { + int color = 4210752; + String text = this.tag.toString(); + if (mouseX >= this.x && mouseY >= this.y && mouseX < this.x + 140 && mouseY < this.y + 12) + color = 0xFFFFFF; + if (this.tag.equals(FilterModifierModuleItem.getFilterTag(FilterModifierModuleGui.this.container.moduleStack))) + text = TextFormatting.BOLD + text; + FilterModifierModuleGui.this.font.drawString(matrix, text, this.x, this.y, color); + FilterModifierModuleGui.this.getMinecraft().getTextureManager().bindTexture(TEXTURE); + } + + private boolean onClicked(double mouseX, double mouseY, int button) { + if (button != 0) + return false; + if (mouseX < this.x || mouseY < this.y || mouseX >= this.x + 140 || mouseY >= this.y + 12) + return false; + PacketButton.sendAndExecute(FilterModifierModuleGui.this.container.tile.getPos(), PacketButton.ButtonResult.TAG_FILTER, FilterModifierModuleGui.this.tags.indexOf(this.tag)); + FilterModifierModuleGui.this.getMinecraft().getSoundHandler().play(SimpleSound.master(SoundEvents.UI_BUTTON_CLICK, 1)); + return true; + } + } +} diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/modifier/FilterModifierModuleItem.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/modifier/FilterModifierModuleItem.java new file mode 100644 index 0000000..34a7a20 --- /dev/null +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/modifier/FilterModifierModuleItem.java @@ -0,0 +1,71 @@ +package de.ellpeck.prettypipes.pipe.modules.modifier; + +import de.ellpeck.prettypipes.Registry; +import de.ellpeck.prettypipes.items.IModule; +import de.ellpeck.prettypipes.items.ModuleItem; +import de.ellpeck.prettypipes.misc.ItemEquality; +import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; +import joptsimple.internal.Strings; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.world.World; + +import javax.annotation.Nullable; +import java.util.List; + +public class FilterModifierModuleItem extends ModuleItem { + + public final ItemEquality.Type type; + + public FilterModifierModuleItem(String name, ItemEquality.Type type) { + super(name); + this.type = type; + this.setRegistryName(name); + } + + @Override + public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) { + return other != this; + } + + @Override + public boolean hasContainer(ItemStack module, PipeTileEntity tile) { + return this.type == ItemEquality.Type.TAG; + } + + @Override + public AbstractPipeContainer getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) { + return new FilterModifierModuleContainer(Registry.filterModifierModuleContainer, windowId, player, tile.getPos(), moduleIndex); + } + + @Override + public void addInformation(ItemStack stack, @Nullable World worldIn, List tooltip, ITooltipFlag flagIn) { + super.addInformation(stack, worldIn, tooltip, flagIn); + } + + public ItemEquality getEqualityType(ItemStack stack) { + if (this.type == ItemEquality.Type.TAG) { + return ItemEquality.tag(getFilterTag(stack)); + } else { + return this.type.getDefaultInstance(); + } + } + + public static ResourceLocation getFilterTag(ItemStack stack) { + if (!stack.hasTag()) + return null; + String tag = stack.getTag().getString("filter_tag"); + if (Strings.isNullOrEmpty(tag)) + return null; + return new ResourceLocation(tag); + } + + public static void setFilterTag(ItemStack stack, ResourceLocation tag) { + stack.getOrCreateTag().putString("filter_tag", tag.toString()); + } +} diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/retrieval/RetrievalModuleItem.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/retrieval/RetrievalModuleItem.java index 22c8359..1c606bc 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/modules/retrieval/RetrievalModuleItem.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/retrieval/RetrievalModuleItem.java @@ -4,7 +4,7 @@ import de.ellpeck.prettypipes.Registry; import de.ellpeck.prettypipes.items.IModule; import de.ellpeck.prettypipes.items.ModuleItem; import de.ellpeck.prettypipes.items.ModuleTier; -import de.ellpeck.prettypipes.misc.ItemEqualityType; +import de.ellpeck.prettypipes.misc.ItemEquality; import de.ellpeck.prettypipes.misc.ItemFilter; import de.ellpeck.prettypipes.network.PipeNetwork; import de.ellpeck.prettypipes.pipe.PipeTileEntity; @@ -35,7 +35,7 @@ public class RetrievalModuleItem extends ModuleItem { return; PipeNetwork network = PipeNetwork.get(tile.getWorld()); - ItemEqualityType[] equalityTypes = ItemFilter.getEqualityTypes(tile); + ItemEquality[] equalityTypes = ItemFilter.getEqualityTypes(tile); // loop through filters to see which items to pull for (ItemFilter subFilter : tile.getFilters()) { for (int f = 0; f < subFilter.getSlots(); f++) { diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/stacksize/StackSizeModuleItem.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/stacksize/StackSizeModuleItem.java index beb7b42..e021680 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/modules/stacksize/StackSizeModuleItem.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/stacksize/StackSizeModuleItem.java @@ -3,7 +3,7 @@ package de.ellpeck.prettypipes.pipe.modules.stacksize; import de.ellpeck.prettypipes.Registry; import de.ellpeck.prettypipes.items.IModule; import de.ellpeck.prettypipes.items.ModuleItem; -import de.ellpeck.prettypipes.misc.ItemEqualityType; +import de.ellpeck.prettypipes.misc.ItemEquality; import de.ellpeck.prettypipes.pipe.PipeTileEntity; import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; import net.minecraft.entity.player.PlayerEntity; @@ -51,7 +51,7 @@ public class StackSizeModuleItem extends ModuleItem { ItemStack stored = destination.getStackInSlot(i); if (stored.isEmpty()) continue; - if (!ItemEqualityType.compareItems(stored, stack)) + if (!ItemEquality.compareItems(stored, stack)) continue; amount += stored.getCount(); if (amount >= max) diff --git a/src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalTileEntity.java b/src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalTileEntity.java index 8ddd6aa..e338b50 100644 --- a/src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalTileEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalTileEntity.java @@ -5,10 +5,8 @@ import com.google.common.collect.ListMultimap; import de.ellpeck.prettypipes.PrettyPipes; import de.ellpeck.prettypipes.Registry; import de.ellpeck.prettypipes.Utility; -import de.ellpeck.prettypipes.items.IModule; -import de.ellpeck.prettypipes.items.ModuleItem; import de.ellpeck.prettypipes.misc.EquatableItemStack; -import de.ellpeck.prettypipes.misc.ItemEqualityType; +import de.ellpeck.prettypipes.misc.ItemEquality; import de.ellpeck.prettypipes.network.NetworkItem; import de.ellpeck.prettypipes.network.NetworkLocation; import de.ellpeck.prettypipes.network.PipeNetwork; @@ -79,17 +77,17 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity { for (ItemStack stack : items) { int amount = 0; // check existing items - NetworkItem network = this.networkItems.get(new EquatableItemStack(stack, ItemEqualityType.NBT)); + NetworkItem network = this.networkItems.get(new EquatableItemStack(stack, ItemEquality.NBT)); if (network != null) { amount = network.getLocations().stream() - .mapToInt(l -> l.getItemAmount(this.world, stack, ItemEqualityType.NBT)) + .mapToInt(l -> l.getItemAmount(this.world, stack, ItemEquality.NBT)) .sum(); } // check craftables if (amount <= 0 && highestAmount <= 0) { PipeTileEntity pipe = this.getConnectedPipe(); if (pipe != null) - amount = PipeNetwork.get(this.world).getCraftableAmount(pipe.getPos(), null, stack, new Stack<>(), ItemEqualityType.NBT); + amount = PipeNetwork.get(this.world).getCraftableAmount(pipe.getPos(), null, stack, new Stack<>(), ItemEquality.NBT); } if (amount > highestAmount) { highestAmount = amount; @@ -119,7 +117,7 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity { int lowestAvailable = getAvailableCrafts(pipe, this.craftItems.getSlots(), i -> ItemHandlerHelper.copyStackWithSize(this.getRequestedCraftItem(i), 1), this::isGhostItem, s -> { NetworkItem item = this.networkItems.get(s); return item != null ? item.getLocations() : Collections.emptyList(); - }, onItemUnavailable(player), new Stack<>(), ItemEqualityType.NBT); + }, onItemUnavailable(player), new Stack<>(), ItemEquality.NBT); if (lowestAvailable > 0) { // if we're limiting the amount, pretend we only have that amount available if (maxAmount < lowestAvailable) @@ -196,7 +194,7 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity { return remain; } - public static int getAvailableCrafts(PipeTileEntity tile, int slots, Function inputFunction, Predicate isGhost, Function> locationsFunction, Consumer unavailableConsumer, Stack dependencyChain, ItemEqualityType... equalityTypes) { + public static int getAvailableCrafts(PipeTileEntity tile, int slots, Function inputFunction, Predicate isGhost, Function> locationsFunction, Consumer unavailableConsumer, Stack dependencyChain, ItemEquality... equalityTypes) { PipeNetwork network = PipeNetwork.get(tile.getWorld()); // the highest amount we can craft with the items we have int lowestAvailable = Integer.MAX_VALUE; diff --git a/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalTileEntity.java b/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalTileEntity.java index 952eda7..532814a 100644 --- a/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalTileEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalTileEntity.java @@ -4,7 +4,7 @@ import de.ellpeck.prettypipes.PrettyPipes; import de.ellpeck.prettypipes.Registry; import de.ellpeck.prettypipes.Utility; import de.ellpeck.prettypipes.misc.EquatableItemStack; -import de.ellpeck.prettypipes.misc.ItemEqualityType; +import de.ellpeck.prettypipes.misc.ItemEquality; import de.ellpeck.prettypipes.network.NetworkItem; import de.ellpeck.prettypipes.network.NetworkLocation; import de.ellpeck.prettypipes.network.NetworkLock; @@ -91,7 +91,7 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine if (!this.existingRequests.isEmpty()) { NetworkLock request = this.existingRequests.remove(); network.resolveNetworkLock(request); - network.requestExistingItem(request.location, pipe.getPos(), this.pos, request, request.stack, ItemEqualityType.NBT); + network.requestExistingItem(request.location, pipe.getPos(), this.pos, request, request.stack, ItemEquality.NBT); update = true; } } @@ -126,7 +126,7 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine PipeTileEntity pipe = this.getConnectedPipe(); if (pipe == null) return; - this.networkItems = this.collectItems(ItemEqualityType.NBT); + this.networkItems = this.collectItems(ItemEquality.NBT); if (playersToSync.length > 0) { List clientItems = this.networkItems.values().stream().map(NetworkItem::asStack).collect(Collectors.toList()); List clientCraftables = PipeNetwork.get(this.world).getAllCraftables(pipe.getPos()).stream().map(Pair::getRight).collect(Collectors.toList()); @@ -156,9 +156,9 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine } public int requestItemImpl(ItemStack stack, Consumer unavailableConsumer) { - NetworkItem item = this.networkItems.get(new EquatableItemStack(stack, ItemEqualityType.NBT)); + NetworkItem item = this.networkItems.get(new EquatableItemStack(stack, ItemEquality.NBT)); Collection locations = item == null ? Collections.emptyList() : item.getLocations(); - Pair, ItemStack> ret = requestItemLater(this.world, this.getConnectedPipe().getPos(), locations, unavailableConsumer, stack, new Stack<>(), ItemEqualityType.NBT); + Pair, ItemStack> ret = requestItemLater(this.world, this.getConnectedPipe().getPos(), locations, unavailableConsumer, stack, new Stack<>(), ItemEquality.NBT); this.existingRequests.addAll(ret.getLeft()); return stack.getCount() - ret.getRight().getCount(); } @@ -170,7 +170,7 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine .toArray(PlayerEntity[]::new); } - private Map collectItems(ItemEqualityType... equalityTypes) { + private Map collectItems(ItemEquality... equalityTypes) { PipeNetwork network = PipeNetwork.get(this.world); network.startProfile("terminal_collect_items"); PipeTileEntity pipe = this.getConnectedPipe(); @@ -269,7 +269,7 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine return true; } - public static Pair, ItemStack> requestItemLater(World world, BlockPos destPipe, Collection locations, Consumer unavailableConsumer, ItemStack stack, Stack dependencyChain, ItemEqualityType... equalityTypes) { + public static Pair, ItemStack> requestItemLater(World world, BlockPos destPipe, Collection locations, Consumer unavailableConsumer, ItemStack stack, Stack dependencyChain, ItemEquality... equalityTypes) { List requests = new ArrayList<>(); ItemStack remain = stack.copy(); PipeNetwork network = PipeNetwork.get(world); diff --git a/src/main/resources/assets/prettypipes/lang/en_us.json b/src/main/resources/assets/prettypipes/lang/en_us.json index 7e03564..a4ef008 100644 --- a/src/main/resources/assets/prettypipes/lang/en_us.json +++ b/src/main/resources/assets/prettypipes/lang/en_us.json @@ -43,7 +43,7 @@ "info.prettypipes.stack_size_module": "Limits the amount of items that can enter adjacent inventories\nAutomatically prevents over-sending", "info.prettypipes.damage_filter_modifier": "Causes any filter slots to filter by item damage", "info.prettypipes.nbt_filter_modifier": "Causes any filter slots to filter by item data (NBT)", - "info.prettypipes.tag_filter_modifier": "Causes any filter slots to filter by tags\n(Modern equivalent of the Ore Dictionary)", + "info.prettypipes.tag_filter_modifier": "Causes any filter slots to filter by tags\nTag can be chosen from items in filter slots", "info.prettypipes.mod_filter_modifier": "Causes any filter slots to filter by mod", "info.prettypipes.redstone_module": "Allows disabling the pipe with a redstone signal\nWorks for both extraction and retrieval", "info.prettypipes.item_terminal": "Allows viewing and requesting all items in a pipe network\nAlso has slots for putting items into the network", diff --git a/src/main/resources/assets/prettypipes/textures/gui/pipe.png b/src/main/resources/assets/prettypipes/textures/gui/pipe.png index 5d2260f..f4e58ea 100644 Binary files a/src/main/resources/assets/prettypipes/textures/gui/pipe.png and b/src/main/resources/assets/prettypipes/textures/gui/pipe.png differ