ArgumentReader

class ArgumentReader<S, out D : ArgumentDescriptor<*>>(    val context: CommandContext<S>,     val name: String,     val argumentDescriptor: D)

Argument readers are a general access point for obtaining argument values from the command context.

Accessors are defined as extensions methods on the reader allowing reading of arguments with specific descriptors from contexts with specific source types S

Author

Cypher121

Samples

import com.mojang.brigadier.CommandDispatcher
import net.minecraft.command.argument.PosArgument
import net.minecraft.command.argument.Vec3ArgumentType
import net.minecraft.network.MessageType
import net.minecraft.server.command.ServerCommandSource
import net.minecraft.text.Text
import net.minecraft.util.math.Vec3d
import org.quiltmc.qkl.wrapper.minecraft.brigadier.*
import org.quiltmc.qkl.wrapper.minecraft.brigadier.argument.*
import org.quiltmc.qkl.wrapper.minecraft.brigadier.util.entity
import org.quiltmc.qkl.wrapper.minecraft.brigadier.util.required
import org.quiltmc.qkl.wrapper.minecraft.brigadier.util.sendFeedback
import org.quiltmc.qkl.wrapper.minecraft.brigadier.util.server
import kotlin.random.Random
fun main() { 
   //sampleStart 
   //some special command source your code needs
//e.g. commands coming from external integrations
abstract class CustomSource {
    abstract fun calculateVec3(pos: PosArgument): Vec3d

    abstract fun useVec3ForSomething(vec: Vec3d)
}

//can use any name including `value`
//`custom` added for clarity
fun ArgumentReader<CustomSource, DefaultArgumentDescriptor<Vec3ArgumentType>>.customValue(): Vec3d =
    context.source.calculateVec3(posArgument())

val dispatcher: CommandDispatcher<CustomSource> = stub()

dispatcher.register("customSourceCommand") {
    required(vec3("pos")) { getPos ->
        execute {
            val vec = getPos().customValue()

            source.useVec3ForSomething(vec)
        }
    }
} 
   //sampleEnd
}

Constructors

Link copied to clipboard
fun <S, out D : ArgumentDescriptor<*>> ArgumentReader(    context: CommandContext<S>,     name: String,     argumentDescriptor: D)

Properties

Link copied to clipboard
val argumentDescriptor: D

descriptor provided for the argument's declaration

Link copied to clipboard
val context: CommandContext<S>

CommandContext on which the command is being executed

Link copied to clipboard
val name: String

name of the argument as declared in the command

Extensions

Link copied to clipboard
@JvmName(name = "absoluteRotationArg")
fun ArgumentReader<ServerCommandSource, DefaultArgumentDescriptor<RotationArgumentType>>.absolute(): Vec2f

Reads the Vec2f value from the argument in the receiver ArgumentReader, converting the contained PosArgument to an absolute rotation.

Link copied to clipboard

Reads the Identifier value from the argument in the receiver ArgumentReader as an Advancement.

Link copied to clipboard

Reads the Identifier value from the argument in the receiver ArgumentReader as a LootFunction.

Link copied to clipboard

Reads the Identifier value from the argument in the receiver ArgumentReader as a LootCondition.

Link copied to clipboard

Reads the Identifier value from the argument in the receiver ArgumentReader as a Recipe.

Link copied to clipboard
@JvmName(name = "defaultToAllKnownListScoreHolderArg")
fun ArgumentReader<ServerCommandSource, ListScoreHolderArgumentDescriptor>.defaultToAllKnown(): Collection<String>

Reads all score holder names from the argument in the receiver ArgumentReader.

Link copied to clipboard
Link copied to clipboard

Reads the collection of CommandFunctions from the argument in the receiver ArgumentReader.

Link copied to clipboard
@JvmName(name = "optionalEntityArg")
fun ArgumentReader<ServerCommandSource, ListEntityArgumentDescriptor>.optional(): Collection<Entity>

Reads the collection of entities from the argument in the receiver ArgumentReader.

@JvmName(name = "optionalPlayerArg")
fun ArgumentReader<ServerCommandSource, ListPlayerArgumentDescriptor>.optional(): Collection<ServerPlayerEntity>

Reads the collection of players from the argument in the receiver ArgumentReader.

Link copied to clipboard
@JvmName(name = "requiredEntityArg")
fun ArgumentReader<ServerCommandSource, ListEntityArgumentDescriptor>.required(): Collection<Entity>

Reads the collection of entities from the argument in the receiver ArgumentReader.

@JvmName(name = "requiredPlayerArg")
fun ArgumentReader<ServerCommandSource, ListPlayerArgumentDescriptor>.required(): Collection<ServerPlayerEntity>

Reads the collection of players from the argument in the receiver ArgumentReader.

Link copied to clipboard

Reads the BlockPos value from the argument in the receiver ArgumentReader.

Link copied to clipboard

Reads the SignedMessage value from the argument in the receiver ArgumentReader.

