#Making a container item
25 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
Theres this thread which could be useful https://discord.com/channels/303440391124942858/1388812702675374121
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
i forgot to mention but making it only accept currency items would be appreciated
implementing bundle is not as easy as you may think. At least not easier than shulker.
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.
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
oh I misread it
check these if you want a pop up inventory
#1257504502777380875 message
#1279263174167756815 message
[➤](#1257504502777380875 message)
Inspired by https://discord.com/channels/303440391124942858/1257092061098934324
Icons are from custom font
server_scripts: code
client_scripts: code
(you may need to remove the recipe book button)
I've got this now, but it just deletes the items
Paste version of wallet_menu.js from @tidal sandal
if possible I would also like to know if changing the amount of columns is possible
The menu content is not saved into anything
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"))
})
There is only so many menu types you could use in vanilla and kubejs. If you want something else, you might need other mods.
so i replace my code with this and the other one?
Yes. They exceeds the discord msg limit so I break it down to two parts.
ah, alright