Skip to content

Conversation

@ItsNature
Copy link
Collaborator

@ItsNature ItsNature commented Mar 13, 2025

Overview

Description:
The Inventory Module introduces new NBT tags that enhance item interactions within a player's inventory. This feature enables custom behaviors such as making items unclickable, copying text to the clipboard, opening URLs, and executing commands.

Changes:
Introduced new NBT tags to items.

  • Unclickable: Prevents interaction with items.
  • Copy To Clipboard: Copies predefined text to a player's clipboard.
  • Open URL: Opens a specified URL when clicked.
  • Suggest Command: Suggests a command in the chat input field.
  • Run Command: Executes a command upon clicking the item.

Added code & command examples for the Glint & Saturation module

Command Example

Unclickable Item

/summon item ~ ~1 ~ {Item:{id:"minecraft:stone",Count:1b,tag:{display:{Name:"§c§lUNCLICKABLE"},lunar:{unclickable:true}}}}

Copy To Clipboard Item

/summon item ~ ~1 ~ {Item:{id:"minecraft:paper",Count:1b,tag:{display:{Name:"§9§lCOPY TO CLIPBOARD"},lunar:{unclickable:true,copyToClipboard:"lunarclient.com"}}}}

Open URL Item

/summon item ~ ~1 ~ {Item:{id:"minecraft:torch",Count:1b,tag:{display:{Name:"§6§lOPEN URL"},lunar:{unclickable:true,openUrl:"https://lunarclient.com"}}}}

Suggest Command Item

/summon item ~ ~1 ~ {Item:{id:"minecraft:book",Count:1b,tag:{display:{Name:"§2§lSUGGEST COMMAND"},lunar:{unclickable:true,suggestCommand:"/apollo"}}}}

Run Command Item

/summon item ~ ~1 ~ {Item:{id:"minecraft:writable_book",Count:1b,tag:{display:{Name:"§d§lRUN COMMAND"},lunar:{unclickable:true,runCommand:"/apollo"}}}}

Code Example

Item Creation

public void inventoryModuleNMSExample(Player player) {
    Inventory inventory = Bukkit.createInventory(player, 5 * 9);

    ItemStack unclickableItem = ItemUtil.itemWithName(
        Material.STONE,
        ChatColor.RED.toString() + ChatColor.BOLD + "UNCLICKABLE"
    );

    inventory.setItem(11, ItemUtil.addTag(unclickableItem, "unclickable", true));

    ItemStack copyToClipboardItem = ItemUtil.itemWithName(
        Material.PAPER,
        ChatColor.BLUE.toString() + ChatColor.BOLD + "COPY TO CLIPBOARD"
    );

    copyToClipboardItem = ItemUtil.addTag(copyToClipboardItem, "unclickable", true);
    inventory.setItem(14, ItemUtil.addTag(copyToClipboardItem, "copyToClipboard", "lunarclient.com"));

    ItemStack openUrlItem = ItemUtil.itemWithName(
        Material.TORCH,
        ChatColor.GOLD.toString() + ChatColor.BOLD + "OPEN URL"
    );

    openUrlItem = ItemUtil.addTag(openUrlItem, "unclickable", true);
    inventory.setItem(17, ItemUtil.addTag(openUrlItem, "openUrl", "https://lunarclient.com"));

    ItemStack suggestCommandItem = ItemUtil.itemWithName(
        Material.BOOK,
        ChatColor.GREEN.toString() + ChatColor.BOLD + "SUGGEST COMMAND"
    );

    suggestCommandItem = ItemUtil.addTag(suggestCommandItem, "unclickable", true);
    inventory.setItem(29, ItemUtil.addTag(suggestCommandItem, "suggestCommand", "/apollo"));

    ItemStack runCommandItem = ItemUtil.itemWithName(
        Material.BOOK_AND_QUILL,
        ChatColor.LIGHT_PURPLE.toString() + ChatColor.BOLD + "RUN COMMAND"
    );

    runCommandItem = ItemUtil.addTag(runCommandItem, "unclickable", true);
    inventory.setItem(33, ItemUtil.addTag(runCommandItem, "runCommand", "/apollo"));

    player.openInventory(inventory);
}

