2
Scoreboard help
Hi,
I was wondering how I could make it so if I grab a diamond out of my creative inventory, it increased the value on the scoreboard from 0 to 1 because the diamond is in my inventory/hotbar.
However, I can't find any tutorials on how to do this, so if I could at least get some help from any of you that would be much appreciated, thanks!
Also if you're confused what I mean, please let me know!
Thanks!
Techneshun
I was wondering how I could make it so if I grab a diamond out of my creative inventory, it increased the value on the scoreboard from 0 to 1 because the diamond is in my inventory/hotbar.
However, I can't find any tutorials on how to do this, so if I could at least get some help from any of you that would be much appreciated, thanks!
Also if you're confused what I mean, please let me know!
Thanks!
Techneshun
Create an account or sign in to comment.
9
2
The main problem has already been identified: interactions with the creative inventory fall outside normal game mechanics. You can verify this for yourself: pause your game, go to the statistics and click 'Items'; you will only see 6 item "interactions": mined, broken, crafted, used, picked up and dropped. As you can imagine: what you're looking for falls outside these categories.
But it can be done, and in my opinion it isn't as difficult as being claimed, though... maybe that's just me; it is a little complex when thinking about it I suppose. The keyword: advancements! In specific: custom advancements, a good source of info on them can be found here (official wiki page on advancements) and maybe you may also enjoy my PMC guide on advancements.
See, the key to your problem is to detect "incoming" diamonds in a users inventory. And guess what? The minecraft:inventory_changed trigger is exactly what you need: it will detect a change in a players inventory. Set the trigger to look for diamonds and you're well on your way.
That's the other cool thing about advancements: they allow you to run a function as a form of reward. And just in case you (or a random reader) didn't know: a function is nothing more but a collection of Minecraft command(s), but stored in a separate file. That's the key to the scoreboard: as soon as a "diamond inventory change" has been detected you then "reward" the player by triggering a function which increases a predefined scoreboard entry, optionally you can even add a failsave check to make sure that there are actually diamonds added to the players inventory.
/scoreboard objectives add diamonds trigger
If you use a 'trigger objective' then the player can use the /trigger command to increase this themselves. Well, the player or the server which uses the players credentials, for example when firing up a function.
It's been a while since I messed with this, but... I'll have a look see later this evening to see if I can cook something up.
But it can be done, and in my opinion it isn't as difficult as being claimed, though... maybe that's just me; it is a little complex when thinking about it I suppose. The keyword: advancements! In specific: custom advancements, a good source of info on them can be found here (official wiki page on advancements) and maybe you may also enjoy my PMC guide on advancements.
See, the key to your problem is to detect "incoming" diamonds in a users inventory. And guess what? The minecraft:inventory_changed trigger is exactly what you need: it will detect a change in a players inventory. Set the trigger to look for diamonds and you're well on your way.
That's the other cool thing about advancements: they allow you to run a function as a form of reward. And just in case you (or a random reader) didn't know: a function is nothing more but a collection of Minecraft command(s), but stored in a separate file. That's the key to the scoreboard: as soon as a "diamond inventory change" has been detected you then "reward" the player by triggering a function which increases a predefined scoreboard entry, optionally you can even add a failsave check to make sure that there are actually diamonds added to the players inventory.
/scoreboard objectives add diamonds trigger
If you use a 'trigger objective' then the player can use the /trigger command to increase this themselves. Well, the player or the server which uses the players credentials, for example when firing up a function.
It's been a while since I messed with this, but... I'll have a look see later this evening to see if I can cook something up.
2
So, I made a promise which I intend to keep ;) Sorry for the delay, real life sometimes gets in the way so to speak.
I got it working 😎
Now... step one is to create a datapack in your world folder. It should probably have a folder "datapacks" already, create some new files & folders in there:
[code]
datapacks/
+- diamond_count/
+- pack.mcmeta
+- data/
+- dia/
+- advancements/
+- counter.json
+- functions/
+- add.mcfunction
[/code]
SO... create a folder diamond_count (notice the / behind it? That means it's a folder!). In that folder you create the file "pack.mcmeta" and another folder "data". In the data folder you create the 'functions' and 'advancements' folder in which you create the files shown above.
And here are the files:
pack.mcmeta:
counter.json:
(sorry, can't be bothered to indent the whole thing, just grab an editor to do that for you or... use as-is)
add.json:
(you don't need the 'say' command, but it'll help you check that everything works as intended).
How to make this work
Dump the whole thing in the world folder (as per above instructions) and also make sure to create a scoreboard objective called "dia_count". How? => /scoreboard objectives add dia_count dummy.
If you set the whole thing up while the world was active you'll need to use the /reload command. Check that the datapack is active by using /datapack list.
After that things should work out just fine. The moment you give someone a diamond (or they grab one from the creative inventory) then dia_count will get added. Use /scoreboard players list @p to check for the objective on yourself, use a player name to check theirs.
I got it working 😎
Now... step one is to create a datapack in your world folder. It should probably have a folder "datapacks" already, create some new files & folders in there:
[code]
datapacks/
+- diamond_count/
+- pack.mcmeta
+- data/
+- dia/
+- advancements/
+- counter.json
+- functions/
+- add.mcfunction
[/code]
SO... create a folder diamond_count (notice the / behind it? That means it's a folder!). In that folder you create the file "pack.mcmeta" and another folder "data". In the data folder you create the 'functions' and 'advancements' folder in which you create the files shown above.
And here are the files:
pack.mcmeta:
{
"pack":{
"pack_format": 6,
"description": "Diamond administrative pack"
}
}
counter.json:
{
"parent": "minecraft:recipes/root",
"rewards": {
"function": "dia:add"
},
"criteria": {
"got_a_diamond": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"item": "minecraft:diamond"
}
]
}
}
}
}
(sorry, can't be bothered to indent the whole thing, just grab an editor to do that for you or... use as-is)
add.json:
say got a diamond!
scoreboard players add @s dia_count 1
advancement revoke @s only dia:counter
(you don't need the 'say' command, but it'll help you check that everything works as intended).
How to make this work
Dump the whole thing in the world folder (as per above instructions) and also make sure to create a scoreboard objective called "dia_count". How? => /scoreboard objectives add dia_count dummy.
If you set the whole thing up while the world was active you'll need to use the /reload command. Check that the datapack is active by using /datapack list.
After that things should work out just fine. The moment you give someone a diamond (or they grab one from the creative inventory) then dia_count will get added. Use /scoreboard players list @p to check for the objective on yourself, use a player name to check theirs.
2
Holy moly, thank you soooo much!!
This helps me so much now.
Thank you, very much. very appreciated.
:)
This helps me so much now.
Thank you, very much. very appreciated.
:)
2
Happy to help! Be sure to drop me a message if something isn't working for you, I just noticed that the spacing up there is kinda bad, but hopefully it works out with the folder structure. If you need some help with the datapack then maybe this guide can help.
1
Ok, its me again and I completely forgot to show this to you but something isn't right or working.
Like I grabbed a diamond but still theres no value.
All it says is "Can't get value of dia_count for Techneshun; none is set.
Also, when you told me where to put files and their names, I'm a bit confused because this says: [code]
datapacks/
+- diamond_count/
+- pack.mcmeta
+- data/
+- dia/
+- advancements/
+- counter.json
+- functions/
+- add.mcfunction
[/code]
But this says:
add.json:
Could you help with this?
Like I grabbed a diamond but still theres no value.
All it says is "Can't get value of dia_count for Techneshun; none is set.
Also, when you told me where to put files and their names, I'm a bit confused because this says: [code]
datapacks/
+- diamond_count/
+- pack.mcmeta
+- data/
+- dia/
+- advancements/
+- counter.json
+- functions/
+- add.mcfunction
[/code]
But this says:
add.json:
say got a diamond!
scoreboard players add @s dia_count 1
advancement revoke @s only dia:counter
Could you help with this?
1
I can try... since I already removed the datapack from my game I can now simulate what needs to be done. Ok, first things first, a better folder structure because the above one sucks. Yah, when you're typing you can uses spaces and I didn't realize all the indention would get removed. So lets fix that first:
+ datapacks/
++ diamondcounter
++++ pack.mcmeta
++++ data/
++++++ dia/
++++++++ advancements/
++++++++++ counter.json
++++++++ functions/
++++++++++ add.mcfunction
So: create the directory structure in the datapacks folder for whatever world save you want to use (you'll find those in the saves subfolder within your Minecraft program folder, on Windows this is in: "%appdata%\.minecraft". (open your filemanager ('explorer'), and paste that bold stuff in the address bar, you'll see)). I strongly suggest you set this up while the game isn't running (or at least without having your world loaded / active).
In this example I've used "diamondcounter" instead of "diamond_count", that's because the name of this folder is completely unimportant. It's the stuff underneath which is...
Lessee, hopefully this also helps:
"data\dia" basically means that the data directory is empty apart from the dia subfolder, that's why they added it together.
diamondcounter only contains the 'pack.mcmeta' file and the 'data' subfolder. The 'data' subfolder only contains 2 other subfolders namely 'advancements' and 'functions'. Then 'advancements' contains the file 'counter.json' and 'functions' contains 'add.mcfunction'.
NOW.. once you set this up then load your world and run this command: "/datapack list":
Don't mind the other datapacks, it's about file/diamondcount here. (I just discovered a new OptiFine feature: the inability to save screenshots, "fun").
Then you give yourself a diamond and... I see what you mean. My bad! 😒
Yes, before you can use the setup you need to add the scoreboard objective yourself: "/scoreboard objectives add dia_count dummy". I completely forgot about that... 🤦♂️ I was looking into "minecraft:load", which is a function that gets executed as soon as you load a datapack but couldn't easily add something to check for the existence of the scoreboard objective, and I definitely didn't want to "just" create the objective even if it already existed because that would always generate an error message.
See? Don't mind the other scoreboards, this world is filled with all sorts of stuff.
Hopefully this cleared things up a bit... so, you need to create the scoreboard objective yourself ("/scoreboard objectives add dia_count dummy") and then you should be good to go. This command is only needed once, the objective gets saved with your world (as you can see in the above screenshot, I merely loaded it to verify what was going on).
+ datapacks/
++ diamondcounter
++++ pack.mcmeta
++++ data/
++++++ dia/
++++++++ advancements/
++++++++++ counter.json
++++++++ functions/
++++++++++ add.mcfunction
So: create the directory structure in the datapacks folder for whatever world save you want to use (you'll find those in the saves subfolder within your Minecraft program folder, on Windows this is in: "%appdata%\.minecraft". (open your filemanager ('explorer'), and paste that bold stuff in the address bar, you'll see)). I strongly suggest you set this up while the game isn't running (or at least without having your world loaded / active).
In this example I've used "diamondcounter" instead of "diamond_count", that's because the name of this folder is completely unimportant. It's the stuff underneath which is...
Lessee, hopefully this also helps:
"data\dia" basically means that the data directory is empty apart from the dia subfolder, that's why they added it together.
diamondcounter only contains the 'pack.mcmeta' file and the 'data' subfolder. The 'data' subfolder only contains 2 other subfolders namely 'advancements' and 'functions'. Then 'advancements' contains the file 'counter.json' and 'functions' contains 'add.mcfunction'.
NOW.. once you set this up then load your world and run this command: "/datapack list":
Don't mind the other datapacks, it's about file/diamondcount here. (I just discovered a new OptiFine feature: the inability to save screenshots, "fun").
Then you give yourself a diamond and... I see what you mean. My bad! 😒
Yes, before you can use the setup you need to add the scoreboard objective yourself: "/scoreboard objectives add dia_count dummy". I completely forgot about that... 🤦♂️ I was looking into "minecraft:load", which is a function that gets executed as soon as you load a datapack but couldn't easily add something to check for the existence of the scoreboard objective, and I definitely didn't want to "just" create the objective even if it already existed because that would always generate an error message.
See? Don't mind the other scoreboards, this world is filled with all sorts of stuff.
Hopefully this cleared things up a bit... so, you need to create the scoreboard objective yourself ("/scoreboard objectives add dia_count dummy") and then you should be good to go. This command is only needed once, the objective gets saved with your world (as you can see in the above screenshot, I merely loaded it to verify what was going on).
2
The act of taking the item out of the inventory is undetectable, so you instead need a way to distinguish diamonds taken from creative mode from other diamonds. This is a difficult problem that requires advanced datapacking. There are 4 sources of these: Mining diamond ore without silk, looting chests, smelting diamond ore, and decrafting diamond blocks. Mined and looted diamonds can both be edited in loot tables, while crafted and smelted ones can't have their NBT changed. Therefore, if we tried to use NBT to track "legal" diamonds we would have an issue. Diamonds that were pulled out of a furnace or crafting table could not stack with ones you mined until after you put them down in a different slot. However, there is no other way to mark them as different and no easy way to detect how many diamonds a player picks up from a chest or puts into one so it will have to work for now.
Furnaces are a little bit more complicated: Whenever a player's "diamonds crafted" scoreboard value goes up they have either picked up a smelted diamond or decrafted a diamond block. In the case of a furnace, the player must either drop the item or place it in their inventory. The "diamonds crafted" scoreboard will act as a variable for how many legal diamonds the player has remaining, and we will count it back down as the diamonds get the consumed or get the NBT tag added to them. If the player throws diamonds out then rep;lace them with tagged diamonds and decrease the "diamonds crafted" score by the number of dropped diamonds. If the "diamonds crafted" score goes negative, that many diamonds were obtained through /give or creative inventory. The "diamonds crafted" value should also be taken down whenever untagged diamonds are detected in the player's inventory (and they should be tagged).
There is one last possibility to think of: What if a player grabs diamonds out of a crafting table and then crafts with them? Then the total number of diamonds could be greater than 1 when the player leaves the crafting table and they can grab diamonds from the creative inventory undetected. To do everything flawlessly, you need to keep track of how many tagged diamonds are removed from the player's inventory (whenever their "diamonds crafted" is positive) and how many are put back, as well as what diamond items are crafted and how much they cost. After the player leaves the crafting table or furnace, diamonds crafted - crafted diamonds thrown - crafted diamonds put in inventory - (value of diamond items crafted - old diamonds taken from inventory and not returned or thrown) should equal 0.
Furnaces are a little bit more complicated: Whenever a player's "diamonds crafted" scoreboard value goes up they have either picked up a smelted diamond or decrafted a diamond block. In the case of a furnace, the player must either drop the item or place it in their inventory. The "diamonds crafted" scoreboard will act as a variable for how many legal diamonds the player has remaining, and we will count it back down as the diamonds get the consumed or get the NBT tag added to them. If the player throws diamonds out then rep;lace them with tagged diamonds and decrease the "diamonds crafted" score by the number of dropped diamonds. If the "diamonds crafted" score goes negative, that many diamonds were obtained through /give or creative inventory. The "diamonds crafted" value should also be taken down whenever untagged diamonds are detected in the player's inventory (and they should be tagged).
There is one last possibility to think of: What if a player grabs diamonds out of a crafting table and then crafts with them? Then the total number of diamonds could be greater than 1 when the player leaves the crafting table and they can grab diamonds from the creative inventory undetected. To do everything flawlessly, you need to keep track of how many tagged diamonds are removed from the player's inventory (whenever their "diamonds crafted" is positive) and how many are put back, as well as what diamond items are crafted and how much they cost. After the player leaves the crafting table or furnace, diamonds crafted - crafted diamonds thrown - crafted diamonds put in inventory - (value of diamond items crafted - old diamonds taken from inventory and not returned or thrown) should equal 0.
1
Ah, that makes more sense. I just had this idea from a video I found but when I tried nothing seemed to work. So that makes more sense.
https://youtu.be/9F9wHSKxFW8?t=74 1:14 thru 1:19 shows it when Wilbur grabs a nether star into his hot bar and the scoreboard for it increases. But since I think they used plugins I know its not really possible in Minecraft.
Thank you!
Techneshun
https://youtu.be/9F9wHSKxFW8?t=74 1:14 thru 1:19 shows it when Wilbur grabs a nether star into his hot bar and the scoreboard for it increases. But since I think they used plugins I know its not really possible in Minecraft.
Thank you!
Techneshun
1
Detecting a nether star is a bit easier since they only drop from the wither. You don't need to deal with the crafting or chest loot at all. Just change the wither loot table to add an NBT tag to all legit nether stars. Therefore, all untagged stars are pulled from creative. There isn't the same issue as diamonds where they can be obtained through crafting.