Compare commits

..

No commits in common. "4968ed9ef176006c0e4a3fe9b6136013bd8f1376" and "f8c8842fa96b9ce43cb26d8933512f2d1dd76eb3" have entirely different histories.

20 changed files with 59 additions and 252 deletions

View file

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

View file

@ -1,11 +1,9 @@
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;
@ -19,9 +17,9 @@ public interface IModule {
void tick(ItemStack module, PipeBlockEntity tile);
boolean canNetworkSee(ItemStack module, PipeBlockEntity tile, Direction direction, IItemHandler handler);
boolean canNetworkSee(ItemStack module, PipeBlockEntity tile);
boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack, Direction direction, IItemHandler destination);
boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack);
int getMaxInsertionAmount(ItemStack module, PipeBlockEntity tile, ItemStack stack, IItemHandler destination);
@ -46,6 +44,4 @@ 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,12 +2,10 @@ 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;
@ -47,12 +45,12 @@ public abstract class ModuleItem extends Item implements IModule {
}
@Override
public boolean canNetworkSee(ItemStack module, PipeBlockEntity tile, Direction direction, IItemHandler handler) {
public boolean canNetworkSee(ItemStack module, PipeBlockEntity tile) {
return true;
}
@Override
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack, Direction direction, IItemHandler destination) {
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack) {
return true;
}
@ -105,9 +103,4 @@ 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

