#Making a container item

25 messages · Page 1 of 1 (latest)

tidal sandal
#

I am currently making a currency system for my minecraft server, but I ran into an issue when creating a wallet like item.

is there a way of creating an item with an inventory?

unique drumBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

lament herald
tidal sandal
#

yea but It's an unfinished script with some stuff not completely working

#

but wouldn't making an item with an inventory different from a bundle be simpler?

#

Making a container item

tidal sandal
#

i forgot to mention but making it only accept currency items would be appreciated

gloomy rune
#

As for what you want, you can use the example script mentioned above, but create a shulkerbox itemstack inside the event and get the item cap with it.

#

And put the shulker nbt to wallet item at the end of the event.

tidal sandal
#

no I meant to say that making a bundle would be harder than just an inventory to pop up when right clicking the item

#

at least i think

gloomy rune
#

oh I misread it

fervent slateBOT
tidal sandal
fervent slateBOT
#

Paste version of wallet_menu.js from @tidal sandal

tidal sandal
#

if possible I would also like to know if changing the amount of columns is possible

gloomy rune
#

The menu content is not saved into anything

gloomy rune
#
const $Capabilities =  new (Java.loadClass("net.minecraftforge.common.capabilities.ForgeCapabilities"))()
const /**@type {Internal.Capability} */ $ItemHandler = $Capabilities.ITEM_HANDLER

const playersOpenedWallet = {}
ItemEvents.rightClicked("kubejs:wallet", event => {
    const $SimpleMenuProvider = Java.loadClass("net.minecraft.world.SimpleMenuProvider");
    const $ChestMenu = Java.loadClass("net.minecraft.world.inventory.ChestMenu");
    const $InvWrapper = Java.loadClass("net.minecraftforge.items.wrapper.InvWrapper")
    let /**@type {Internal.ChestMenu} */ menu
    const/**@type {Internal.MenuProvider} */ menuProvider = new $SimpleMenuProvider(
        (i, inv, p) => {
            menu = $ChestMenu.oneRow(i, inv)
            return menu
        },
        Component.translatable("container.wallet")
    )
    const {player, item:wallet} = event
    player.openMenu(menuProvider)
    const/**@type {Internal.CombinedInvWrapper} */ inventory = new $InvWrapper(menu.container)

    const shulker = Item.of("shulker_box", {})
    if(!wallet.nbt) wallet.nbt = {}
    const walletContent = wallet.nbt.getCompound("Wallet")
    if(walletContent) shulker.nbt.put("BlockEntityTag", walletContent)
    const shulkerCap = shulker.item.initCapabilities(shulker, shulker.nbt)
    const /**@type {Internal.CombinedInvWrapper} */ shulkerInv = shulkerCap.getCapability($ItemHandler).resolve().get()
    Array.from(Array(inventory.slots).keys()).forEach(i => {
        inventory.insertItem(i, shulkerInv.getStackInSlot(i), false)
    })
    playersOpenedWallet[player.uuid.hashCode()] = {wallet: wallet, inventory: inventory}
})
#
PlayerEvents.inventoryClosed(event => {
    const /**@type {{wallet: Internal.ItemStack, shulker: Internal.ItemStack, inventory: Internal.CombinedInvWrapper}} */ walletAndShulker = playersOpenedWallet[event.player.uuid.hashCode()]
    if(!walletAndShulker) return;
    const {wallet, inventory} = walletAndShulker
    const shulker = Item.of("shulker_box", {})
    const shulkerCap = shulker.item.initCapabilities(shulker, null)
    const /**@type {Internal.CombinedInvWrapper} */ shulkerInv = shulkerCap.getCapability($ItemHandler).resolve().get()
    Array.from(Array(inventory.slots).keys()).forEach(i => {
        shulkerInv.insertItem(i, inventory.getStackInSlot(i), false)
    })
    wallet.nbt.put("Wallet", shulker.nbt.getCompound("BlockEntityTag"))
})
gloomy rune
tidal sandal
gloomy rune
#

Yes. They exceeds the discord msg limit so I break it down to two parts.

tidal sandal
#

ah, alright