-
Notifications
You must be signed in to change notification settings - Fork 0
Update datapack initialization to use scheduled function calls #18
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |||||
| "templates": { | ||||||
| "pack.mcmeta": "{\n \"pack\": {\n \"pack_format\": {{pack_format}},\n \"supported_formats\": [48, 57],\n \"description\": \"{{packDescription}}\"\n }\n}", | ||||||
| "datapack.init.header": "################################################################\n# #\n# default init.mcfunction file generated by Minecraft-Script #\n# #\n################################################################\n", | ||||||
| "datapack.init": "scoreboard objectives add mcs_math dummy \"Minecraft-Script Math\"\nscoreboard objectives add mcs_click {{clickScoreboardCriterion}} \"Minecraft-Script Click\"\n\nfunction {{datapack_id}}:user_functions/init", | ||||||
| "datapack.init": "scoreboard objectives add mcs_math dummy \"Minecraft-Script Math\"\nscoreboard objectives add mcs_click {{clickScoreboardCriterion}} \"Minecraft-Script Click\"\n\nschedule function {{datapack_id}}:user_functions/init 20t", | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Delaying Prompt for AI agents
Suggested change
|
||||||
| "datapack.main.header": "################################################################\n# #\n# default main.mcfunction file generated by Minecraft-Script #\n# #\n################################################################\n", | ||||||
| "datapack.main": "function {{datapack_id}}:user_functions/main", | ||||||
| "datapack.kill.header": "################################################################\n# #\n# default kill.mcfunction file generated by Minecraft-Script #\n# #\n################################################################\n", | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |||||
| "templates": { | ||||||
| "pack.mcmeta": "{\n \"pack\": {\n \"pack_format\": {{pack_format}},\n \"supported_formats\": [61, 61],\n \"description\": \"{{packDescription}}\"\n }\n}", | ||||||
| "datapack.init.header": "################################################################\n# #\n# default init.mcfunction file generated by Minecraft-Script #\n# #\n################################################################\n", | ||||||
| "datapack.init": "scoreboard objectives add mcs_math dummy \"Minecraft-Script Math\"\nscoreboard objectives add mcs_click {{clickScoreboardCriterion}} \"Minecraft-Script Click\"\n\nfunction {{datapack_id}}:user_functions/init", | ||||||
| "datapack.init": "scoreboard objectives add mcs_math dummy \"Minecraft-Script Math\"\nscoreboard objectives add mcs_click {{clickScoreboardCriterion}} \"Minecraft-Script Click\"\n\nschedule function {{datapack_id}}:user_functions/init 20t", | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Delaying Prompt for AI agents
Suggested change
|
||||||
| "datapack.main.header": "################################################################\n# #\n# default main.mcfunction file generated by Minecraft-Script #\n# #\n################################################################\n", | ||||||
| "datapack.main": "function {{datapack_id}}:user_functions/main", | ||||||
| "datapack.kill.header": "################################################################\n# #\n# default kill.mcfunction file generated by Minecraft-Script #\n# #\n################################################################\n", | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |||||
| "templates": { | ||||||
| "pack.mcmeta": "{\n \"pack\": {\n \"pack_format\": {{pack_format}},\n \"supported_formats\": [71, 71],\n \"description\": \"{{packDescription}}\"\n }\n}", | ||||||
| "datapack.init.header": "################################################################\n# #\n# default init.mcfunction file generated by Minecraft-Script #\n# #\n################################################################\n", | ||||||
| "datapack.init": "scoreboard objectives add mcs_math dummy \"Minecraft-Script Math\"\nscoreboard objectives add mcs_click {{clickScoreboardCriterion}} \"Minecraft-Script Click\"\n\nfunction {{datapack_id}}:user_functions/init", | ||||||
| "datapack.init": "scoreboard objectives add mcs_math dummy \"Minecraft-Script Math\"\nscoreboard objectives add mcs_click {{clickScoreboardCriterion}} \"Minecraft-Script Click\"\n\nschedule function {{datapack_id}}:user_functions/init 20t", | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Delaying Prompt for AI agents
Suggested change
|
||||||
| "datapack.main.header": "################################################################\n# #\n# default main.mcfunction file generated by Minecraft-Script #\n# #\n################################################################\n", | ||||||
| "datapack.main": "function {{datapack_id}}:user_functions/main", | ||||||
| "datapack.kill.header": "################################################################\n# #\n# default kill.mcfunction file generated by Minecraft-Script #\n# #\n################################################################\n", | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |||||
| "templates": { | ||||||
| "pack.mcmeta": "{\n \"pack\": {\n \"pack_format\": {{pack_format}},\n \"supported_formats\": [80, 80],\n \"description\": \"{{packDescription}}\"\n }\n}", | ||||||
| "datapack.init.header": "################################################################\n# #\n# default init.mcfunction file generated by Minecraft-Script #\n# #\n################################################################\n", | ||||||
| "datapack.init": "scoreboard objectives add mcs_math dummy \"Minecraft-Script Math\"\nscoreboard objectives add mcs_click {{clickScoreboardCriterion}} \"Minecraft-Script Click\"\n\nfunction {{datapack_id}}:user_functions/init", | ||||||
| "datapack.init": "scoreboard objectives add mcs_math dummy \"Minecraft-Script Math\"\nscoreboard objectives add mcs_click {{clickScoreboardCriterion}} \"Minecraft-Script Click\"\n\nschedule function {{datapack_id}}:user_functions/init 20t", | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Deferring Prompt for AI agents
Suggested change
|
||||||
| "datapack.main.header": "################################################################\n# #\n# default main.mcfunction file generated by Minecraft-Script #\n# #\n################################################################\n", | ||||||
| "datapack.main": "function {{datapack_id}}:user_functions/main", | ||||||
| "datapack.kill.header": "################################################################\n# #\n# default kill.mcfunction file generated by Minecraft-Script #\n# #\n################################################################\n", | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |||||
| "templates": { | ||||||
| "pack.mcmeta": "{\n \"pack\": {\n \"min_format\": [{{formatMinMajor}}, {{formatMinMinor}}],\n \"max_format\": [{{formatMaxMajor}}, {{formatMaxMinor}}],\n \"description\": \"{{packDescription}}\"\n }\n}", | ||||||
| "datapack.init.header": "################################################################\n# #\n# default init.mcfunction file generated by Minecraft-Script #\n# #\n################################################################\n", | ||||||
| "datapack.init": "scoreboard objectives add mcs_math dummy \"Minecraft-Script Math\"\nscoreboard objectives add mcs_click {{clickScoreboardCriterion}} \"Minecraft-Script Click\"\n\nfunction {{datapack_id}}:user_functions/init", | ||||||
| "datapack.init": "scoreboard objectives add mcs_math dummy \"Minecraft-Script Math\"\nscoreboard objectives add mcs_click {{clickScoreboardCriterion}} \"Minecraft-Script Click\"\n\nschedule function {{datapack_id}}:user_functions/init 20t", | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Delaying Prompt for AI agents
Suggested change
|
||||||
| "datapack.main.header": "################################################################\n# #\n# default main.mcfunction file generated by Minecraft-Script #\n# #\n################################################################\n", | ||||||
| "datapack.main": "function {{datapack_id}}:user_functions/main", | ||||||
| "datapack.kill.header": "################################################################\n# #\n# default kill.mcfunction file generated by Minecraft-Script #\n# #\n################################################################\n", | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |||||
| "templates": { | ||||||
| "pack.mcmeta": "{\n \"pack\": {\n \"min_format\": [{{formatMinMajor}}, {{formatMinMinor}}],\n \"max_format\": [{{formatMaxMajor}}, {{formatMaxMinor}}],\n \"description\": \"{{packDescription}}\"\n }\n}", | ||||||
| "datapack.init.header": "################################################################\n# #\n# default init.mcfunction file generated by Minecraft-Script #\n# #\n################################################################\n", | ||||||
| "datapack.init": "scoreboard objectives add mcs_math dummy \"Minecraft-Script Math\"\nscoreboard objectives add mcs_click {{clickScoreboardCriterion}} \"Minecraft-Script Click\"\n\nfunction {{datapack_id}}:user_functions/init", | ||||||
| "datapack.init": "scoreboard objectives add mcs_math dummy \"Minecraft-Script Math\"\nscoreboard objectives add mcs_click {{clickScoreboardCriterion}} \"Minecraft-Script Click\"\n\nschedule function {{datapack_id}}:user_functions/init 20t", | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Delaying Prompt for AI agents
Suggested change
|
||||||
| "datapack.main.header": "################################################################\n# #\n# default main.mcfunction file generated by Minecraft-Script #\n# #\n################################################################\n", | ||||||
| "datapack.main": "function {{datapack_id}}:user_functions/main", | ||||||
| "datapack.kill.header": "################################################################\n# #\n# default kill.mcfunction file generated by Minecraft-Script #\n# #\n################################################################\n", | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package dev.spyc0der.minecraftscript; | ||
|
|
||
| public record McsCommandResult(boolean success, String message) { | ||
| public static McsCommandResult ok(String message) { | ||
| return new McsCommandResult(true, message); | ||
| } | ||
|
|
||
| public static McsCommandResult error(String message) { | ||
| return new McsCommandResult(false, message); | ||
| } | ||
|
|
||
| public McsCommandResult acknowledged(String command) { | ||
| String prefix = command == null || command.isBlank() | ||
| ? "MCS command acknowledged: " | ||
| : "MCS command acknowledged: " + command + ": "; | ||
| return new McsCommandResult(success, prefix + message); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| package dev.spyc0der.minecraftscript; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
|
|
||
| public final class McsCommandService { | ||
| private McsCommandService() { | ||
| } | ||
|
|
||
| public static List<String> packNameSuggestions() { | ||
| McsWorldPackManager packManager = McsModRuntime.packManager(); | ||
| if (packManager == null) { | ||
| return List.of(); | ||
| } | ||
| try { | ||
| return packManager.discoverPackNames(); | ||
| } catch (IOException error) { | ||
| return List.of(); | ||
| } | ||
| } | ||
|
|
||
| public static McsCommandResult setHotReloading(boolean enabled, String packName) { | ||
| McsWorldPackManager packManager = McsModRuntime.packManager(); | ||
| if (packManager == null) { | ||
| return McsCommandResult.error("Minecraft Script is not active on this server."); | ||
| } | ||
| try { | ||
| McsCommandResult result = packManager.setHotReloading(enabled, packName); | ||
| if (result.success() && (packName == null || packName.isBlank())) { | ||
| McsModRuntime.applyHotReloadState(enabled); | ||
| } | ||
| return result; | ||
| } catch (IOException error) { | ||
| return McsCommandResult.error("Could not save MCS config: " + error.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| public static McsCommandResult setPackEnabled(String packName, boolean enabled) { | ||
| McsWorldPackManager packManager = McsModRuntime.packManager(); | ||
| McsServerAccess serverAccess = McsModRuntime.serverAccess(); | ||
| if (packManager == null || serverAccess == null) { | ||
| return McsCommandResult.error("Minecraft Script is not active on this server."); | ||
| } | ||
| try { | ||
| McsCommandResult result = packManager.setPackEnabled(packName, enabled); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents |
||
| if (result.success()) { | ||
| serverAccess.executeReload(); | ||
| } | ||
| return result; | ||
| } catch (IOException error) { | ||
| return McsCommandResult.error("Could not update pack state: " + error.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| public static McsCommandResult listPacks() { | ||
| McsWorldPackManager packManager = McsModRuntime.packManager(); | ||
| if (packManager == null) { | ||
| return McsCommandResult.error("Minecraft Script is not active on this server."); | ||
| } | ||
| try { | ||
| return packManager.listPacks(); | ||
| } catch (IOException error) { | ||
| return McsCommandResult.error("Could not list MCS packs: " + error.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| public static McsCommandResult createPack(String packName, String scope) { | ||
| McsWorldPackManager packManager = McsModRuntime.packManager(); | ||
| McsServerAccess serverAccess = McsModRuntime.serverAccess(); | ||
| if (packManager == null || serverAccess == null) { | ||
| return McsCommandResult.error("Minecraft Script is not active on this server."); | ||
| } | ||
| McsPackSource source = parsePackScope(scope); | ||
| if (source == null) { | ||
| return McsCommandResult.error("Scope must be 'global' or 'local'."); | ||
| } | ||
| try { | ||
| McsCommandResult result = packManager.createPack(packName, source); | ||
| if (result.success()) { | ||
| serverAccess.executeReload(); | ||
| } | ||
| return result; | ||
| } catch (IOException error) { | ||
| return McsCommandResult.error("Could not create MCS pack: " + error.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| private static McsPackSource parsePackScope(String scope) { | ||
| if (scope == null) { | ||
| return null; | ||
| } | ||
| return switch (scope.trim().toLowerCase()) { | ||
| case "global" -> McsPackSource.GLOBAL; | ||
| case "local" -> McsPackSource.WORLD; | ||
| default -> null; | ||
| }; | ||
| } | ||
|
|
||
| public static McsCommandResult reload(String packName) { | ||
| McsWorldPackManager packManager = McsModRuntime.packManager(); | ||
| McsServerAccess serverAccess = McsModRuntime.serverAccess(); | ||
| if (packManager == null || serverAccess == null) { | ||
| return McsCommandResult.error("Minecraft Script is not active on this server."); | ||
| } | ||
| try { | ||
| McsCommandResult result = packManager.reload(packName); | ||
| if (result.success()) { | ||
| serverAccess.executeReload(); | ||
| } | ||
| return result; | ||
| } catch (IOException error) { | ||
| return McsCommandResult.error("Could not reload MCS packs: " + error.getMessage()); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Scheduling
user_functions/init20 ticks later allowsmainto run before initialization completes, introducing an init/main ordering race.Prompt for AI agents