Skip to content

Commit

Permalink
show the next terminal on the next terminal button (fix #265)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mari023 committed May 23, 2024
1 parent 7b89126 commit 551e475
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/main/java/de/mari_023/ae2wtlib/TextConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public static MutableComponent formatTerminalName(String terminal) {

public static final Component TERMINAL_EMPTY = Component
.literal("This terminal does not contain any other Terminals");
public static final Component CYCLE_TOOLTIP = Component.translatable("gui.ae2wtlib.cycle_terminal.desc");
public static final Component CYCLE_TOOLTIP = Component.translatable("gui.ae2wtlib.cycle_terminal.desc")
.append("\n").append(Component.translatable("gui.ae2wtlib.cycle_terminal.desc1"));

public static final MutableComponent TRASH = Component.translatable("gui.ae2wtlib.trash");

Expand Down
8 changes: 7 additions & 1 deletion src/main/java/de/mari_023/ae2wtlib/wat/WATScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,27 @@
import appeng.client.gui.widgets.UpgradesPanel;
import appeng.menu.SlotSemantics;

import de.mari_023.ae2wtlib.terminal.WTMenuHost;
import de.mari_023.ae2wtlib.wut.CycleTerminalButton;
import de.mari_023.ae2wtlib.wut.IUniversalTerminalCapable;

public class WATScreen extends PatternAccessTermScreen<WATMenu> implements IUniversalTerminalCapable {
public WATScreen(WATMenu container, Inventory playerInventory, Component title, ScreenStyle style) {
super(container, playerInventory, title, style);
if (getMenu().isWUT())
addToLeftToolbar(new CycleTerminalButton(btn -> cycleTerminal()));
addToLeftToolbar(new CycleTerminalButton(this));

widgets.add("upgrades", new UpgradesPanel(getMenu().getSlots(SlotSemantics.UPGRADE), getMenu().getHost()));
if (getMenu().getToolbox().isPresent())
widgets.add("toolbox", new ToolboxPanel(style, getMenu().getToolbox().getName()));
widgets.add("singularityBackground", new BackgroundPanel(style.getImage("singularityBackground")));
}

@Override
public WTMenuHost getHost() {
return (WTMenuHost) getMenu().getHost();
}

@Override
public void storeState() {
}
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/de/mari_023/ae2wtlib/wct/WCTScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import de.mari_023.ae2wtlib.AE2wtlib;
import de.mari_023.ae2wtlib.TextConstants;
import de.mari_023.ae2wtlib.terminal.ItemButton;
import de.mari_023.ae2wtlib.terminal.WTMenuHost;
import de.mari_023.ae2wtlib.wct.magnet_card.MagnetMode;
import de.mari_023.ae2wtlib.wut.CycleTerminalButton;
import de.mari_023.ae2wtlib.wut.IUniversalTerminalCapable;
Expand All @@ -26,7 +27,7 @@ public class WCTScreen extends CraftingTermScreen<WCTMenu> implements IUniversal
public WCTScreen(WCTMenu container, Inventory playerInventory, Component title, ScreenStyle style) {
super(container, playerInventory, title, style);
if (getMenu().isWUT())
addToLeftToolbar(new CycleTerminalButton(btn -> cycleTerminal()));
addToLeftToolbar(new CycleTerminalButton(this));

magnetCardToggleButton = new ItemButton(btn -> setMagnetMode(),
AE2wtlib.id("textures/item/magnet_card.png"));
Expand Down Expand Up @@ -101,4 +102,9 @@ public boolean keyPressed(int keyCode, int scanCode, int keyPressed) {
return checkForTerminalKeys(keyCode, scanCode);
return true;
}

@Override
public WTMenuHost getHost() {
return (WTMenuHost) getMenu().getHost();
}
}
8 changes: 7 additions & 1 deletion src/main/java/de/mari_023/ae2wtlib/wet/WETScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
import appeng.client.gui.style.ScreenStyle;
import appeng.client.gui.widgets.BackgroundPanel;

import de.mari_023.ae2wtlib.terminal.WTMenuHost;
import de.mari_023.ae2wtlib.wut.CycleTerminalButton;
import de.mari_023.ae2wtlib.wut.IUniversalTerminalCapable;

public class WETScreen extends PatternEncodingTermScreen<WETMenu> implements IUniversalTerminalCapable {
public WETScreen(WETMenu container, Inventory playerInventory, Component title, ScreenStyle style) {
super(container, playerInventory, title, style);
if (getMenu().isWUT())
addToLeftToolbar(new CycleTerminalButton(btn -> cycleTerminal()));
addToLeftToolbar(new CycleTerminalButton(this));
widgets.add("singularityBackground", new BackgroundPanel(style.getImage("singularityBackground")));
}

Expand All @@ -25,4 +26,9 @@ public boolean keyPressed(int keyCode, int scanCode, int keyPressed) {
return checkForTerminalKeys(keyCode, scanCode);
return true;
}

@Override
public WTMenuHost getHost() {
return (WTMenuHost) getMenu().getHost();
}
}
39 changes: 34 additions & 5 deletions src/main/java/de/mari_023/ae2wtlib/wut/CycleTerminalButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,33 @@
import java.util.Collections;
import java.util.List;

import com.mojang.blaze3d.platform.Lighting;
import com.mojang.blaze3d.systems.RenderSystem;

import org.jetbrains.annotations.NotNull;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.renderer.Rect2i;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;

import appeng.client.gui.widgets.ITooltip;
import appeng.core.AppEng;

import de.mari_023.ae2wtlib.AE2wtlib;
import de.mari_023.ae2wtlib.TextConstants;

public class CycleTerminalButton extends Button implements ITooltip {
public CycleTerminalButton(OnPress onPress) {
super(0, 0, 16, 16, Component.empty(), onPress, Button.DEFAULT_NARRATION);
private final ItemStack nextTerminal;

public CycleTerminalButton(IUniversalTerminalCapable terminalScreen) {
super(0, 0, 16, 16, Component.empty(), btn -> terminalScreen.cycleTerminal(), Button.DEFAULT_NARRATION);
this.nextTerminal = terminalScreen.nextTerminal();
visible = true;
active = true;
}
Expand All @@ -42,7 +50,6 @@ public boolean isTooltipAreaVisible() {
}

public static final ResourceLocation TEXTURE_STATES = AppEng.makeId("textures/guis/states.png");
public static final ResourceLocation nextTerminal = AE2wtlib.id("textures/item/wireless_universal_terminal.png");

@Override
public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partial) {
Expand All @@ -62,7 +69,29 @@ public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float
else
RenderSystem.setShaderColor(0.5f, 0.5f, 0.5f, 1.0f);

guiGraphics.blit(nextTerminal, getX() + 1, getY() + 1, 14, 14, 0, 0, 512, 512, 512, 512);
renderScaledItem(guiGraphics, nextTerminal, getX(), getY());

guiGraphics.pose().popPose();
}

private void renderScaledItem(GuiGraphics guiGraphics, ItemStack stack, int x, int y) {
guiGraphics.pose().pushPose();

var mc = Minecraft.getInstance();

BakedModel bakedmodel = mc.getItemRenderer().getModel(stack, null, null, 0);
guiGraphics.pose().translate((float) (x + 8), (float) (y + 8), (float) (150));
guiGraphics.pose().scale(16.0F * (14F / 16F), -16.0F * (14F / 16F), 16.0F * (14F / 16F));
boolean flag = !bakedmodel.usesBlockLight();
if (flag) {
Lighting.setupForFlatItems();
}
mc.getItemRenderer().render(stack, ItemDisplayContext.GUI, false, guiGraphics.pose(),
guiGraphics.bufferSource(), 15728880, OverlayTexture.NO_OVERLAY, bakedmodel);
guiGraphics.flush();
if (flag) {
Lighting.setupFor3DItems();
}

guiGraphics.pose().popPose();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
package de.mari_023.ae2wtlib.wut;

import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.network.PacketDistributor;

import appeng.client.Hotkeys;
import appeng.core.network.serverbound.HotkeyPacket;

import de.mari_023.ae2wtlib.networking.CycleTerminalPacket;
import de.mari_023.ae2wtlib.terminal.WTMenuHost;

public interface IUniversalTerminalCapable {
default void cycleTerminal() {
storeState();
PacketDistributor.sendToServer(new CycleTerminalPacket(isHandlingRightClick()));
}

default ItemStack nextTerminal() {
return new ItemStack(
WUTHandler.wirelessTerminals.get(WUTHandler.nextTerminal(getHost().getItemStack(), false)).item());
}

WTMenuHost getHost();

boolean isHandlingRightClick();

void storeState();
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/de/mari_023/ae2wtlib/wut/WUTHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,16 @@ public static boolean hasTerminal(ItemStack terminal, String terminalName) {
*/
public static void cycle(Player player, ItemMenuHostLocator locator, ItemStack itemStack,
boolean isHandlingRightClick) {
String nextTerminal = nextTerminal(itemStack, isHandlingRightClick);
itemStack.set(AE2wtlibComponents.CURRENT_TERMINAL, nextTerminal);
updateClientTerminal((ServerPlayer) player, locator, itemStack);
}

public static String nextTerminal(ItemStack itemStack, boolean reverse) {
String nextTerminal = getCurrentTerminal(itemStack);
do {
int i;
if (isHandlingRightClick) {
if (reverse) {
i = terminalNames.indexOf(nextTerminal) - 1;
if (i == -1)
i = terminalNames.size() - 1;
Expand All @@ -119,8 +125,7 @@ public static void cycle(Player player, ItemMenuHostLocator locator, ItemStack i
}
nextTerminal = terminalNames.get(i);
} while (itemStack.get(wirelessTerminals.get(nextTerminal).componentType()) == null);
itemStack.set(AE2wtlibComponents.CURRENT_TERMINAL, nextTerminal);
updateClientTerminal((ServerPlayer) player, locator, itemStack);
return nextTerminal;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/ae2wtlib/lang/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"gui.ae2wtlib.magnetcard.desc.inv": "Items werden in das Inventar eingesammelt",
"gui.ae2wtlib.magnetcard.desc.me": "Items werden in das Inventar eingesammelt",
"gui.ae2wtlib.cycle_terminal.desc": "nächste Konsole Öffnen",
"gui.ae2wtlib.cycle_terminal.desc1": "Rechtsklick um die vorherige Konsole zu Öffnen",
"gui.ae2wtlib.magnetcard.hotkey": "Magnet Karte: ",
"gui.ae2wtlib.restock": "Nachfüllen: ",
"gui.ae2wtlib.off": "Aus",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/ae2wtlib/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"gui.ae2wtlib.magnetcard.desc.inv": "ʎɹoʇuǝʌuI oʇ dnʞɔᴉԀ",
"gui.ae2wtlib.magnetcard.desc.me": "ǝw oʇ dnʞɔᴉԀ",
"gui.ae2wtlib.cycle_terminal.desc": "lɐuᴉɯɹǝ⟘ ʇxǝu uǝdO",
"gui.ae2wtlib.cycle_terminal.desc1": "lɐuᴉɯɹǝ⟘ snoᴉʌǝɹd uǝdO oʇ ʞɔᴉlɔ ʇɥƃᴉɹ",
"gui.ae2wtlib.magnetcard.hotkey": "pɹɐƆ ʇǝuƃɐW: ",
"gui.ae2wtlib.restock": " :ʞɔoʇsǝᴚ",
"gui.ae2wtlib.off": "ɟɟO",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/ae2wtlib/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"gui.ae2wtlib.magnetcard.desc.inv": "Pickup to Inventory",
"gui.ae2wtlib.magnetcard.desc.me": "Pickup to ME",
"gui.ae2wtlib.cycle_terminal.desc": "Open next Terminal",
"gui.ae2wtlib.cycle_terminal.desc1": "Right click to open previous terminal",
"gui.ae2wtlib.magnetcard.hotkey": "Magnet Card: ",
"gui.ae2wtlib.restock": "Restock: ",
"gui.ae2wtlib.off": "Off",
Expand Down

0 comments on commit 551e475

Please sign in to comment.