1+ /*
2+ * Copyright 2024 The Quilt Project
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package com.lambda.brigadier.argument
18+
19+ import com.lambda.brigadier.*
20+ import com.lambda.brigadier.assumeSourceNotUsed
21+ import net.minecraft.advancement.AdvancementEntry
22+ import net.minecraft.command.argument.IdentifierArgumentType
23+ import net.minecraft.loot.condition.LootCondition
24+ import net.minecraft.loot.function.LootFunction
25+ import net.minecraft.recipe.RecipeEntry
26+ import net.minecraft.server.command.ServerCommandSource
27+ import net.minecraft.util.Identifier
28+
29+ /* *
30+ * Reads the [Identifier] value from the
31+ * argument in the receiver [ArgumentReader].
32+ *
33+ * @see IdentifierArgumentType.getIdentifier
34+ */
35+ @JvmName(" valueIdentifierArg" )
36+ @BrigadierDsl
37+ fun DefaultArgumentReader<IdentifierArgumentType>.value (): Identifier {
38+ return IdentifierArgumentType .getIdentifier(context.assumeSourceNotUsed(), name)
39+ }
40+
41+ /* *
42+ * Reads the [Identifier] value from the
43+ * argument in the receiver [ArgumentReader]
44+ * as an [AdvancementEntry].
45+ *
46+ * @see IdentifierArgumentType.getAdvancementArgument
47+ */
48+ @BrigadierDsl
49+ fun ArgumentReader <
50+ ServerCommandSource ,
51+ DefaultArgumentDescriptor <
52+ IdentifierArgumentType
53+ >
54+ >.asAdvancement (): AdvancementEntry {
55+ return IdentifierArgumentType .getAdvancementArgument(context, name)
56+ }
57+
58+ /* *
59+ * Reads the [Identifier] value from the
60+ * argument in the receiver [ArgumentReader]
61+ * as a [LootCondition].
62+ *
63+ * @see IdentifierArgumentType.getPredicateArgument
64+ */
65+ @BrigadierDsl
66+ fun ArgumentReader <
67+ ServerCommandSource ,
68+ DefaultArgumentDescriptor <
69+ IdentifierArgumentType
70+ >
71+ >.asPredicate (): LootCondition {
72+ return IdentifierArgumentType .getPredicateArgument(context, name)
73+ }
74+
75+ /* *
76+ * Reads the [Identifier] value from the
77+ * argument in the receiver [ArgumentReader]
78+ * as a [LootFunction].
79+ *
80+ * @see IdentifierArgumentType.getItemModifierArgument
81+ */
82+ @BrigadierDsl
83+ fun ArgumentReader <
84+ ServerCommandSource ,
85+ DefaultArgumentDescriptor <
86+ IdentifierArgumentType
87+ >
88+ >.asItemModifier (): LootFunction {
89+ return IdentifierArgumentType .getItemModifierArgument(context, name)
90+ }
91+
92+ /* *
93+ * Reads the [Identifier] value from the
94+ * argument in the receiver [ArgumentReader]
95+ * as a [RecipeEntry].
96+ *
97+ * @see IdentifierArgumentType.getRecipeArgument
98+ */
99+ @BrigadierDsl
100+ fun ArgumentReader <
101+ ServerCommandSource ,
102+ DefaultArgumentDescriptor <
103+ IdentifierArgumentType
104+ >
105+ >.asRecipe (): RecipeEntry <* > {
106+ return IdentifierArgumentType .getRecipeArgument(context, name)
107+ }
108+
109+ /* *
110+ * Creates an identifier argument with [name] as the parameter name.
111+ */
112+ @BrigadierDsl
113+ fun <S > identifier (
114+ name : String
115+ ): DefaultArgumentConstructor <S , IdentifierArgumentType > {
116+ return argument(name, IdentifierArgumentType .identifier())
117+ }
0 commit comments