@ -1,106 +0,0 @@
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,22 +48,17 @@ public class ItemFilter extends ItemStackHandler {
}
@OnlyIn(Dist.CLIENT)
public List<AbstractWidget> getButtons(Screen gui, int x, int y, boolean rightAligned) {
public List<AbstractWidget> getButtons(Screen gui, int x, int y) {
List<AbstractWidget> buttons = new ArrayList<>();
if (this.canModifyWhitelist) {
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 -> {
Supplier<Component> whitelistText = () -> Component.translatable("info." + PrettyPipes.ID + "." + (this.isWhitelist ? "whitelist" : "blacklist"));
buttons.add(new Button(x, y, 70, 20, whitelistText.get(), button -> {
PacketButton.sendAndExecute(this.pipe.getBlockPos(), PacketButton.ButtonResult.FILTER_CHANGE, 0);
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);
}
});
button.setMessage(whitelistText.get());
}));
}
if (this.canPopulateFromInventories) {
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)) {
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)) {
@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(Direction.values(), stack, false, preventOversending);
var dest = pipe.getAvailableDestination(stack, false, preventOversending);
if (dest == null || dest.getLeft().equals(startInventory))
continue;
var sup = (Function<Float, IPipeItem>) speed -> itemSupplier.apply(dest.getRight(), speed);
@ -324,9 +324,11 @@ 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 || !pipe.canNetworkSee(dir, handler))
if (handler == null)
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,8 +26,6 @@ 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;
@ -123,10 +121,6 @@ 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(Direction.values(), stack, force, preventOversending);
var dest = this.getAvailableDestination(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(Direction[] directions, ItemStack stack, boolean force, boolean preventOversending) {
public Pair<BlockPos, ItemStack> getAvailableDestination(ItemStack stack, boolean force, boolean preventOversending) {
if (!this.canWork())
return null;
for (var dir : directions) {
if (!force && this.streamModules().anyMatch(m -> !m.getRight().canAcceptItem(m.getLeft(), this, stack)))
return null;
for (var dir : Direction.values()) {
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,9 +314,13 @@ 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.getItemHandler(dir) != null)
if (this.isConnectedInventory(dir))
return true;
var connectable = this.getPipeConnectable(dir);
if (connectable != null && connectable.allowsModules(this.worldPosition, dir))
@ -325,8 +329,8 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
return false;
}
public boolean canNetworkSee(Direction direction, IItemHandler handler) {
return this.streamModules().allMatch(m -> m.getRight().canNetworkSee(m.getLeft(), this, direction, handler));
public boolean canNetworkSee() {
return this.streamModules().allMatch(m -> m.getRight().canNetworkSee(m.getLeft(), this));
}
public Stream<Pair<ItemStack, IModule>> streamModules() {

View file

@ -13,12 +13,10 @@ 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;
@ -56,12 +54,12 @@ public class CraftingModuleItem extends ModuleItem {
}
@Override
public boolean canNetworkSee(ItemStack module, PipeBlockEntity tile, Direction direction, IItemHandler handler) {
public boolean canNetworkSee(ItemStack module, PipeBlockEntity tile) {
return false;
}
@Override
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack, Direction direction, IItemHandler destination) {
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack) {
return false;
}
@ -75,7 +73,7 @@ public class CraftingModuleItem extends ModuleItem {
network.startProfile("crafting_ingredients");
var request = tile.craftIngredientRequests.peek();
var equalityTypes = ItemFilter.getEqualityTypes(tile);
var dest = tile.getAvailableDestination(Direction.values(), request.stack, true, true);
var dest = tile.getAvailableDestination(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,7 +1,5 @@
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;
@ -11,10 +9,9 @@ import net.minecraft.world.inventory.MenuType;
import javax.annotation.Nullable;
public class ExtractionModuleContainer extends AbstractPipeContainer<ExtractionModuleItem> implements IFilteredContainer, IDirectionContainer {
public class ExtractionModuleContainer extends AbstractPipeContainer<ExtractionModuleItem> implements IFilteredContainer {
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);
@ -23,8 +20,6 @@ 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);
}
@ -33,16 +28,10 @@ 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,8 +13,7 @@ public class ExtractionModuleGui extends AbstractPipeGui<ExtractionModuleContain
@Override
protected void init() {
super.init();
for (var widget : this.menu.filter.getButtons(this, this.leftPos + this.imageWidth - 7, this.topPos + 17 + 32 + 20, true))
for (var widget : this.menu.filter.getButtons(this, this.leftPos + 7, this.topPos + 17 + 32 + 20))
this.addRenderableWidget(widget);
this.addRenderableWidget(this.menu.directionSelector.getButton(this.leftPos + 7, this.topPos + 17 + 32 + 20));
}
}

View file

@ -4,7 +4,6 @@ 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;
@ -13,7 +12,6 @@ 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 {
@ -35,12 +33,12 @@ public class ExtractionModuleItem extends ModuleItem {
if (!tile.shouldWorkNow(this.speed) || !tile.canWork())
return;
var filter = this.getItemFilter(module, tile);
var dirSelector = this.getDirectionSelector(module, tile);
for (var dir : dirSelector.directions()) {
var network = PipeNetwork.get(tile.getLevel());
for (var dir : Direction.values()) {
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())
@ -57,13 +55,13 @@ public class ExtractionModuleItem extends ModuleItem {
}
@Override
public boolean canNetworkSee(ItemStack module, PipeBlockEntity tile, Direction direction, IItemHandler handler) {
return !this.getDirectionSelector(module, tile).has(direction);
public boolean canNetworkSee(ItemStack module, PipeBlockEntity tile) {
return false;
}
@Override
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack, Direction direction, IItemHandler destination) {
return !this.getDirectionSelector(module, tile).has(direction);
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack) {
return false;
}
@Override
@ -85,9 +83,4 @@ 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,7 +1,5 @@
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;
@ -11,10 +9,9 @@ import net.minecraft.world.inventory.MenuType;
import javax.annotation.Nullable;
public class FilterModuleContainer extends AbstractPipeContainer<FilterModuleItem> implements IFilteredContainer, IDirectionContainer {
public class FilterModuleContainer extends AbstractPipeContainer<FilterModuleItem> implements IFilteredContainer {
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);
@ -29,8 +26,6 @@ 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);
}
@ -39,17 +34,10 @@ 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,9 +14,7 @@ public class FilterModuleGui extends AbstractPipeGui<FilterModuleContainer> {
@Override
protected void init() {
super.init();
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))
for (var widget : this.menu.filter.getButtons(this, this.leftPos + 7, this.topPos + 17 + 32 + 18 * Mth.ceil(this.menu.filter.getSlots() / 9F) + 2))
this.addRenderableWidget(widget);
this.addRenderableWidget(this.menu.directionSelector.getButton(this.leftPos + 7, buttonsY));
}
}

View file

@ -4,15 +4,12 @@ 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 {
@ -26,8 +23,9 @@ public class FilterModuleItem extends ModuleItem {
}
@Override
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);
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack) {
var filter = this.getItemFilter(module, tile);
return filter.isAllowed(stack);
}
@Override
@ -51,9 +49,4 @@ 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,7 +1,5 @@
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;
@ -11,10 +9,9 @@ import net.minecraft.world.inventory.MenuType;
import javax.annotation.Nullable;
public class RetrievalModuleContainer extends AbstractPipeContainer<RetrievalModuleItem> implements IFilteredContainer, IDirectionContainer {
public class RetrievalModuleContainer extends AbstractPipeContainer<RetrievalModuleItem> implements IFilteredContainer {
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);
@ -23,8 +20,6 @@ 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);
}
@ -33,16 +28,10 @@ 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,8 +13,7 @@ public class RetrievalModuleGui extends AbstractPipeGui<RetrievalModuleContainer
@Override
protected void init() {
super.init();
for (var widget : this.menu.filter.getButtons(this, this.leftPos + this.imageWidth - 7, this.topPos + 17 + 32 + 20, true))
for (var widget : this.menu.filter.getButtons(this, this.leftPos + 7, this.topPos + 17 + 32 + 20))
this.addRenderableWidget(widget);
this.addRenderableWidget(this.menu.directionSelector.getButton(this.leftPos + 7, this.topPos + 17 + 32 + 20));
}
}

View file

@ -4,16 +4,13 @@ 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 {
@ -34,8 +31,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()) {
@ -45,8 +42,8 @@ public class RetrievalModuleItem extends ModuleItem {
continue;
var copy = filtered.copy();
copy.setCount(this.maxExtraction);
var dest = tile.getAvailableDestination(directions, copy, true, this.preventOversending);
if (dest.getRight().isEmpty())
var dest = tile.getAvailableDestination(copy, true, this.preventOversending);
if (dest == null)
continue;
var remain = dest.getRight().copy();
// are we already waiting for crafting results? If so, don't request those again
@ -58,13 +55,13 @@ public class RetrievalModuleItem extends ModuleItem {
}
@Override
public boolean canNetworkSee(ItemStack module, PipeBlockEntity tile, Direction direction, IItemHandler handler) {
return !this.getDirectionSelector(module, tile).has(direction);
public boolean canNetworkSee(ItemStack module, PipeBlockEntity tile) {
return false;
}
@Override
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack, Direction direction, IItemHandler destination) {
return !this.getDirectionSelector(module, tile).has(direction);
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack) {
return false;
}
@Override
@ -89,9 +86,4 @@ 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.isPresent())
if (widget.isEmpty())
return;
var stack = widget.get().stack.copy();
stack.setCount(1);

View file

@ -62,13 +62,11 @@
"container.prettypipes.item_terminal": "Item Terminal",
"container.prettypipes.crafting_terminal": "Crafting Terminal",
"container.prettypipes.pressurizer": "Pipe Pressurizer",
"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.whitelist": "Allowed",
"info.prettypipes.blacklist": "Disallowed",
"info.prettypipes.shift": "Hold Shift for info",
"info.prettypipes.populate": "P",
"info.prettypipes.populate.description": "Populate filter slots with items from adjacent inventories",
"info.prettypipes.populate": "Populate",
"info.prettypipes.populate.description": "Filters 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",
@ -90,12 +88,5 @@
"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",
"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"
"info.prettypipes.too_many_pipes_connected": "The terminal can only be connected to a single pipe at a time"
}