mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-25 04:58:34 +01:00
fixed pipes sharing filter and extraction modules not behaving correctly
closes #185
This commit is contained in:
parent
f34c89f914
commit
7d54b5d936
6 changed files with 30 additions and 17 deletions
|
@ -71,14 +71,14 @@ public class ItemFilter extends ItemStackHandler {
|
||||||
} else if (id == 1 && this.canPopulateFromInventories) {
|
} else if (id == 1 && this.canPopulateFromInventories) {
|
||||||
var changed = false;
|
var changed = false;
|
||||||
// populate filter from inventories
|
// populate filter from inventories
|
||||||
var filters = this.pipe.getFilters();
|
var filters = this.pipe.getFilters(null);
|
||||||
for (var direction : Direction.values()) {
|
for (var direction : Direction.values()) {
|
||||||
var handler = this.pipe.getItemHandler(direction);
|
var handler = this.pipe.getItemHandler(direction);
|
||||||
if (handler == null)
|
if (handler == null)
|
||||||
continue;
|
continue;
|
||||||
for (var i = 0; i < handler.getSlots(); i++) {
|
for (var i = 0; i < handler.getSlots(); i++) {
|
||||||
var stack = handler.getStackInSlot(i);
|
var stack = handler.getStackInSlot(i);
|
||||||
if (stack.isEmpty() || this.isFiltered(stack))
|
if (stack.isEmpty() || this.isFiltered(stack, null))
|
||||||
continue;
|
continue;
|
||||||
var copy = stack.copy();
|
var copy = stack.copy();
|
||||||
copy.setCount(1);
|
copy.setCount(1);
|
||||||
|
@ -97,14 +97,14 @@ public class ItemFilter extends ItemStackHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAllowed(ItemStack stack) {
|
public boolean isAllowed(ItemStack stack, Direction direction) {
|
||||||
return this.isFiltered(stack) == this.isWhitelist;
|
return this.isFiltered(stack, direction) == this.isWhitelist;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isFiltered(ItemStack stack) {
|
private boolean isFiltered(ItemStack stack, Direction direction) {
|
||||||
var types = ItemFilter.getEqualityTypes(this.pipe);
|
var types = ItemFilter.getEqualityTypes(this.pipe);
|
||||||
// also check if any filter increase modules have the item we need
|
// also check if any filter increase modules have the item we need
|
||||||
for (ItemStackHandler handler : this.pipe.getFilters()) {
|
for (ItemStackHandler handler : this.pipe.getFilters(direction)) {
|
||||||
for (var i = 0; i < handler.getSlots(); i++) {
|
for (var i = 0; i < handler.getSlots(); i++) {
|
||||||
var filter = handler.getStackInSlot(i);
|
var filter = handler.getStackInSlot(i);
|
||||||
if (filter.isEmpty())
|
if (filter.isEmpty())
|
||||||
|
@ -162,5 +162,7 @@ public class ItemFilter extends ItemStackHandler {
|
||||||
|
|
||||||
default void onFilterPopulated() {
|
default void onFilterPopulated() {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -382,10 +382,15 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
|
||||||
.filter(m -> m != null && m >= 0).findFirst().orElse(index);
|
.filter(m -> m != null && m >= 0).findFirst().orElse(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ItemFilter> getFilters() {
|
public List<ItemFilter> getFilters(Direction direction) {
|
||||||
return this.streamModules()
|
return this.streamModules().map(p -> {
|
||||||
.map(p -> p.getRight().getItemFilter(p.getLeft(), this))
|
if (direction != null) {
|
||||||
.filter(Objects::nonNull).collect(Collectors.toList());
|
var dir = p.getRight().getDirectionSelector(p.getLeft(), this);
|
||||||
|
if (dir != null && !dir.has(direction))
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return p.getRight().getItemFilter(p.getLeft(), this);
|
||||||
|
}).filter(Objects::nonNull).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class ExtractionModuleItem extends ModuleItem {
|
||||||
var stack = handler.extractItem(j, this.maxExtraction, true);
|
var stack = handler.extractItem(j, this.maxExtraction, true);
|
||||||
if (stack.isEmpty())
|
if (stack.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
if (!filter.isAllowed(stack))
|
if (!filter.isAllowed(stack, dir))
|
||||||
continue;
|
continue;
|
||||||
var remain = network.routeItem(tile.getBlockPos(), tile.getBlockPos().relative(dir), stack, this.preventOversending);
|
var remain = network.routeItem(tile.getBlockPos(), tile.getBlockPos().relative(dir), stack, this.preventOversending);
|
||||||
if (remain.getCount() != stack.getCount()) {
|
if (remain.getCount() != stack.getCount()) {
|
||||||
|
@ -90,4 +90,5 @@ public class ExtractionModuleItem extends ModuleItem {
|
||||||
public DirectionSelector getDirectionSelector(ItemStack module, PipeBlockEntity tile) {
|
public DirectionSelector getDirectionSelector(ItemStack module, PipeBlockEntity tile) {
|
||||||
return new DirectionSelector(module, tile);
|
return new DirectionSelector(module, tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class FilterModuleItem extends ModuleItem {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack, Direction direction, IItemHandler destination) {
|
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack, Direction direction, IItemHandler destination) {
|
||||||
return !this.getDirectionSelector(module, tile).has(direction) || this.getItemFilter(module, tile).isAllowed(stack);
|
return !this.getDirectionSelector(module, tile).has(direction) || this.getItemFilter(module, tile).isAllowed(stack, direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -56,4 +56,5 @@ public class FilterModuleItem extends ModuleItem {
|
||||||
public DirectionSelector getDirectionSelector(ItemStack module, PipeBlockEntity tile) {
|
public DirectionSelector getDirectionSelector(ItemStack module, PipeBlockEntity tile) {
|
||||||
return new DirectionSelector(module, tile);
|
return new DirectionSelector(module, tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class FilterModifierModuleContainer extends AbstractPipeContainer<FilterM
|
||||||
|
|
||||||
public List<ResourceLocation> getTags() {
|
public List<ResourceLocation> getTags() {
|
||||||
Set<ResourceLocation> unsortedTags = new HashSet<>();
|
Set<ResourceLocation> unsortedTags = new HashSet<>();
|
||||||
for (var filter : this.tile.getFilters()) {
|
for (var filter : this.tile.getFilters(null)) {
|
||||||
for (var i = 0; i < filter.getSlots(); i++) {
|
for (var i = 0; i < filter.getSlots(); i++) {
|
||||||
var stack = filter.getStackInSlot(i);
|
var stack = filter.getStackInSlot(i);
|
||||||
stack.getTags().forEach(t -> unsortedTags.add(t.location()));
|
stack.getTags().forEach(t -> unsortedTags.add(t.location()));
|
||||||
|
@ -33,4 +33,5 @@ public class FilterModifierModuleContainer extends AbstractPipeContainer<FilterM
|
||||||
protected void addSlots() {
|
protected void addSlots() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@ import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class RetrievalModuleItem extends ModuleItem {
|
public class RetrievalModuleItem extends ModuleItem {
|
||||||
|
|
||||||
private final int maxExtraction;
|
private final int maxExtraction;
|
||||||
|
@ -38,9 +40,9 @@ public class RetrievalModuleItem extends ModuleItem {
|
||||||
var network = PipeNetwork.get(tile.getLevel());
|
var network = PipeNetwork.get(tile.getLevel());
|
||||||
var equalityTypes = ItemFilter.getEqualityTypes(tile);
|
var equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||||
// loop through filters to see which items to pull
|
// loop through filters to see which items to pull
|
||||||
for (var subFilter : tile.getFilters()) {
|
Arrays.stream(directions).flatMap(d -> tile.getFilters(d).stream()).distinct().forEach(f -> {
|
||||||
for (var f = 0; f < subFilter.getSlots(); f++) {
|
for (var i = 0; i < f.getSlots(); i++) {
|
||||||
var filtered = subFilter.getStackInSlot(f);
|
var filtered = f.getStackInSlot(i);
|
||||||
if (filtered.isEmpty())
|
if (filtered.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
var copy = filtered.copy();
|
var copy = filtered.copy();
|
||||||
|
@ -54,7 +56,7 @@ public class RetrievalModuleItem extends ModuleItem {
|
||||||
if (network.requestItem(tile.getBlockPos(), dest.getLeft(), remain, equalityTypes).isEmpty())
|
if (network.requestItem(tile.getBlockPos(), dest.getLeft(), remain, equalityTypes).isEmpty())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -94,4 +96,5 @@ public class RetrievalModuleItem extends ModuleItem {
|
||||||
public DirectionSelector getDirectionSelector(ItemStack module, PipeBlockEntity tile) {
|
public DirectionSelector getDirectionSelector(ItemStack module, PipeBlockEntity tile) {
|
||||||
return new DirectionSelector(module, tile);
|
return new DirectionSelector(module, tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue