Compare commits

...

8 commits

Author SHA1 Message Date
Ell
4968ed9ef1 1.13.1 2022-07-04 13:25:10 +02:00
Ell
c1b6063ca4 merge fixes 2022-07-04 13:21:24 +02:00
Ell
69fa29aa46 Merge branch '1.18'
# Conflicts:
#	build.gradle
#	src/main/java/de/ellpeck/prettypipes/Registry.java
#	src/main/java/de/ellpeck/prettypipes/misc/ItemFilter.java
#	src/main/java/de/ellpeck/prettypipes/pipe/modules/retrieval/RetrievalModuleItem.java
#	src/main/java/de/ellpeck/prettypipes/terminal/containers/CraftingTerminalGui.java
#	src/main/java/de/ellpeck/prettypipes/terminal/containers/ItemTerminalGui.java
2022-07-04 13:17:48 +02:00
Ell
c1ccdd8486 1.12.5 2022-07-01 00:08:38 +02:00
Ell
626d8efe2e added default "all sides" option which restores the old behavior 2022-07-01 00:05:11 +02:00
Ell
1b061759e1 1.12.4 2022-06-30 16:38:03 +02:00
Ell
50c44df49f also added direction selector to the other modules 2022-06-30 16:35:01 +02:00
Ell
3451451c4f added direction selector system 2022-06-30 16:00:33 +02:00
20 changed files with 252 additions and 59 deletions

View file

@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'
version = '1.13.0'
version = '1.13.1'
group = 'de.ellpeck.prettypipes' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'PrettyPipes'

View file

@ -1,9 +1,11 @@
package de.ellpeck.prettypipes.items;
import de.ellpeck.prettypipes.misc.DirectionSelector;
import de.ellpeck.prettypipes.misc.ItemFilter;
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
@ -17,9 +19,9 @@ public interface IModule {
void tick(ItemStack module, PipeBlockEntity tile);
boolean canNetworkSee(ItemStack module, PipeBlockEntity tile);
boolean canNetworkSee(ItemStack module, PipeBlockEntity tile, Direction direction, IItemHandler handler);
boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack);
boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack, Direction direction, IItemHandler destination);
int getMaxInsertionAmount(ItemStack module, PipeBlockEntity tile, ItemStack stack, IItemHandler destination);
@ -44,4 +46,6 @@ public interface IModule {
Integer getCustomNextNode(ItemStack module, PipeBlockEntity tile, List<BlockPos> nodes, int index);
ItemFilter getItemFilter(ItemStack module, PipeBlockEntity tile);
DirectionSelector getDirectionSelector(ItemStack module, PipeBlockEntity tile);
}

View file

@ -2,10 +2,12 @@ package de.ellpeck.prettypipes.items;
import de.ellpeck.prettypipes.Registry;
import de.ellpeck.prettypipes.Utility;
import de.ellpeck.prettypipes.misc.DirectionSelector;
import de.ellpeck.prettypipes.misc.ItemFilter;
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
@ -45,12 +47,12 @@ public abstract class ModuleItem extends Item implements IModule {
}
@Override
public boolean canNetworkSee(ItemStack module, PipeBlockEntity tile) {
public boolean canNetworkSee(ItemStack module, PipeBlockEntity tile, Direction direction, IItemHandler handler) {
return true;
}
@Override
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack) {
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack, Direction direction, IItemHandler destination) {
return true;
}
@ -103,4 +105,9 @@ public abstract class ModuleItem extends Item implements IModule {
public ItemFilter getItemFilter(ItemStack module, PipeBlockEntity tile) {
return null;
}
@Override
public DirectionSelector getDirectionSelector(ItemStack module, PipeBlockEntity tile) {
return null;
}
}

View file

