mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-26 05:28:33 +01:00
Compare commits
No commits in common. "3d5f592647449ccbb5d259c4247168b97113300a" and "a410e9cb29d428b96f23ea605e0e5219c8b8caac" have entirely different histories.
3d5f592647
...
a410e9cb29
11 changed files with 40 additions and 142 deletions
|
@ -34,7 +34,7 @@ mod_name=PrettyPipes
|
||||||
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
||||||
mod_license=MIT
|
mod_license=MIT
|
||||||
# The mod version. See https://semver.org/
|
# The mod version. See https://semver.org/
|
||||||
mod_version=1.18.0
|
mod_version=1.17.2
|
||||||
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
||||||
# This should match the base package used for the mod sources.
|
# This should match the base package used for the mod sources.
|
||||||
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||||
|
|
|
@ -48,7 +48,4 @@ public interface IModule {
|
||||||
ItemFilter getItemFilter(ItemStack module, PipeBlockEntity tile);
|
ItemFilter getItemFilter(ItemStack module, PipeBlockEntity tile);
|
||||||
|
|
||||||
DirectionSelector getDirectionSelector(ItemStack module, PipeBlockEntity tile);
|
DirectionSelector getDirectionSelector(ItemStack module, PipeBlockEntity tile);
|
||||||
|
|
||||||
ItemStack store(ItemStack module, PipeBlockEntity tile, ItemStack stack, Direction direction);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,9 +108,4 @@ public abstract class ModuleItem extends Item implements IModule {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack store(ItemStack module, PipeBlockEntity tile, ItemStack stack, Direction direction) {
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,12 +63,10 @@ public class ItemFilter {
|
||||||
List<AbstractWidget> buttons = new ArrayList<>();
|
List<AbstractWidget> buttons = new ArrayList<>();
|
||||||
if (this.canModifyWhitelist) {
|
if (this.canModifyWhitelist) {
|
||||||
var whitelistText = (Supplier<String>) () -> "info." + PrettyPipes.ID + "." + (this.isWhitelist ? "whitelist" : "blacklist");
|
var whitelistText = (Supplier<String>) () -> "info." + PrettyPipes.ID + "." + (this.isWhitelist ? "whitelist" : "blacklist");
|
||||||
var tooltip = (Supplier<Tooltip>) () -> Tooltip.create(Component.translatable(whitelistText.get() + ".description").withStyle(ChatFormatting.GRAY));
|
|
||||||
buttons.add(Button.builder(Component.translatable(whitelistText.get()), button -> {
|
buttons.add(Button.builder(Component.translatable(whitelistText.get()), button -> {
|
||||||
PacketButton.sendAndExecute(this.pipe.getBlockPos(), PacketButton.ButtonResult.FILTER_CHANGE, List.of(0));
|
PacketButton.sendAndExecute(this.pipe.getBlockPos(), PacketButton.ButtonResult.FILTER_CHANGE, List.of(0));
|
||||||
button.setMessage(Component.translatable(whitelistText.get()));
|
button.setMessage(Component.translatable(whitelistText.get()));
|
||||||
button.setTooltip(tooltip.get());
|
}).bounds(x - 20, y, 20, 20).tooltip(Tooltip.create(Component.translatable(whitelistText.get() + ".description").withStyle(ChatFormatting.GRAY))).build());
|
||||||
}).bounds(x - 20, y, 20, 20).tooltip(tooltip.get()).build());
|
|
||||||
}
|
}
|
||||||
if (this.canPopulateFromInventories) {
|
if (this.canPopulateFromInventories) {
|
||||||
buttons.add(Button.builder(Component.translatable("info." + PrettyPipes.ID + ".populate"), button -> PacketButton.sendAndExecute(this.pipe.getBlockPos(), PacketButton.ButtonResult.FILTER_CHANGE, List.of(1))).bounds(x - 42, y, 20, 20).tooltip(Tooltip.create(Component.translatable("info." + PrettyPipes.ID + ".populate.description").withStyle(ChatFormatting.GRAY))).build());
|
buttons.add(Button.builder(Component.translatable("info." + PrettyPipes.ID + ".populate"), button -> PacketButton.sendAndExecute(this.pipe.getBlockPos(), PacketButton.ButtonResult.FILTER_CHANGE, List.of(1))).bounds(x - 42, y, 20, 20).tooltip(Tooltip.create(Component.translatable("info." + PrettyPipes.ID + ".populate.description").withStyle(ChatFormatting.GRAY))).build());
|
||||||
|
|
|
@ -202,7 +202,13 @@ public class PipeItem implements IPipeItem {
|
||||||
|
|
||||||
protected ItemStack store(PipeBlockEntity currPipe) {
|
protected ItemStack store(PipeBlockEntity currPipe) {
|
||||||
var dir = Utility.getDirectionFromOffset(this.destInventory, this.getDestPipe());
|
var dir = Utility.getDirectionFromOffset(this.destInventory, this.getDestPipe());
|
||||||
return currPipe.store(this.stack, dir);
|
var connectable = currPipe.getPipeConnectable(dir);
|
||||||
|
if (connectable != null)
|
||||||
|
return connectable.insertItem(currPipe.getBlockPos(), dir, this.stack, false);
|
||||||
|
var handler = currPipe.getItemHandler(dir);
|
||||||
|
if (handler != null)
|
||||||
|
return ItemHandlerHelper.insertItemStacked(handler, this.stack, false);
|
||||||
|
return this.stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PipeBlockEntity getNextTile(PipeBlockEntity currPipe, boolean progress) {
|
protected PipeBlockEntity getNextTile(PipeBlockEntity currPipe, boolean progress) {
|
||||||
|
|
|
@ -6,7 +6,6 @@ import de.ellpeck.prettypipes.items.IModule;
|
||||||
import de.ellpeck.prettypipes.misc.ItemFilter.IFilteredContainer;
|
import de.ellpeck.prettypipes.misc.ItemFilter.IFilteredContainer;
|
||||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||||
import de.ellpeck.prettypipes.pipe.modules.craft.CraftingModuleContainer;
|
|
||||||
import de.ellpeck.prettypipes.pipe.modules.modifier.FilterModifierModuleContainer;
|
import de.ellpeck.prettypipes.pipe.modules.modifier.FilterModifierModuleContainer;
|
||||||
import de.ellpeck.prettypipes.pipe.modules.modifier.FilterModifierModuleItem;
|
import de.ellpeck.prettypipes.pipe.modules.modifier.FilterModifierModuleItem;
|
||||||
import de.ellpeck.prettypipes.pipe.modules.stacksize.StackSizeModuleItem;
|
import de.ellpeck.prettypipes.pipe.modules.stacksize.StackSizeModuleItem;
|
||||||
|
@ -95,18 +94,6 @@ public record PacketButton(BlockPos pos, int result, List<Integer> data) impleme
|
||||||
if (player.containerMenu instanceof IFilteredContainer filtered)
|
if (player.containerMenu instanceof IFilteredContainer filtered)
|
||||||
filtered.getFilter().onButtonPacket(filtered, data.getFirst());
|
filtered.getFilter().onButtonPacket(filtered, data.getFirst());
|
||||||
}),
|
}),
|
||||||
ENSURE_ITEM_ORDER_BUTTON((pos, data, player) -> {
|
|
||||||
if (player.containerMenu instanceof CraftingModuleContainer container) {
|
|
||||||
container.ensureItemOrder = !container.ensureItemOrder;
|
|
||||||
container.modified = true;
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
INSERT_SINGLES_BUTTON((pos, data, player) -> {
|
|
||||||
if (player.containerMenu instanceof CraftingModuleContainer container) {
|
|
||||||
container.insertSingles = !container.insertSingles;
|
|
||||||
container.modified = true;
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
STACK_SIZE_MODULE_BUTTON((pos, data, player) -> {
|
STACK_SIZE_MODULE_BUTTON((pos, data, player) -> {
|
||||||
var container = (AbstractPipeContainer<?>) player.containerMenu;
|
var container = (AbstractPipeContainer<?>) player.containerMenu;
|
||||||
var moduleData = container.moduleStack.getOrDefault(StackSizeModuleItem.Data.TYPE, StackSizeModuleItem.Data.DEFAULT);
|
var moduleData = container.moduleStack.getOrDefault(StackSizeModuleItem.Data.TYPE, StackSizeModuleItem.Data.DEFAULT);
|
||||||
|
|
|
@ -4,6 +4,7 @@ import de.ellpeck.prettypipes.PrettyPipes;
|
||||||
import de.ellpeck.prettypipes.Registry;
|
import de.ellpeck.prettypipes.Registry;
|
||||||
import de.ellpeck.prettypipes.Utility;
|
import de.ellpeck.prettypipes.Utility;
|
||||||
import de.ellpeck.prettypipes.items.IModule;
|
import de.ellpeck.prettypipes.items.IModule;
|
||||||
|
import de.ellpeck.prettypipes.misc.EquatableItemStack;
|
||||||
import de.ellpeck.prettypipes.misc.ItemFilter;
|
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||||
import de.ellpeck.prettypipes.network.NetworkLock;
|
import de.ellpeck.prettypipes.network.NetworkLock;
|
||||||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||||
|
@ -38,7 +39,6 @@ import net.neoforged.neoforge.capabilities.BlockCapability;
|
||||||
import net.neoforged.neoforge.capabilities.Capabilities;
|
import net.neoforged.neoforge.capabilities.Capabilities;
|
||||||
import net.neoforged.neoforge.common.util.Lazy;
|
import net.neoforged.neoforge.common.util.Lazy;
|
||||||
import net.neoforged.neoforge.items.IItemHandler;
|
import net.neoforged.neoforge.items.IItemHandler;
|
||||||
import net.neoforged.neoforge.items.ItemHandlerHelper;
|
|
||||||
import net.neoforged.neoforge.items.ItemStackHandler;
|
import net.neoforged.neoforge.items.ItemStackHandler;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
import org.apache.commons.lang3.tuple.Triple;
|
import org.apache.commons.lang3.tuple.Triple;
|
||||||
|
@ -72,7 +72,7 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// crafting module slot, ingredient request network lock
|
// crafting module slot, ingredient request network lock
|
||||||
public final List<Pair<Integer, NetworkLock>> craftIngredientRequests = new ArrayList<>();
|
public final Queue<Pair<Integer, NetworkLock>> craftIngredientRequests = new LinkedList<>();
|
||||||
// crafting module slot, destination pipe for the result, result item
|
// crafting module slot, destination pipe for the result, result item
|
||||||
public final List<Triple<Integer, BlockPos, ItemStack>> craftResultRequests = new ArrayList<>();
|
public final List<Triple<Integer, BlockPos, ItemStack>> craftResultRequests = new ArrayList<>();
|
||||||
public PressurizerBlockEntity pressurizer;
|
public PressurizerBlockEntity pressurizer;
|
||||||
|
@ -416,23 +416,6 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
|
||||||
}).filter(Objects::nonNull).collect(Collectors.toList());
|
}).filter(Objects::nonNull).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack store(ItemStack stack, Direction direction) {
|
|
||||||
var modules = this.streamModules().iterator();
|
|
||||||
while (modules.hasNext()) {
|
|
||||||
var module = modules.next();
|
|
||||||
stack = module.getRight().store(module.getLeft(), this, stack, direction);
|
|
||||||
if (stack.isEmpty())
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
var connectable = this.getPipeConnectable(direction);
|
|
||||||
if (connectable != null)
|
|
||||||
return connectable.insertItem(this.getBlockPos(), direction, stack, false);
|
|
||||||
var handler = this.getItemHandler(direction);
|
|
||||||
if (handler != null)
|
|
||||||
return ItemHandlerHelper.insertItemStacked(handler, stack, false);
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component getDisplayName() {
|
public Component getDisplayName() {
|
||||||
return Component.translatable("container." + PrettyPipes.ID + ".pipe");
|
return Component.translatable("container." + PrettyPipes.ID + ".pipe");
|
||||||
|
|
|
@ -6,17 +6,12 @@ import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.inventory.MenuType;
|
import net.minecraft.world.inventory.MenuType;
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.neoforged.neoforge.items.ItemStackHandler;
|
import net.neoforged.neoforge.items.ItemStackHandler;
|
||||||
import net.neoforged.neoforge.items.SlotItemHandler;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class CraftingModuleContainer extends AbstractPipeContainer<CraftingModuleItem> {
|
public class CraftingModuleContainer extends AbstractPipeContainer<CraftingModuleItem> {
|
||||||
|
|
||||||
public ItemStackHandler input;
|
public ItemStackHandler input;
|
||||||
public ItemStackHandler output;
|
public ItemStackHandler output;
|
||||||
public boolean ensureItemOrder;
|
|
||||||
public boolean insertSingles;
|
|
||||||
public boolean modified;
|
public boolean modified;
|
||||||
|
|
||||||
public CraftingModuleContainer(MenuType<?> type, int id, Player player, BlockPos pos, int moduleIndex) {
|
public CraftingModuleContainer(MenuType<?> type, int id, Player player, BlockPos pos, int moduleIndex) {
|
||||||
|
@ -26,9 +21,6 @@ public class CraftingModuleContainer extends AbstractPipeContainer<CraftingModul
|
||||||
@Override
|
@Override
|
||||||
protected void addSlots() {
|
protected void addSlots() {
|
||||||
var contents = this.moduleStack.get(CraftingModuleItem.Contents.TYPE);
|
var contents = this.moduleStack.get(CraftingModuleItem.Contents.TYPE);
|
||||||
this.ensureItemOrder = contents.ensureItemOrder();
|
|
||||||
this.insertSingles = contents.insertSingles();
|
|
||||||
|
|
||||||
this.input = Utility.copy(contents.input());
|
this.input = Utility.copy(contents.input());
|
||||||
for (var i = 0; i < this.input.getSlots(); i++) {
|
for (var i = 0; i < this.input.getSlots(); i++) {
|
||||||
this.addSlot(new FilterSlot(this.input, i, (176 - this.input.getSlots() * 18) / 2 + 1 + i % 9 * 18, 17 + 32 + i / 9 * 18, false) {
|
this.addSlot(new FilterSlot(this.input, i, (176 - this.input.getSlots() * 18) / 2 + 1 + i % 9 * 18, 17 + 32 + i / 9 * 18, false) {
|
||||||
|
@ -57,7 +49,7 @@ public class CraftingModuleContainer extends AbstractPipeContainer<CraftingModul
|
||||||
public void removed(Player playerIn) {
|
public void removed(Player playerIn) {
|
||||||
super.removed(playerIn);
|
super.removed(playerIn);
|
||||||
if (this.modified) {
|
if (this.modified) {
|
||||||
this.moduleStack.set(CraftingModuleItem.Contents.TYPE, new CraftingModuleItem.Contents(this.input, this.output, this.ensureItemOrder, this.insertSingles));
|
this.moduleStack.set(CraftingModuleItem.Contents.TYPE, new CraftingModuleItem.Contents(this.input, this.output));
|
||||||
this.tile.setChanged();
|
this.tile.setChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,10 @@
|
||||||
package de.ellpeck.prettypipes.pipe.modules.craft;
|
package de.ellpeck.prettypipes.pipe.modules.craft;
|
||||||
|
|
||||||
import de.ellpeck.prettypipes.PrettyPipes;
|
|
||||||
import de.ellpeck.prettypipes.packets.PacketButton;
|
|
||||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui;
|
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui;
|
||||||
import net.minecraft.ChatFormatting;
|
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.client.gui.components.Button;
|
|
||||||
import net.minecraft.client.gui.components.Tooltip;
|
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class CraftingModuleGui extends AbstractPipeGui<CraftingModuleContainer> {
|
public class CraftingModuleGui extends AbstractPipeGui<CraftingModuleContainer> {
|
||||||
|
|
||||||
public CraftingModuleGui(CraftingModuleContainer screenContainer, Inventory inv, Component titleIn) {
|
public CraftingModuleGui(CraftingModuleContainer screenContainer, Inventory inv, Component titleIn) {
|
||||||
|
@ -24,23 +16,4 @@ public class CraftingModuleGui extends AbstractPipeGui<CraftingModuleContainer>
|
||||||
super.renderBg(graphics, partialTicks, mouseX, mouseY);
|
super.renderBg(graphics, partialTicks, mouseX, mouseY);
|
||||||
graphics.blit(AbstractPipeGui.TEXTURE, this.leftPos + 176 / 2 - 16 / 2, this.topPos + 32 + 18 * 2, 176, 80, 16, 16);
|
graphics.blit(AbstractPipeGui.TEXTURE, this.leftPos + 176 / 2 - 16 / 2, this.topPos + 32 + 18 * 2, 176, 80, 16, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
super.init();
|
|
||||||
var cacheText = (Supplier<String>) () -> "info." + PrettyPipes.ID + ".ensure_item_order_" + (this.menu.ensureItemOrder ? "on" : "off");
|
|
||||||
this.addRenderableWidget(Button.builder(Component.translatable(cacheText.get()), button -> {
|
|
||||||
PacketButton.sendAndExecute(this.menu.tile.getBlockPos(), PacketButton.ButtonResult.ENSURE_ITEM_ORDER_BUTTON, List.of());
|
|
||||||
button.setMessage(Component.translatable(cacheText.get()));
|
|
||||||
}).bounds(this.leftPos + this.imageWidth - 7 - 20, this.topPos + 17 + 32 + 18 * 2 + 2, 20, 20).tooltip(
|
|
||||||
Tooltip.create(Component.translatable("info." + PrettyPipes.ID + ".ensure_item_order.description").withStyle(ChatFormatting.GRAY))).build());
|
|
||||||
|
|
||||||
var singleText = (Supplier<String>) () -> "info." + PrettyPipes.ID + ".insert_singles_" + (this.menu.insertSingles ? "on" : "off");
|
|
||||||
this.addRenderableWidget(Button.builder(Component.translatable(singleText.get()), button -> {
|
|
||||||
PacketButton.sendAndExecute(this.menu.tile.getBlockPos(), PacketButton.ButtonResult.INSERT_SINGLES_BUTTON, List.of());
|
|
||||||
button.setMessage(Component.translatable(singleText.get()));
|
|
||||||
}).bounds(this.leftPos + this.imageWidth - 7 - 20 - 22, this.topPos + 17 + 32 + 18 * 2 + 2, 20, 20).tooltip(
|
|
||||||
Tooltip.create(Component.translatable("info." + PrettyPipes.ID + ".insert_singles.description").withStyle(ChatFormatting.GRAY))).build());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,12 +23,13 @@ import net.minecraft.world.entity.player.Inventory;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.neoforged.neoforge.items.IItemHandler;
|
import net.neoforged.neoforge.items.IItemHandler;
|
||||||
import net.neoforged.neoforge.items.ItemHandlerHelper;
|
|
||||||
import net.neoforged.neoforge.items.ItemStackHandler;
|
import net.neoforged.neoforge.items.ItemStackHandler;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
import org.apache.commons.lang3.tuple.Triple;
|
import org.apache.commons.lang3.tuple.Triple;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Stack;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class CraftingModuleItem extends ModuleItem {
|
public class CraftingModuleItem extends ModuleItem {
|
||||||
|
@ -36,7 +37,7 @@ public class CraftingModuleItem extends ModuleItem {
|
||||||
private final int speed;
|
private final int speed;
|
||||||
|
|
||||||
public CraftingModuleItem(String name, ModuleTier tier) {
|
public CraftingModuleItem(String name, ModuleTier tier) {
|
||||||
super(name, new Properties().component(Contents.TYPE, new Contents(new ItemStackHandler(tier.forTier(1, 4, 9)), new ItemStackHandler(tier.forTier(1, 2, 4)), false, false)));
|
super(name, new Properties().component(Contents.TYPE, new Contents(new ItemStackHandler(tier.forTier(1, 4, 9)), new ItemStackHandler(tier.forTier(1, 2, 4)))));
|
||||||
this.speed = tier.forTier(20, 10, 5);
|
this.speed = tier.forTier(20, 10, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,29 +75,23 @@ public class CraftingModuleItem extends ModuleItem {
|
||||||
// process crafting ingredient requests
|
// process crafting ingredient requests
|
||||||
if (!tile.craftIngredientRequests.isEmpty()) {
|
if (!tile.craftIngredientRequests.isEmpty()) {
|
||||||
network.startProfile("crafting_ingredients");
|
network.startProfile("crafting_ingredients");
|
||||||
var request = tile.craftIngredientRequests.getFirst();
|
var request = tile.craftIngredientRequests.peek();
|
||||||
if (request.getLeft() == slot) {
|
if (request.getLeft() == slot) {
|
||||||
var lock = request.getRight();
|
var lock = request.getRight();
|
||||||
var equalityTypes = ItemFilter.getEqualityTypes(tile);
|
var equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||||
var dest = tile.getAvailableDestination(Direction.values(), lock.stack, true, true);
|
var dest = tile.getAvailableDestination(Direction.values(), lock.stack, true, true);
|
||||||
if (dest != null) {
|
if (dest != null) {
|
||||||
var ensureItemOrder = module.get(Contents.TYPE).ensureItemOrder;
|
var requestRemain = network.requestExistingItem(lock.location, tile.getBlockPos(), dest.getLeft(), lock, dest.getRight(), equalityTypes);
|
||||||
// if we're ensuring the correct item order and the item is already on the way, don't do anything yet
|
network.resolveNetworkLock(lock);
|
||||||
if (!ensureItemOrder || network.getPipeItemsOnTheWay(dest.getLeft()).findAny().isEmpty()) {
|
tile.craftIngredientRequests.remove();
|
||||||
var requestRemain = network.requestExistingItem(lock.location, tile.getBlockPos(), dest.getLeft(), lock, dest.getRight(), equalityTypes);
|
|
||||||
network.resolveNetworkLock(lock);
|
|
||||||
tile.craftIngredientRequests.remove(request);
|
|
||||||
|
|
||||||
// if we couldn't fit all items into the destination, create another request for the rest
|
// if we couldn't fit all items into the destination, create another request for the rest
|
||||||
var remain = lock.stack.copy();
|
var remain = lock.stack.copy();
|
||||||
remain.shrink(dest.getRight().getCount() - requestRemain.getCount());
|
remain.shrink(dest.getRight().getCount() - requestRemain.getCount());
|
||||||
if (!remain.isEmpty()) {
|
if (!remain.isEmpty()) {
|
||||||
var remainRequest = new NetworkLock(lock.location, remain);
|
var remainRequest = new NetworkLock(lock.location, remain);
|
||||||
// if we're ensuring item order, we need to insert the remaining request at the start so that it gets processed first
|
tile.craftIngredientRequests.add(Pair.of(slot, remainRequest));
|
||||||
var index = ensureItemOrder ? 0 : tile.craftResultRequests.size();
|
network.createNetworkLock(remainRequest);
|
||||||
tile.craftIngredientRequests.add(index, Pair.of(slot, remainRequest));
|
|
||||||
network.createNetworkLock(remainRequest);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,20 +181,16 @@ public class CraftingModuleItem extends ModuleItem {
|
||||||
var craftableCrafts = Mth.ceil(craftableAmount / (float) resultAmount);
|
var craftableCrafts = Mth.ceil(craftableAmount / (float) resultAmount);
|
||||||
var toCraft = Math.min(craftableCrafts, requiredCrafts);
|
var toCraft = Math.min(craftableCrafts, requiredCrafts);
|
||||||
|
|
||||||
var contents = module.get(Contents.TYPE);
|
var input = module.get(Contents.TYPE).input;
|
||||||
// if we're ensuring item order, all items for a single recipe should be sent in order first before starting on the next one!
|
for (var i = 0; i < input.getSlots(); i++) {
|
||||||
for (var c = contents.ensureItemOrder ? toCraft : 1; c > 0; c--) {
|
var in = input.getStackInSlot(i);
|
||||||
for (var i = 0; i < contents.input.getSlots(); i++) {
|
if (in.isEmpty())
|
||||||
var in = contents.input.getStackInSlot(i);
|
continue;
|
||||||
if (in.isEmpty())
|
var copy = in.copy();
|
||||||
continue;
|
copy.setCount(in.getCount() * toCraft);
|
||||||
var copy = in.copy();
|
var ret = ItemTerminalBlockEntity.requestItemLater(tile.getLevel(), tile.getBlockPos(), items, unavailableConsumer, copy, CraftingModuleItem.addDependency(dependencyChain, module), equalityTypes);
|
||||||
if (!contents.ensureItemOrder)
|
for (var lock : ret.getLeft())
|
||||||
copy.setCount(in.getCount() * toCraft);
|
tile.craftIngredientRequests.add(Pair.of(slot, lock));
|
||||||
var ret = ItemTerminalBlockEntity.requestItemLater(tile.getLevel(), tile.getBlockPos(), items, unavailableConsumer, copy, CraftingModuleItem.addDependency(dependencyChain, module), equalityTypes);
|
|
||||||
for (var lock : ret.getLeft())
|
|
||||||
tile.craftIngredientRequests.add(Pair.of(slot, lock));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var remain = stack.copy();
|
var remain = stack.copy();
|
||||||
|
@ -212,22 +203,6 @@ public class CraftingModuleItem extends ModuleItem {
|
||||||
return remain;
|
return remain;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack store(ItemStack module, PipeBlockEntity tile, ItemStack stack, Direction direction) {
|
|
||||||
if (module.get(Contents.TYPE).insertSingles) {
|
|
||||||
var handler = tile.getItemHandler(direction);
|
|
||||||
if (handler != null) {
|
|
||||||
while (!stack.isEmpty()) {
|
|
||||||
var remain = ItemHandlerHelper.insertItem(handler, stack.copyWithCount(1), false);
|
|
||||||
if (!remain.isEmpty())
|
|
||||||
break;
|
|
||||||
stack.shrink(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getResultAmountPerCraft(ItemStack module, ItemStack stack, ItemEquality... equalityTypes) {
|
private int getResultAmountPerCraft(ItemStack module, ItemStack stack, ItemEquality... equalityTypes) {
|
||||||
var output = module.get(Contents.TYPE).output;
|
var output = module.get(Contents.TYPE).output;
|
||||||
var resultAmount = 0;
|
var resultAmount = 0;
|
||||||
|
@ -245,13 +220,11 @@ public class CraftingModuleItem extends ModuleItem {
|
||||||
return deps;
|
return deps;
|
||||||
}
|
}
|
||||||
|
|
||||||
public record Contents(ItemStackHandler input, ItemStackHandler output, boolean ensureItemOrder, boolean insertSingles) {
|
public record Contents(ItemStackHandler input, ItemStackHandler output) {
|
||||||
|
|
||||||
public static final Codec<Contents> CODEC = RecordCodecBuilder.create(i -> i.group(
|
public static final Codec<Contents> CODEC = RecordCodecBuilder.create(i -> i.group(
|
||||||
Utility.ITEM_STACK_HANDLER_CODEC.fieldOf("input").forGetter(d -> d.input),
|
Utility.ITEM_STACK_HANDLER_CODEC.fieldOf("input").forGetter(d -> d.input),
|
||||||
Utility.ITEM_STACK_HANDLER_CODEC.fieldOf("output").forGetter(d -> d.output),
|
Utility.ITEM_STACK_HANDLER_CODEC.fieldOf("output").forGetter(d -> d.output)
|
||||||
Codec.BOOL.optionalFieldOf("ensure_item_order", false).forGetter(d -> d.ensureItemOrder),
|
|
||||||
Codec.BOOL.optionalFieldOf("insert_singles", false).forGetter(d -> d.insertSingles)
|
|
||||||
).apply(i, Contents::new));
|
).apply(i, Contents::new));
|
||||||
public static final DataComponentType<Contents> TYPE = DataComponentType.<Contents>builder().persistent(Contents.CODEC).cacheEncoding().build();
|
public static final DataComponentType<Contents> TYPE = DataComponentType.<Contents>builder().persistent(Contents.CODEC).cacheEncoding().build();
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
"info.prettypipes.nbt_filter_modifier": "Causes any filter slots to filter by item data (NBT)",
|
"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\nTag can be chosen from items in filter slots",
|
"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.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 extraction, retrieval and crafting",
|
"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",
|
"info.prettypipes.item_terminal": "Allows viewing and requesting all items in a pipe network\nAlso has slots for putting items into the network",
|
||||||
"info.prettypipes.crafting_terminal": "Allows requesting ingredients for crafting recipes\nSupports auto-filling from JEI if installed",
|
"info.prettypipes.crafting_terminal": "Allows requesting ingredients for crafting recipes\nSupports auto-filling from JEI if installed",
|
||||||
"info.prettypipes.pressurizer": "Drastically increases item speed in the entire pipe network\nRequires FE (or RF) for each item transferred",
|
"info.prettypipes.pressurizer": "Drastically increases item speed in the entire pipe network\nRequires FE (or RF) for each item transferred",
|
||||||
|
@ -66,12 +66,6 @@
|
||||||
"info.prettypipes.blacklist": "\u00A74D",
|
"info.prettypipes.blacklist": "\u00A74D",
|
||||||
"info.prettypipes.whitelist.description": "Items in filter slots are allowed",
|
"info.prettypipes.whitelist.description": "Items in filter slots are allowed",
|
||||||
"info.prettypipes.blacklist.description": "Items in filter slots are disallowed",
|
"info.prettypipes.blacklist.description": "Items in filter slots are disallowed",
|
||||||
"info.prettypipes.insert_singles_on": "\u00A72S",
|
|
||||||
"info.prettypipes.insert_singles_off": "\u00A74\u00A7mS",
|
|
||||||
"info.prettypipes.insert_singles.description": "Whether items should be inserted one at a time, rather than as a stack\nRecommended for use with the Crafter",
|
|
||||||
"info.prettypipes.ensure_item_order_on": "\u00A72O",
|
|
||||||
"info.prettypipes.ensure_item_order_off": "\u00A74\u00A7mO",
|
|
||||||
"info.prettypipes.ensure_item_order.description": "Whether the module should wait for items to be inserted in the order they appear in the input slots\nRecommended for use with the Crafter",
|
|
||||||
"info.prettypipes.shift": "Hold Shift for info",
|
"info.prettypipes.shift": "Hold Shift for info",
|
||||||
"info.prettypipes.populate": "P",
|
"info.prettypipes.populate": "P",
|
||||||
"info.prettypipes.populate.description": "Populate filter slots with items from adjacent inventories",
|
"info.prettypipes.populate.description": "Populate filter slots with items from adjacent inventories",
|
||||||
|
|
Loading…
Reference in a new issue