2020-05-08 22:58:16 +02:00
|
|
|
package de.ellpeck.prettypipes.terminal.containers;
|
|
|
|
|
2022-05-20 09:38:51 +02:00
|
|
|
import com.mojang.blaze3d.platform.InputConstants;
|
2020-05-08 22:58:16 +02:00
|
|
|
import de.ellpeck.prettypipes.PrettyPipes;
|
2020-05-09 13:40:46 +02:00
|
|
|
import de.ellpeck.prettypipes.packets.PacketButton;
|
2023-07-07 19:54:52 +02:00
|
|
|
import net.minecraft.client.gui.GuiGraphics;
|
2021-12-02 16:55:04 +01:00
|
|
|
import net.minecraft.client.gui.components.Button;
|
2022-06-30 16:00:33 +02:00
|
|
|
import net.minecraft.client.gui.screens.Screen;
|
2021-12-02 16:55:04 +01:00
|
|
|
import net.minecraft.network.chat.Component;
|
2021-12-02 12:31:04 +01:00
|
|
|
import net.minecraft.resources.ResourceLocation;
|
2021-12-02 16:55:04 +01:00
|
|
|
import net.minecraft.world.entity.player.Inventory;
|
2024-03-07 16:00:49 +01:00
|
|
|
import net.neoforged.neoforge.network.PacketDistributor;
|
2020-05-08 22:58:16 +02:00
|
|
|
|
|
|
|
public class CraftingTerminalGui extends ItemTerminalGui {
|
2021-12-02 16:55:04 +01:00
|
|
|
|
2020-05-08 22:58:16 +02:00
|
|
|
private static final ResourceLocation TEXTURE = new ResourceLocation(PrettyPipes.ID, "textures/gui/crafting_terminal.png");
|
2020-05-09 01:00:59 +02:00
|
|
|
private Button requestButton;
|
2020-05-08 22:58:16 +02:00
|
|
|
|
2021-12-02 16:55:04 +01:00
|
|
|
public CraftingTerminalGui(ItemTerminalContainer screenContainer, Inventory inv, Component titleIn) {
|
2020-05-08 22:58:16 +02:00
|
|
|
super(screenContainer, inv, titleIn);
|
2021-12-02 16:55:04 +01:00
|
|
|
this.imageWidth = 256;
|
2020-05-08 22:58:16 +02:00
|
|
|
}
|
|
|
|
|
2020-05-09 01:00:59 +02:00
|
|
|
@Override
|
|
|
|
protected void init() {
|
|
|
|
super.init();
|
2023-07-07 19:54:52 +02:00
|
|
|
this.requestButton = this.addRenderableWidget(Button.builder(Component.translatable("info." + PrettyPipes.ID + ".request"), button -> {
|
2022-06-30 16:00:33 +02:00
|
|
|
var amount = ItemTerminalGui.requestModifier();
|
2022-05-20 09:38:51 +02:00
|
|
|
// also allow holding backspace instead of alt for people whose alt key is inaccessible (linux?)
|
2022-06-30 16:00:33 +02:00
|
|
|
var force = Screen.hasAltDown() || InputConstants.isKeyDown(this.minecraft.getWindow().getWindow(), 259) ? 1 : 0;
|
2024-03-07 16:00:49 +01:00
|
|
|
PacketDistributor.SERVER.noArg().send(new PacketButton(this.menu.tile.getBlockPos(), PacketButton.ButtonResult.CRAFT_TERMINAL_REQUEST, amount, force));
|
2023-07-07 19:54:52 +02:00
|
|
|
}).bounds(this.leftPos + 8, this.topPos + 100, 50, 20).build());
|
2020-05-09 15:42:09 +02:00
|
|
|
this.tick();
|
2020-05-09 01:00:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-02 16:55:04 +01:00
|
|
|
public void containerTick() {
|
|
|
|
super.containerTick();
|
|
|
|
var tile = this.getCraftingContainer().getTile();
|
2020-05-09 14:56:58 +02:00
|
|
|
this.requestButton.active = false;
|
2021-12-02 16:55:04 +01:00
|
|
|
for (var i = 0; i < tile.craftItems.getSlots(); i++) {
|
|
|
|
var stack = tile.getRequestedCraftItem(i);
|
2020-05-09 15:42:09 +02:00
|
|
|
if (!stack.isEmpty() && stack.getCount() < stack.getMaxStackSize()) {
|
2020-05-09 14:56:58 +02:00
|
|
|
this.requestButton.active = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-07-07 19:54:52 +02:00
|
|
|
protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) {
|
|
|
|
super.renderLabels(graphics, mouseX, mouseY);
|
2020-05-09 14:56:58 +02:00
|
|
|
|
2021-12-02 16:55:04 +01:00
|
|
|
var container = this.getCraftingContainer();
|
|
|
|
var tile = container.getTile();
|
|
|
|
for (var i = 0; i < tile.ghostItems.getSlots(); i++) {
|
2020-05-09 14:56:58 +02:00
|
|
|
if (!tile.craftItems.getStackInSlot(i).isEmpty())
|
|
|
|
continue;
|
2021-12-02 16:55:04 +01:00
|
|
|
var ghost = tile.ghostItems.getStackInSlot(i);
|
2020-05-09 14:56:58 +02:00
|
|
|
if (ghost.isEmpty())
|
|
|
|
continue;
|
2021-12-02 16:55:04 +01:00
|
|
|
var finalI = i;
|
|
|
|
var slot = container.slots.stream().filter(s -> s.container == container.craftInventory && s.getSlotIndex() == finalI).findFirst().orElse(null);
|
2020-05-09 14:56:58 +02:00
|
|
|
if (slot == null)
|
|
|
|
continue;
|
2023-07-07 19:54:52 +02:00
|
|
|
graphics.renderItem(ghost, slot.x, slot.y);
|
|
|
|
graphics.renderItemDecorations(this.font, ghost, slot.x, slot.y, "0");
|
2020-05-09 14:56:58 +02:00
|
|
|
}
|
2020-05-09 01:00:59 +02:00
|
|
|
}
|
|
|
|
|
2020-05-08 22:58:16 +02:00
|
|
|
@Override
|
|
|
|
protected ResourceLocation getTexture() {
|
2022-06-30 16:00:33 +02:00
|
|
|
return CraftingTerminalGui.TEXTURE;
|
2020-05-08 22:58:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected int getXOffset() {
|
|
|
|
return 65;
|
|
|
|
}
|
2020-05-09 01:00:59 +02:00
|
|
|
|
|
|
|
protected CraftingTerminalContainer getCraftingContainer() {
|
2021-12-02 16:55:04 +01:00
|
|
|
return (CraftingTerminalContainer) this.menu;
|
2020-05-09 01:00:59 +02:00
|
|
|
}
|
2024-03-07 16:00:49 +01:00
|
|
|
|
2020-05-08 22:58:16 +02:00
|
|
|
}
|