Skip to content

Commit

Permalink
Re-add Client-side ItemInfo command.
Browse files Browse the repository at this point in the history
  • Loading branch information
covers1624 committed Sep 8, 2023
1 parent 4a101d7 commit d2b835f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import codechicken.lib.internal.command.admin.KillAllCommand;
import codechicken.lib.internal.command.admin.MiscCommands;
import codechicken.lib.internal.command.client.HighlightCommand;
import codechicken.lib.internal.command.client.ItemInfoCommand;
import codechicken.lib.internal.command.client.RenderItemToFileCommand;
import codechicken.lib.internal.command.dev.DevCommands;
import com.mojang.brigadier.CommandDispatcher;
Expand Down Expand Up @@ -38,6 +39,7 @@ private static void registerServerCommands(RegisterCommandsEvent event) {
private static void registerClientCommands(RegisterClientCommandsEvent event) {
CommandDispatcher<CommandSourceStack> dispatcher = event.getDispatcher();
HighlightCommand.register(dispatcher);
ItemInfoCommand.register(dispatcher);
RenderItemToFileCommand.register(dispatcher);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package codechicken.lib.internal.command.client;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.registries.ForgeRegistries;

import static net.minecraft.commands.Commands.literal;

/**
* Created by covers1624 on 2/9/22.
*/
public class ItemInfoCommand {

public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(literal("ccl")
.then(literal("item_info")
.executes(ItemInfoCommand::execute)
)
);
}

private static int execute(CommandContext<CommandSourceStack> command) {
CommandSourceStack ctx = command.getSource();
Player player = command.getSource().getPlayer();
ItemStack stack = player.getMainHandItem();
if (stack.isEmpty()) {
stack = player.getOffhandItem();
}
if (stack.isEmpty()) return 0;

String tag = stack.hasTag() ? stack.getTag().toString() : "Item has no NBT.";
ctx.sendSuccess(Component.literal("Registry Name: " + ForgeRegistries.ITEMS.getKey(stack.getItem())), false);
ctx.sendSuccess(Component.literal("NBT : " + tag), false);
return 0;
}
}

0 comments on commit d2b835f

Please sign in to comment.