generated from KessokuTeaTime/Example-Mod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
292 additions
and
25 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
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
52 changes: 52 additions & 0 deletions
52
src/main/java/net/krlite/rei_collapsible_entries/client/command/HeldItemInfoCommand.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,52 @@ | ||
package net.krlite.rei_collapsible_entries.client.command; | ||
|
||
import com.mojang.brigadier.Command; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; | ||
import net.krlite.rei_collapsible_entries.REICollapsibleEntries; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.text.ClickEvent; | ||
import net.minecraft.text.HoverEvent; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Formatting; | ||
import net.minecraft.util.Identifier; | ||
|
||
public class HeldItemInfoCommand implements Command<FabricClientCommandSource> { | ||
@Override | ||
@SuppressWarnings("all") | ||
public int run(CommandContext<FabricClientCommandSource> context) { | ||
ItemStack stack = context.getSource().getPlayer().getMainHandStack(); | ||
Identifier itemId = Registries.ITEM.getId(stack.getItem()); | ||
|
||
if (stack.isOf(Items.AIR)) | ||
return 0; | ||
|
||
// Tags | ||
if (stack.getItem().getRegistryEntry().streamTags().findAny().isPresent()) | ||
context.getSource().sendFeedback(streamTags(stack)); | ||
|
||
return SINGLE_SUCCESS; | ||
} | ||
|
||
@SuppressWarnings("deprecation") | ||
private Text streamTags(ItemStack stack) { | ||
return stack.getItem().getRegistryEntry().streamTags() | ||
.map(tag -> Text.translatable("command." + REICollapsibleEntries.ID + ".held_item_info.tag_prefix") | ||
.formatted(Formatting.GRAY, Formatting.ITALIC) | ||
.append(Text.literal(tag.id().toString()) | ||
.styled(style -> style | ||
.withColor(Formatting.YELLOW) | ||
.withHoverEvent(new HoverEvent( | ||
HoverEvent.Action.SHOW_TEXT, | ||
Text.literal(tag.id().toString()).formatted(Formatting.YELLOW) | ||
)) | ||
.withClickEvent(new ClickEvent( | ||
ClickEvent.Action.COPY_TO_CLIPBOARD, | ||
tag.id().toString()) | ||
)) | ||
)) | ||
.reduce((a, b) -> a.append(" ").append(b)).orElse(Text.empty()); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ava/net/krlite/rei_collapsible_entries/client/listener/ClientCommandRegistryListener.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,17 @@ | ||
package net.krlite.rei_collapsible_entries.client.listener; | ||
|
||
import com.mojang.brigadier.CommandDispatcher; | ||
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; | ||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; | ||
import net.krlite.rei_collapsible_entries.REICollapsibleEntries; | ||
import net.krlite.rei_collapsible_entries.client.command.HeldItemInfoCommand; | ||
import net.minecraft.command.CommandRegistryAccess; | ||
|
||
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; | ||
|
||
public class ClientCommandRegistryListener implements ClientCommandRegistrationCallback { | ||
@Override | ||
public void register(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess registryAccess) { | ||
dispatcher.register(literal(REICollapsibleEntries.ID).then(literal("i").executes(new HeldItemInfoCommand()))); | ||
} | ||
} |
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
Oops, something went wrong.