Helper Class

public final class ItemUtil {

    public static ItemStack itemWithName(Material material, String name) {
        ItemStack item = new ItemStack(material);

        ItemMeta itemMeta = item.getItemMeta();
        itemMeta.setDisplayName(name);

        item.setItemMeta(itemMeta);
        return item;
    }

    public static ItemStack addTag(ItemStack item, String key, Object value) {
        net.minecraft.server.v1_8_R3.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
        NBTTagCompound tag = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();

        NBTTagCompound lunarTag = tag.getCompound("lunar");
        if (lunarTag == null) {
            lunarTag = new NBTTagCompound();
        }

        if (value instanceof Integer) {
            lunarTag.setInt(key, (Integer) value);
        } else if (value instanceof Double) {
            lunarTag.setDouble(key, (Double) value);
        } else if (value instanceof Float) {
            lunarTag.setFloat(key, (Float) value);
        } else if (value instanceof Boolean) {
            lunarTag.setBoolean(key, (Boolean) value);
        } else if (value instanceof String) {
            lunarTag.setString(key, (String) value);
        }

        tag.set("lunar", lunarTag);
        nmsItem.setTag(tag);

        return CraftItemStack.asBukkitCopy(nmsItem);
    }

    private ItemUtil() {
    }

}

Review Request Checklist

  • Your code follows the style guidelines of this project.
  • I have performed a self-review of my code.
  • I have tested this change myself. (If applicable)
  • I have made corresponding changes to the documentation. (If applicable)
  • The branch name follows the projects naming conventions. (e.g. feature/add-module & bugfix/fix-issue)

@ItsNature ItsNature added the type: Enhancement Feature improvement or addition label Mar 13, 2025
@ItsNature ItsNature force-pushed the feature/inventory-module branch from 0d12e05 to a37f86c Compare March 14, 2025 12:29
@ItsNature ItsNature mentioned this pull request Mar 25, 2025
@ItsNature ItsNature merged commit d013f55 into version/1.1.7 Mar 25, 2025
2 checks passed
@ItsNature ItsNature deleted the feature/inventory-module branch March 25, 2025 18:32
ItsNature added a commit that referenced this pull request Mar 29, 2025
* Deploy as 1.1.7-SNAPSHOT

