diff --git a/src/main/java/de/ellpeck/prettypipes/items/IModule.java b/src/main/java/de/ellpeck/prettypipes/items/IModule.java index ff77258..9c5ee49 100644 --- a/src/main/java/de/ellpeck/prettypipes/items/IModule.java +++ b/src/main/java/de/ellpeck/prettypipes/items/IModule.java @@ -1,5 +1,6 @@ package de.ellpeck.prettypipes.items; +import de.ellpeck.prettypipes.misc.ItemFilter; import de.ellpeck.prettypipes.pipe.PipeTileEntity; import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; import net.minecraft.entity.player.PlayerEntity; @@ -41,4 +42,6 @@ public interface IModule { ItemStack craft(ItemStack module, PipeTileEntity tile, BlockPos destPipe, Consumer unavailableConsumer, ItemStack stack, Stack dependencyChain); Integer getCustomNextNode(ItemStack module, PipeTileEntity tile, List nodes, int index); + + ItemFilter getItemFilter(ItemStack module, PipeTileEntity tile); } diff --git a/src/main/java/de/ellpeck/prettypipes/items/ModuleItem.java b/src/main/java/de/ellpeck/prettypipes/items/ModuleItem.java index 60fae92..629323d 100644 --- a/src/main/java/de/ellpeck/prettypipes/items/ModuleItem.java +++ b/src/main/java/de/ellpeck/prettypipes/items/ModuleItem.java @@ -2,6 +2,7 @@ package de.ellpeck.prettypipes.items; import de.ellpeck.prettypipes.Registry; import de.ellpeck.prettypipes.Utility; +import de.ellpeck.prettypipes.misc.ItemFilter; import de.ellpeck.prettypipes.pipe.PipeTileEntity; import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; import net.minecraft.client.util.ITooltipFlag; @@ -98,4 +99,9 @@ public abstract class ModuleItem extends Item implements IModule { public Integer getCustomNextNode(ItemStack module, PipeTileEntity tile, List nodes, int index) { return null; } + + @Override + public ItemFilter getItemFilter(ItemStack module, PipeTileEntity tile) { + return null; + } } diff --git a/src/main/java/de/ellpeck/prettypipes/misc/ItemFilter.java b/src/main/java/de/ellpeck/prettypipes/misc/ItemFilter.java index fe99ad1..d1ecbc6 100644 --- a/src/main/java/de/ellpeck/prettypipes/misc/ItemFilter.java +++ b/src/main/java/de/ellpeck/prettypipes/misc/ItemFilter.java @@ -5,7 +5,6 @@ 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.filter.FilterIncreaseModuleItem; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.Widget; import net.minecraft.client.gui.widget.button.Button; @@ -25,7 +24,6 @@ import org.apache.commons.lang3.tuple.Pair; import java.util.ArrayList; import java.util.List; import java.util.function.Supplier; -import java.util.stream.Collectors; public class ItemFilter extends ItemStackHandler { @@ -80,7 +78,7 @@ public class ItemFilter extends ItemStackHandler { this.save(); } else if (id == 1 && this.canPopulateFromInventories) { // populate filter from inventories - List filters = this.getAllFilters(); + List filters = this.pipe.getFilters(); for (Direction direction : Direction.values()) { IItemHandler handler = this.pipe.getItemHandler(direction); if (handler == null) @@ -110,7 +108,7 @@ public class ItemFilter extends ItemStackHandler { private boolean isFiltered(ItemStack stack) { ItemEqualityType[] types = getEqualityTypes(this.pipe); // also check if any filter increase modules have the item we need - for (ItemStackHandler handler : this.getAllFilters()) { + for (ItemStackHandler handler : this.pipe.getFilters()) { for (int i = 0; i < handler.getSlots(); i++) { ItemStack filter = handler.getStackInSlot(i); if (filter.isEmpty()) @@ -122,16 +120,6 @@ public class ItemFilter extends ItemStackHandler { return false; } - public List getAllFilters() { - List filters = this.pipe.streamModules() - .filter(p -> p.getRight() instanceof FilterIncreaseModuleItem) - .map(p -> new ItemFilter(18, p.getLeft(), this.pipe)) - .collect(Collectors.toList()); - // add ourselves to the front - filters.add(0, this); - return filters; - } - public void save() { if (this.modified) { this.stack.getOrCreateTag().put("filter", this.serializeNBT()); diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java b/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java index 2f68aa3..01d2818 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java @@ -5,6 +5,7 @@ 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.ItemFilter; import de.ellpeck.prettypipes.network.NetworkLock; import de.ellpeck.prettypipes.network.PipeNetwork; import de.ellpeck.prettypipes.pipe.containers.MainPipeContainer; @@ -406,6 +407,12 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide .filter(Objects::nonNull).findFirst().orElse(index); } + public List getFilters() { + return this.streamModules() + .map(p -> p.getRight().getItemFilter(p.getLeft(), this)) + .filter(Objects::nonNull).collect(Collectors.toList()); + } + @Override public void remove() { super.remove(); diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/extraction/ExtractionModuleContainer.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/extraction/ExtractionModuleContainer.java index ea015a8..fe5a10d 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/modules/extraction/ExtractionModuleContainer.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/extraction/ExtractionModuleContainer.java @@ -20,7 +20,7 @@ public class ExtractionModuleContainer extends AbstractPipeContainer getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) { return new ExtractionModuleContainer(Registry.extractionModuleContainer, windowId, player, tile.getPos(), moduleIndex); } + + @Override + public ItemFilter getItemFilter(ItemStack module, PipeTileEntity tile) { + return new ItemFilter(this.filterSlots, module, tile); + } } diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/filter/FilterIncreaseModuleContainer.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/filter/FilterIncreaseModuleContainer.java index 10cd975..c8827cd 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/modules/filter/FilterIncreaseModuleContainer.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/filter/FilterIncreaseModuleContainer.java @@ -1,13 +1,11 @@ package de.ellpeck.prettypipes.pipe.modules.filter; -import de.ellpeck.prettypipes.misc.FilterSlot; 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.inventory.container.Slot; import net.minecraft.util.math.BlockPos; -import net.minecraftforge.items.ItemStackHandler; public class FilterIncreaseModuleContainer extends AbstractPipeContainer implements ItemFilter.IFilteredContainer { @@ -19,8 +17,7 @@ public class FilterIncreaseModuleContainer extends AbstractPipeContainer getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) { return new FilterIncreaseModuleContainer(Registry.filterIncreaseModuleContainer, windowId, player, tile.getPos(), moduleIndex); } + + @Override + public ItemFilter getItemFilter(ItemStack module, PipeTileEntity tile) { + ItemFilter filter = new ItemFilter(18, module, tile); + filter.canModifyWhitelist = false; + return filter; + } } diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/insertion/FilterModuleContainer.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/insertion/FilterModuleContainer.java index efb358e..74d4815 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/modules/insertion/FilterModuleContainer.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/insertion/FilterModuleContainer.java @@ -20,8 +20,7 @@ public class FilterModuleContainer extends AbstractPipeContainer getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) { return new FilterModuleContainer(Registry.filterModuleContainer, windowId, player, tile.getPos(), moduleIndex); } + + @Override + public ItemFilter getItemFilter(ItemStack module, PipeTileEntity tile) { + ItemFilter filter = new ItemFilter(this.filterSlots, module, tile); + filter.canPopulateFromInventories = this.canPopulateFromInventories; + return filter; + } } diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/retrieval/RetrievalModuleContainer.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/retrieval/RetrievalModuleContainer.java index da756c2..b1a8159 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/modules/retrieval/RetrievalModuleContainer.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/retrieval/RetrievalModuleContainer.java @@ -20,8 +20,7 @@ public class RetrievalModuleContainer extends AbstractPipeContainer getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) { return new RetrievalModuleContainer(Registry.retrievalModuleContainer, windowId, player, tile.getPos(), moduleIndex); } + + @Override + public ItemFilter getItemFilter(ItemStack module, PipeTileEntity tile) { + ItemFilter filter = new ItemFilter(this.filterSlots, module, tile); + filter.canModifyWhitelist = false; + filter.isWhitelist = true; + return filter; + } }