From 1c5a3a118d06eec5c0735ff8134bf73ca29cb26b Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 30 Mar 2022 14:26:38 +0200 Subject: [PATCH] allow holding Alt to request anyway Closes #118 --- .../de/ellpeck/prettypipes/packets/PacketButton.java | 2 +- .../terminal/CraftingTerminalBlockEntity.java | 12 +++++++++--- .../terminal/ItemTerminalBlockEntity.java | 12 ++++++++---- .../terminal/containers/CraftingTerminalGui.java | 3 ++- .../resources/assets/prettypipes/lang/en_us.json | 1 + 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/ellpeck/prettypipes/packets/PacketButton.java b/src/main/java/de/ellpeck/prettypipes/packets/PacketButton.java index 41f365e..9dcce0b 100644 --- a/src/main/java/de/ellpeck/prettypipes/packets/PacketButton.java +++ b/src/main/java/de/ellpeck/prettypipes/packets/PacketButton.java @@ -112,7 +112,7 @@ public class PacketButton { }), CRAFT_TERMINAL_REQUEST((pos, data, player) -> { var tile = Utility.getBlockEntity(CraftingTerminalBlockEntity.class, player.level, pos); - tile.requestCraftingItems(player, data[0]); + tile.requestCraftingItems(player, data[0], data[1] > 0); }), CANCEL_CRAFTING((pos, data, player) -> { var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, player.level, pos); diff --git a/src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalBlockEntity.java b/src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalBlockEntity.java index 35ceb2a..4c372e9 100644 --- a/src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalBlockEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalBlockEntity.java @@ -105,7 +105,7 @@ public class CraftingTerminalBlockEntity extends ItemTerminalBlockEntity { } } - public void requestCraftingItems(Player player, int maxAmount) { + public void requestCraftingItems(Player player, int maxAmount, boolean force) { var pipe = this.getConnectedPipe(); if (pipe == null) return; @@ -116,7 +116,10 @@ public class CraftingTerminalBlockEntity extends ItemTerminalBlockEntity { var lowestAvailable = getAvailableCrafts(pipe, this.craftItems.getSlots(), i -> ItemHandlerHelper.copyStackWithSize(this.getRequestedCraftItem(i), 1), this::isGhostItem, s -> { var item = this.networkItems.get(s); return item != null ? item.getLocations() : Collections.emptyList(); - }, onItemUnavailable(player), new Stack<>(), ItemEquality.NBT); + }, onItemUnavailable(player, force), new Stack<>(), ItemEquality.NBT); + // if we're forcing, just pretend we have one available + if (lowestAvailable <= 0 && force) + lowestAvailable = maxAmount; if (lowestAvailable > 0) { // if we're limiting the amount, pretend we only have that amount available if (maxAmount < lowestAvailable) @@ -127,10 +130,13 @@ public class CraftingTerminalBlockEntity extends ItemTerminalBlockEntity { continue; requested = requested.copy(); requested.setCount(lowestAvailable); - this.requestItemImpl(requested, onItemUnavailable(player)); + this.requestItemImpl(requested, onItemUnavailable(player, force)); } player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".sending_ingredients", lowestAvailable).setStyle(Style.EMPTY.applyFormat(ChatFormatting.GREEN)), UUID.randomUUID()); } + else{ + player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".hold_alt"), UUID.randomUUID()); + } network.endProfile(); } diff --git a/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalBlockEntity.java b/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalBlockEntity.java index b7d1a1b..ae67e5b 100644 --- a/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalBlockEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalBlockEntity.java @@ -163,11 +163,11 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect .filter(s -> ItemEquality.compareItems(s, filter) && s.getTag().hashCode() == nbtHash) .findFirst().orElse(filter); } - var requested = this.requestItemImpl(stack, onItemUnavailable(player)); + var requested = this.requestItemImpl(stack, onItemUnavailable(player, false)); if (requested > 0) { player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".sending", requested, stack.getHoverName()).setStyle(Style.EMPTY.applyFormat(ChatFormatting.GREEN)), UUID.randomUUID()); } else { - onItemUnavailable(player).accept(stack); + onItemUnavailable(player, false).accept(stack); } network.endProfile(); } @@ -315,7 +315,11 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect return Pair.of(requests, remain); } - public static Consumer onItemUnavailable(Player player) { - return s -> player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".not_found", s.getHoverName()).setStyle(Style.EMPTY.applyFormat(ChatFormatting.RED)), UUID.randomUUID()); + public static Consumer onItemUnavailable(Player player, boolean ignore) { + return s -> { + if (ignore) + return; + player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".not_found", s.getHoverName()).setStyle(Style.EMPTY.applyFormat(ChatFormatting.RED)), UUID.randomUUID()); + }; } } diff --git a/src/main/java/de/ellpeck/prettypipes/terminal/containers/CraftingTerminalGui.java b/src/main/java/de/ellpeck/prettypipes/terminal/containers/CraftingTerminalGui.java index a7112cd..5b66724 100644 --- a/src/main/java/de/ellpeck/prettypipes/terminal/containers/CraftingTerminalGui.java +++ b/src/main/java/de/ellpeck/prettypipes/terminal/containers/CraftingTerminalGui.java @@ -25,7 +25,8 @@ public class CraftingTerminalGui extends ItemTerminalGui { super.init(); this.requestButton = this.addRenderableWidget(new Button(this.leftPos + 8, this.topPos + 100, 50, 20, new TranslatableComponent("info." + PrettyPipes.ID + ".request"), button -> { var amount = requestModifier(); - PacketHandler.sendToServer(new PacketButton(this.menu.tile.getBlockPos(), PacketButton.ButtonResult.CRAFT_TERMINAL_REQUEST, amount)); + var force = hasAltDown() ? 1 : 0; + PacketHandler.sendToServer(new PacketButton(this.menu.tile.getBlockPos(), PacketButton.ButtonResult.CRAFT_TERMINAL_REQUEST, amount, force)); })); this.tick(); } diff --git a/src/main/resources/assets/prettypipes/lang/en_us.json b/src/main/resources/assets/prettypipes/lang/en_us.json index 8dff158..52545d3 100644 --- a/src/main/resources/assets/prettypipes/lang/en_us.json +++ b/src/main/resources/assets/prettypipes/lang/en_us.json @@ -72,6 +72,7 @@ "info.prettypipes.limit_to_max_off": "Don't limit to one stack", "info.prettypipes.request": "Request", "info.prettypipes.not_found": "%s not found", + "info.prettypipes.hold_alt": "Hold Alt to request anyway", "info.prettypipes.sending": "Sending %s %s", "info.prettypipes.sending_ingredients": "Sending %s sets of ingredients", "info.prettypipes.order": "Order by %s",