1

How to make and add a function to minecraft file

PluffyPlays's Avatar PluffyPlays4/25/18 7:24 pm
1 emeralds 2.6k 4
5/6/2018 1:39 pm
Dominizo's Avatar Dominizo
Hello, I'm wondering how to add a function to a minecraft file.
I don't need to know where to go, I need to know how to do it (like the code) and also if there is any sort of software or something that helps. I'm on an ubuntu/linux computer and I would like to alter the files so I can make a lightning stick in 1.12.2
Otherwise if you know how to make a lightning stick in 1.12.2 without creating a function that would be helpful too.
THANKS!
Posted by PluffyPlays's Avatar
PluffyPlays
Level 2 : Apprentice Miner
0

Create an account or sign in to comment.

4

1
04/28/2018 12:35 amhistory
Level 29 : Expert Engineer
SUPERIONtheKnight
SUPERIONtheKnight's Avatar
A few warnings, this is a rather long read. Also, the examples I'm providing are rather basic and one will spam your chat. As such, I recommend reading the whole post so that you understand how to turn off the spam before you follow any examples. One last thing I'd like to point out is that everything about commands/functions/etc is going to change in 1.13. If you want more info on what's changing, here is a wiki page explaining all of that stuff. :)

A function file is simply a list of Minecraft commands inside of a .mcfunction file. They are placed inside of "worldsave"/data/functions/"namespace".

The "namespace" can be called whatever you want it to be as it's basically the name of your function pack. For this example, I will be calling it "myfunctionpack" as that's basically what this is.

Function files can also be named whatever you want. For this example, we will be calling our first function file "main.mcfunction". The reason for this is because it will be the "main" file we use to run other function files.

Functions are read from top to bottom, and each line inside of a function file is read as a single command. Now unlike command blocks, you are not allowed use a "/" at the beginning of a command. Here's a quick and very basic example of what a function file might look like.
say I run First!
say I run Second!
say I run Last!
If you specify a # at the beginning of the line, you can have comments. Comments are ignored by Minecraft and are purely meant to help you remember what things do.
#This is a comment.
say I run First!
#This is another comment.
say I run Second!
#This is yet another Comment!
say I run Last!
Now before we test to see if this works, you might need to use the command /reload in chat. /reload does what the name suggests, it reloads any functions so that they use the new changes.

We can test this by running the /function command in chat. To run the function, we start by specifying the namespace followed by the path. This allows you to organize files into separate folders too.
/function myfunctionpack:main

If everything went well, you should see the following printed into chat.
I run First!
I run Second!
I run Last!


Now while this is cool, it isn't very useful if it's only going to run once when typed into chat. To get around this, You have two options. You can put the function command into a repeating command block, or you can use the gamerule "gameLoopFunction". Either method will run 20 times a second(once per game tick). With all of that said though, both methods have their drawbacks.

With the command block, you need to make sure that it's inside the worldspawnpoint. The reason for this is because it will stop running if the player gets too far away from it. The worldspawnpoint however, will make the command block run no matter how far away the player is.

With the gamerule, you are limited to only being able to use one function file. The reason for this is that gamerules simply can not have multiple values.

For simplicity, we will use the gamerule to further explain how functions work.
/gamerule gameLoopFunction myfunctionpack:main

If you run the above command, you should expect to see the same messages we saw before, but running 20 times a second.
I run First!
I run Second!
I run Last!
I run First!
I run Second!
I run Last!
I run First!
I run Second
I run Last!
etc...


You can stop this spam by setting the gamerule back to its default value.
/gamerule gameLoopFunction -

Now while you could put everything inside of this one function file, things will get very messy and harder to read. As an added drawback, you will have a much harder time using recursion, which can be very handy depending on what you are doing.

So how do we fix this? We do so by using more function files. They can be accessed with the function command I mentioned earlier which can also be used inside of any function file. So as an example, we will replace anything we currently have inside of "main.mcfunction" with this command.
function myfunctionpack:saysomething

And inside of "saysomething.mcfunction", we can do other stuff like this.
say Howdy!

Now if you run the following command in chat./function myfunctionpack:main

You should see the following printed on to the screen.
"Howdy!"


Now obviously these examples are useless, but I hope that they helped you understand how to use functions. I also didn't mention everything, so I highly recommend checking out the Minecraft Wiki. It is very helpful in figuring out how to use functions/commands. Also, here is another link to the wiki page showing what's changing in 1.13 so you don't have to scroll back up. :P

I hope you found this helpful. If I wasn't clear about something, or if there is something else you need help with, let me know and I will try to help you to the best of my ability.

~SUPERIONtheKnight
1
04/25/2018 7:29 pm
Level 6 : Apprentice Network
Dominizo
Dominizo's Avatar
hold a tool and do ./pt smite?
1
04/27/2018 7:30 pm
Level 2 : Apprentice Miner
PluffyPlays
PluffyPlays's Avatar
i mean no mods or plugins but if there is a 1.12.2 mod i would get that
1
05/06/2018 1:39 pm
Level 6 : Apprentice Network
Dominizo
Dominizo's Avatar
./pt is a part of Essentials?
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome