#Adding Lore to Items in Minecraft Bedrock Edition Addons Using Scripts

1 messages · Page 1 of 1 (latest)

craggy orchid
#

Explanation:

Imports:

import { system, world } from "@minecraft/server";

This line imports essential modules from the @minecraft/server package. system is used to run scheduled tasks and manage timing, while world allows us to interact with and access game elements like players and their inventories.

const your_custom_item = "minecraft:diamond";

Here, your_custom_item is a variable holding the ID of the item we want to modify. Replace "minecraft:diamond" with the ID of your specific item (e.g., "modmaker:dull_axe" for a custom item).

#

Function:

function checkPlayerInventory() {
  for (const player of world.getPlayers()) {
    const inventory = player.getComponent('minecraft:inventory').container;
    
    for (let i = 0; i < inventory.size; i++) {
      const item = inventory.getItem(i);
      
      if (item && item.typeId === your_custom_item) {
        item.setLore([
          '§r§l§0hi this is 1 line', 
          'wow a second line', 
          'you can only have 20 lines and 50 characters'
        ]);
        
        inventory.setItem(i, item);
      }
    }
  }
  
  system.runTimeout(checkPlayerInventory, 10);
}

Function Explanation:

This function periodically updates the lore of specific items in all players' inventories:

Iterate Through Players:

The function loops through every player in the game world to access their inventory.
Access Inventory:

For each player, it retrieves their inventory, allowing us to examine and modify the items.
Check Inventory Slots:

It then checks each slot in the inventory for items.
Identify Target Items:

If an item matches the specified type, its lore is updated. Lore is the descriptive text associated with the item.
Update Item:

The item with updated lore is placed back into its original slot, making the changes visible to the player.
Re-Schedule Function:

The function schedules itself to run again after a short delay to keep inventories updated.
This ensures that all specified items across players' inventories consistently have the updated lore and accommodates any new or changed items over time.

#

Start Script:

checkPlayerInventory();```
This line initiates the checkPlayerInventory function, starting the process of checking and updating player inventories.

Conclusion:

And that’s it! 🎉 This script will automatically add lore to specified items in all players' inventories and keep it updated. Modify the lore text and item ID as needed to fit your specific use case. If you have any questions or run into issues, don't hesitate to ask. Happy coding.
dark tide
#

Thats not adding lore setting adding lore.

let lore = item.getLore()
lore.push('itemtext') 
item.setLore(lore)
#
  system.runTimeout(checkPlayerInventory, 10);
``` This will just run the code a second time after 10 ticks, you need to use 

```js
system.runInterval``` to have it looped
iron bolt
#

@dark tide smh.

trim inlet
#

Aint no way

trim heart
#

😭

craggy orchid
dark tide
craggy orchid
#

i didnt know

#

im still new to scripting

dark tide
#

adding and setting lore has also already been posted here

craggy orchid
#

it has

#

oh yeah

#

well if its already been done so much for this

iron bolt
craggy orchid
#

either way they basiccly do tthe same thing without the parameters

iron bolt
# iron bolt

@craggy orchid this is the result of me putting the same text in the same tool he used.

craggy orchid
#

it sucks too because i just wanted to make a tutorial

solid shoreBOT
#
Info

This bot was created by SmokeyStack for the purpose of making a FAQ bot for the Bedrock Add-Ons Discord Server.

Managing Entries

To manage entries, please make a pull request on GitHub.

Source Code
iron bolt
craggy orchid
#

ok

simple musk
#

why not test scripts yourself and upload scripts

#

to see if it work or not

strong dagger
#

is there a way to get the item in creative inventory? i mean, if item is not in player's invetory yet, but just in creative on