#I need help optimizing my datapack badly.

1 messages · Page 1 of 1 (latest)

hollow osprey
#

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.

hollow osprey
#
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
slim plankBOT
#

<@&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

meager cape
#

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.

hollow osprey
#

would this fix most of the lag, like 90%+ or like 20%

balmy tulip
#

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

hollow osprey
#

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*

hollow osprey
#

alright, will replace with inventory*

#

items entity

balmy tulip
hollow osprey
#

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

balmy tulip
#

Particles probably aren't your biggest issue. Have you tried with these changes yet?

hollow osprey
#

will test right now.