fix: projection command
This commit is contained in:
parent
929474ff19
commit
906263cb2b
@ -1,6 +1,5 @@
|
||||
package quaedam.projection
|
||||
|
||||
import com.mojang.brigadier.arguments.StringArgumentType.string
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder.literal
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder.argument
|
||||
import com.mojang.brigadier.context.CommandContext
|
||||
@ -9,9 +8,9 @@ import net.minecraft.commands.CommandSourceStack
|
||||
import net.minecraft.commands.arguments.ResourceArgument.resource
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.core.Holder
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.nbt.ListTag
|
||||
import net.minecraft.nbt.NbtUtils
|
||||
import quaedam.projector.Projector
|
||||
import java.util.*
|
||||
|
||||
object ProjectionCommand {
|
||||
|
||||
@ -22,10 +21,6 @@ object ProjectionCommand {
|
||||
.then(
|
||||
literal<CommandSourceStack>("dump")
|
||||
.requires { it.hasPermission(2) }
|
||||
.then(
|
||||
argument<CommandSourceStack, String>("path", string())
|
||||
.executes(::dumpPath)
|
||||
)
|
||||
.executes(::dump)
|
||||
)
|
||||
.then(
|
||||
@ -36,10 +31,6 @@ object ProjectionCommand {
|
||||
"type",
|
||||
resource(ctx, ProjectionEffectType.registryKey)
|
||||
)
|
||||
.then(
|
||||
argument<CommandSourceStack, String>("path", string())
|
||||
.executes(::getPath)
|
||||
)
|
||||
.executes(::get)
|
||||
)
|
||||
)
|
||||
@ -47,7 +38,7 @@ object ProjectionCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private fun dump(ctx: CommandContext<CommandSourceStack>, path: String = ""): Int {
|
||||
private fun dump(ctx: CommandContext<CommandSourceStack>): Int {
|
||||
val pos = BlockPos(
|
||||
ctx.source.position.x.toInt(),
|
||||
ctx.source.position.y.toInt(),
|
||||
@ -55,14 +46,13 @@ object ProjectionCommand {
|
||||
)
|
||||
val data = Projector.findNearbyProjectors(ctx.source.level, pos)
|
||||
.map { ctx.source.level.getBlockEntity(it)!!.saveWithFullMetadata() }
|
||||
ctx.source.sendSystemMessage(Component.nbt(path, true, Optional.empty()) { data.stream() })
|
||||
val tag = ListTag()
|
||||
tag.addAll(data)
|
||||
ctx.source.sendSystemMessage(NbtUtils.toPrettyComponent(tag))
|
||||
return 0
|
||||
}
|
||||
|
||||
private fun dumpPath(ctx: CommandContext<CommandSourceStack>) =
|
||||
dump(ctx, path = ctx.getArgument("path", String::class.java))
|
||||
|
||||
private fun get(ctx: CommandContext<CommandSourceStack>, path: String = ""): Int {
|
||||
private fun get(ctx: CommandContext<CommandSourceStack>): Int {
|
||||
val pos = BlockPos(
|
||||
ctx.source.position.x.toInt(),
|
||||
ctx.source.position.y.toInt(),
|
||||
@ -71,11 +61,10 @@ object ProjectionCommand {
|
||||
val type = ctx.getArgument("type", Holder.Reference::class.java).value() as ProjectionEffectType<*>
|
||||
val data = Projector.findNearbyProjections(ctx.source.level, pos, type)
|
||||
.map { it.toNbt() }
|
||||
ctx.source.sendSystemMessage(Component.nbt(path, true, Optional.empty()) { data.stream() })
|
||||
val tag = ListTag()
|
||||
tag.addAll(data)
|
||||
ctx.source.sendSystemMessage(NbtUtils.toPrettyComponent(tag))
|
||||
return 0
|
||||
}
|
||||
|
||||
private fun getPath(ctx: CommandContext<CommandSourceStack>) =
|
||||
dump(ctx, path = ctx.getArgument("path", String::class.java))
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user