@ -0,0 +1,106 @@
package de.ellpeck.prettypipes.misc;
import de.ellpeck.prettypipes.PrettyPipes;
import de.ellpeck.prettypipes.packets.PacketButton;
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.gui.widget.ExtendedButton;
import org.apache.commons.lang3.ArrayUtils;
public class DirectionSelector {
private static final Direction[] ALL = ArrayUtils.addAll(Direction.values(), (Direction) null);
// null means old behavior, which is all directions
private Direction direction;
private boolean modified;
private final ItemStack stack;
private final PipeBlockEntity pipe;
public DirectionSelector(ItemStack stack, PipeBlockEntity pipe) {
this.stack = stack;
this.pipe = pipe;
this.load();
}
@OnlyIn(Dist.CLIENT)
public AbstractWidget getButton(int x, int y) {
return new ExtendedButton(x, y, 100, 20, Component.translatable("info." + PrettyPipes.ID + ".populate"), button ->
PacketButton.sendAndExecute(this.pipe.getBlockPos(), PacketButton.ButtonResult.DIRECTION_SELECTOR)) {
@Override
public Component getMessage() {
var pipe = DirectionSelector.this.pipe;
var dir = DirectionSelector.this.direction;
var msg = Component.translatable("dir." + PrettyPipes.ID + "." + (dir != null ? dir.getName() : "all"));
if (dir != null) {
var blockName = pipe.getItemHandler(dir) != null ? pipe.getLevel().getBlockState(pipe.getBlockPos().relative(dir)).getBlock().getName() : null;
if (blockName != null)
msg = msg.append(" (").append(blockName).append(")");
}
return msg;
}
};
}
public void onButtonPacket() {
var dir = this.direction;
do {
dir = DirectionSelector.ALL[(ArrayUtils.indexOf(DirectionSelector.ALL, dir) + 1) % DirectionSelector.ALL.length];
} while (!this.isDirectionValid(dir));
if (this.direction != dir) {
this.direction = dir;
this.modified = true;
}
}
public void save() {
if (!this.modified)
return;
this.modified = false;
var tag = new CompoundTag();
if (this.direction != null)
tag.putString("direction", this.direction.getName());
this.stack.getOrCreateTag().put("direction_selector", tag);
}
public void load() {
if (this.stack.hasTag()) {
var tag = this.stack.getTag().getCompound("direction_selector");
this.direction = Direction.byName(tag.getString("direction"));
}
}
public Direction[] directions() {
return this.direction != null ? new Direction[]{this.direction} : Direction.values();
}
public boolean has(Direction dir) {
return this.direction == null || this.direction == dir;
}
private boolean isDirectionValid(Direction dir) {
if (dir == null)
return true;
if (this.pipe.getItemHandler(dir) == null)
return false;
return this.pipe.streamModules()
.filter(p -> p.getLeft() != this.stack)
.map(p -> p.getRight().getDirectionSelector(p.getLeft(), this.pipe))
.noneMatch(p -> p != null && p.direction == dir);
}
public interface IDirectionContainer {
DirectionSelector getSelector();
}
}

View file

