#How many functions is too much?

1 messages · Page 1 of 1 (latest)

copper lantern
#

I am working on a datapack that detects when a custom_model_data flint_and_steel is used and gives an advancement for it. The advancement runs a raycast that gives found tnt entities a certain tag. Now I want to do the exact same but for a flint_and_steel with a different custom model data, and give the tnt a different tag. Is it the most efficient way to do this to use separate functions for everything: add another start_raycast and raycast function, for every time I want to tag it differently / use a different advanement? Or is there a better way?

And for funtions: is it better to have more functions and less code in each function, or less funtions and more code in each function?

robust martenBOT
#

<@&1201956957406109788>

Someone will come and help soon!

💬 While you wait, take this time to provide more context and details.

🙇 After a while, hit the Summon Helpers button to ping the helper team. They'll be happy to help you

✅ Once your question has been resolved (or you no longer need it), please click Resolve Question or run /resolve

glass sinew
#

Having more functions increases load time, having longer, more complex functions decreases performance

#

So most of the time you want more functions instead

copper lantern
#

So, most of the times I should use more functions?
in the case of my datapack, there would be no problem if I add more and more functions?

elfin thorn
#

Load time really isn’t that big of a deal, the biggest issue is performance. How much your datapack lags is pretty important.

#

So, in your case, I would go with multiple functions.

median badger
# copper lantern I am working on a datapack that detects when a custom_model_data flint_and_steel...

you can add several requirements in the achievement, why you can check the requirements separately

for example, painting a sheep

{
  "criteria": {
    "r1": {
      "trigger": "minecraft:player_interacted_with_entity",
      "conditions": {
        "item": {
          "items": "minecraft:white_dye"
        },
        "entity": {
          "type": "minecraft:sheep"
        }
      }
    },
    "r2": {
      "trigger": "minecraft:player_interacted_with_entity",
      "conditions": {
        "item": {
          "items": "minecraft:red_dye"
        },
        "entity": {
          "type": "minecraft:sheep"
        }
      }
    }
  },
  "requirements": [
    [
      "r1",
      "r2"
    ]
  ],
  "rewards": {
    "function": "namespace:function"
  }
}

function:

execute if entity @s[advancement={namespace:name={r1=true}}] run say white!
execute if entity @s[advancement={namespace:name={r2=true}}] run say red!
... 
advancement revoke @s only namespace:name

depending on the requirement, you can issue different tags to TNT

copper lantern
#

How many can you add? Because this really helps in the advancement process of the code.
Thank you

copper lantern
#

The requirements in an advancement

median badger
#

It doesn't really matter.

copper lantern
#

Okay, thank you.

robust martenBOT
# robust marten <@&1201956957406109788>
Question Closed

Your question, #1243919937064407121 (How many functions is too much?), was resolved!

Original Message

#1243919937064407121 message

Duration open

12m

robust martenBOT
#
🗑️ Recycling Thread

This thread has been inactive for some time, so I'm going to archive it.

If you're still using the thread, just send a message and it'll pop back on the thread list.