Compatibility
Minecraft: Java Edition
Platforms
75% of ad revenue goes to creators
Support creators and Modrinth ad-free with Modrinth+Links
Creators
Details
Names and Lore
This is a simple datapack that allows player to add custom names and custom lore to their items, and to edit the properties of those names and lore. All of the functionality is built into /trigger commands so this will not require any permission setup by default and can be used by any player on a server.
How it Works
All of the player input is done through a book and quill, with different data stored on different pages. Page 1 is used for custom names, Page 2 is used for custom lore, and page 3 is used to store a hexidecimal color value. After entering the data on these pages DO NOT SIGN THE BOOK, instead hit "done". When a player holds a book and quill in their offhand and an item in their mainhand they are able to use the commands to add new custom names and lore. Do not hit the enter key when putting text onto pages or a "new line" character will be included in your names/lore.
Commands
There are 9 total commands that are accesible to all players through the /trigger command, and all of them include the namespace of the datapack in the command to prevent data conflicts with other datapacks. For example, the "help" command is accessed with:
/trigger names_and_lore_help
The 9 commands are as follows:
- new_name - sets the name of the held item to page 1 of the offhand book
- new_lore - sets the lore of the held item to page 2 of the offhand book
- hex_color_name - sets the name color of the held item to page 3 of the offhand book
- hex_color_lore set # - sets the specified lore line color of the held item to page 3 of the offhand book
- clear_lore - clears all the lore data on the held item
- clear_lore_line set # - clears the specified lore lines' data, and shifts the following lore lines down by 1
- open_name_menu - opens a menu in text chat used to customize the color, text formatting, and font of the held items name
- open_lore_menu set # - opens a menu in text chat used to customize the color, text formatting, and font of the held items specified line of lore
- help - Gives an explanation similar to this one in text chat on how to use the datapack
For the commands that alter the lore data of an item, they are all able to take a numeric input to specify which line you want to edit. If a player does not use the "set #" following the command it defaults to editing the first line of lore, and if a player enters a number outside the range of lines, such as -8 or 74, it will be clamped to the lowest or highest value respectively.
For the hex_color commands the hex values "#" symbol is omitted when being entered in a book. This means that if a player wants the color white as a hex value what they should enter in the book is
FFFFFF
as opposed to #FFFFFF.
Settings
There are two values that are meant to act as settings for server owners/admins to be able to tweak limits I set in place. One of them is a player scoreboard value under a username of ?lore. This objective is called names_and_lore_lore_limit and is set to 6 by default and on load. I chose 6 as the default limit as I personally found having more than 6 lines of lore on an item began to cover too much of the inventory screens when moused over, but allowing for more lines will not necessarily break anything in-game. While this scoreboard value can be changed and the change will work immediately a /reload will reset it back to 6. This value can be permanently changed in the load.mcfunction file of the datapack.
The second option is for the default maximum number of characters that can be on a book page and still applied to an item. This is not stored in a scoreboard value but instead is hardcoded in 2 of the different mcfunction files: format_name_new and format_lore_new. The default value is 100 characters and going over this limit will have names and lore on items so long that they cover the entire screen AND are still able to scroll off the screen. With the 100 character limit it is possible to have a name/lore entry reach about ~90% across the screen if the only characters used are maximum width characters such as a capital W, but generally names can become long but not obstructively so.
The main function checking for player /triggers and resetting them takes place in the ticker.mcfuntion file, which ends with a 20 tick timer delay. This means if a player is trying to input commands faster than once every second they will get a "You cannot trigger this objective yet" error until the one second timer has elapsed. This is to reduce server load by checking data more frequently that is needed, but if desired this can be lowered and still function fine. An important note related to this delay is it is measured in ticks, not seconds. This does mean on a server/world that is experiencing a very high MSPT the time it takes for those 20 ticks to pass may become longer than 1 second.
Uninstall
There is a function named uninstall.mcfunction that will remove the scoreboard objectives used in the datapack, and the data storage belongs to the datapack. After running this command you have cleared all the data this datapack put into the game and can safely remove it. Not using this uninstall function will just leave a few scoreboard values that wont break anything because they use my namespace as a leading name, and a fake player name (?lore) for 2 scores.
Addtional Notes
Because of how player input data is stored and handled in this datapack, I would not be surprised if this had data overlap issues with its 20 tick timer and many players in a server using it simultaneously. The use case I designed this for was in a small realm with a few friends where this wouldn't be an issue, and this does work perfectly for that case. If you want to use this on a server that has hundreds of players you can try to lower the tick delay or wait for people to get their main set of gear renamed and not interacting with the datapack frequently and the problem will go away over time.
With all of that out of the way, these lat 2 paragraphs will be for excuse making. This is my first datapack and I expect that there will be early issues discovered by other users, once this is in the wild, that I missed. I made sure to account for edge-cases in the text gathering and formatting systems, and I know that for normal use this datapack functions correctly. Allowing players to use custom input with a book should raise concerns about Arbitrary Code Execution (ACE) in the form of using commands normally requiring OP to use, but I am 99% certain that this is not possible due to how the input is proccessed and applied.
Trying to search online about custom item naming as of 1.21.5's release is met with mostly very old results that are no longer possible, are just demonstrations of using /give with custom data, or are just outdated because of text/json formatting changes in 1.21.5 so establishing the method to do all this took a good amount of research and time for someone who is new to datapacks. I hope this is helpful to people wanting exactly what this datapack offers and I hope this is found by people searching for how to make their own setup as well.