-
-
Notifications
You must be signed in to change notification settings - Fork 3
AmbleScript ( LUA ) & JSON defined GUIs #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
duzos
wants to merge
38
commits into
main
Choose a base branch
from
api/gui
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 17 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
6f1ab0a
json defined guis
duzos dc3db9d
woops i replaced all "json" with "registry" by accident
duzos a4915b3
add builders for each ui elements, add AmbleContainer#copyFrom to rem…
duzos de119c1
remove stupid lambda
duzos fb1d0bf
remove LVTI
duzos c605ad1
fallback msg
duzos 34c794f
add json data to error msg so they know which block it is
duzos 62b7c7e
json buttons & command running buttons
duzos 802ea35
add Lua scripting support for GUI elements
duzos 9a56e17
add LuaJ dependency for GUI scripting
duzos 1980f92
Refactor GUI scripting into general-purpose script system
duzos 30252ca
Expand Lua scripting API with world, player, entity, and item methods
duzos 4436c17
Add playSoundAt method to MinecraftData for Lua scripting support
duzos 9a69fd1
Add script lifecycle system with enable/disable/tick functionality
duzos 6f3bf61
Add server-side scripting support with ServerScriptManager and commands
duzos 853649b
Filter script command suggestions by available methods
duzos e3e1532
Address PR review feedback for AmbleScript and GUI system
duzos 9428647
Address PR review feedback: MethodHandles, getExecutor, LuaScript ref…
duzos 1116d63
Fix corrupted import in AmbleButton.java
duzos 494aa3d
Add support for checking any key in isKeyPressed
duzos bcc9d82
Add comprehensive documentation for Lua scripting and JSON GUI systems
duzos 92f7274
Add skin system API, documentation, and example scripts
duzos dc58258
Update mod_version to 1.1.16
duzos 5a993ef
Add data generation support and translation keys for skin and script …
duzos 82e84b7
Add generated test files to .gitignore
duzos 74ecf73
Refactor script suggestion providers for improved clarity and functio…
duzos 2196af3
Add cross-script function calling support and enhance Lua scripting d…
duzos 2d72265
Implement AmbleElement interface in LuaElement and add findFirstText …
duzos cd69e61
Refactor getDisplayId method to improve string manipulation for scrip…
duzos 105cf49
Merge remote-tracking branch 'origin/api/gui' into api/gui
duzos 671edfd
Add AmbleButton and AmbleText parsers for JSON element handling
duzos 50a5fec
Add AmbleEntityDisplay component for dynamic entity rendering in GUI
duzos 2c722ca
Add AmbleTextInput component and implement focus handling in GUI
duzos 760825d
Refactor command return values to use Command.SINGLE_SUCCESS for cons…
duzos 17a44e4
fix build
duzos fe0f238
Refactor command return values to use Command.SINGLE_SUCCESS for cons…
duzos a12bd5c
Add run2/ to .gitignore to exclude additional run directory
duzos 4209380
name "testmodClient" user "Dev"
duzos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
220 changes: 220 additions & 0 deletions
220
src/main/java/dev/amble/lib/client/command/ClientScriptCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,220 @@ | ||
| package dev.amble.lib.client.command; | ||
|
|
||
| import com.mojang.brigadier.CommandDispatcher; | ||
| import com.mojang.brigadier.context.CommandContext; | ||
| import com.mojang.brigadier.suggestion.SuggestionProvider; | ||
| import dev.amble.lib.AmbleKit; | ||
| import dev.amble.lib.script.LuaScript; | ||
| import dev.amble.lib.script.ScriptManager; | ||
| import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; | ||
| import net.minecraft.client.MinecraftClient; | ||
| import net.minecraft.command.CommandSource; | ||
| import net.minecraft.command.argument.IdentifierArgumentType; | ||
| import net.minecraft.text.Text; | ||
| import net.minecraft.util.Formatting; | ||
| import net.minecraft.util.Identifier; | ||
| import org.luaj.vm2.LuaValue; | ||
|
|
||
| import java.util.Set; | ||
|
|
||
| import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; | ||
| import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; | ||
|
|
||
| /** | ||
| * Client-side command for managing client scripts. | ||
| * Usage: /amblescript [execute|enable|disable|toggle|list|available] [script_id] | ||
| */ | ||
| public class ClientScriptCommand { | ||
|
|
||
| private static final String SCRIPT_PREFIX = "script/"; | ||
| private static final String SCRIPT_SUFFIX = ".lua"; | ||
|
|
||
| /** | ||
| * Converts a full script identifier to a display-friendly format. | ||
| * Removes the "script/" prefix and ".lua" suffix. | ||
| */ | ||
| private static String getDisplayId(Identifier id) { | ||
| return id.getPath().replace(SCRIPT_PREFIX, "").replace(SCRIPT_SUFFIX, ""); | ||
|
duzos marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| /** | ||
| * Converts a user-provided script ID to the full internal identifier. | ||
| */ | ||
| private static Identifier toFullScriptId(Identifier scriptId) { | ||
| return scriptId.withPrefixedPath(SCRIPT_PREFIX).withSuffixedPath(SCRIPT_SUFFIX); | ||
| } | ||
|
|
||
| private static final SuggestionProvider<FabricClientCommandSource> SCRIPT_SUGGESTIONS = (context, builder) -> { | ||
| return CommandSource.suggestIdentifiers( | ||
| ScriptManager.getInstance().getCache().keySet().stream() | ||
| .map(id -> Identifier.of(id.getNamespace(), getDisplayId(id))), | ||
| builder | ||
| ); | ||
| }; | ||
|
|
||
| private static final SuggestionProvider<FabricClientCommandSource> ENABLED_SCRIPT_SUGGESTIONS = (context, builder) -> { | ||
| return CommandSource.suggestIdentifiers( | ||
| ScriptManager.getInstance().getEnabledScripts().stream() | ||
| .map(id -> Identifier.of(id.getNamespace(), getDisplayId(id))), | ||
| builder | ||
| ); | ||
| }; | ||
|
|
||
| public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher) { | ||
| dispatcher.register(literal("amblescript") | ||
| .then(literal("execute") | ||
| .then(argument("id", IdentifierArgumentType.identifier()) | ||
| .suggests(SCRIPT_SUGGESTIONS) | ||
| .executes(ClientScriptCommand::execute))) | ||
| .then(literal("enable") | ||
| .then(argument("id", IdentifierArgumentType.identifier()) | ||
| .suggests(SCRIPT_SUGGESTIONS) | ||
| .executes(ClientScriptCommand::enable))) | ||
| .then(literal("disable") | ||
| .then(argument("id", IdentifierArgumentType.identifier()) | ||
| .suggests(ENABLED_SCRIPT_SUGGESTIONS) | ||
| .executes(ClientScriptCommand::disable))) | ||
| .then(literal("toggle") | ||
| .then(argument("id", IdentifierArgumentType.identifier()) | ||
| .suggests(SCRIPT_SUGGESTIONS) | ||
| .executes(ClientScriptCommand::toggle))) | ||
| .then(literal("list") | ||
| .executes(ClientScriptCommand::listEnabled)) | ||
| .then(literal("available") | ||
| .executes(ClientScriptCommand::listAvailable))); | ||
| } | ||
|
|
||
| private static int execute(CommandContext<FabricClientCommandSource> context) { | ||
| Identifier scriptId = context.getArgument("id", Identifier.class); | ||
| Identifier fullScriptId = toFullScriptId(scriptId); | ||
|
|
||
| try { | ||
| LuaScript script = ScriptManager.getInstance().load( | ||
| fullScriptId, | ||
| MinecraftClient.getInstance().getResourceManager() | ||
| ); | ||
|
|
||
| if (script.onExecute() == null || script.onExecute().isnil()) { | ||
| context.getSource().sendError(Text.literal("Script '" + scriptId + "' has no onExecute function")); | ||
| return 0; | ||
| } | ||
|
|
||
| LuaValue data = ScriptManager.getInstance().getScriptData(fullScriptId); | ||
| script.onExecute().call(data); | ||
| context.getSource().sendFeedback(Text.literal("Executed script: " + scriptId)); | ||
| return 1; | ||
|
duzos marked this conversation as resolved.
Outdated
|
||
| } catch (Exception e) { | ||
| context.getSource().sendError(Text.literal("Failed to execute script '" + scriptId + "': " + e.getMessage())); | ||
| AmbleKit.LOGGER.error("Failed to execute script {}", scriptId, e); | ||
| return 0; | ||
| } | ||
| } | ||
|
|
||
| private static int enable(CommandContext<FabricClientCommandSource> context) { | ||
| Identifier scriptId = context.getArgument("id", Identifier.class); | ||
| Identifier fullScriptId = toFullScriptId(scriptId); | ||
|
|
||
| // Ensure script is loaded | ||
| try { | ||
| ScriptManager.getInstance().load(fullScriptId, MinecraftClient.getInstance().getResourceManager()); | ||
| } catch (Exception e) { | ||
| context.getSource().sendError(Text.literal("Script '" + scriptId + "' not found")); | ||
|
duzos marked this conversation as resolved.
Outdated
|
||
| return 0; | ||
| } | ||
|
|
||
| if (ScriptManager.getInstance().isEnabled(fullScriptId)) { | ||
| context.getSource().sendError(Text.literal("Script '" + scriptId + "' is already enabled")); | ||
|
duzos marked this conversation as resolved.
Outdated
|
||
| return 0; | ||
| } | ||
|
|
||
| if (ScriptManager.getInstance().enable(fullScriptId)) { | ||
| context.getSource().sendFeedback(Text.literal("Enabled script: " + scriptId).formatted(Formatting.GREEN)); | ||
|
duzos marked this conversation as resolved.
Outdated
|
||
| return 1; | ||
| } else { | ||
| context.getSource().sendError(Text.literal("Failed to enable script '" + scriptId + "'")); | ||
|
duzos marked this conversation as resolved.
Outdated
|
||
| return 0; | ||
| } | ||
| } | ||
|
|
||
| private static int disable(CommandContext<FabricClientCommandSource> context) { | ||
| Identifier scriptId = context.getArgument("id", Identifier.class); | ||
| Identifier fullScriptId = toFullScriptId(scriptId); | ||
|
|
||
| if (!ScriptManager.getInstance().isEnabled(fullScriptId)) { | ||
| context.getSource().sendError(Text.literal("Script '" + scriptId + "' is not enabled")); | ||
|
duzos marked this conversation as resolved.
Outdated
|
||
| return 0; | ||
| } | ||
|
|
||
| if (ScriptManager.getInstance().disable(fullScriptId)) { | ||
| context.getSource().sendFeedback(Text.literal("Disabled script: " + scriptId).formatted(Formatting.RED)); | ||
|
duzos marked this conversation as resolved.
Outdated
|
||
| return 1; | ||
| } else { | ||
| context.getSource().sendError(Text.literal("Failed to disable script '" + scriptId + "'")); | ||
|
duzos marked this conversation as resolved.
Outdated
|
||
| return 0; | ||
| } | ||
| } | ||
|
|
||
| private static int toggle(CommandContext<FabricClientCommandSource> context) { | ||
| Identifier scriptId = context.getArgument("id", Identifier.class); | ||
| Identifier fullScriptId = toFullScriptId(scriptId); | ||
|
|
||
| // Ensure script is loaded | ||
| try { | ||
| ScriptManager.getInstance().load(fullScriptId, MinecraftClient.getInstance().getResourceManager()); | ||
| } catch (Exception e) { | ||
| context.getSource().sendError(Text.literal("Script '" + scriptId + "' not found")); | ||
|
duzos marked this conversation as resolved.
Outdated
|
||
| return 0; | ||
| } | ||
|
|
||
| boolean wasEnabled = ScriptManager.getInstance().isEnabled(fullScriptId); | ||
| ScriptManager.getInstance().toggle(fullScriptId); | ||
|
|
||
| if (wasEnabled) { | ||
| context.getSource().sendFeedback(Text.literal("Disabled script: " + scriptId).formatted(Formatting.RED)); | ||
| } else { | ||
| context.getSource().sendFeedback(Text.literal("Enabled script: " + scriptId).formatted(Formatting.GREEN)); | ||
| } | ||
| return 1; | ||
| } | ||
|
|
||
| private static int listEnabled(CommandContext<FabricClientCommandSource> context) { | ||
| Set<Identifier> enabled = ScriptManager.getInstance().getEnabledScripts(); | ||
|
|
||
| if (enabled.isEmpty()) { | ||
| context.getSource().sendFeedback(Text.literal("No client scripts are currently enabled").formatted(Formatting.GRAY)); | ||
| return 1; | ||
| } | ||
|
|
||
| context.getSource().sendFeedback(Text.literal("━━━ Enabled Client Scripts (" + enabled.size() + ") ━━━").formatted(Formatting.GOLD, Formatting.BOLD)); | ||
| for (Identifier id : enabled) { | ||
| String displayId = getDisplayId(id); | ||
| context.getSource().sendFeedback( | ||
| Text.literal("✓ ").formatted(Formatting.GREEN) | ||
| .append(Text.literal(id.getNamespace() + ":" + displayId).formatted(Formatting.WHITE)) | ||
| ); | ||
| } | ||
| return 1; | ||
| } | ||
|
|
||
| private static int listAvailable(CommandContext<FabricClientCommandSource> context) { | ||
| Set<Identifier> available = ScriptManager.getInstance().getCache().keySet(); | ||
| Set<Identifier> enabled = ScriptManager.getInstance().getEnabledScripts(); | ||
|
|
||
| if (available.isEmpty()) { | ||
| context.getSource().sendFeedback(Text.literal("No client scripts available").formatted(Formatting.GRAY)); | ||
| return 1; | ||
| } | ||
|
|
||
| context.getSource().sendFeedback(Text.literal("━━━ Available Client Scripts (" + available.size() + ") ━━━").formatted(Formatting.GOLD, Formatting.BOLD)); | ||
| for (Identifier id : available) { | ||
| String displayId = getDisplayId(id); | ||
| Text statusIcon = enabled.contains(id) | ||
| ? Text.literal("✓ ").formatted(Formatting.GREEN) | ||
| : Text.literal("○ ").formatted(Formatting.GRAY); | ||
| context.getSource().sendFeedback( | ||
| statusIcon.copy().append(Text.literal(id.getNamespace() + ":" + displayId).formatted(Formatting.WHITE)) | ||
| ); | ||
| } | ||
| return 1; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.