From b3c57de5082c61408c32d5ee8b623765934d297c Mon Sep 17 00:00:00 2001 From: BlayTheNinth <1933180+BlayTheNinth@users.noreply.github.com> Date: Sat, 30 Dec 2023 22:05:22 +0100 Subject: [PATCH] Fix printer model, add tooltip to lock button --- .../{LockButton.java => InputLockButton.java} | 22 ++++++++++++++++--- .../client/gui/screen/BlenderScreen.java | 6 ++--- .../client/gui/screen/PrinterScreen.java | 4 ++-- .../assets/forbiddensmoothies/lang/en_us.json | 2 ++ .../models/block/printer.json | 1 + 5 files changed, 26 insertions(+), 9 deletions(-) rename shared/src/main/java/net/blay09/mods/forbiddensmoothies/client/gui/{LockButton.java => InputLockButton.java} (53%) diff --git a/shared/src/main/java/net/blay09/mods/forbiddensmoothies/client/gui/LockButton.java b/shared/src/main/java/net/blay09/mods/forbiddensmoothies/client/gui/InputLockButton.java similarity index 53% rename from shared/src/main/java/net/blay09/mods/forbiddensmoothies/client/gui/LockButton.java rename to shared/src/main/java/net/blay09/mods/forbiddensmoothies/client/gui/InputLockButton.java index 28125a1..2dfd33e 100644 --- a/shared/src/main/java/net/blay09/mods/forbiddensmoothies/client/gui/LockButton.java +++ b/shared/src/main/java/net/blay09/mods/forbiddensmoothies/client/gui/InputLockButton.java @@ -2,18 +2,20 @@ import net.blay09.mods.forbiddensmoothies.ForbiddenSmoothies; import net.blay09.mods.forbiddensmoothies.menu.InputLockableMenu; -import net.blay09.mods.forbiddensmoothies.menu.PrinterMenu; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.Tooltip; +import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipPositioner; +import net.minecraft.client.gui.screens.inventory.tooltip.DefaultTooltipPositioner; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; -public class LockButton extends Button { +public class InputLockButton extends Button { private static final ResourceLocation guiTexture = new ResourceLocation(ForbiddenSmoothies.MOD_ID, "textures/gui/printer.png"); private final InputLockableMenu menu; - public LockButton(int x, int y, int width, int height, OnPress onPress, InputLockableMenu menu) { + public InputLockButton(int x, int y, int width, int height, OnPress onPress, InputLockableMenu menu) { super(x, y, width, height, Component.translatable("gui.forbiddensmoothies.lockButton"), onPress, DEFAULT_NARRATION); this.menu = menu; } @@ -22,5 +24,19 @@ public LockButton(int x, int y, int width, int height, OnPress onPress, InputLoc protected void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { final var locked = menu.isLockedInputs(); guiGraphics.blit(guiTexture, getX(), getY(), locked ? 216 : 196, isHovered ? 20 : 0, 20, 20); + + if(isHovered) { + setTooltip(createTooltip()); + } + } + + private Tooltip createTooltip() { + final var component = menu.isLockedInputs() ? Component.translatable("tooltip.forbiddensmoothies.unlockInputs") : Component.translatable("tooltip.forbiddensmoothies.lockInputs"); + return Tooltip.create(component); + } + + @Override + protected ClientTooltipPositioner createTooltipPositioner() { + return DefaultTooltipPositioner.INSTANCE; } } diff --git a/shared/src/main/java/net/blay09/mods/forbiddensmoothies/client/gui/screen/BlenderScreen.java b/shared/src/main/java/net/blay09/mods/forbiddensmoothies/client/gui/screen/BlenderScreen.java index c4d5d6b..d9c04fa 100644 --- a/shared/src/main/java/net/blay09/mods/forbiddensmoothies/client/gui/screen/BlenderScreen.java +++ b/shared/src/main/java/net/blay09/mods/forbiddensmoothies/client/gui/screen/BlenderScreen.java @@ -2,17 +2,15 @@ import net.blay09.mods.balm.api.Balm; import net.blay09.mods.forbiddensmoothies.ForbiddenSmoothies; -import net.blay09.mods.forbiddensmoothies.client.gui.LockButton; +import net.blay09.mods.forbiddensmoothies.client.gui.InputLockButton; import net.blay09.mods.forbiddensmoothies.client.gui.PowerMeterWidget; import net.blay09.mods.forbiddensmoothies.menu.BlenderMenu; -import net.blay09.mods.forbiddensmoothies.menu.PrinterMenu; import net.blay09.mods.forbiddensmoothies.network.SetInputLockMessage; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -import net.minecraft.world.inventory.Slot; public class BlenderScreen extends AbstractContainerScreen { @@ -28,7 +26,7 @@ public BlenderScreen(BlenderMenu menu, Inventory inventory, Component title) { protected void init() { super.init(); - final var lockButton = new LockButton(leftPos + 7, topPos + 17, 20, 20, button -> { + final var lockButton = new InputLockButton(leftPos + 7, topPos + 17, 20, 20, button -> { Balm.getNetworking().sendToServer(new SetInputLockMessage(!menu.isLockedInputs())); menu.setLockedInputs(!menu.isLockedInputs()); }, menu); diff --git a/shared/src/main/java/net/blay09/mods/forbiddensmoothies/client/gui/screen/PrinterScreen.java b/shared/src/main/java/net/blay09/mods/forbiddensmoothies/client/gui/screen/PrinterScreen.java index 9431bc4..4e39377 100644 --- a/shared/src/main/java/net/blay09/mods/forbiddensmoothies/client/gui/screen/PrinterScreen.java +++ b/shared/src/main/java/net/blay09/mods/forbiddensmoothies/client/gui/screen/PrinterScreen.java @@ -2,7 +2,7 @@ import net.blay09.mods.balm.api.Balm; import net.blay09.mods.forbiddensmoothies.ForbiddenSmoothies; -import net.blay09.mods.forbiddensmoothies.client.gui.LockButton; +import net.blay09.mods.forbiddensmoothies.client.gui.InputLockButton; import net.blay09.mods.forbiddensmoothies.client.gui.PowerMeterWidget; import net.blay09.mods.forbiddensmoothies.menu.PrinterMenu; import net.blay09.mods.forbiddensmoothies.network.SetInputLockMessage; @@ -26,7 +26,7 @@ public PrinterScreen(PrinterMenu menu, Inventory inventory, Component title) { protected void init() { super.init(); - final var lockButton = new LockButton(leftPos + 7, topPos + 17, 20, 20, button -> { + final var lockButton = new InputLockButton(leftPos + 7, topPos + 17, 20, 20, button -> { Balm.getNetworking().sendToServer(new SetInputLockMessage(!menu.isLockedInputs())); menu.setLockedInputs(!menu.isLockedInputs()); }, menu); diff --git a/shared/src/main/resources/assets/forbiddensmoothies/lang/en_us.json b/shared/src/main/resources/assets/forbiddensmoothies/lang/en_us.json index 049a8ab..7b3544f 100644 --- a/shared/src/main/resources/assets/forbiddensmoothies/lang/en_us.json +++ b/shared/src/main/resources/assets/forbiddensmoothies/lang/en_us.json @@ -5,6 +5,8 @@ "container.forbiddensmoothies.printer": "Printer", "itemGroup.forbiddensmoothies.forbiddensmoothies": "Forbidden Smoothies", "gui.forbiddensmoothies.lockButton": "Toggle Input Lock", + "tooltip.forbiddensmoothies.lockInputs": "Lock Input Slots", + "tooltip.forbiddensmoothies.unlockInputs": "Unlock Input Slots", "tooltip.forbiddensmoothies.energyStored": "%d FE", "tooltip.forbiddensmoothies.energyConsumed": "Consuming %d FE/t", "config.forbiddensmoothies": "Forbidden Smoothies" diff --git a/shared/src/main/resources/assets/forbiddensmoothies/models/block/printer.json b/shared/src/main/resources/assets/forbiddensmoothies/models/block/printer.json index d834079..f491e59 100644 --- a/shared/src/main/resources/assets/forbiddensmoothies/models/block/printer.json +++ b/shared/src/main/resources/assets/forbiddensmoothies/models/block/printer.json @@ -1,5 +1,6 @@ { "credit": "Made with Blockbench", + "parent": "block/block", "render_type": "cutout", "textures": { "0": "forbiddensmoothies:block/printer_glass",