|
1 | 1 | package net.quiltservertools.interdimensional.command |
2 | 2 |
|
3 | | -import net.quiltservertools.interdimensional.command.argument.ServerDimensionArgument |
4 | | -import net.quiltservertools.interdimensional.command.InterdimensionalCommand.info |
5 | | -import net.quiltservertools.interdimensional.command.InterdimensionalCommand.success |
6 | | -import net.quiltservertools.interdimensional.command.argument.DimensionOverrideArgumentType |
7 | | -import net.quiltservertools.interdimensional.customGenerator |
8 | | -import net.quiltservertools.interdimensional.world.RuntimeWorldManager |
9 | | -import com.mojang.brigadier.arguments.StringArgumentType |
10 | 3 | import com.mojang.brigadier.context.CommandContext |
11 | 4 | import com.mojang.brigadier.tree.LiteralCommandNode |
12 | 5 | import me.lucko.fabric.api.permissions.v0.Permissions |
13 | | -import net.minecraft.command.argument.IdentifierArgumentType |
14 | 6 | import net.minecraft.server.command.CommandManager |
15 | 7 | import net.minecraft.server.command.ServerCommandSource |
16 | | -import net.minecraft.server.world.ServerWorld |
17 | | -import net.minecraft.util.Identifier |
18 | | -import net.minecraft.util.registry.Registry |
19 | | -import net.minecraft.world.Difficulty |
20 | | -import net.minecraft.world.gen.chunk.ChunkGenerator |
21 | 8 | import net.quiltservertools.interdimensional.gui.CreateGuiHandler |
22 | | -import xyz.nucleoid.fantasy.RuntimeWorldConfig |
23 | 9 |
|
24 | 10 | object CreateCommand : Command { |
25 | 11 | override fun register(): LiteralCommandNode<ServerCommandSource> { |
26 | 12 | return CommandManager.literal("create") |
27 | 13 | .requires(Permissions.require("interdimensional.command.create", 3)) |
28 | | - .then( |
29 | | - CommandManager.literal("gui") |
30 | 14 | .executes { |
31 | 15 | createSgui(it) |
32 | 16 | } |
33 | | - ) |
34 | | - .then(CommandManager.argument("identifier", IdentifierArgumentType.identifier()) |
35 | | - .then( |
36 | | - ServerDimensionArgument.dimension("maplike") |
37 | | - .executes { ctx: CommandContext<ServerCommandSource> -> |
38 | | - run( |
39 | | - ServerDimensionArgument.get(ctx, "maplike"), |
40 | | - "", |
41 | | - IdentifierArgumentType.getIdentifier(ctx, "identifier"), |
42 | | - ctx |
43 | | - ) |
44 | | - } |
45 | | - .then(CommandManager.argument("overrides", StringArgumentType.greedyString()) |
46 | | - .suggests(DimensionOverrideArgumentType) |
47 | | - .executes { ctx: CommandContext<ServerCommandSource> -> |
48 | | - run( |
49 | | - ServerDimensionArgument.get(ctx, "maplike"), |
50 | | - StringArgumentType.getString(ctx, "overrides"), |
51 | | - IdentifierArgumentType.getIdentifier(ctx, "identifier"), |
52 | | - ctx |
53 | | - ) |
54 | | - }) |
55 | | - ) |
56 | | - ) |
57 | 17 | .build() |
58 | 18 | } |
59 | 19 |
|
60 | | - private fun run( |
61 | | - maplike: ServerWorld, |
62 | | - args: String, |
63 | | - identifier: Identifier, |
64 | | - ctx: CommandContext<ServerCommandSource> |
65 | | - ): Int { |
66 | | - val propertyMap: HashMap<String, Any> = DimensionOverrideArgumentType.rawProperties(args) |
67 | | - val scs = ctx.source!! |
68 | | - scs.sendFeedback("Creating dimension $identifier".info(), false) |
69 | | - |
70 | | - val config = RuntimeWorldConfig() |
71 | | - val generator: ChunkGenerator = |
72 | | - if (scs.player.customGenerator != null && propertyMap.containsKey("custom_generator") && propertyMap["custom_generator"] as Boolean) { |
73 | | - scs.player.customGenerator!! |
74 | | - } else { |
75 | | - maplike.chunkManager.chunkGenerator |
76 | | - } |
77 | | - config.setDimensionType(maplike.dimension) |
78 | | - config.generator = generator |
79 | | - config.seed = scs.world.seed |
80 | | - config.difficulty = scs.world.difficulty |
81 | | - |
82 | | - if (propertyMap.containsKey("type")) { |
83 | | - config.setDimensionType( |
84 | | - scs.server.registryManager.get(Registry.DIMENSION_TYPE_KEY).get(propertyMap["type"] as Identifier) |
85 | | - ) |
86 | | - } |
87 | | - if (propertyMap.containsKey("generator")) { |
88 | | - config.generator = |
89 | | - scs.server.saveProperties.generatorOptions.dimensions.get(propertyMap["generator"] as Identifier) |
90 | | - ?.chunkGenerator ?: maplike.chunkManager.chunkGenerator |
91 | | - } |
92 | | - |
93 | | - if (propertyMap.containsKey("seed")) { |
94 | | - config.seed = propertyMap["seed"] as Long |
95 | | - if (config.generator != null) { |
96 | | - config.generator = config.generator!!.withSeed(propertyMap["seed"] as Long) |
97 | | - } |
98 | | - } |
99 | | - |
100 | | - if (propertyMap.containsKey("difficulty")) { |
101 | | - when (propertyMap["difficulty"] as String) { |
102 | | - "peaceful" -> config.difficulty = Difficulty.PEACEFUL |
103 | | - "easy" -> config.difficulty = Difficulty.EASY |
104 | | - "normal" -> config.difficulty = Difficulty.NORMAL |
105 | | - "hard" -> config.difficulty = Difficulty.HARD |
106 | | - } |
107 | | - } |
108 | | - |
109 | | - RuntimeWorldManager.add(config, identifier) |
110 | | - scs.sendFeedback("Created new world: $identifier".success(), true) |
111 | | - |
112 | | - return 1 |
113 | | - } |
114 | | - |
115 | | - //todo change commands here to use data class and create new generator |
116 | | - |
117 | 20 | private fun createSgui(ctx: CommandContext<ServerCommandSource>): Int { |
118 | 21 | CreateGuiHandler(ctx.source.player).open() |
119 | 22 | return 1 |
|
0 commit comments