Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"command.ac_guideme.block_tags": ":sbɐ⟘ ʞɔoןᗺ",
"command.ac_guideme.count": "%s :ʇunoƆ",
"command.ac_guideme.item": "%s :ɯǝʇI",
"command.ac_guideme.item_tags": ":sbɐ⟘ ɯǝʇI",
"command.ac_guideme.mod": "%s :poW",
"gui.ac_guideme.mod_info.loaded": "¡pǝpɐoꞀ sı %s",
"gui.ac_guideme.mod_info.unloaded": "¡pǝpɐoꞀ ʇ,usı %s"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"command.ac_guideme.block_tags": "Block Tags:",
"command.ac_guideme.count": "Count: %s",
"command.ac_guideme.item": "Item: %s",
"command.ac_guideme.item_tags": "Item Tags:",
"command.ac_guideme.mod": "Mod: %s",
"gui.ac_guideme.mod_info.loaded": "%s is Loaded!",
"gui.ac_guideme.mod_info.unloaded": "%s isn't Loaded!"
}
83 changes: 70 additions & 13 deletions src/main/java/dev/anvilcraft/guideme/command/GetHandCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,103 @@
import com.mojang.brigadier.context.CommandContext;
import net.minecraft.ChatFormatting;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.Holder;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

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

public class GetHandCommand {

public static void registerCommand(LiteralArgumentBuilder<CommandSourceStack> parent) {
LiteralArgumentBuilder<CommandSourceStack> commandRoot = literal("hand").executes(GetHandCommand::showInfo);
parent.then(commandRoot);
}

private static int showInfo(CommandContext<CommandSourceStack> ctx) {
ServerPlayer player = ctx.getSource().getPlayer();
AtomicInteger returnValue = new AtomicInteger(0);
if (player == null) return returnValue.get();
returnValue.set(1);
List<Component> components = new ArrayList<>();

ItemStack itemStack = player.getMainHandItem();
Item item = itemStack.getItem();

Component message = Component.translatable(
"command.ac_guideme.item",
itemStack.getDisplayName()
).withStyle(ChatFormatting.GREEN);
components.add(Component.nullToEmpty("=========="));

// Item ID
Component itemMessage = Component.translatable("command.ac_guideme.item", item.toString())
.withStyle(ChatFormatting.GREEN, ChatFormatting.BOLD);
components.add(copy(itemMessage, item.toString()));

ctx.getSource().sendSystemMessage(copy(message, item.toString()));
return returnValue.get();
}
// Count
int count = itemStack.getCount();
Component countMessage = Component.translatable("command.ac_guideme.count", count).withStyle(ChatFormatting.YELLOW);
components.add(copy(countMessage, String.valueOf(count)));

public static void registerCommand(LiteralArgumentBuilder<CommandSourceStack> parent) {
LiteralArgumentBuilder<CommandSourceStack> commandRoot = literal("hand")
.executes(GetHandCommand::showInfo);
parent.then(commandRoot);
// Mod
String modInfo = getMod(item.toString());
Component ModMessage = Component.translatable("command.ac_guideme.mod", modInfo).withStyle(ChatFormatting.RED);
components.add(copy(ModMessage, modInfo));

// Item Tag
Holder<Item> itemHolder = itemStack.getItemHolder();
List<TagKey<Item>> itemTagKeys = itemHolder.tags().toList();
if (!itemHolder.tags().toList().isEmpty()) {
Component head = Component.translatable("command.ac_guideme.item_tags").withStyle(ChatFormatting.DARK_AQUA);
components.add(head);
for (TagKey<Item> tagKey : itemTagKeys) {
String tagId = "#%s".formatted(tagKey.location());
components.add(copy(Component.literal(tagId).withStyle(ChatFormatting.AQUA), tagId));
}
}

// Block Tag
if (item instanceof BlockItem blockItem) {
Block block = blockItem.getBlock();
Holder<Block> blockHolder = block.builtInRegistryHolder();
List<TagKey<Block>> blockTagKeys = blockHolder.tags().toList();
if (!blockTagKeys.isEmpty()) {
Component head = Component.translatable("command.ac_guideme.block_tags").withStyle(ChatFormatting.DARK_AQUA);
components.add(head);
for (TagKey<Block> tagKey : blockTagKeys) {
String tagId = "#%s".formatted(tagKey.location());
components.add(copy(Component.literal(tagId).withStyle(ChatFormatting.AQUA), tagId));
}
}
}


components.add(Component.nullToEmpty("=========="));

for (Component component : components) {
player.sendSystemMessage(component);
}

return returnValue.get();
}

private static Component copy(Component c, String copy) {
private static Component copy(Component c, String info) {
return Component.literal("- ")
.withStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, copy)))
.withStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, info)))
.append(c);
}

private static String getMod(String item) {
if (!item.contains(":")) return item;
String[] parts = item.split(":", 2);
return parts[0];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
package dev.anvilcraft.guideme.command;

import net.minecraft.MethodsReturnNonnullByDefault;

import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
public class CommandLang {
public static void init(RegistrateLangProvider provider) {
provider.add("command.ac_guideme.item", "Item: %s");
provider.add("command.ac_guideme.count", "Count: %s");
provider.add("command.ac_guideme.mod", "Mod: %s");
provider.add("command.ac_guideme.item_tags", "Item Tags:");
provider.add("command.ac_guideme.block_tags", "Block Tags:");
}
}
5 changes: 5 additions & 0 deletions src/main/resources/assets/anvilcraft_guideme/lang/zh_cn.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"command.ac_guideme.block_tags": "方块Tag:",
"command.ac_guideme.count": "数量: %s",
"command.ac_guideme.item": "物品: %s",
"command.ac_guideme.item_tags": "物品Tag:",
"command.ac_guideme.mod": "模组: %s",
"gui.ac_guideme.mod_info.loaded": "%s 已加载!",
"gui.ac_guideme.mod_info.unloaded": "%s 未加载!"
}