From b5e895c37ef0985fa9d272cf919b9040dd8e4e32 Mon Sep 17 00:00:00 2001 From: wizjany Date: Fri, 28 Jun 2019 18:02:06 -0400 Subject: [PATCH] Update info tool to components. --- .../worldedit/command/tool/QueryTool.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java index a199b2b7f..2c4e8ff87 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java @@ -22,15 +22,20 @@ package com.sk89q.worldedit.command.tool; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.blocks.MobSpawnerBlock; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Platform; +import com.sk89q.worldedit.internal.block.BlockStateIdAccess; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; +import com.sk89q.worldedit.util.formatting.text.format.TextColor; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; +import java.util.OptionalInt; + /** * Looks up information about a block. */ @@ -49,16 +54,21 @@ public class QueryTool implements BlockTool { BlockVector3 blockPoint = clicked.toVector().toBlockPoint(); BaseBlock block = editSession.getFullBlock(blockPoint); - player.print("\u00A79@" + clicked.toVector() + ": " + "\u00A7e" - + block.getBlockType().getName() + "\u00A77" + " (" - + block.toString() + ") " - + "\u00A7f" - + " (" + world.getBlockLightLevel(blockPoint) + "/" + world.getBlockLightLevel(blockPoint.add(0, 1, 0)) + ")"); - - if (block instanceof MobSpawnerBlock) { - player.printRaw("\u00A7e" + "Mob Type: " - + ((MobSpawnerBlock) block).getMobType()); + TextComponent.Builder builder = TextComponent.builder(); + builder.append(TextComponent.of("@" + clicked.toVector().toBlockPoint() + ": ", TextColor.BLUE)); + builder.append(TextComponent.of(block.getBlockType().getName(), TextColor.YELLOW)); + builder.append(TextComponent.of(" (" + block + ") ", TextColor.GRAY) + .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Block state")))); + final OptionalInt internalId = BlockStateIdAccess.getBlockStateId(block.toImmutableState()); + if (internalId.isPresent()) { + builder.append(TextComponent.of(" (" + internalId.getAsInt() + ") ", TextColor.DARK_GRAY) + .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Internal ID")))); } + builder.append(TextComponent.of(" (" + world.getBlockLightLevel(blockPoint) + "/" + + world.getBlockLightLevel(blockPoint.add(0, 1, 0)) + ")", TextColor.WHITE) + .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Block Light/Light Above")))); + + player.print(builder.build()); return true; }