Skip to content

Conversation

@duzos
Copy link
Member

@duzos duzos commented Jan 8, 2026

accidentally merged #58

duzos added 11 commits January 7, 2026 04:54
- Add core Lua infrastructure (GuiScript, GuiScriptManager, LuaBinder, LuaExpose annotation)

- Add LuaElement wrapper to expose AmbleElement properties to Lua scripts

- Add Minecraft API bindings (MinecraftData, MinecraftEntity, LuaItemStack)

- Integrate script callbacks (onInit, onClick, onRelease, onHover) into AmbleButton

- Add script property support in JSON GUI definitions

- Improve AmbleText with proper text wrapping and shadow toggle

- Add setDimensions helper to AmbleElement
- Rename GuiScript to AmbleScript and GuiScriptManager to ScriptManager

- Move scripts from gui/script/ to script/ folder for broader use

- Add ExecuteScriptCommand (/amblescript execute) to run scripts via chat

- Auto-discover scripts on resource reload for command tab-completion

- Add onExecute callback support for scripts triggered by command
@duzos duzos requested a review from drtheodor January 8, 2026 15:32
@duzos duzos self-assigned this Jan 8, 2026
@duzos duzos added the enhancement New feature or request label Jan 8, 2026
duzos added 5 commits January 8, 2026 15:35
Introduce server-side Lua scripting system parallel to client scripts:

- Add ServerScriptManager for managing data pack scripts

- Add ServerScriptCommand with enable/disable/execute/toggle/list commands

- Refactor Lua bindings to shared script.lua package

- Add ServerMinecraftData with server-specific APIs

- Include example server scripts (admin_commands, tick_counter, etc.)
- enable/disable/toggle only suggest scripts with onTick method

- execute only suggests scripts with onExecute method
@duzos duzos marked this pull request as ready for review January 8, 2026 21:51
Key improvements:

- Extract AbstractScriptManager for DRY between client/server scripts

- Add type-specific coercion methods to LuaBinder for clarity

- Add toString methods for Vector3f, Vec3d, BlockPos in Lua

- Add structured NBT access via nbt() method, deprecate nbtString()

- Use IntIntImmutablePair from fastutil in AmbleElement

- Add text caching in AmbleText to avoid recalculation

- Add @ApiStatus.Internal and javadoc to LuaElement.unwrap()

- Add init() method with javadoc to AmbleGuiRegistry

- Pass resourceId to parse() for better error context

- Add validation for array sizes and identifier parsing

- Add FALLBACK_LAYOUT constant in AmbleContainer

- Add script name logging via setScriptName/getLogPrefix

- Rename ExecuteScriptCommand to ClientScriptCommand

- Use Command.SINGLE_SUCCESS consistently
@drtheodor drtheodor self-requested a review January 9, 2026 00:07
@duzos
Copy link
Member Author

duzos commented Jan 9, 2026

All review comments have been addressed. Changes include:

  • LuaElement: Added Javadoc explaining the wrapper/facade pattern
  • AmbleGuiRegistry: Added TODO for DatapackRegistry discussion, init() is already called from AmbleKitClient
  • AmbleContainer: Added TRANSPARENT constant for transparent color
  • AmbleText: Added clarifying comment for transient cache fields
  • LuaBinder: Converted to use MethodHandles for better performance
  • MinecraftData: Renamed getPlayer() to getExecutor() with updated docs
  • LuaScript: Refactored to store Globals and look up GUI callbacks on demand
  • ServerScriptManager: Converted onServerTick to lambda

Ready for re-review. @drtheodor

@duzos
Copy link
Member Author

duzos commented Jan 9, 2026

Implemented support for checking any registered keybind, not just the hardcoded movement keys.

Changes to \isKeyPressed:

  • Added more common shorthand names: \inventory, \drop, \chat, \pick_item, \swap_hands\
  • Falls back to searching all registered keybinds by their translation key
  • Matches both exact translation keys (e.g., \key.inventory) and suffix matches (e.g., \inventory)

New method \getKeybinds():

  • Returns a list of all registered keybind translation keys
  • Useful for scripts to discover available keybinds

This allows Lua scripts to check any keybind from vanilla Minecraft or mods.

- Support shorthand keybind names: forward, jump, inventory, sprint, etc.

- Support raw keyboard keys: r, h, space, left_shift, escape, f1, etc.

- Support registered keybind translation keys

- Add isMouseButtonPressed for mouse button checks

- Falls back through keybinds then raw keys for maximum flexibility
@duzos
Copy link
Member Author

duzos commented Jan 9, 2026

Updated: Merged the functionality into a single \isKeyPressed\ method that now supports:

  1. Shorthand keybind names: \ orward, \jump, \inventory, \sprint, etc.
  2. Raw keyboard keys:
    , \h, \space, \left_shift, \escape, \ 1, etc.
  3. Registered keybind translation keys: \key.inventory, \key.sprint, etc.

Example usage in Lua:
\\lua
-- Check raw keys
if minecraft.isKeyPressed('r') then print('R is pressed!') end
if minecraft.isKeyPressed('space') then print('Space is pressed!') end

-- Still works with keybinds
if minecraft.isKeyPressed('jump') then print('Jump keybind pressed!') end
\\

Also added \isMouseButtonPressed()\ for mouse button checks.

@duzos duzos requested a review from drtheodor January 9, 2026 01:11
duzos and others added 3 commits January 9, 2026 01:29
- Add LUA_SCRIPTING.md with full API reference, lifecycle callbacks, and examples

- Add GUI_SYSTEM.md with JSON structure docs, properties reference, and Lua integration

- Update README.md with brief descriptions and links to new documentation

- Fix AmbleGuiRegistry to auto-create child AmbleText when button has text property
}

@LuaExpose
public int x() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This question still stands.

@duzos duzos requested a review from drtheodor January 11, 2026 20:30
@duzos duzos requested a review from drtheodor January 11, 2026 22:33
Copy link
Member

@drtheodor drtheodor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants