I made a large datapack to play with my friends. We had 10 people on a high quality server, and it was very laggy.
I could use help understanding how to optimize, but the only thing that would need optimization is tick.mcfunction, as it runs the other functions, so it would be ok to not optimize the others. I can send the whole tick.mcfunction, but for now, I will just send the general tick stuff + 1 of the custom items. The custom items are all the same, but with different abilities, so i can learn from what you tell me and apply that to the others.
#I need help optimizing my datapack badly.
1 messages · Page 1 of 1 (latest)
team add saddle
#say TICK
scoreboard players add @a second 1
execute as @a at @s if score @s second matches 20 run scoreboard players remove @s cooldowntimer 1
execute as @a at @s if score @s second matches 20 run scoreboard players set @s second 0
scoreboard players enable @a cooldown
execute as @a at @s if score @s cooldown matches 1.. run tellraw @p ["",{"text":"You have ","color":"gold"},{"score":{"name":"@s","objective":"cooldowntimer"},"color":"dark_gray"},{"text":" seconds until your orb ability is ready again!","color":"gold"}]
execute as @a at @s if score @s cooldown matches 1.. run playsound minecraft:entity.experience_orb.pickup
execute as @a at @s if score @s cooldown matches 1.. run scoreboard players set @s cooldown 0
execute as @a at @s if entity @s[nbt={Inventory:[{id:"minecraft:carrot_on_a_stick",components:{"minecraft:custom_model_data":1010}}]}] run function orb:wardenorb
execute as @a at @s if entity @s[nbt={Inventory:[{id:"minecraft:written_book",components:{"minecraft:custom_model_data":1020}}]}] run scoreboard players enable @s rerollwarden
execute as @a at @s unless entity @s[nbt={Inventory:[{id:"minecraft:written_book",components:{"minecraft:custom_model_data":1020}}]}] run scoreboard players reset @s rerollwarden
execute as @a at @s if score @s rerollwarden matches 1.. run function orb:rerollwarden
execute as @a at @s if score @s rerollwarden matches 1.. run function orb:rerollwarden
#warden
<@&1201956957406109788>
Someone will come and help soon!
💬 While you wait, take this time to provide more context and details.
🙇 If nobody has answered you by <t:1736645856:t>, feel free to use the Summon Helpers button to ping our helper team.
✅ Once your question has been resolved (or you no longer need it), please click Resolve Question or run /resolve
You have a lot of “execute as @a” commands.
Create a file called “player_loop.mcfunction” and take all of the commands that start with “execute as @a” inside this function file. Then, change all of the “@a” to “@s”.
Inside “tick.mcfunction”, add one line that reads: “execute as @a at @s run function namespace:player_loop”.
The problem is that you are executing as all players for a bunch of different commands, which results in unnecessary lag as the game has to get each player for each command ||and this is made worse by the fact that the commands are running each tick||
By sticking the commands all in one function, it only has to do the heavy finding and executing overhead, once.
would this fix most of the lag, like 90%+ or like 20%
There's no way to guess by how much, but it's going to be a huge start
And we can go from there
You're also doing NBT checks that can probably be converted to if items checks, which will be the next big fix you can make
if i do items entity @s inventory* does that check if every item in my inventory is something or does that check if i have 1+ of an item in my inventory
[nbt={Inventory:[{id:"minecraft:carrot_on_a_stick",components:{"minecraft:custom_model_data":1010}}]}]
am i able to replcae this with items entity @s inventory*
The latter
I think you want to do container.*, cause inventory does not include the hotbar
ah, ok
all nbt checks converted to items entity container*
anything else? I figure that particles could be reduced, but they only happen at each person a max of 1 time every few minutes, so it shouldnt be a huge deal
Particles probably aren't your biggest issue. Have you tried with these changes yet?
will test right now.