Skip to content

Commit

Permalink
Fix printer model, add tooltip to lock button
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Dec 30, 2023
1 parent 3d9edf8 commit b3c57de
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlenderMenu> {

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"credit": "Made with Blockbench",
"parent": "block/block",
"render_type": "cutout",
"textures": {
"0": "forbiddensmoothies:block/printer_glass",
Expand Down

0 comments on commit b3c57de

Please sign in to comment.