This commit is contained in:
Ell 2022-03-30 14:51:18 +02:00
parent 58f665452d
commit 43bf12924f
5 changed files with 21 additions and 14 deletions

View file

@ -112,7 +112,7 @@ public class PacketButton {
}),
CRAFT_TERMINAL_REQUEST((pos, data, player) -> {
CraftingTerminalTileEntity tile = Utility.getTileEntity(CraftingTerminalTileEntity.class, player.world, pos);
tile.requestCraftingItems(player, data[0]);
tile.requestCraftingItems(player, data[0], data[1] > 0);
}),
CANCEL_CRAFTING((pos, data, player) -> {
ItemTerminalTileEntity tile = Utility.getTileEntity(ItemTerminalTileEntity.class, player.world, pos);

View file

@ -106,7 +106,7 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity {
}
}
public void requestCraftingItems(PlayerEntity player, int maxAmount) {
public void requestCraftingItems(PlayerEntity player, int maxAmount, boolean force) {
PipeTileEntity pipe = this.getConnectedPipe();
if (pipe == null)
return;
@ -117,7 +117,10 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity {
int lowestAvailable = getAvailableCrafts(pipe, this.craftItems.getSlots(), i -> ItemHandlerHelper.copyStackWithSize(this.getRequestedCraftItem(i), 1), this::isGhostItem, s -> {
NetworkItem 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)
@ -128,9 +131,11 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity {
continue;
requested = requested.copy();
requested.setCount(lowestAvailable);
this.requestItemImpl(requested, onItemUnavailable(player));
this.requestItemImpl(requested, onItemUnavailable(player, force));
}
player.sendMessage(new TranslationTextComponent("info." + PrettyPipes.ID + ".sending_ingredients", lowestAvailable).setStyle(Style.EMPTY.setFormatting(TextFormatting.GREEN)), UUID.randomUUID());
} else {
player.sendMessage(new TranslationTextComponent("info." + PrettyPipes.ID + ".hold_alt"), UUID.randomUUID());
}
network.endProfile();
}

View file

@ -166,11 +166,11 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
.filter(s -> ItemEquality.compareItems(s, filter) && s.getTag().hashCode() == nbtHash)
.findFirst().orElse(filter);
}
int requested = this.requestItemImpl(stack, onItemUnavailable(player));
int requested = this.requestItemImpl(stack, onItemUnavailable(player, false));
if (requested > 0) {
player.sendMessage(new TranslationTextComponent("info." + PrettyPipes.ID + ".sending", requested, stack.getDisplayName()).setStyle(Style.EMPTY.setFormatting(TextFormatting.GREEN)), UUID.randomUUID());
} else {
onItemUnavailable(player).accept(stack);
onItemUnavailable(player, false).accept(stack);
}
network.endProfile();
}
@ -321,7 +321,11 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
return Pair.of(requests, remain);
}
public static Consumer<ItemStack> onItemUnavailable(PlayerEntity player) {
return s -> player.sendMessage(new TranslationTextComponent("info." + PrettyPipes.ID + ".not_found", s.getDisplayName()).setStyle(Style.EMPTY.setFormatting(TextFormatting.RED)), UUID.randomUUID());
public static Consumer<ItemStack> onItemUnavailable(PlayerEntity player, boolean ignore) {
return s -> {
if (ignore)
return;
player.sendMessage(new TranslationTextComponent("info." + PrettyPipes.ID + ".not_found", s.getDisplayName()).setStyle(Style.EMPTY.setFormatting(TextFormatting.RED)), UUID.randomUUID());
};
}
}

View file

@ -1,16 +1,11 @@
package de.ellpeck.prettypipes.terminal.containers;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import de.ellpeck.prettypipes.PrettyPipes;
import de.ellpeck.prettypipes.packets.PacketButton;
import de.ellpeck.prettypipes.packets.PacketHandler;
import de.ellpeck.prettypipes.packets.PacketRequest;
import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
@ -19,6 +14,7 @@ import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
public class CraftingTerminalGui extends ItemTerminalGui {
private static final ResourceLocation TEXTURE = new ResourceLocation(PrettyPipes.ID, "textures/gui/crafting_terminal.png");
private Button requestButton;
@ -32,7 +28,8 @@ public class CraftingTerminalGui extends ItemTerminalGui {
super.init();
this.requestButton = this.addButton(new Button(this.guiLeft + 8, this.guiTop + 100, 50, 20, new TranslationTextComponent("info." + PrettyPipes.ID + ".request"), button -> {
int amount = requestModifier();
PacketHandler.sendToServer(new PacketButton(this.container.tile.getPos(), PacketButton.ButtonResult.CRAFT_TERMINAL_REQUEST, amount));
int force = hasAltDown() ? 1 : 0;
PacketHandler.sendToServer(new PacketButton(this.container.tile.getPos(), PacketButton.ButtonResult.CRAFT_TERMINAL_REQUEST, amount, force));
}));
this.tick();
}

View file

@ -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",