Link copied to clipboard
@JvmName(name = "valueEntitySummonArg")
fun ArgumentReader<*, DefaultArgumentDescriptor<EntitySummonArgumentType>>.value(): Identifier

Reads the entity summon Identifier value of the argument in the receiver ArgumentReader.

@JvmName(name = "valueSingleEntityArg")
fun ArgumentReader<ServerCommandSource, SingleEntityArgumentDescriptor>.value(): Entity

Reads the Entity value from the argument in the receiver ArgumentReader.

@JvmName(name = "valueEnumClassArg")
fun <T : Enum<T>> ArgumentReader<*, TypedEnumArgumentDescriptor<T>>.value(): T

Reads the enum value of type T from the argument in the receiver ArgumentReader.

@JvmName(name = "valueEnumStringArg")
fun ArgumentReader<*, StringEnumArgumentDescriptor>.value(): String

Reads the string value from the argument in the receiver ArgumentReader.

@JvmName(name = "valueEnumMappedArg")
fun <T> ArgumentReader<*, MappedStringEnumArgumentDescriptor<T>>.value(): T

Reads the string value from the argument in the receiver ArgumentReader and converts it to a value of type T according to the map provided when creating the argument.

@JvmName(name = "valueDimensionArg")
fun ArgumentReader<ServerCommandSource, DefaultArgumentDescriptor<DimensionArgumentType>>.value(): ServerWorld

Reads the ServerWorld value for the selected dimension from the argument in the receiver ArgumentReader.

@JvmName(name = "valueAngleArg")
fun ArgumentReader<ServerCommandSource, DefaultArgumentDescriptor<AngleArgumentType>>.value(): Float

Reads the float value from the argument in the receiver ArgumentReader.

@JvmName(name = "valueBlockPosArg")
fun ArgumentReader<ServerCommandSource, DefaultArgumentDescriptor<BlockPosArgumentType>>.value(): BlockPos

Reads the BlockPos value from the argument in the receiver ArgumentReader.

@JvmName(name = "valueColumnPosArg")
fun ArgumentReader<ServerCommandSource, DefaultArgumentDescriptor<ColumnPosArgumentType>>.value(): ColumnPos

Reads the ColumnPos value from the argument in the receiver ArgumentReader.

@JvmName(name = "valueVec2Arg")
fun ArgumentReader<ServerCommandSource, DefaultArgumentDescriptor<Vec2ArgumentType>>.value(): Vec2f

Reads the Vec2f value from the argument in the receiver ArgumentReader.

@JvmName(name = "valueVec3Arg")
fun ArgumentReader<ServerCommandSource, DefaultArgumentDescriptor<Vec3ArgumentType>>.value(): Vec3d

Reads the Vec3d value from the argument in the receiver ArgumentReader.

@JvmName(name = "valueGameProfileArg")
fun ArgumentReader<ServerCommandSource, DefaultArgumentDescriptor<GameProfileArgumentType>>.value(): Collection<GameProfile>

Reads the GameProfile value from the argument in the receiver ArgumentReader.

@JvmName(name = "valueTeamArg")
fun ArgumentReader<ServerCommandSource, DefaultArgumentDescriptor<TeamArgumentType>>.value(): Team

Reads the Team value from the argument in the receiver ArgumentReader.

@JvmName(name = "valuePlayerArg")
fun ArgumentReader<ServerCommandSource, SinglePlayerArgumentDescriptor>.value(): ServerPlayerEntity

Reads the ServerPlayerEntity value from the argument in the receiver ArgumentReader.

@JvmName(name = "valueScoreboardObjectiveArg")
fun ArgumentReader<ServerCommandSource, DefaultArgumentDescriptor<ScoreboardObjectiveArgumentType>>.value(): ScoreboardObjective

Reads the ScoreboardObjective value from the argument in the receiver ArgumentReader.

@JvmName(name = "valueSingleScoreHolderArg")
fun ArgumentReader<ServerCommandSource, SingleScoreHolderArgumentDescriptor>.value(): String

Reads the score holder name from the argument in the receiver ArgumentReader.

@JvmName(name = "valueListScoreHolderArg")
fun ArgumentReader<ServerCommandSource, ListScoreHolderArgumentDescriptor>.value(): Collection<String>

Reads all score holder names from the argument in the receiver ArgumentReader.

@JvmName(name = "valueMessageArg")
fun ArgumentReader<ServerCommandSource, DefaultArgumentDescriptor<MessageArgumentType>>.value(): Text

Reads the message's Text value from the argument in the receiver ArgumentReader.

Link copied to clipboard
@JvmName(name = "writableScoreboardObjectiveArg")
fun ArgumentReader<ServerCommandSource, DefaultArgumentDescriptor<ScoreboardObjectiveArgumentType>>.writable(): ScoreboardObjective

Reads the ScoreboardObjective value from the argument in the receiver ArgumentReader.