Topic category: Help with MCreator software
Okay, sorry if this has been discussed elsewhere, if it was I missed it. I am currently working on a mod that incorporates many RPG elements into minecraft. I've gotten a lot to work but I am having one issue. I would like to add Encumbrance to the game. The best way I can figure to do this would be to set a Local Variable for the blocks/items name it Weight, and give it a value. Then on my Master Player Code that runs on Update Tick, the code would calculate the weight of each item in the inventory (which will be easier after the next update according to the change log), and then slow the player's speed based on how heavy their items are.
My issue is I have been trying to find a way for my master procedure to read a local variable from the block/item that is in my inventory. Essentially "code A" reads local variable from "code B" and makes use of the data. I've tried many ways and can't figure how to do this. Any help would be great, thanks!
Local variables are only accessible inside their own procedures; you simply can't access them from another procedure. Instead, you probably want to use NBT data. NBT data is saved by the item and can be accessed from any procedure. To give and item an NBT tag with a number that is its weight you'll want to use the Set NBT number tag "tag name" of (Provided itemstack) to _ block found in the Item procedures tab. Just make "tag name" "weight", (Provided itemstack) to the itemstack you want to change the weight of, and _ to the weight of the item. To access the weight of the item use the Get NBT number tag "tag name" of (Provided itemstack) block.
Thank you so much! Will try this when i get home!
Read https://mcreator.net/wiki/variables