-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-add Client-side ItemInfo command.
- Loading branch information
1 parent
4a101d7
commit d2b835f
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/codechicken/lib/internal/command/client/ItemInfoCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |