From 86b5ab70db245dfc7187ad9c368e0ca4b36a40aa Mon Sep 17 00:00:00 2001 From: UnRealDinnerbone Date: Mon, 19 Aug 2024 09:45:15 -0500 Subject: [PATCH 1/6] Update Fabric-API to 1.21.1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 8614615..3a54dca 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,7 +16,7 @@ neoforge_version=21.1.13 neoforge_version_range=[21.1.0,) neoforge_loader_version=4 fabric_loader_version=0.15.11 -fabric_api_version=0.101.2+1.21 +fabric_api_version=0.102.1+1.21.1 fabric_api_version_range=>=0.100.1+1.21 architectury_version=13.0.6 # There are too many of these now From 911f19c407aaeaa4e026c28197dbddcaa96d6f33 Mon Sep 17 00:00:00 2001 From: UnRealDinnerbone Date: Mon, 19 Aug 2024 09:47:50 -0500 Subject: [PATCH 2/6] Fix command permissions and weather command --- .../mods/ftblibrary/FTBLibraryCommands.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/common/src/main/java/dev/ftb/mods/ftblibrary/FTBLibraryCommands.java b/common/src/main/java/dev/ftb/mods/ftblibrary/FTBLibraryCommands.java index fa23c39..b91d9d0 100644 --- a/common/src/main/java/dev/ftb/mods/ftblibrary/FTBLibraryCommands.java +++ b/common/src/main/java/dev/ftb/mods/ftblibrary/FTBLibraryCommands.java @@ -1,5 +1,6 @@ package dev.ftb.mods.ftblibrary; +import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; @@ -39,8 +40,8 @@ public class FTBLibraryCommands { public static void registerCommands(CommandDispatcher dispatcher, CommandBuildContext commandBuildContext, Commands.CommandSelection type) { var command = Commands.literal("ftblibrary") - .requires(commandSource -> commandSource.hasPermission(2)) .then(Commands.literal("gamemode") + .requires(commandSource -> commandSource.hasPermission(Commands.LEVEL_GAMEMASTERS)) .executes(context -> { if (!context.getSource().getPlayerOrException().isCreative()) { context.getSource().getPlayerOrException().setGameMode(GameType.CREATIVE); @@ -48,20 +49,23 @@ public static void registerCommands(CommandDispatcher dispat context.getSource().getPlayerOrException().setGameMode(GameType.SURVIVAL); } - return 1; + return Command.SINGLE_SUCCESS; }) ) .then(Commands.literal("rain") + .requires(commandSource -> commandSource.hasPermission(Commands.LEVEL_GAMEMASTERS)) .executes(context -> { - if (context.getSource().getLevel().isRaining()) { - context.getSource().getLevel().setWeatherParameters(6000, 0, false, false); // clear + //Use overworld as that controls the weather for the whole server + if (context.getSource().getServer().overworld().isRaining()) { + context.getSource().getServer().overworld().setWeatherParameters(6000, 0, false, false); // clear } else { - context.getSource().getLevel().setWeatherParameters(0, 6000, true, false);// rain + context.getSource().getServer().overworld().setWeatherParameters(0, 6000, true, false);// rain } - return 1; + return Command.SINGLE_SUCCESS; }) ) .then(Commands.literal("day") + .requires(commandSource -> commandSource.hasPermission(Commands.LEVEL_GAMEMASTERS)) .executes(context -> { var addDay = (24000L - (context.getSource().getLevel().getDayTime() % 24000L) + 6000L) % 24000L; @@ -71,10 +75,11 @@ public static void registerCommands(CommandDispatcher dispat } } - return 1; + return Command.SINGLE_SUCCESS; }) ) .then(Commands.literal("night") + .requires(commandSource -> commandSource.hasPermission(Commands.LEVEL_GAMEMASTERS)) .executes(context -> { var addDay = (24000L - (context.getSource().getLevel().getDayTime() % 24000L) + 18000L) % 24000L; @@ -84,10 +89,11 @@ public static void registerCommands(CommandDispatcher dispat } } - return 1; + return Command.SINGLE_SUCCESS; }) ) .then(Commands.literal("nbtedit") + .requires(commandSource -> commandSource.hasPermission(Commands.LEVEL_GAMEMASTERS)) .then(Commands.literal("block") .then(Commands.argument("pos", BlockPosArgument.blockPos()) .executes(context -> editNBT(context, (info, tag) -> editBlockNBT(context, info, tag))) @@ -111,7 +117,7 @@ public static void registerCommands(CommandDispatcher dispat .requires(CommandSourceStack::isPlayer) .executes(context -> { NetworkManager.sendToPlayer(context.getSource().getPlayerOrException(), new EditConfigPacket(true)); - return 1; + return Command.SINGLE_SUCCESS; }) ); @@ -123,7 +129,7 @@ public static void registerCommands(CommandDispatcher dispat } else { UITesting.openTestScreen(); } - return 1; + return Command.SINGLE_SUCCESS; }) ); } @@ -140,7 +146,7 @@ private static int editNBT(CommandContext context, NBTEditCa if (!info.isEmpty()) { EDITING_NBT.put(player.getUUID(), info); NetworkManager.sendToPlayer(player, new EditNBTPacket(info, tag)); - return 1; + return Command.SINGLE_SUCCESS; } return 0; From 7de707de874b4aa3ac52a9f4418aec5d7dd2fa56 Mon Sep 17 00:00:00 2001 From: Des Herriott Date: Mon, 19 Aug 2024 16:14:28 +0100 Subject: [PATCH 3/6] build: version -> 2101.1.2, added changelog --- CHANGELOG.md | 25 +++++++++++++++++++++++++ gradle.properties | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..f30396c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,25 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [2101.1.2] + +### Fixed +* Fixed `/ftblibrary clientconfig` command not being usable without op perms + +## [2101.1.1] + +### Fixed +* Fixed a couple of minor GUI drawing artifacts in some screens + +## [2101.1.0] + +### Changed +* Updated to MC 1.21.1 + +### Added +* Sidebar buttons (from FTB Library and all mods which add buttons) are now all repositionable and toggleable + * New sidebar button to open client config for FTB Library (can be used to hide sidebar entirely) + * Client config can also be opened via `/ftblibrary clientconfig` command diff --git a/gradle.properties b/gradle.properties index 3a54dca..00f489d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.daemon=false # Mod mod_id=ftblibrary readable_name=FTB Library -mod_version=2101.1.1 +mod_version=2101.1.2 mod_author=FTB Team # Maven archives_base_name=ftb-library From 4a0e32352e9703770da35464f087362398f8964e Mon Sep 17 00:00:00 2001 From: UnRealDinnerbone Date: Tue, 20 Aug 2024 11:04:24 -0500 Subject: [PATCH 4/6] [1.21.1] More overriders for 3PanelScreen, and Togglable Button (#118) * Make scrollbar and bottom panel configurable * Add Toggleable Button and Remove Fabric Mixin * Add opinion to change bottom panel height * Set required fabric api version Update to new Fabric do it our mixin removal * Formatting fixes --- .../dev/ftb/mods/ftblibrary/ui/Button.java | 14 ++++- .../ftb/mods/ftblibrary/ui/SimpleButton.java | 11 +++- .../mods/ftblibrary/ui/ToggleableButton.java | 54 +++++++++++++++++++ .../ui/misc/AbstractThreePanelScreen.java | 29 +++++++--- .../assets/ftblibrary/lang/en_us.json | 2 + .../fabric/AbstractContainerScreenMixin.java | 26 --------- .../resources/ftblibrary-fabric.mixins.json | 1 - gradle.properties | 2 +- 8 files changed, 101 insertions(+), 38 deletions(-) create mode 100644 common/src/main/java/dev/ftb/mods/ftblibrary/ui/ToggleableButton.java delete mode 100644 fabric/src/main/java/dev/ftb/mods/ftblibrary/core/mixin/fabric/AbstractContainerScreenMixin.java diff --git a/common/src/main/java/dev/ftb/mods/ftblibrary/ui/Button.java b/common/src/main/java/dev/ftb/mods/ftblibrary/ui/Button.java index 106c547..ba50bd5 100644 --- a/common/src/main/java/dev/ftb/mods/ftblibrary/ui/Button.java +++ b/common/src/main/java/dev/ftb/mods/ftblibrary/ui/Button.java @@ -11,6 +11,7 @@ public abstract class Button extends Widget { protected Component title; protected Icon icon; + private boolean forceButtonSize; public Button(Panel panel, Component t, Icon i) { super(panel); @@ -38,6 +39,11 @@ public Button setIcon(Icon i) { return this; } + public Button setForceButtonSize(boolean forceButtonSize) { + this.forceButtonSize = forceButtonSize; + return this; + } + public void drawBackground(GuiGraphics graphics, Theme theme, int x, int y, int w, int h) { theme.drawButton(graphics, x, y, w, h, getWidgetType()); } @@ -49,9 +55,13 @@ public void drawIcon(GuiGraphics graphics, Theme theme, int x, int y, int w, int @Override public void draw(GuiGraphics graphics, Theme theme, int x, int y, int w, int h) { GuiHelper.setupDrawing(); - var s = h >= 16 ? 16 : 8; drawBackground(graphics, theme, x, y, w, h); - drawIcon(graphics, theme, x + (w - s) / 2, y + (h - s) / 2, s, s); + if (forceButtonSize) { + var s = h >= 16 ? 16 : 8; + drawIcon(graphics, theme, x + (w - s) / 2, y + (h - s) / 2, s, s); + }else { + drawIcon(graphics, theme, x, y, w, h); + } } @Override diff --git a/common/src/main/java/dev/ftb/mods/ftblibrary/ui/SimpleButton.java b/common/src/main/java/dev/ftb/mods/ftblibrary/ui/SimpleButton.java index 13a2809..401db12 100644 --- a/common/src/main/java/dev/ftb/mods/ftblibrary/ui/SimpleButton.java +++ b/common/src/main/java/dev/ftb/mods/ftblibrary/ui/SimpleButton.java @@ -9,8 +9,9 @@ import java.util.List; public class SimpleButton extends Button { - private final Callback consumer; + private Callback consumer; private final List tooltip; + public SimpleButton(Panel panel, Component text, Icon icon, Callback c) { super(panel, text, icon); consumer = c; @@ -32,6 +33,10 @@ public void addMouseOverText(TooltipList list) { } } + public void setConsumer(Callback consumer) { + this.consumer = consumer; + } + @Override public void drawBackground(GuiGraphics graphics, Theme theme, int x, int y, int w, int h) { } @@ -39,7 +44,9 @@ public void drawBackground(GuiGraphics graphics, Theme theme, int x, int y, int @Override public void onClicked(MouseButton button) { playClickSound(); - consumer.onClicked(this, button); + if (consumer != null) { + consumer.onClicked(this, button); + } } public interface Callback { diff --git a/common/src/main/java/dev/ftb/mods/ftblibrary/ui/ToggleableButton.java b/common/src/main/java/dev/ftb/mods/ftblibrary/ui/ToggleableButton.java new file mode 100644 index 0000000..cc8a9ca --- /dev/null +++ b/common/src/main/java/dev/ftb/mods/ftblibrary/ui/ToggleableButton.java @@ -0,0 +1,54 @@ +package dev.ftb.mods.ftblibrary.ui; + +import dev.ftb.mods.ftblibrary.icon.Icon; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; + +public class ToggleableButton extends SimpleButton { + + private Component enabledText; + private Component disabledText; + + private boolean state; + + public ToggleableButton(Panel panel, boolean defaultState, Icon enabled, Icon disabled, ToggleableCallback toggleableCallback) { + super(panel, Component.empty(), defaultState ? enabled : disabled, null); + this.state = defaultState; + this.setConsumer((widget, button) -> { + this.state = !this.state; + widget.setIcon(this.state ? enabled : disabled); + toggleableCallback.onClicked(widget, this.state); + }); + this.enabledText = Component.translatable("ftblibrary.gui.enabled").withStyle(ChatFormatting.GREEN); + this.disabledText = Component.translatable("ftblibrary.gui.disabled").withStyle(ChatFormatting.RED); + updateTitle(); + } + + public Component getEnabledText() { + return enabledText; + } + + public ToggleableButton setEnabledText(Component enabledText) { + this.enabledText = enabledText; + updateTitle(); + return this; + } + + public Component getDisabledText() { + return disabledText; + } + + public ToggleableButton setDisabledText(Component disabledText) { + this.disabledText = disabledText; + updateTitle(); + return this; + } + + private void updateTitle() { + setTitle(state ? enabledText : disabledText); + } + + public interface ToggleableCallback { + void onClicked(SimpleButton widget, boolean newState); + } +} diff --git a/common/src/main/java/dev/ftb/mods/ftblibrary/ui/misc/AbstractThreePanelScreen.java b/common/src/main/java/dev/ftb/mods/ftblibrary/ui/misc/AbstractThreePanelScreen.java index be94732..e212cea 100644 --- a/common/src/main/java/dev/ftb/mods/ftblibrary/ui/misc/AbstractThreePanelScreen.java +++ b/common/src/main/java/dev/ftb/mods/ftblibrary/ui/misc/AbstractThreePanelScreen.java @@ -19,13 +19,14 @@ public abstract class AbstractThreePanelScreen extends BaseScre protected final PanelScrollBar scrollBar; private boolean showBottomPanel = true; private boolean showCloseButton = false; + private boolean showScrollBar = true; protected AbstractThreePanelScreen() { super(); topPanel = createTopPanel(); mainPanel = createMainPanel(); - bottomPanel = new BottomPanel(); + bottomPanel = createBottomPanel(); scrollBar = new PanelScrollBar(this, ScrollBar.Plane.VERTICAL, mainPanel); } @@ -33,7 +34,9 @@ protected AbstractThreePanelScreen() { public void addWidgets() { add(topPanel); add(mainPanel); - add(scrollBar); + if (showScrollBar) { + add(scrollBar); + } if (showBottomPanel) { add(bottomPanel); } @@ -47,18 +50,20 @@ public void alignWidgets() { topPanel.alignWidgets(); var inset = mainPanelInset(); - int bottomPanelHeight = showBottomPanel ? BOTTOM_PANEL_H + inset.getSecond() : 0; + int bottomPanelHeight = showBottomPanel ? getBottomPanelHeight() + inset.getSecond() : 0; mainPanel.setPosAndSize(inset.getFirst(), topPanelHeight + inset.getSecond(), width - inset.getFirst() * 2, height - topPanelHeight - inset.getSecond() * 2 - bottomPanelHeight); mainPanel.alignWidgets(); if (showBottomPanel) { - bottomPanel.setPosAndSize(0, height - BOTTOM_PANEL_H, width, BOTTOM_PANEL_H); + bottomPanel.setPosAndSize(0, height - getBottomPanelHeight(), width, getBottomPanelHeight()); bottomPanel.alignWidgets(); } - scrollBar.setPosAndSize(mainPanel.getPosX() + mainPanel.getWidth() - getScrollbarWidth(), mainPanel.getPosY(), getScrollbarWidth(), mainPanel.getHeight()); + if (showScrollBar) { + scrollBar.setPosAndSize(mainPanel.getPosX() + mainPanel.getWidth() - getScrollbarWidth(), mainPanel.getPosY(), getScrollbarWidth(), mainPanel.getHeight()); + } } @Override @@ -72,7 +77,7 @@ public void tick() { super.tick(); int prevWidth = mainPanel.width; - int newWidth = (scrollBar.shouldDraw() ? getGui().width - getScrollbarWidth() - 2 : getGui().width) - mainPanelInset().getFirst() * 2; + int newWidth = (!showScrollBar && scrollBar.shouldDraw() ? getGui().width - getScrollbarWidth() - 2 : getGui().width) - mainPanelInset().getFirst() * 2; if (prevWidth != newWidth) { mainPanel.setWidth(newWidth); mainPanel.alignWidgets(); @@ -91,6 +96,10 @@ protected Pair mainPanelInset() { return NO_INSET; } + protected int getBottomPanelHeight() { + return BOTTOM_PANEL_H; + } + protected int getScrollbarWidth() { return SCROLLBAR_WIDTH; } @@ -99,6 +108,10 @@ protected Panel createTopPanel() { return new TopPanel(); } + protected Panel createBottomPanel() { + return new BottomPanel(); + } + public void showBottomPanel(boolean show) { showBottomPanel = show; } @@ -107,6 +120,10 @@ public void showCloseButton(boolean show) { showCloseButton = show; } + public void showScrollBar(boolean show) { + showScrollBar = show; + } + protected class TopPanel extends Panel { private final SimpleButton closeButton; diff --git a/common/src/main/resources/assets/ftblibrary/lang/en_us.json b/common/src/main/resources/assets/ftblibrary/lang/en_us.json index 52b5fd4..dc2281c 100644 --- a/common/src/main/resources/assets/ftblibrary/lang/en_us.json +++ b/common/src/main/resources/assets/ftblibrary/lang/en_us.json @@ -75,6 +75,8 @@ "ftblibrary.gui.edit_tag_value": "Edit Tag Value", "ftblibrary.gui.no_selection": "Nothing Selected", "ftblibrary.gui.key_reference": "Key Reference", + "ftblibrary.gui.enabled": "Enabled", + "ftblibrary.gui.disabled": "Disabled", "ftblibrary.client_settings": "Client Config", "ftblibrary.client_settings.tooltips": "Tooltips", "ftblibrary.client_settings.tooltips.item_modname": "Show Mod Name in Item Select GUI", diff --git a/fabric/src/main/java/dev/ftb/mods/ftblibrary/core/mixin/fabric/AbstractContainerScreenMixin.java b/fabric/src/main/java/dev/ftb/mods/ftblibrary/core/mixin/fabric/AbstractContainerScreenMixin.java deleted file mode 100644 index 31881df..0000000 --- a/fabric/src/main/java/dev/ftb/mods/ftblibrary/core/mixin/fabric/AbstractContainerScreenMixin.java +++ /dev/null @@ -1,26 +0,0 @@ -package dev.ftb.mods.ftblibrary.core.mixin.fabric; - -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; -import net.minecraft.network.chat.Component; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -// Need to make sure mouseReleased is called for widgets -// See https://github.com/FabricMC/fabric/pull/4010 -@Mixin(AbstractContainerScreen.class) -public abstract class AbstractContainerScreenMixin extends Screen { - - protected AbstractContainerScreenMixin(Component component) { - super(component); - } - - @Inject(at = @At("HEAD"), method = "mouseReleased", cancellable = true) - public void onMouseReleased(double mouseX, double mouseY, int button, CallbackInfoReturnable info) { - if (super.mouseReleased(mouseX, mouseY, button)) { - info.setReturnValue(true); - } - } -} diff --git a/fabric/src/main/resources/ftblibrary-fabric.mixins.json b/fabric/src/main/resources/ftblibrary-fabric.mixins.json index f2fb898..cbd5874 100644 --- a/fabric/src/main/resources/ftblibrary-fabric.mixins.json +++ b/fabric/src/main/resources/ftblibrary-fabric.mixins.json @@ -6,7 +6,6 @@ "PlayerMixin" ], "client": [ - "AbstractContainerScreenMixin", "KeyMappingAccessor" ], "injectors": { diff --git a/gradle.properties b/gradle.properties index 00f489d..41a33b0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,7 @@ neoforge_version_range=[21.1.0,) neoforge_loader_version=4 fabric_loader_version=0.15.11 fabric_api_version=0.102.1+1.21.1 -fabric_api_version_range=>=0.100.1+1.21 +fabric_api_version_range=>=0.102.1+1.21.1 architectury_version=13.0.6 # There are too many of these now rei_version=16.0.754 From d353ba391935d5abdb2610dacf1458392b3a8ec8 Mon Sep 17 00:00:00 2001 From: UnRealDinnerbone Date: Wed, 21 Aug 2024 09:44:23 -0500 Subject: [PATCH 5/6] Call updateTitle on button clicked --- .../main/java/dev/ftb/mods/ftblibrary/ui/ToggleableButton.java | 1 + 1 file changed, 1 insertion(+) diff --git a/common/src/main/java/dev/ftb/mods/ftblibrary/ui/ToggleableButton.java b/common/src/main/java/dev/ftb/mods/ftblibrary/ui/ToggleableButton.java index cc8a9ca..e318f14 100644 --- a/common/src/main/java/dev/ftb/mods/ftblibrary/ui/ToggleableButton.java +++ b/common/src/main/java/dev/ftb/mods/ftblibrary/ui/ToggleableButton.java @@ -17,6 +17,7 @@ public ToggleableButton(Panel panel, boolean defaultState, Icon enabled, Icon di this.setConsumer((widget, button) -> { this.state = !this.state; widget.setIcon(this.state ? enabled : disabled); + updateTitle(); toggleableCallback.onClicked(widget, this.state); }); this.enabledText = Component.translatable("ftblibrary.gui.enabled").withStyle(ChatFormatting.GREEN); From fe533a3759def5b14b8855d21e751e026ff72119 Mon Sep 17 00:00:00 2001 From: UnRealDinnerbone Date: Wed, 21 Aug 2024 11:40:29 -0500 Subject: [PATCH 6/6] Fix scrollbar width changing --- .../ftb/mods/ftblibrary/ui/misc/AbstractThreePanelScreen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/dev/ftb/mods/ftblibrary/ui/misc/AbstractThreePanelScreen.java b/common/src/main/java/dev/ftb/mods/ftblibrary/ui/misc/AbstractThreePanelScreen.java index e212cea..377d867 100644 --- a/common/src/main/java/dev/ftb/mods/ftblibrary/ui/misc/AbstractThreePanelScreen.java +++ b/common/src/main/java/dev/ftb/mods/ftblibrary/ui/misc/AbstractThreePanelScreen.java @@ -77,7 +77,7 @@ public void tick() { super.tick(); int prevWidth = mainPanel.width; - int newWidth = (!showScrollBar && scrollBar.shouldDraw() ? getGui().width - getScrollbarWidth() - 2 : getGui().width) - mainPanelInset().getFirst() * 2; + int newWidth = (showScrollBar && scrollBar.shouldDraw() ? getGui().width - getScrollbarWidth() - 2 : getGui().width) - mainPanelInset().getFirst() * 2; if (prevWidth != newWidth) { mainPanel.setWidth(newWidth); mainPanel.alignWidgets();