2020-05-07 18:30:40 +02:00
|
|
|
package de.ellpeck.prettypipes.terminal.containers;
|
|
|
|
|
2021-12-02 16:55:04 +01:00
|
|
|
import com.mojang.blaze3d.platform.InputConstants;
|
2020-05-07 18:30:40 +02:00
|
|
|
import de.ellpeck.prettypipes.PrettyPipes;
|
|
|
|
import de.ellpeck.prettypipes.misc.ItemTerminalWidget;
|
2020-05-08 20:56:27 +02:00
|
|
|
import de.ellpeck.prettypipes.misc.PlayerPrefs;
|
2020-05-07 23:06:35 +02:00
|
|
|
import de.ellpeck.prettypipes.packets.PacketButton;
|
2020-05-07 21:10:29 +02:00
|
|
|
import de.ellpeck.prettypipes.packets.PacketRequest;
|
2020-05-08 16:06:17 +02:00
|
|
|
import joptsimple.internal.Strings;
|
2023-07-07 19:54:52 +02:00
|
|
|
import net.minecraft.client.gui.GuiGraphics;
|
2021-12-02 14:44:26 +01:00
|
|
|
import net.minecraft.client.gui.components.Button;
|
|
|
|
import net.minecraft.client.gui.components.EditBox;
|
2023-07-07 19:54:52 +02:00
|
|
|
import net.minecraft.client.gui.components.Renderable;
|
2021-12-19 17:27:21 +01:00
|
|
|
import net.minecraft.client.gui.components.events.GuiEventListener;
|
|
|
|
import net.minecraft.client.gui.narration.NarratableEntry;
|
2022-06-30 16:00:33 +02:00
|
|
|
import net.minecraft.client.gui.screens.Screen;
|
2021-12-02 14:44:26 +01:00
|
|
|
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
2021-12-02 16:55:04 +01:00
|
|
|
import net.minecraft.client.resources.language.I18n;
|
2021-12-02 14:44:26 +01:00
|
|
|
import net.minecraft.network.chat.Component;
|
2021-12-02 16:55:04 +01:00
|
|
|
import net.minecraft.resources.ResourceLocation;
|
|
|
|
import net.minecraft.util.Mth;
|
2021-12-02 14:44:26 +01:00
|
|
|
import net.minecraft.world.entity.player.Inventory;
|
2021-12-02 12:31:04 +01:00
|
|
|
import net.minecraft.world.item.ItemStack;
|
2021-12-04 13:35:04 +01:00
|
|
|
import net.minecraft.world.item.TooltipFlag;
|
2024-03-07 16:00:49 +01:00
|
|
|
import net.neoforged.neoforge.network.PacketDistributor;
|
2020-10-14 22:30:02 +02:00
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
2020-05-07 18:30:40 +02:00
|
|
|
|
2020-05-07 23:06:35 +02:00
|
|
|
import java.util.*;
|
2020-05-07 21:10:29 +02:00
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Stream;
|
2020-05-07 18:30:40 +02:00
|
|
|
|
2021-12-02 14:44:26 +01:00
|
|
|
public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContainer> {
|
2020-10-14 22:30:02 +02:00
|
|
|
|
2020-05-07 18:30:40 +02:00
|
|
|
private static final ResourceLocation TEXTURE = new ResourceLocation(PrettyPipes.ID, "textures/gui/item_terminal.png");
|
2020-10-14 22:30:02 +02:00
|
|
|
|
2020-10-20 00:52:56 +02:00
|
|
|
public List<ItemStack> currentlyCrafting;
|
2021-12-02 14:44:26 +01:00
|
|
|
public EditBox search;
|
2020-10-20 00:52:56 +02:00
|
|
|
|
2020-10-14 22:30:02 +02:00
|
|
|
// craftables have the second parameter set to true
|
|
|
|
private final List<Pair<ItemStack, Boolean>> sortedItems = new ArrayList<>();
|
2020-05-07 21:10:29 +02:00
|
|
|
private List<ItemStack> items;
|
2020-10-14 22:30:02 +02:00
|
|
|
private List<ItemStack> craftables;
|
2020-05-07 21:10:29 +02:00
|
|
|
private Button minusButton;
|
|
|
|
private Button plusButton;
|
|
|
|
private Button requestButton;
|
2020-05-07 23:06:35 +02:00
|
|
|
private Button orderButton;
|
|
|
|
private Button ascendingButton;
|
2020-10-20 00:52:56 +02:00
|
|
|
private Button cancelCraftingButton;
|
2020-05-08 16:06:17 +02:00
|
|
|
private String lastSearchText;
|
2020-05-07 21:10:29 +02:00
|
|
|
private int requestAmount = 1;
|
2020-05-07 21:50:50 +02:00
|
|
|
private int scrollOffset;
|
2020-10-20 00:52:56 +02:00
|
|
|
private ItemStack hoveredCrafting;
|
2020-12-04 19:51:20 +01:00
|
|
|
private boolean isScrolling;
|
2020-05-07 18:30:40 +02:00
|
|
|
|
2021-12-02 14:44:26 +01:00
|
|
|
public ItemTerminalGui(ItemTerminalContainer screenContainer, Inventory inv, Component titleIn) {
|
2020-05-07 18:30:40 +02:00
|
|
|
super(screenContainer, inv, titleIn);
|
2021-12-02 14:44:26 +01:00
|
|
|
this.imageWidth = 176 + 15;
|
|
|
|
this.imageHeight = 236;
|
2020-05-07 18:30:40 +02:00
|
|
|
}
|
|
|
|
|
2020-05-07 21:10:29 +02:00
|
|
|
@Override
|
|
|
|
protected void init() {
|
|
|
|
super.init();
|
2021-08-15 06:40:16 +02:00
|
|
|
|
2022-06-30 16:00:33 +02:00
|
|
|
this.search = this.addRenderableWidget(new EditBox(this.font, this.leftPos + this.getXOffset() + 97, this.topPos + 6, 86, 8, Component.literal("")));
|
2021-12-02 14:44:26 +01:00
|
|
|
this.search.setBordered(false);
|
2021-08-15 06:40:16 +02:00
|
|
|
this.lastSearchText = "";
|
|
|
|
if (this.items != null)
|
|
|
|
this.updateWidgets();
|
|
|
|
|
2023-07-07 19:54:52 +02:00
|
|
|
this.plusButton = this.addRenderableWidget(Button.builder(Component.literal("+"), button -> {
|
2022-06-30 16:00:33 +02:00
|
|
|
var modifier = ItemTerminalGui.requestModifier();
|
2020-05-07 21:10:29 +02:00
|
|
|
if (modifier > 1 && this.requestAmount == 1) {
|
|
|
|
this.requestAmount = modifier;
|
|
|
|
} else {
|
|
|
|
this.requestAmount += modifier;
|
|
|
|
}
|
2020-10-14 18:32:10 +02:00
|
|
|
// 384 items is 6 stacks, which is what fits into the terminal slots
|
2020-05-07 21:10:29 +02:00
|
|
|
if (this.requestAmount > 384)
|
|
|
|
this.requestAmount = 384;
|
2023-07-07 19:54:52 +02:00
|
|
|
}).bounds(this.leftPos + this.getXOffset() + 95 - 7 + 12, this.topPos + 103, 12, 12).build());
|
|
|
|
this.minusButton = this.addRenderableWidget(Button.builder(Component.literal("-"), button -> {
|
2022-06-30 16:00:33 +02:00
|
|
|
this.requestAmount -= ItemTerminalGui.requestModifier();
|
2020-05-07 21:10:29 +02:00
|
|
|
if (this.requestAmount < 1)
|
|
|
|
this.requestAmount = 1;
|
2023-07-07 19:54:52 +02:00
|
|
|
}).bounds(this.leftPos + this.getXOffset() + 95 - 7 - 24, this.topPos + 103, 12, 12).build());
|
2020-05-07 21:10:29 +02:00
|
|
|
this.minusButton.active = false;
|
2023-07-07 19:54:52 +02:00
|
|
|
this.requestButton = this.addRenderableWidget(Button.builder(Component.translatable("info." + PrettyPipes.ID + ".request"), button -> {
|
2021-12-02 16:55:04 +01:00
|
|
|
var widget = this.streamWidgets().filter(w -> w.selected).findFirst();
|
2020-05-07 21:10:29 +02:00
|
|
|
if (!widget.isPresent())
|
|
|
|
return;
|
2021-12-02 16:55:04 +01:00
|
|
|
var stack = widget.get().stack.copy();
|
2020-05-07 21:10:29 +02:00
|
|
|
stack.setCount(1);
|
2024-03-07 16:00:49 +01:00
|
|
|
PacketDistributor.SERVER.noArg().send(new PacketRequest(this.menu.tile.getBlockPos(), stack, this.requestAmount));
|
2020-05-07 21:10:29 +02:00
|
|
|
this.requestAmount = 1;
|
2023-07-07 19:54:52 +02:00
|
|
|
}).bounds(this.leftPos + this.getXOffset() + 95 - 7 - 25, this.topPos + 115, 50, 20).build());
|
2020-05-07 21:10:29 +02:00
|
|
|
this.requestButton.active = false;
|
2023-07-07 19:54:52 +02:00
|
|
|
this.orderButton = this.addRenderableWidget(Button.builder(Component.literal(""), button -> {
|
2020-05-08 16:06:17 +02:00
|
|
|
if (this.sortedItems == null)
|
2020-05-07 23:06:35 +02:00
|
|
|
return;
|
2021-12-02 16:55:04 +01:00
|
|
|
var prefs = PlayerPrefs.get();
|
2020-05-08 20:56:27 +02:00
|
|
|
prefs.terminalItemOrder = prefs.terminalItemOrder.next();
|
|
|
|
prefs.save();
|
|
|
|
this.updateWidgets();
|
2023-07-07 19:54:52 +02:00
|
|
|
}).bounds(this.leftPos - 22, this.topPos, 20, 20).build());
|
|
|
|
this.ascendingButton = this.addRenderableWidget(Button.builder(Component.literal(""), button -> {
|
2020-05-08 16:06:17 +02:00
|
|
|
if (this.sortedItems == null)
|
2020-05-07 23:06:35 +02:00
|
|
|
return;
|
2021-12-02 16:55:04 +01:00
|
|
|
var prefs = PlayerPrefs.get();
|
2020-05-08 20:56:27 +02:00
|
|
|
prefs.terminalAscending = !prefs.terminalAscending;
|
|
|
|
prefs.save();
|
|
|
|
this.updateWidgets();
|
2023-07-07 19:54:52 +02:00
|
|
|
}).bounds(this.leftPos - 22, this.topPos + 22, 20, 20).build());
|
|
|
|
this.cancelCraftingButton = this.addRenderableWidget(Button.builder(Component.translatable("info." + PrettyPipes.ID + ".cancel_all"), b -> {}).bounds(this.leftPos + this.imageWidth + 4, this.topPos + 4 + 64, 54, 20).build());
|
2020-10-20 00:52:56 +02:00
|
|
|
this.cancelCraftingButton.visible = false;
|
2021-12-02 16:55:04 +01:00
|
|
|
for (var y = 0; y < 4; y++) {
|
|
|
|
for (var x = 0; x < 9; x++)
|
|
|
|
this.addRenderableWidget(new ItemTerminalWidget(this.leftPos + this.getXOffset() + 8 + x * 18, this.topPos + 18 + y * 18, x, y, this));
|
2020-05-07 21:10:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-08 22:58:16 +02:00
|
|
|
protected int getXOffset() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-07 21:10:29 +02:00
|
|
|
@Override
|
2021-12-02 16:55:04 +01:00
|
|
|
public void containerTick() {
|
|
|
|
super.containerTick();
|
2020-05-07 21:10:29 +02:00
|
|
|
this.requestButton.active = this.streamWidgets().anyMatch(w -> w.selected);
|
|
|
|
this.plusButton.active = this.requestAmount < 384;
|
|
|
|
this.minusButton.active = this.requestAmount > 1;
|
2020-05-08 16:06:17 +02:00
|
|
|
|
2020-05-17 16:24:24 +02:00
|
|
|
if (this.items != null) {
|
2021-12-02 16:55:04 +01:00
|
|
|
var text = this.search.getValue();
|
2020-05-17 16:24:24 +02:00
|
|
|
if (!this.lastSearchText.equals(text)) {
|
|
|
|
this.lastSearchText = text;
|
|
|
|
this.updateWidgets();
|
|
|
|
}
|
2020-05-08 16:06:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-04 19:51:20 +01:00
|
|
|
@Override
|
|
|
|
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
2021-12-02 14:44:26 +01:00
|
|
|
if (button == 0 && mouseX >= this.leftPos + this.getXOffset() + 172 && this.topPos + mouseY >= 18 && mouseX < this.leftPos + this.getXOffset() + 172 + 12 && mouseY < this.topPos + 18 + 70) {
|
2020-12-04 19:51:20 +01:00
|
|
|
this.isScrolling = true;
|
|
|
|
return true;
|
2023-07-07 19:54:52 +02:00
|
|
|
} else if (button == 1 && mouseX >= this.search.getX() && mouseX <= this.search.getX() + this.search.getWidth() && mouseY >= this.search.getY() && mouseY <= this.search.getY() + 8) {
|
2022-05-20 10:43:40 +02:00
|
|
|
this.search.setValue("");
|
2023-07-07 19:54:52 +02:00
|
|
|
this.search.setFocused(true);
|
2022-05-20 10:43:40 +02:00
|
|
|
this.setFocused(this.search);
|
|
|
|
return true;
|
2020-12-04 19:51:20 +01:00
|
|
|
}
|
|
|
|
return super.mouseClicked(mouseX, mouseY, button);
|
|
|
|
}
|
|
|
|
|
2020-10-30 20:44:37 +01:00
|
|
|
@Override
|
|
|
|
public boolean mouseReleased(double mouseX, double mouseY, int button) {
|
|
|
|
// we have to do the click logic here because JEI is activated when letting go of the mouse button
|
|
|
|
// and vanilla buttons are activated when the click starts, so we'll always invoke jei accidentally by default
|
2023-07-07 20:44:52 +02:00
|
|
|
if (button == 0 && this.cancelCraftingButton.visible && this.cancelCraftingButton.isHovered()) {
|
2020-10-30 20:44:37 +01:00
|
|
|
if (this.currentlyCrafting != null && !this.currentlyCrafting.isEmpty()) {
|
2024-03-07 16:00:49 +01:00
|
|
|
PacketDistributor.SERVER.noArg().send(new PacketButton(this.menu.tile.getBlockPos(), PacketButton.ButtonResult.CANCEL_CRAFTING));
|
2020-10-30 20:44:37 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2020-12-04 19:51:20 +01:00
|
|
|
if (button == 0)
|
|
|
|
this.isScrolling = false;
|
2020-10-30 20:44:37 +01:00
|
|
|
return super.mouseReleased(mouseX, mouseY, button);
|
|
|
|
}
|
|
|
|
|
2020-12-04 19:51:20 +01:00
|
|
|
@Override
|
|
|
|
public boolean mouseDragged(double mouseX, double mouseY, int i, double j, double k) {
|
|
|
|
if (this.isScrolling) {
|
2021-12-02 16:55:04 +01:00
|
|
|
var percentage = Mth.clamp(((float) mouseY - (this.topPos + 18) - 7.5F) / (70 - 15), 0, 1);
|
|
|
|
var offset = (int) (percentage * (float) (this.sortedItems.size() / 9 - 3));
|
2020-12-04 19:51:20 +01:00
|
|
|
if (offset != this.scrollOffset) {
|
|
|
|
this.scrollOffset = offset;
|
|
|
|
this.updateWidgets();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return super.mouseDragged(mouseX, mouseY, i, j, k);
|
|
|
|
}
|
|
|
|
|
2020-05-08 16:06:17 +02:00
|
|
|
@Override
|
|
|
|
public boolean keyPressed(int x, int y, int z) {
|
|
|
|
// for some reason we have to do this to make the text field allow the inventory key to be typed
|
|
|
|
if (this.search.isFocused()) {
|
2021-12-02 16:55:04 +01:00
|
|
|
var mouseKey = InputConstants.getKey(x, y);
|
|
|
|
if (this.minecraft.options.keyInventory.isActiveAndMatches(mouseKey))
|
2020-05-08 16:06:17 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return super.keyPressed(x, y, z);
|
2020-05-07 21:10:29 +02:00
|
|
|
}
|
|
|
|
|
2020-10-20 00:52:56 +02:00
|
|
|
public void updateItemList(List<ItemStack> items, List<ItemStack> craftables, List<ItemStack> currentlyCrafting) {
|
2020-05-08 16:06:17 +02:00
|
|
|
this.items = items;
|
2020-10-14 22:30:02 +02:00
|
|
|
this.craftables = craftables;
|
2020-10-20 00:52:56 +02:00
|
|
|
this.currentlyCrafting = currentlyCrafting;
|
2020-05-07 21:50:50 +02:00
|
|
|
this.updateWidgets();
|
2020-05-07 21:10:29 +02:00
|
|
|
}
|
|
|
|
|
2020-05-08 21:19:32 +02:00
|
|
|
public void updateWidgets() {
|
2021-12-02 16:55:04 +01:00
|
|
|
var prefs = PlayerPrefs.get();
|
2022-06-30 16:00:33 +02:00
|
|
|
this.ascendingButton.setMessage(Component.literal(prefs.terminalAscending ? "^" : "v"));
|
|
|
|
this.orderButton.setMessage(Component.literal(prefs.terminalItemOrder.name().substring(0, 1)));
|
2020-10-20 00:52:56 +02:00
|
|
|
this.cancelCraftingButton.visible = this.currentlyCrafting != null && !this.currentlyCrafting.isEmpty();
|
2020-05-08 20:56:27 +02:00
|
|
|
|
2021-12-02 16:55:04 +01:00
|
|
|
var comparator = prefs.terminalItemOrder.comparator;
|
2020-05-08 20:56:27 +02:00
|
|
|
if (!prefs.terminalAscending)
|
2020-05-07 23:06:35 +02:00
|
|
|
comparator = comparator.reversed();
|
2020-05-08 16:06:17 +02:00
|
|
|
|
2020-10-14 22:30:02 +02:00
|
|
|
// add all items to the sorted items list
|
|
|
|
this.sortedItems.clear();
|
2021-12-02 16:55:04 +01:00
|
|
|
for (var stack : this.items)
|
2020-10-14 22:30:02 +02:00
|
|
|
this.sortedItems.add(Pair.of(stack, false));
|
2021-12-02 16:55:04 +01:00
|
|
|
for (var stack : this.craftables)
|
2020-10-14 22:30:02 +02:00
|
|
|
this.sortedItems.add(Pair.of(stack, true));
|
|
|
|
|
|
|
|
// compare by craftability first, and then by the player's chosen order
|
|
|
|
Comparator<Pair<ItemStack, Boolean>> fullComparator = Comparator.comparing(Pair::getRight);
|
|
|
|
this.sortedItems.sort(fullComparator.thenComparing(Pair::getLeft, comparator));
|
2020-05-08 16:06:17 +02:00
|
|
|
|
2021-12-02 16:55:04 +01:00
|
|
|
var searchText = this.search.getValue();
|
2020-05-08 16:06:17 +02:00
|
|
|
if (!Strings.isNullOrEmpty(searchText)) {
|
|
|
|
this.sortedItems.removeIf(s -> {
|
2021-12-02 16:55:04 +01:00
|
|
|
var search = searchText;
|
2020-05-08 16:06:17 +02:00
|
|
|
String toCompare;
|
|
|
|
if (search.startsWith("@")) {
|
2021-12-04 13:35:04 +01:00
|
|
|
// search mod id
|
2020-10-15 20:52:59 +02:00
|
|
|
toCompare = s.getLeft().getItem().getCreatorModId(s.getLeft());
|
2020-05-08 16:06:17 +02:00
|
|
|
search = search.substring(1);
|
2021-12-04 13:35:04 +01:00
|
|
|
} else if (search.startsWith("#")) {
|
|
|
|
// search item description
|
|
|
|
var hoverText = s.getLeft().getTooltipLines(this.minecraft.player,
|
|
|
|
this.minecraft.options.advancedItemTooltips ? TooltipFlag.Default.ADVANCED : TooltipFlag.Default.NORMAL);
|
|
|
|
toCompare = hoverText.stream().map(Component::getString).collect(Collectors.joining("\n"));
|
|
|
|
search = search.substring(1);
|
2020-05-08 16:06:17 +02:00
|
|
|
} else {
|
|
|
|
// don't use formatted text here since we want to search for name
|
2021-12-28 11:58:37 +01:00
|
|
|
toCompare = s.getLeft().getHoverName().getString();
|
2020-05-08 16:06:17 +02:00
|
|
|
}
|
|
|
|
return !toCompare.toLowerCase(Locale.ROOT).contains(search.toLowerCase(Locale.ROOT));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.sortedItems.size() < 9 * 4)
|
|
|
|
this.scrollOffset = 0;
|
2020-05-07 23:06:35 +02:00
|
|
|
|
2021-12-02 16:55:04 +01:00
|
|
|
var widgets = this.streamWidgets().collect(Collectors.toList());
|
|
|
|
for (var i = 0; i < widgets.size(); i++) {
|
|
|
|
var widget = widgets.get(i);
|
|
|
|
var index = i + this.scrollOffset * 9;
|
2020-05-08 16:06:17 +02:00
|
|
|
if (index >= this.sortedItems.size()) {
|
2020-05-07 21:10:29 +02:00
|
|
|
widget.stack = ItemStack.EMPTY;
|
2020-10-14 22:30:02 +02:00
|
|
|
widget.craftable = false;
|
2020-05-07 21:10:29 +02:00
|
|
|
widget.visible = false;
|
|
|
|
} else {
|
2021-12-02 16:55:04 +01:00
|
|
|
var stack = this.sortedItems.get(index);
|
2020-10-14 22:30:02 +02:00
|
|
|
widget.stack = stack.getLeft();
|
|
|
|
widget.craftable = stack.getRight();
|
2020-05-07 21:10:29 +02:00
|
|
|
widget.visible = true;
|
2020-05-07 18:30:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-07-07 19:54:52 +02:00
|
|
|
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
2024-02-03 22:01:43 +01:00
|
|
|
this.renderBackground(graphics, mouseX, mouseY, partialTicks);
|
2023-07-07 19:54:52 +02:00
|
|
|
super.render(graphics, mouseX, mouseY, partialTicks);
|
2021-12-02 16:55:04 +01:00
|
|
|
for (var widget : this.renderables) {
|
|
|
|
if (widget instanceof ItemTerminalWidget terminal)
|
2023-07-07 19:54:52 +02:00
|
|
|
terminal.renderToolTip(graphics, mouseX, mouseY);
|
2020-05-07 23:06:35 +02:00
|
|
|
}
|
2020-05-08 16:06:17 +02:00
|
|
|
if (this.sortedItems != null) {
|
2021-12-02 16:55:04 +01:00
|
|
|
var prefs = PlayerPrefs.get();
|
2023-07-07 20:44:52 +02:00
|
|
|
if (this.orderButton.isHovered())
|
2023-07-07 19:54:52 +02:00
|
|
|
graphics.renderTooltip(this.font, Component.translatable("info." + PrettyPipes.ID + ".order", I18n.get("info." + PrettyPipes.ID + ".order." + prefs.terminalItemOrder.name().toLowerCase(Locale.ROOT))), mouseX, mouseY);
|
2023-07-07 20:44:52 +02:00
|
|
|
if (this.ascendingButton.isHovered())
|
2023-07-07 19:54:52 +02:00
|
|
|
graphics.renderTooltip(this.font, Component.translatable("info." + PrettyPipes.ID + "." + (prefs.terminalAscending ? "ascending" : "descending")), mouseX, mouseY);
|
2020-05-07 18:30:40 +02:00
|
|
|
}
|
2023-07-07 20:44:52 +02:00
|
|
|
if (this.cancelCraftingButton.visible && this.cancelCraftingButton.isHovered()) {
|
2021-12-02 16:55:04 +01:00
|
|
|
var tooltip = I18n.get("info." + PrettyPipes.ID + ".cancel_all.desc").split("\n");
|
2023-07-07 19:54:52 +02:00
|
|
|
graphics.renderTooltip(this.font, Arrays.stream(tooltip).map(Component::literal).collect(Collectors.toList()), Optional.empty(), mouseX, mouseY);
|
2020-10-20 00:52:56 +02:00
|
|
|
}
|
|
|
|
if (!this.hoveredCrafting.isEmpty())
|
2023-07-07 19:54:52 +02:00
|
|
|
graphics.renderTooltip(this.font, this.hoveredCrafting, mouseX, mouseY);
|
|
|
|
this.renderTooltip(graphics, mouseX, mouseY);
|
2020-05-07 18:30:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-07-07 19:54:52 +02:00
|
|
|
protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) {
|
2023-07-07 20:44:52 +02:00
|
|
|
graphics.drawString(this.font, this.playerInventoryTitle.getString(), 8 + this.getXOffset(), this.imageHeight - 96 + 2, 4210752, false);
|
|
|
|
graphics.drawString(this.font, this.title.getString(), 8, 6, 4210752, false);
|
2020-05-07 21:10:29 +02:00
|
|
|
|
2021-12-02 16:55:04 +01:00
|
|
|
var amount = String.valueOf(this.requestAmount);
|
2023-07-07 20:44:52 +02:00
|
|
|
graphics.drawString(this.font, amount, (176 + 15 - this.font.width(amount)) / 2 - 7 + this.getXOffset(), 106, 4210752, false);
|
2020-10-20 00:52:56 +02:00
|
|
|
|
|
|
|
if (this.currentlyCrafting != null && !this.currentlyCrafting.isEmpty()) {
|
2023-07-07 20:44:52 +02:00
|
|
|
graphics.drawString(this.font, I18n.get("info." + PrettyPipes.ID + ".crafting"), this.imageWidth + 4, 4 + 6, 4210752, false);
|
2020-10-20 00:52:56 +02:00
|
|
|
if (this.currentlyCrafting.size() > 6)
|
2023-07-07 20:44:52 +02:00
|
|
|
graphics.drawString(this.font, ". . .", this.imageWidth + 24, 4 + 51, 4210752, false);
|
2020-10-20 00:52:56 +02:00
|
|
|
}
|
2020-05-07 18:30:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-07-07 19:54:52 +02:00
|
|
|
protected void renderBg(GuiGraphics graphics, float partialTicks, int mouseX, int mouseY) {
|
|
|
|
graphics.blit(this.getTexture(), this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight);
|
2020-05-07 21:50:50 +02:00
|
|
|
|
2020-05-08 16:06:17 +02:00
|
|
|
if (this.sortedItems != null && this.sortedItems.size() >= 9 * 4) {
|
2021-12-02 16:55:04 +01:00
|
|
|
var percentage = this.scrollOffset / (float) (this.sortedItems.size() / 9 - 3);
|
2023-07-07 19:54:52 +02:00
|
|
|
graphics.blit(this.getTexture(), this.leftPos + this.getXOffset() + 172, this.topPos + 18 + (int) (percentage * (70 - 15)), 232, 241, 12, 15);
|
2020-05-07 21:50:50 +02:00
|
|
|
} else {
|
2023-07-07 19:54:52 +02:00
|
|
|
graphics.blit(this.getTexture(), this.leftPos + this.getXOffset() + 172, this.topPos + 18, 244, 241, 12, 15);
|
2020-05-07 21:50:50 +02:00
|
|
|
}
|
2020-10-20 00:52:56 +02:00
|
|
|
|
|
|
|
// draw the items that are currently crafting
|
|
|
|
this.hoveredCrafting = ItemStack.EMPTY;
|
|
|
|
if (this.currentlyCrafting != null && !this.currentlyCrafting.isEmpty()) {
|
2023-07-07 19:54:52 +02:00
|
|
|
graphics.blit(ItemTerminalGui.TEXTURE, this.leftPos + this.imageWidth, this.topPos + 4, 191, 0, 65, 89);
|
2021-12-02 16:55:04 +01:00
|
|
|
|
|
|
|
var x = 0;
|
|
|
|
var y = 0;
|
|
|
|
for (var stack : this.currentlyCrafting) {
|
|
|
|
var itemX = this.leftPos + this.imageWidth + 4 + x * 18;
|
|
|
|
var itemY = this.topPos + 4 + 16 + y * 18;
|
2023-07-07 19:54:52 +02:00
|
|
|
graphics.renderItem(stack, itemX, itemY);
|
|
|
|
graphics.renderItemDecorations(this.font, stack, itemX, itemY, String.valueOf(stack.getCount()));
|
2020-10-20 00:52:56 +02:00
|
|
|
if (mouseX >= itemX && mouseY >= itemY && mouseX < itemX + 16 && mouseY < itemY + 18)
|
|
|
|
this.hoveredCrafting = stack;
|
|
|
|
x++;
|
|
|
|
if (x >= 3) {
|
|
|
|
x = 0;
|
|
|
|
y++;
|
|
|
|
if (y >= 2)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-07 21:50:50 +02:00
|
|
|
}
|
|
|
|
|
2020-05-08 22:58:16 +02:00
|
|
|
protected ResourceLocation getTexture() {
|
2022-06-30 16:00:33 +02:00
|
|
|
return ItemTerminalGui.TEXTURE;
|
2020-05-08 22:58:16 +02:00
|
|
|
}
|
|
|
|
|
2020-05-07 21:50:50 +02:00
|
|
|
@Override
|
2024-02-03 22:01:43 +01:00
|
|
|
public boolean mouseScrolled(double x, double y, double scrollX, double scrollY) {
|
2020-05-08 16:06:17 +02:00
|
|
|
if (this.sortedItems != null && this.sortedItems.size() >= 9 * 4) {
|
2024-02-03 22:01:43 +01:00
|
|
|
var offset = Mth.clamp(this.scrollOffset - (int) Math.signum(scrollY), 0, this.sortedItems.size() / 9 - 3);
|
2020-05-07 21:50:50 +02:00
|
|
|
if (offset != this.scrollOffset) {
|
|
|
|
this.scrollOffset = offset;
|
|
|
|
this.updateWidgets();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2020-05-07 18:30:40 +02:00
|
|
|
}
|
|
|
|
|
2021-12-19 17:27:21 +01:00
|
|
|
@Override
|
2023-07-07 19:54:52 +02:00
|
|
|
public <T extends GuiEventListener & Renderable & NarratableEntry> T addRenderableWidget(T p_169406_) {
|
2021-12-19 17:27:21 +01:00
|
|
|
// overriding to public for JEIPrettyPipesPlugin
|
|
|
|
return super.addRenderableWidget(p_169406_);
|
|
|
|
}
|
|
|
|
|
2020-05-07 21:10:29 +02:00
|
|
|
public Stream<ItemTerminalWidget> streamWidgets() {
|
2021-12-02 16:55:04 +01:00
|
|
|
return this.renderables.stream()
|
2020-05-07 21:10:29 +02:00
|
|
|
.filter(w -> w instanceof ItemTerminalWidget)
|
|
|
|
.map(w -> (ItemTerminalWidget) w);
|
|
|
|
}
|
|
|
|
|
2020-10-14 18:32:10 +02:00
|
|
|
public static int requestModifier() {
|
2022-06-30 16:00:33 +02:00
|
|
|
if (Screen.hasControlDown()) {
|
2020-05-07 21:10:29 +02:00
|
|
|
return 10;
|
2022-06-30 16:00:33 +02:00
|
|
|
} else if (Screen.hasShiftDown()) {
|
2020-05-07 21:10:29 +02:00
|
|
|
return 64;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
2020-05-07 18:30:40 +02:00
|
|
|
}
|
2024-02-03 22:01:43 +01:00
|
|
|
|
2020-05-07 18:30:40 +02:00
|
|
|
}
|