Skip to content

Commit

Permalink
add debug command to get block and entity id and class
Browse files Browse the repository at this point in the history
(cherry picked from commit dcf0340)
  • Loading branch information
deirn committed Jun 27, 2024
1 parent 388a40a commit 0f13cfc
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/main/java/mcp/mobius/waila/command/ServerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import mcp.mobius.waila.plugin.PluginLoader;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.EntityArgument;
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -67,6 +68,42 @@ protected void register(ArgumentBuilderBuilder<CommandSourceStack> command) {
.then(Commands.literal("debug"))
.requires(source -> source.hasPermission(Commands.LEVEL_ADMINS))

.then(Commands.literal("getBlockInfo"))
.then(Commands.argument("pos", BlockPosArgument.blockPos()))
.executes(context -> {
var source = context.getSource();
var world = source.getLevel();
var pos = BlockPosArgument.getLoadedBlockPos(context, "pos");
var block = world.getBlockState(pos).getBlock();

//noinspection deprecation
source.sendSuccess(() -> Component.literal("Block ID: " + block.builtInRegistryHolder().key().location()), false);
source.sendSuccess(() -> Component.literal("Block class: " + block.getClass().getName()), false);

var blockEntity = world.getBlockEntity(pos);
if (blockEntity != null) {
//noinspection DataFlowIssue
source.sendSuccess(() -> Component.literal("Block entity type ID: " + blockEntity.getType().builtInRegistryHolder().key().location()), false);
source.sendSuccess(() -> Component.literal("Block entity class: " + blockEntity.getClass().getName()), false);
}

return 1;
})
.pop("pos", "getBlockInfo")

.then(Commands.literal("getEntityInfo"))
.then(Commands.argument("target", EntityArgument.entity()))
.executes(context -> {
var source = context.getSource();
var entity = EntityArgument.getEntity(context, "target");

//noinspection deprecation
source.sendSuccess(() -> Component.literal("Entity type ID: " + entity.getType().builtInRegistryHolder().key().location()), false);
source.sendSuccess(() -> Component.literal("Entity class: " + entity.getClass().getName()), false);
return 1;
})
.pop("target", "getEntityInfo")

.then(Commands.literal("lockContainer"))
.then(Commands.argument("pos", BlockPosArgument.blockPos()))
.then(Commands.argument("lock", StringArgumentType.string()))
Expand Down

0 comments on commit 0f13cfc

Please sign in to comment.