@ -48,17 +48,22 @@ public class ItemFilter extends ItemStackHandler {
}
@OnlyIn(Dist.CLIENT)
public List<AbstractWidget> getButtons(Screen gui, int x, int y) {
public List<AbstractWidget> getButtons(Screen gui, int x, int y, boolean rightAligned) {
List<AbstractWidget> buttons = new ArrayList<>();
if (this.canModifyWhitelist) {
Supplier<Component> whitelistText = () -> Component.translatable("info." + PrettyPipes.ID + "." + (this.isWhitelist ? "whitelist" : "blacklist"));
buttons.add(new Button(x, y, 70, 20, whitelistText.get(), button -> {
var whitelistText = (Supplier<String>) () -> "info." + PrettyPipes.ID + "." + (this.isWhitelist ? "whitelist" : "blacklist");
buttons.add(new Button(x - 20, y, 20, 20, Component.translatable(whitelistText.get()), button -> {
PacketButton.sendAndExecute(this.pipe.getBlockPos(), PacketButton.ButtonResult.FILTER_CHANGE, 0);
button.setMessage(whitelistText.get());
}));
button.setMessage(Component.translatable(whitelistText.get()));
}) {
@Override
public void renderToolTip(PoseStack matrix, int x, int y) {
gui.renderTooltip(matrix, Component.translatable(whitelistText.get() + ".description").withStyle(ChatFormatting.GRAY), x, y);
}
});
}
if (this.canPopulateFromInventories) {
buttons.add(new Button(x + 72, y, 70, 20, Component.translatable("info." + PrettyPipes.ID + ".populate"), button -> PacketButton.sendAndExecute(this.pipe.getBlockPos(), PacketButton.ButtonResult.FILTER_CHANGE, 1)) {
buttons.add(new Button(x - 42, y, 20, 20, Component.translatable("info." + PrettyPipes.ID + ".populate"), button -> PacketButton.sendAndExecute(this.pipe.getBlockPos(), PacketButton.ButtonResult.FILTER_CHANGE, 1)) {
@Override
public void renderToolTip(PoseStack matrix, int x, int y) {
gui.renderTooltip(matrix, Component.translatable("info." + PrettyPipes.ID + ".populate.description").withStyle(ChatFormatting.GRAY), x, y);

View file

@ -147,7 +147,7 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
if (!this.world.isLoaded(pipePos))
continue;
var pipe = this.getPipe(pipePos);
var dest = pipe.getAvailableDestination(stack, false, preventOversending);
var dest = pipe.getAvailableDestination(Direction.values(), stack, false, preventOversending);
if (dest == null || dest.getLeft().equals(startInventory))
continue;
var sup = (Function<Float, IPipeItem>) speed -> itemSupplier.apply(dest.getRight(), speed);
@ -324,11 +324,9 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
if (!this.world.isLoaded(dest))
continue;
var pipe = this.getPipe(dest);
if (!pipe.canNetworkSee())
continue;
for (var dir : Direction.values()) {
var handler = pipe.getItemHandler(dir);
if (handler == null)
if (handler == null || !pipe.canNetworkSee(dir, handler))
continue;
// check if this handler already exists (double-connected pipes, double chests etc.)
if (info.stream().anyMatch(l -> handler.equals(l.getItemHandler(this.world))))

View file

@ -26,6 +26,8 @@ import org.apache.logging.log4j.util.TriConsumer;
import javax.annotation.Nullable;
import java.util.function.Supplier;
import static de.ellpeck.prettypipes.misc.DirectionSelector.IDirectionContainer;
public class PacketButton {
private BlockPos pos;
@ -121,6 +123,10 @@ public class PacketButton {
TAG_FILTER((pos, data, player) -> {
var container = (FilterModifierModuleContainer) player.containerMenu;
FilterModifierModuleItem.setFilterTag(container.moduleStack, container.getTags().get(data[0]));
}),
DIRECTION_SELECTOR((pos, data, player) -> {
if (player.containerMenu instanceof IDirectionContainer filtered)
filtered.getSelector().onButtonPacket();
});
public final TriConsumer<BlockPos, int[], Player> action;

View file

@ -166,7 +166,7 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
}
public Pair<BlockPos, ItemStack> getAvailableDestinationOrConnectable(ItemStack stack, boolean force, boolean preventOversending) {
var dest = this.getAvailableDestination(stack, force, preventOversending);
var dest = this.getAvailableDestination(Direction.values(), stack, force, preventOversending);
if (dest != null)
return dest;
// if there's no available destination, try inserting into terminals etc.
@ -184,15 +184,15 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
return null;
}
public Pair<BlockPos, ItemStack> getAvailableDestination(ItemStack stack, boolean force, boolean preventOversending) {
public Pair<BlockPos, ItemStack> getAvailableDestination(Direction[] directions, ItemStack stack, boolean force, boolean preventOversending) {
if (!this.canWork())
return null;
if (!force && this.streamModules().anyMatch(m -> !m.getRight().canAcceptItem(m.getLeft(), this, stack)))
return null;
for (var dir : Direction.values()) {
for (var dir : directions) {
var handler = this.getItemHandler(dir);
if (handler == null)
continue;
if (!force && this.streamModules().anyMatch(m -> !m.getRight().canAcceptItem(m.getLeft(), this, stack, dir, handler)))
continue;
var remain = ItemHandlerHelper.insertItem(handler, stack, true);
// did we insert anything?
if (remain.getCount() == stack.getCount())
@ -314,13 +314,9 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
return null;
}
public boolean isConnectedInventory(Direction dir) {
return this.getItemHandler(dir) != null;
}
public boolean canHaveModules() {
for (var dir : Direction.values()) {
if (this.isConnectedInventory(dir))
if (this.getItemHandler(dir) != null)
return true;
var connectable = this.getPipeConnectable(dir);
if (connectable != null && connectable.allowsModules(this.worldPosition, dir))
@ -329,8 +325,8 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
return false;
}
public boolean canNetworkSee() {
return this.streamModules().allMatch(m -> m.getRight().canNetworkSee(m.getLeft(), this));
public boolean canNetworkSee(Direction direction, IItemHandler handler) {
return this.streamModules().allMatch(m -> m.getRight().canNetworkSee(m.getLeft(), this, direction, handler));
}
public Stream<Pair<ItemStack, IModule>> streamModules() {

View file

@ -13,10 +13,12 @@ import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
import de.ellpeck.prettypipes.terminal.CraftingTerminalBlockEntity;
import de.ellpeck.prettypipes.terminal.ItemTerminalBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemStackHandler;
import org.apache.commons.lang3.tuple.Pair;
@ -54,12 +56,12 @@ public class CraftingModuleItem extends ModuleItem {
}
@Override
public boolean canNetworkSee(ItemStack module, PipeBlockEntity tile) {
public boolean canNetworkSee(ItemStack module, PipeBlockEntity tile, Direction direction, IItemHandler handler) {
return false;
}
@Override
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack) {
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack, Direction direction, IItemHandler destination) {
return false;
}
@ -73,7 +75,7 @@ public class CraftingModuleItem extends ModuleItem {
network.startProfile("crafting_ingredients");
var request = tile.craftIngredientRequests.peek();
var equalityTypes = ItemFilter.getEqualityTypes(tile);
var dest = tile.getAvailableDestination(request.stack, true, true);
var dest = tile.getAvailableDestination(Direction.values(), request.stack, true, true);
if (dest != null) {
var requestRemain = network.requestExistingItem(request.location, tile.getBlockPos(), dest.getLeft(), request, dest.getRight(), equalityTypes);
network.resolveNetworkLock(request);

View file

@ -1,5 +1,7 @@
package de.ellpeck.prettypipes.pipe.modules.extraction;
import de.ellpeck.prettypipes.misc.DirectionSelector;
import de.ellpeck.prettypipes.misc.DirectionSelector.IDirectionContainer;
import de.ellpeck.prettypipes.misc.ItemFilter;
import de.ellpeck.prettypipes.misc.ItemFilter.IFilteredContainer;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
@ -9,9 +11,10 @@ import net.minecraft.world.inventory.MenuType;
import javax.annotation.Nullable;
public class ExtractionModuleContainer extends AbstractPipeContainer<ExtractionModuleItem> implements IFilteredContainer {
public class ExtractionModuleContainer extends AbstractPipeContainer<ExtractionModuleItem> implements IFilteredContainer, IDirectionContainer {
public ItemFilter filter;
public DirectionSelector directionSelector;
public ExtractionModuleContainer(@Nullable MenuType<?> type, int id, Player player, BlockPos pos, int moduleIndex) {
super(type, id, player, pos, moduleIndex);
@ -20,6 +23,8 @@ public class ExtractionModuleContainer extends AbstractPipeContainer<ExtractionM
@Override
protected void addSlots() {
this.filter = this.module.getItemFilter(this.moduleStack, this.tile);
this.directionSelector = this.module.getDirectionSelector(this.moduleStack, this.tile);
for (var slot : this.filter.getSlots((176 - this.module.filterSlots * 18) / 2 + 1, 17 + 32))
this.addSlot(slot);
}
@ -28,10 +33,16 @@ public class ExtractionModuleContainer extends AbstractPipeContainer<ExtractionM
public void removed(Player playerIn) {
super.removed(playerIn);
this.filter.save();
this.directionSelector.save();
}
@Override
public ItemFilter getFilter() {
return this.filter;
}
@Override
public DirectionSelector getSelector() {
return this.directionSelector;
}
}

View file

@ -13,7 +13,8 @@ public class ExtractionModuleGui extends AbstractPipeGui<ExtractionModuleContain
@Override
protected void init() {
super.init();
for (var widget : this.menu.filter.getButtons(this, this.leftPos + 7, this.topPos + 17 + 32 + 20))
for (var widget : this.menu.filter.getButtons(this, this.leftPos + this.imageWidth - 7, this.topPos + 17 + 32 + 20, true))
this.addRenderableWidget(widget);
this.addRenderableWidget(this.menu.directionSelector.getButton(this.leftPos + 7, this.topPos + 17 + 32 + 20));
}
}

View file

@ -4,6 +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.DirectionSelector;
import de.ellpeck.prettypipes.misc.ItemFilter;
import de.ellpeck.prettypipes.network.PipeNetwork;
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
@ -12,6 +13,7 @@ import net.minecraft.core.Direction;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
public class ExtractionModuleItem extends ModuleItem {
@ -33,12 +35,12 @@ public class ExtractionModuleItem extends ModuleItem {
if (!tile.shouldWorkNow(this.speed) || !tile.canWork())
return;
var filter = this.getItemFilter(module, tile);
var network = PipeNetwork.get(tile.getLevel());
for (var dir : Direction.values()) {
var dirSelector = this.getDirectionSelector(module, tile);
for (var dir : dirSelector.directions()) {
var handler = tile.getItemHandler(dir);
if (handler == null)
continue;
var network = PipeNetwork.get(tile.getLevel());
for (var j = 0; j < handler.getSlots(); j++) {
var stack = handler.extractItem(j, this.maxExtraction, true);
if (stack.isEmpty())
@ -55,13 +57,13 @@ public class ExtractionModuleItem extends ModuleItem {
}
@Override
public boolean canNetworkSee(ItemStack module, PipeBlockEntity tile) {
return false;
public boolean canNetworkSee(ItemStack module, PipeBlockEntity tile, Direction direction, IItemHandler handler) {
return !this.getDirectionSelector(module, tile).has(direction);
}
@Override
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack) {
return false;
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack, Direction direction, IItemHandler destination) {
return !this.getDirectionSelector(module, tile).has(direction);
}
@Override
@ -83,4 +85,9 @@ public class ExtractionModuleItem extends ModuleItem {
public ItemFilter getItemFilter(ItemStack module, PipeBlockEntity tile) {
return new ItemFilter(this.filterSlots, module, tile);
}
@Override
public DirectionSelector getDirectionSelector(ItemStack module, PipeBlockEntity tile) {
return new DirectionSelector(module, tile);
}
}

View file

@ -1,5 +1,7 @@
package de.ellpeck.prettypipes.pipe.modules.insertion;
import de.ellpeck.prettypipes.misc.DirectionSelector;
import de.ellpeck.prettypipes.misc.DirectionSelector.IDirectionContainer;
import de.ellpeck.prettypipes.misc.ItemFilter;
import de.ellpeck.prettypipes.misc.ItemFilter.IFilteredContainer;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
@ -9,9 +11,10 @@ import net.minecraft.world.inventory.MenuType;
import javax.annotation.Nullable;
public class FilterModuleContainer extends AbstractPipeContainer<FilterModuleItem> implements IFilteredContainer {
public class FilterModuleContainer extends AbstractPipeContainer<FilterModuleItem> implements IFilteredContainer, IDirectionContainer {
public ItemFilter filter;
public DirectionSelector directionSelector;
public FilterModuleContainer(@Nullable MenuType<?> type, int id, Player player, BlockPos pos, int moduleIndex) {
super(type, id, player, pos, moduleIndex);
@ -26,6 +29,8 @@ public class FilterModuleContainer extends AbstractPipeContainer<FilterModuleIte
@Override
protected void addSlots() {
this.filter = this.module.getItemFilter(this.moduleStack, this.tile);
this.directionSelector = this.module.getDirectionSelector(this.moduleStack, this.tile);
for (var slot : this.filter.getSlots((176 - Math.min(this.module.filterSlots, 9) * 18) / 2 + 1, 17 + 32))
this.addSlot(slot);
}
@ -34,10 +39,17 @@ public class FilterModuleContainer extends AbstractPipeContainer<FilterModuleIte
public void removed(Player playerIn) {
super.removed(playerIn);
this.filter.save();
this.directionSelector.save();
}
@Override
public ItemFilter getFilter() {
return this.filter;
}
@Override
public DirectionSelector getSelector() {
return this.directionSelector;
}
}

View file

@ -14,7 +14,9 @@ public class FilterModuleGui extends AbstractPipeGui<FilterModuleContainer> {
@Override
protected void init() {
super.init();
for (var widget : this.menu.filter.getButtons(this, this.leftPos + 7, this.topPos + 17 + 32 + 18 * Mth.ceil(this.menu.filter.getSlots() / 9F) + 2))
var buttonsY = this.topPos + 17 + 32 + 18 * Mth.ceil(this.menu.filter.getSlots() / 9F) + 2;
for (var widget : this.menu.filter.getButtons(this, this.leftPos + this.imageWidth - 7, buttonsY, true))
this.addRenderableWidget(widget);
this.addRenderableWidget(this.menu.directionSelector.getButton(this.leftPos + 7, buttonsY));
}
}

View file

@ -4,12 +4,15 @@ 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.DirectionSelector;
import de.ellpeck.prettypipes.misc.ItemFilter;
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
public class FilterModuleItem extends ModuleItem {
@ -23,9 +26,8 @@ public class FilterModuleItem extends ModuleItem {
}
@Override
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack) {
var filter = this.getItemFilter(module, tile);
return filter.isAllowed(stack);
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);
}
@Override
@ -49,4 +51,9 @@ public class FilterModuleItem extends ModuleItem {
filter.canPopulateFromInventories = this.canPopulateFromInventories;
return filter;
}
@Override
public DirectionSelector getDirectionSelector(ItemStack module, PipeBlockEntity tile) {
return new DirectionSelector(module, tile);
}
}

View file

@ -1,5 +1,7 @@
package de.ellpeck.prettypipes.pipe.modules.retrieval;
import de.ellpeck.prettypipes.misc.DirectionSelector;
import de.ellpeck.prettypipes.misc.DirectionSelector.IDirectionContainer;
import de.ellpeck.prettypipes.misc.ItemFilter;
import de.ellpeck.prettypipes.misc.ItemFilter.IFilteredContainer;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
@ -9,9 +11,10 @@ import net.minecraft.world.inventory.MenuType;
import javax.annotation.Nullable;
public class RetrievalModuleContainer extends AbstractPipeContainer<RetrievalModuleItem> implements IFilteredContainer {
public class RetrievalModuleContainer extends AbstractPipeContainer<RetrievalModuleItem> implements IFilteredContainer, IDirectionContainer {
public ItemFilter filter;
public DirectionSelector directionSelector;
public RetrievalModuleContainer(@Nullable MenuType<?> type, int id, Player player, BlockPos pos, int moduleIndex) {
super(type, id, player, pos, moduleIndex);
@ -20,6 +23,8 @@ public class RetrievalModuleContainer extends AbstractPipeContainer<RetrievalMod
@Override
protected void addSlots() {
this.filter = this.module.getItemFilter(this.moduleStack, this.tile);
this.directionSelector = this.module.getDirectionSelector(this.moduleStack, this.tile);
for (var slot : this.filter.getSlots((176 - this.module.filterSlots * 18) / 2 + 1, 17 + 32))
this.addSlot(slot);
}
@ -28,10 +33,16 @@ public class RetrievalModuleContainer extends AbstractPipeContainer<RetrievalMod
public void removed(Player playerIn) {
super.removed(playerIn);
this.filter.save();
this.directionSelector.save();
}
@Override
public ItemFilter getFilter() {
return this.filter;
}
@Override
public DirectionSelector getSelector() {
return this.directionSelector;
}
}

View file

@ -13,7 +13,8 @@ public class RetrievalModuleGui extends AbstractPipeGui<RetrievalModuleContainer
@Override
protected void init() {
super.init();
for (var widget : this.menu.filter.getButtons(this, this.leftPos + 7, this.topPos + 17 + 32 + 20))
for (var widget : this.menu.filter.getButtons(this, this.leftPos + this.imageWidth - 7, this.topPos + 17 + 32 + 20, true))
this.addRenderableWidget(widget);
this.addRenderableWidget(this.menu.directionSelector.getButton(this.leftPos + 7, this.topPos + 17 + 32 + 20));
}
}

View file

@ -4,13 +4,16 @@ 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.DirectionSelector;
import de.ellpeck.prettypipes.misc.ItemFilter;
import de.ellpeck.prettypipes.network.PipeNetwork;
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
public class RetrievalModuleItem extends ModuleItem {
@ -31,8 +34,8 @@ public class RetrievalModuleItem extends ModuleItem {
public void tick(ItemStack module, PipeBlockEntity tile) {
if (!tile.shouldWorkNow(this.speed) || !tile.canWork())
return;
var directions = this.getDirectionSelector(module, tile).directions();
var network = PipeNetwork.get(tile.getLevel());
var equalityTypes = ItemFilter.getEqualityTypes(tile);
// loop through filters to see which items to pull
for (var subFilter : tile.getFilters()) {
@ -42,8 +45,8 @@ public class RetrievalModuleItem extends ModuleItem {
continue;
var copy = filtered.copy();
copy.setCount(this.maxExtraction);
var dest = tile.getAvailableDestination(copy, true, this.preventOversending);
if (dest == null)
var dest = tile.getAvailableDestination(directions, copy, true, this.preventOversending);
if (dest.getRight().isEmpty())
continue;
var remain = dest.getRight().copy();
// are we already waiting for crafting results? If so, don't request those again
@ -55,13 +58,13 @@ public class RetrievalModuleItem extends ModuleItem {
}
@Override
public boolean canNetworkSee(ItemStack module, PipeBlockEntity tile) {
return false;
public boolean canNetworkSee(ItemStack module, PipeBlockEntity tile, Direction direction, IItemHandler handler) {
return !this.getDirectionSelector(module, tile).has(direction);
}
@Override
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack) {
return false;
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack, Direction direction, IItemHandler destination) {
return !this.getDirectionSelector(module, tile).has(direction);
}
@Override
@ -86,4 +89,9 @@ public class RetrievalModuleItem extends ModuleItem {
filter.isWhitelist = true;
return filter;
}
@Override
public DirectionSelector getDirectionSelector(ItemStack module, PipeBlockEntity tile) {
return new DirectionSelector(module, tile);
}
}

View file

@ -89,7 +89,7 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
this.minusButton.active = false;
this.requestButton = this.addRenderableWidget(new Button(this.leftPos + this.getXOffset() + 95 - 7 - 25, this.topPos + 115, 50, 20, Component.translatable("info." + PrettyPipes.ID + ".request"), button -> {
var widget = this.streamWidgets().filter(w -> w.selected).findFirst();
if (widget.isEmpty())
if (!widget.isPresent())
return;
var stack = widget.get().stack.copy();
stack.setCount(1);

View file

@ -62,11 +62,13 @@
"container.prettypipes.item_terminal": "Item Terminal",
"container.prettypipes.crafting_terminal": "Crafting Terminal",
"container.prettypipes.pressurizer": "Pipe Pressurizer",
"info.prettypipes.whitelist": "Allowed",
"info.prettypipes.blacklist": "Disallowed",
"info.prettypipes.whitelist": "\u00A72A",
"info.prettypipes.blacklist": "\u00A74D",
"info.prettypipes.whitelist.description": "Items in filter slots are allowed",
"info.prettypipes.blacklist.description": "Items in filter slots are disallowed",
"info.prettypipes.shift": "Hold Shift for info",
"info.prettypipes.populate": "Populate",
"info.prettypipes.populate.description": "Filters items from adjacent inventories",
"info.prettypipes.populate": "P",
"info.prettypipes.populate.description": "Populate filter slots with items from adjacent inventories",
"info.prettypipes.max_stack_size": "Maximum item amount",
"info.prettypipes.limit_to_max_on": "Limit to one stack",
"info.prettypipes.limit_to_max_off": "Don't limit to one stack",
@ -88,5 +90,12 @@
"info.prettypipes.cancel_all": "Cancel",
"info.prettypipes.cancel_all.desc": "Stops waiting for current crafting outputs\nDoesn't remove inputs from blocks",
"info.prettypipes.no_pipe_connected": "The terminal needs to be connected to a pipe network",
"info.prettypipes.too_many_pipes_connected": "The terminal can only be connected to a single pipe at a time"
"info.prettypipes.too_many_pipes_connected": "The terminal can only be connected to a single pipe at a time",
"dir.prettypipes.up": "Up",
"dir.prettypipes.down": "Down",
"dir.prettypipes.north": "North",
"dir.prettypipes.east": "East",
"dir.prettypipes.south": "South",
"dir.prettypipes.west": "West",
"dir.prettypipes.all": "All Sides"
}