diff --git a/build.gradle b/build.gradle index abea5ad..41a2983 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.9-SNAPSHOT' + id 'fabric-loom' version '1.11-SNAPSHOT' id 'maven-publish' } @@ -17,6 +17,7 @@ repositories { // See https://docs.gradle.org/current/userguide/declaring_repositories.html // for more information about repositories. + mavenLocal() // owo-lib maven { url 'https://maven.wispforest.io' } } diff --git a/gradle.properties b/gradle.properties index 66cdf8f..79c947a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,17 +4,19 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop -minecraft_version=1.21.4 -yarn_mappings=1.21.4+build.8 -loader_version=0.16.10 + + +minecraft_version=1.21.8 +yarn_mappings=1.21.8+build.1 +loader_version=0.17.2 # Fabric API -fabric_version=0.115.1+1.21.4 +fabric_version=0.128.2+1.21.7 # Mod Properties -mod_version=1.2.6 +mod_version=1.2.8 maven_group=xyz.imcodist.quickmenu archives_base_name=quick-menu # owo-lib -owo_version=0.12.20+1.21.4 \ No newline at end of file +owo_version=0.12.22+1.21.8 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index c1962a7..a4b76b9 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 21d5e09..ca025c8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index aeb74cb..f5feea6 100644 --- a/gradlew +++ b/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -83,7 +85,9 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -130,10 +134,13 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. @@ -141,7 +148,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -149,7 +156,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -198,11 +205,11 @@ fi # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/gradlew.bat b/gradlew.bat index 93e3f59..9d21a21 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,6 +13,8 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/src/main/java/xyz/imcodist/quickmenu/QuickMenu.java b/src/main/java/xyz/imcodist/quickmenu/QuickMenu.java index 64ab010..af81e4a 100644 --- a/src/main/java/xyz/imcodist/quickmenu/QuickMenu.java +++ b/src/main/java/xyz/imcodist/quickmenu/QuickMenu.java @@ -3,10 +3,8 @@ import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.minecraft.client.util.InputUtil; -import xyz.imcodist.quickmenu.other.ActionButtonDataHandler; -import xyz.imcodist.quickmenu.other.KeybindHandler; +import xyz.imcodist.quickmenu.other.*; import xyz.imcodist.quickmenu.other.ModConfig; -import xyz.imcodist.quickmenu.other.ModKeybindings; import xyz.imcodist.quickmenu.ui.MainUI; public class QuickMenu implements ModInitializer { @@ -20,8 +18,10 @@ public void onInitialize() { ModKeybindings.initialize(); ActionButtonDataHandler.initialize(); +// ClientTickEvents.START_CLIENT_TICK.register(ActionButtonDelayHandler.INSTANCE); // On the end of each tick check to see if a keybind has been pressed. ClientTickEvents.END_CLIENT_TICK.register((client) -> { + ActionButtonDelayHandler.INSTANCE.doDelayChecks(); // Check for menu open keybind. if (ModKeybindings.menuOpenKeybinding.isPressed()) { if (!menuKeyPressed) { diff --git a/src/main/java/xyz/imcodist/quickmenu/data/ActionButtonData.java b/src/main/java/xyz/imcodist/quickmenu/data/ActionButtonData.java index e717e1b..7d86545 100644 --- a/src/main/java/xyz/imcodist/quickmenu/data/ActionButtonData.java +++ b/src/main/java/xyz/imcodist/quickmenu/data/ActionButtonData.java @@ -11,7 +11,9 @@ import xyz.imcodist.quickmenu.QuickMenu; import xyz.imcodist.quickmenu.data.command_actions.BaseActionData; import xyz.imcodist.quickmenu.data.command_actions.CommandActionData; +import xyz.imcodist.quickmenu.data.command_actions.DelayActionData; import xyz.imcodist.quickmenu.data.command_actions.KeybindActionData; +import xyz.imcodist.quickmenu.other.ActionButtonDelayHandler; import xyz.imcodist.quickmenu.other.ModConfigModel; import java.util.ArrayList; @@ -34,6 +36,10 @@ public ActionButtonDataJSON toJSON() { jsonData.keybind = keybind; actions.forEach((action) -> { + if(action == null) + { + return; + } ArrayList actionArray = new ArrayList<>(); actionArray.add(action.getJsonType()); actionArray.add(action.getJsonValue()); @@ -67,7 +73,9 @@ public static ActionButtonData fromJSON(ActionButtonDataJSON json) { json.actions.forEach((actionArray) -> { BaseActionData actionData = getActionDataType(actionArray.get(0), actionArray.get(1)); - data.actions.add(actionData); + if(actionData != null) { + data.actions.add(actionData); + } }); if (json.icon != null) { @@ -95,6 +103,11 @@ private static BaseActionData getActionDataType(String type, String value) { keybindActionData.keybindTranslationKey = value; return keybindActionData; } + case "delay" -> { + var delayAction = new DelayActionData(); + delayAction.ticks = Math.max(0, Long.parseLong(value)); + return delayAction; + } } return null; @@ -119,9 +132,55 @@ public void run(boolean isKeybind) { client.player.sendMessage(Text.of("Ran action \"" + name + "\""), true); } } +// MinecraftClient.getInstance() // Run the buttons action. - actions.forEach(BaseActionData::run); +// actions.forEach(BaseActionData::run); + new ActionButtonDataContext(new ArrayList<>(actions), 0).run(); + } + + public static class ActionButtonDataContext { + + private final List actions; + private long delay; + + public ActionButtonDataContext( + List actions, + long delay + ) { + this.actions = actions; + this.delay = delay; + } + + public void run() { + for (var idx = 0; idx < actions.size(); idx++) { + var action = actions.get(idx); + var nextDelay = action.run(); + if (nextDelay > 0) { + // TODO : Envelope the remaining actions in a timer. + var nextSet = new ActionButtonDataContext(actions.subList(idx + 1, actions.size()), nextDelay); + // TODO - Create a timer construct that listens + ActionButtonDelayHandler.INSTANCE.add(nextSet); + return; + } + } + } + + public long getDelay() { + return delay; + } + + public void decrementDelay() + { + delay = Math.max(0, delay - 1); + } + + public boolean isReady() + { + return delay == 0; + } + + } public static class CustomModelDataValues { diff --git a/src/main/java/xyz/imcodist/quickmenu/data/command_actions/BaseActionData.java b/src/main/java/xyz/imcodist/quickmenu/data/command_actions/BaseActionData.java index c9b6e35..950d640 100644 --- a/src/main/java/xyz/imcodist/quickmenu/data/command_actions/BaseActionData.java +++ b/src/main/java/xyz/imcodist/quickmenu/data/command_actions/BaseActionData.java @@ -13,5 +13,7 @@ public String getString() { return "uh oh why are you seeing this"; } - public void run() {} + public long run() { + return 0; + } } diff --git a/src/main/java/xyz/imcodist/quickmenu/data/command_actions/CommandActionData.java b/src/main/java/xyz/imcodist/quickmenu/data/command_actions/CommandActionData.java index 4239ee7..9333980 100644 --- a/src/main/java/xyz/imcodist/quickmenu/data/command_actions/CommandActionData.java +++ b/src/main/java/xyz/imcodist/quickmenu/data/command_actions/CommandActionData.java @@ -23,12 +23,12 @@ public String getString() { } @Override - public void run() { + public long run() { MinecraftClient client = MinecraftClient.getInstance(); - if (client == null) return; + if (client == null) return 0; ClientPlayerEntity player = client.player; - if (player == null) return; + if (player == null) return 0; // Run the command. String commandToRun = command; @@ -44,5 +44,6 @@ public void run() { player.networkHandler.sendChatMessage(commandToRun); } } + return 0; } } diff --git a/src/main/java/xyz/imcodist/quickmenu/data/command_actions/DelayActionData.java b/src/main/java/xyz/imcodist/quickmenu/data/command_actions/DelayActionData.java new file mode 100644 index 0000000..c47b1e4 --- /dev/null +++ b/src/main/java/xyz/imcodist/quickmenu/data/command_actions/DelayActionData.java @@ -0,0 +1,31 @@ +package xyz.imcodist.quickmenu.data.command_actions; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ClientPlayerEntity; + +public class DelayActionData extends BaseActionData { + + public long ticks = 20; + + @Override + public String getJsonType() { + return "delay"; + } + @Override + public String getJsonValue() { + return String.format("%s", ticks); + } + + @Override + public String getTypeString() { return "DLY"; } + @Override + public String getString() { + return String.format("%s", ticks); + } + + @Override + public long run() { + // TODO - rework this function to allow delays + return ticks; + } +} diff --git a/src/main/java/xyz/imcodist/quickmenu/data/command_actions/KeybindActionData.java b/src/main/java/xyz/imcodist/quickmenu/data/command_actions/KeybindActionData.java index 488dd95..08e0ee8 100644 --- a/src/main/java/xyz/imcodist/quickmenu/data/command_actions/KeybindActionData.java +++ b/src/main/java/xyz/imcodist/quickmenu/data/command_actions/KeybindActionData.java @@ -23,7 +23,8 @@ public String getString() { } @Override - public void run() { + public long run() { KeybindHandler.pressKey(keybindTranslationKey); + return 0; } } diff --git a/src/main/java/xyz/imcodist/quickmenu/other/ActionButtonDelayHandler.java b/src/main/java/xyz/imcodist/quickmenu/other/ActionButtonDelayHandler.java new file mode 100644 index 0000000..00d199f --- /dev/null +++ b/src/main/java/xyz/imcodist/quickmenu/other/ActionButtonDelayHandler.java @@ -0,0 +1,36 @@ +package xyz.imcodist.quickmenu.other; + +import net.minecraft.client.MinecraftClient; +import xyz.imcodist.quickmenu.data.ActionButtonData; + +import java.util.ArrayList; +import java.util.List; + +public class ActionButtonDelayHandler { + + public static final ActionButtonDelayHandler INSTANCE = new ActionButtonDelayHandler(); + + private final List delayedActions = new ArrayList<>(); + + private final List actionsInbox = new ArrayList<>(); + + public void add(ActionButtonData.ActionButtonDataContext context){ + actionsInbox.add(context); + } + + + public void doDelayChecks() { + for(var it = delayedActions.iterator(); it.hasNext();){ + var action = it.next(); + action.decrementDelay(); + if(action.isReady()){ + action.run(); + it.remove(); + } + } + if(!actionsInbox.isEmpty()) { + delayedActions.addAll(actionsInbox); + actionsInbox.clear(); + } + } +} diff --git a/src/main/java/xyz/imcodist/quickmenu/ui/ActionEditorUI.java b/src/main/java/xyz/imcodist/quickmenu/ui/ActionEditorUI.java index b485c27..2cc5e8e 100644 --- a/src/main/java/xyz/imcodist/quickmenu/ui/ActionEditorUI.java +++ b/src/main/java/xyz/imcodist/quickmenu/ui/ActionEditorUI.java @@ -23,6 +23,7 @@ import xyz.imcodist.quickmenu.data.ActionButtonData; import xyz.imcodist.quickmenu.data.command_actions.BaseActionData; import xyz.imcodist.quickmenu.data.command_actions.CommandActionData; +import xyz.imcodist.quickmenu.data.command_actions.DelayActionData; import xyz.imcodist.quickmenu.data.command_actions.KeybindActionData; import xyz.imcodist.quickmenu.other.ActionButtonDataHandler; import xyz.imcodist.quickmenu.ui.components.QuickMenuButton; @@ -315,6 +316,16 @@ public void createActions(FlowLayout layout) { property.child(keybindActionButton); } + if (action instanceof DelayActionData delayAction) { + TextBoxComponent textBoxComponent = Components.textBox(Sizing.fill(57)); + + textBoxComponent.setMaxLength(10); + textBoxComponent.text( String.format("%s", delayAction.ticks) ); + + property.child(textBoxComponent); + source = textBoxComponent; + } + // Add the remove button. ButtonComponent removeActionButton = Components.button(Text.literal(" - "), (buttonComponent -> { int currentIndex = actionArray.indexOf(action); @@ -379,6 +390,11 @@ public void updateActionData() { commandAction.command = textBoxSource.getText(); } + if (action instanceof DelayActionData delayAction) { + TextBoxComponent textBoxSource = (TextBoxComponent) source; + delayAction.ticks = Math.max(0, Long.parseLong(textBoxSource.getText())); + } + i.addAndGet(1); }); } diff --git a/src/main/java/xyz/imcodist/quickmenu/ui/popups/ActionPickerUI.java b/src/main/java/xyz/imcodist/quickmenu/ui/popups/ActionPickerUI.java index f5c6fa3..ef1bf11 100644 --- a/src/main/java/xyz/imcodist/quickmenu/ui/popups/ActionPickerUI.java +++ b/src/main/java/xyz/imcodist/quickmenu/ui/popups/ActionPickerUI.java @@ -10,6 +10,7 @@ import net.minecraft.util.Formatting; import xyz.imcodist.quickmenu.data.command_actions.BaseActionData; import xyz.imcodist.quickmenu.data.command_actions.CommandActionData; +import xyz.imcodist.quickmenu.data.command_actions.DelayActionData; import xyz.imcodist.quickmenu.data.command_actions.KeybindActionData; import xyz.imcodist.quickmenu.ui.surfaces.SwitcherSurface; @@ -47,6 +48,7 @@ public ActionPickerUI() { // Create action buttons. addListData("command", "Command", "Runs a chat command."); addListData("keybind", "Keybind", "Activates a keybind."); + addListData("delay", "Delay", "Adds a delay."); for (ArrayList data : listData) { actionsLayout.child(createActionLayout(data)); @@ -91,6 +93,7 @@ private BaseActionData getActionFromType(String type) { switch (type) { case "command" -> {return new CommandActionData();} case "keybind" -> {return new KeybindActionData();} + case "delay" -> { return new DelayActionData(); } } return null; diff --git a/src/main/java/xyz/imcodist/quickmenu/ui/surfaces/SwitcherSurface.java b/src/main/java/xyz/imcodist/quickmenu/ui/surfaces/SwitcherSurface.java index 8b2a2db..917ed28 100644 --- a/src/main/java/xyz/imcodist/quickmenu/ui/surfaces/SwitcherSurface.java +++ b/src/main/java/xyz/imcodist/quickmenu/ui/surfaces/SwitcherSurface.java @@ -4,6 +4,7 @@ import io.wispforest.owo.ui.core.OwoUIDrawContext; import io.wispforest.owo.ui.core.ParentComponent; import io.wispforest.owo.ui.core.Surface; +import net.minecraft.client.gl.RenderPipelines; import net.minecraft.client.render.RenderLayer; import net.minecraft.util.Identifier; @@ -25,15 +26,15 @@ public void draw(OwoUIDrawContext context, ParentComponent component) { int sourceX = (isHeader) ? 0 : 24; // Make sure the background renders as transparent. - if (!isHeader) RenderSystem.enableBlend(); - RenderSystem.setShaderColor(1, 1, 1, 1); +// if (!isHeader) RenderSystem.enableBlend(); // TODO - Figure out if a fix is needed +// RenderSystem.setShaderColor(1, 1, 1, 1); // Draws the texture as a 9 slice. drawNineSlicedTexture(context, x, y, width, height, sourceX, 0, 6, 6, 12, 12, 52, 50); // Undo previous render system changes. - if (!isHeader) RenderSystem.disableBlend(); - RenderSystem.setShaderColor(1, 1, 1, 1); +// if (!isHeader) RenderSystem.disableBlend(); // TODO - Figure out if a fix is needed +// RenderSystem.setShaderColor(1, 1, 1, 1); } public void drawNineSlicedTexture(OwoUIDrawContext context, int x, int y, int width, int height, int sourceX, int sourceY, int sideWidth, int sideHeight, int centerWidth, int centerHeight, int textureWidth, int textureHeight) { @@ -59,7 +60,7 @@ public void drawNineSlicedTexture(OwoUIDrawContext context, int x, int y, int wi } public void drawTexture(OwoUIDrawContext context, int x, int y, int sourceX, int sourceY, int sourceWidth, int sourceHeight, int textureWidth, int textureHeight) { - context.drawTexture(RenderLayer::getGuiTexturedOverlay, Identifier.of("quickmenu", "textures/switcher_textures.png"), x, y, sourceX, sourceY, sourceWidth, sourceHeight, textureWidth, textureHeight); + context.drawTexture(RenderPipelines.GUI_TEXTURED, Identifier.of("quickmenu", "textures/switcher_textures.png"), x, y, sourceX, sourceY, sourceWidth, sourceHeight, textureWidth, textureHeight); } public void drawRepeatingTexture(OwoUIDrawContext context, int x, int y, int sourceX, int sourceY, int sourceWidth, int sourceHeight, int textureWidth, int textureHeight, int width, int height) { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 8c4e37b..4af3dca 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -29,10 +29,11 @@ "quickmenu.mixins.json" ], "depends": { - "fabricloader": ">=0.16.10", - "minecraft": "=1.21.4", + "fabricloader": ">=0.16.14", + "minecraft": ["1.21.7","1.21.8"], "java": ">=21", "fabric-api": "*", + "owo-lib": ">=0.12.22+1.21.8", "fabric-key-binding-api-v1": "*" }