Skip to content

Commit

Permalink
feat: /blueprint-editor save <custom id>
Browse files Browse the repository at this point in the history
  • Loading branch information
andantet committed Jan 15, 2025
1 parent f460608 commit 6f9d86d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_build=8
loader_version=0.16.10

# Mod Properties
mod_version=1.14.8
mod_version=1.14.9
maven_group=net.mcbrawls
mod_id=blueprint

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import net.minecraft.text.Text

object BlueprintEditorCommand {
const val BLUEPRINT_KEY = "blueprint"
const val BLUEPRINT_ID_KEY = "blueprint_id"

private val NOT_BLUEPRINT_EDITOR_WORLD_EXCEPTION = SimpleCommandExceptionType(Text.literal("You are not in a Blueprint editor."))
private val IN_BLUEPRINT_EDITOR_WORLD_EXCEPTION = SimpleCommandExceptionType(Text.literal("You are already in a Blueprint editor. Use /blueprint-editor close to leave."))

Expand All @@ -36,6 +38,11 @@ object BlueprintEditorCommand {
.then(
literal("save")
.executes(::executeSave)
.then(
argument(BLUEPRINT_ID_KEY, IdentifierArgumentType.identifier())
.suggests { _, suggestions -> BlueprintManager.suggestBlueprints(suggestions) }
.executes(::executeSave)
)
)
)
}
Expand Down Expand Up @@ -68,10 +75,19 @@ object BlueprintEditorCommand {
}

private fun executeSave(context: CommandContext<ServerCommandSource>): Int {
val customBlueprintId = runCatching {
IdentifierArgumentType.getIdentifier(context, BLUEPRINT_ID_KEY)
}.getOrNull()

val source = context.source
val world = source.world as? BlueprintEditorWorld ?: throw NOT_BLUEPRINT_EDITOR_WORLD_EXCEPTION.create()
val pathString = world.saveBlueprint()
source.sendFeedback({ Text.literal("Saved editor blueprint: \"$pathString\"") }, true)
if (customBlueprintId != null) {
source.sendFeedback({ Text.literal("Saved editor blueprint as \"$customBlueprintId\"") }, true)
} else {
val world = source.world as? BlueprintEditorWorld ?: throw NOT_BLUEPRINT_EDITOR_WORLD_EXCEPTION.create()
val pathString = world.saveBlueprint()
source.sendFeedback({ Text.literal("Saved editor blueprint: \"$pathString\"") }, true)
}

return 1
}
}

0 comments on commit 6f9d86d

Please sign in to comment.