From 906263cb2ba4cd2243030abe201ab39aab5086cf Mon Sep 17 00:00:00 2001 From: xtex Date: Tue, 4 Jul 2023 16:21:42 +0800 Subject: [PATCH] fix: projection command --- .../quaedam/projection/ProjectionCommand.kt | 31 ++++++------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/common/src/main/kotlin/quaedam/projection/ProjectionCommand.kt b/common/src/main/kotlin/quaedam/projection/ProjectionCommand.kt index 6cc8c61..c44146b 100644 --- a/common/src/main/kotlin/quaedam/projection/ProjectionCommand.kt +++ b/common/src/main/kotlin/quaedam/projection/ProjectionCommand.kt @@ -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("dump") .requires { it.hasPermission(2) } - .then( - argument("path", string()) - .executes(::dumpPath) - ) .executes(::dump) ) .then( @@ -36,10 +31,6 @@ object ProjectionCommand { "type", resource(ctx, ProjectionEffectType.registryKey) ) - .then( - argument("path", string()) - .executes(::getPath) - ) .executes(::get) ) ) @@ -47,7 +38,7 @@ object ProjectionCommand { } } - private fun dump(ctx: CommandContext, path: String = ""): Int { + private fun dump(ctx: CommandContext): 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) = - dump(ctx, path = ctx.getArgument("path", String::class.java)) - - private fun get(ctx: CommandContext, path: String = ""): Int { + private fun get(ctx: CommandContext): 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) = - dump(ctx, path = ctx.getArgument("path", String::class.java)) - } \ No newline at end of file