allow pressing control to request 10 crafting items

Closes #40
This commit is contained in:
Ell 2020-10-14 18:32:10 +02:00
parent a06c91be5a
commit bb06cb34eb
4 changed files with 9 additions and 9 deletions

View file

@ -113,8 +113,7 @@ public class PacketButton {
}),
CRAFT_TERMINAL_REQUEST((pos, data, player) -> {
CraftingTerminalTileEntity tile = Utility.getTileEntity(CraftingTerminalTileEntity.class, player.world, pos);
boolean all = data[0] > 0;
tile.requestCraftingItems(player, all);
tile.requestCraftingItems(player, data[0]);
});
public final TriConsumer<BlockPos, int[], PlayerEntity> action;

View file

@ -93,7 +93,7 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity {
}
}
public void requestCraftingItems(PlayerEntity player, boolean all) {
public void requestCraftingItems(PlayerEntity player, int maxAmount) {
PipeNetwork network = PipeNetwork.get(this.world);
network.startProfile("terminal_request_crafting");
this.updateItems();
@ -137,9 +137,9 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity {
player.sendMessage(new TranslationTextComponent("info." + PrettyPipes.ID + ".not_found", stack.stack.getDisplayName()).setStyle(Style.EMPTY.setFormatting(TextFormatting.RED)), UUID.randomUUID());
}
if (lowestAvailable > 0) {
// if we're only crafting one item, pretend we only have enough for one
if (!all)
lowestAvailable = 1;
// if we're limiting the amount, pretend we only have that amount available
if (maxAmount < lowestAvailable)
lowestAvailable = maxAmount;
for (int i = 0; i < this.craftItems.getSlots(); i++) {
ItemStack requested = this.getRequestedCraftItem(i);
if (requested.isEmpty())

View file

@ -31,8 +31,8 @@ public class CraftingTerminalGui extends ItemTerminalGui {
protected void init() {
super.init();
this.requestButton = this.addButton(new Button(this.guiLeft + 8, this.guiTop + 100, 50, 20, new TranslationTextComponent("info." + PrettyPipes.ID + ".request"), button -> {
int all = hasShiftDown() ? 1 : 0;
PacketHandler.sendToServer(new PacketButton(this.container.tile.getPos(), PacketButton.ButtonResult.CRAFT_TERMINAL_REQUEST, all));
int amount = requestModifier();
PacketHandler.sendToServer(new PacketButton(this.container.tile.getPos(), PacketButton.ButtonResult.CRAFT_TERMINAL_REQUEST, amount));
}));
this.tick();
}

View file

@ -57,6 +57,7 @@ public class ItemTerminalGui extends ContainerScreen<ItemTerminalContainer> {
} else {
this.requestAmount += modifier;
}
// 384 items is 6 stacks, which is what fits into the terminal slots
if (this.requestAmount > 384)
this.requestAmount = 384;
}));
@ -247,7 +248,7 @@ public class ItemTerminalGui extends ContainerScreen<ItemTerminalContainer> {
.map(w -> (ItemTerminalWidget) w);
}
private static int requestModifier() {
public static int requestModifier() {
if (hasControlDown()) {
return 10;
} else if (hasShiftDown()) {