* Various documentation improvements (#185)

* fixes

* remove unnecessary headers

* remove unnecessary headers from beam module

* remove unnecessary headers

* test

* use bold instead of header

* update border color

* Lightweight Documentation Fixes & Improvements (#186)

* Fix waypoint warning hyperlink redirecting to the wrong page

* Remove @type from Team json example

* better live chat message example

* Add new modules & versions (#187)

* Fix Rich Presence Module not working on bungee & velocity (#189)

* Docs - Improvements (#188)

* Update Combat#DISABLE_MISS_PENALTY comment

* add callouts

* fix lightweight player detection examples not matching

---------

Co-authored-by: TrentinTheKid <[email protected]>

* Add Combat module lightweight example docs (#191)

* Feature - NBT Apollo Modules (#195)

* Add Glint, Saturation & Inventory Apollo Modules

* Disable Inventory Module by default

* Feature - Inventory Module (#193)

* Inventory module implementation

* Add inventory to meta.json

* Add callout

* Fix commands format

* Add glint & saturation example integration

* Add unclickable to each item

* Update inventory code example

* Add inventory module overview

* docs: Add disabled by default callout

---------

Co-authored-by: TrentinTheKid <[email protected]>

* Sync LunarClient Mods & Options (#196)

* Sync LunarClient Mods & Options

* Update version tags to 1.1.7

---------

Co-authored-by: LunarClient Bot <[email protected]>

* Documentation - Tebex Module (#199)

* Prepare tebex module for release

* Add Tebex Module documentation

* Fix import order

* minor changes

* Add TebexEmbeddedCheckoutSupport#UNSUPPORTED

---------

Co-authored-by: Trentin <[email protected]>

* Bump to 1.1.7 (#197)

---------

Co-authored-by: Trentin <[email protected]>
Co-authored-by: LunarClient Bot <[email protected]>
ItsNature added a commit that referenced this pull request May 5, 2025
* Deploy as 1.1.7-SNAPSHOT

* Various documentation improvements (#185)

* fixes

* remove unnecessary headers

* remove unnecessary headers from beam module

* remove unnecessary headers

* test

* use bold instead of header

* update border color

* Lightweight Documentation Fixes & Improvements (#186)

* Fix waypoint warning hyperlink redirecting to the wrong page

* Remove @type from Team json example

* better live chat message example

* Add new modules & versions (#187)

* Fix Rich Presence Module not working on bungee & velocity (#189)

* Docs - Improvements (#188)

* Update Combat#DISABLE_MISS_PENALTY comment

* add callouts

* fix lightweight player detection examples not matching

---------

Co-authored-by: TrentinTheKid <[email protected]>

* Add Combat module lightweight example docs (#191)

* Feature - NBT Apollo Modules (#195)

* Add Glint, Saturation & Inventory Apollo Modules

* Disable Inventory Module by default

* Feature - Inventory Module (#193)

* Inventory module implementation

* Add inventory to meta.json

* Add callout

* Fix commands format

* Add glint & saturation example integration

* Add unclickable to each item

* Update inventory code example

* Add inventory module overview

* docs: Add disabled by default callout

---------

Co-authored-by: TrentinTheKid <[email protected]>

* Sync LunarClient Mods & Options (#196)

* Sync LunarClient Mods & Options

* Update version tags to 1.1.7

---------

Co-authored-by: LunarClient Bot <[email protected]>

* Documentation - Tebex Module (#199)

* Prepare tebex module for release

* Add Tebex Module documentation

* Fix import order

* minor changes

* Add TebexEmbeddedCheckoutSupport#UNSUPPORTED

---------

Co-authored-by: Trentin <[email protected]>

* Bump to 1.1.7 (#197)

* Deploy as 1.1.8-SNAPSHOT

* Decouple Gradle Example Implementations into Separate Modules (#200)

* Split bukkit example implementations (API, Json & Proto) to its own gradle modules & improve deploy script

* Rename apollo test server in deploy script

* Remove TnT Countdown Bukkit implementation (#202)

* Feature - Auto Text Hotkey Module (#203)

* Add Auto Text Hotkey Module

* Add `BLOCK_TEXT_INPUTS` boolean option

* add overview

* add word

* Add `BLOCK_CHAT_MESSAGE_TEXT_INPUTS` option

* Add `BLOCK_CHAT_MESSAGE_TEXT_INPUTS` examples

---------

Co-authored-by: TrentinTheKid <[email protected]>

* Test Framework - Add Apollo payload & Border collision tests    (#205)

* Add border collision test

* Improve payload & handshake detection

* Folia Support (#201)

* Add Folia Support

* Add folia to: bug-report.yml, deploy.yml, platform-utilities.mdx

* Register AutoTextHotkeyModule

* Register TntCountdownModule

* Add new download buttons

* Rescaled assets

* Use proper asset name

* Change background height

* Unchange beackground height

* bukkit-example plugin folia support

* chore: improved download page

* chore: update discord urls

* gradle: Fix dynamic dependencies

* Test deploy

* Undo deploy test changes

* Don't wrap title text

* Update Discord URLs

---------

Co-authored-by: Connor Lewis <[email protected]>
Co-authored-by: TrentinTheKid <[email protected]>

* Sync LunarClient Mods & Options (#206)

* Sync LunarClient Mods & Options

* Update version tags to 1.1.8

---------

Co-authored-by: LunarClient Bot <[email protected]>

* Bump to 1.1.8 (#207)

---------

Co-authored-by: Trentin <[email protected]>
Co-authored-by: LunarClient Bot <[email protected]>
Co-authored-by: Connor Lewis <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: Enhancement Feature improvement or addition

Development

Successfully merging this pull request may close these issues.

4 participants