🐀

Your first function

Sandstone MCFunctions

In Sandstone, a Minecraft Function is represented by a normal JavaScript function, wrapped by the MCFunction object.
Let's write your first Minecraft Function. Start VSCode, and open the project folder. In the src directory, create a new file named helloworld.ts, with the following content:
import { MCFunction, say } from 'sandstone'

MCFunction('hello', () => {
	say('Hello world!') 
})
πŸ’‘
You can delete the display.ts file.

Building the data pack

To build the data pack, type the following command in your terminal:
# Using NPM
npm run watch -- --verbose
# Using Sand
sand run watch --verbose
πŸ’‘
The --verbose option logs the result in your console! It’s very useful when discovering Sandstone.
This will build the data pack, and rebuild each time you change something. It will also log the result in the console.
You should see the following output in your console:
## Function default:hello
say Hello world!

βœ“ Successfully wrote data pack to "..."
πŸŽ‰ Congratulations! You just ran your first Sandstone program. You can check the resulting data pack. Try opening a world and run your first function!
ℹ️
If you forgot where you saved your data pack, or want to change the location, you can modify the saveOptions specified in sandstone.config.ts.

Explanation

Let's do a line-by-line explanation.
import { MCFunction, say } from 'sandstone'
This imports what we need to use. Here, we need one command, say, and one Sandstone resource, MCFunction.
MCFunction('hello', () => {...})
This line tells Sandstone we want to create a new MCFunction, called hello. We do not have to specify the namespace: the default one will be used. If you want, you can specify the namespace yourself, like you would in Minecraft: mynamespace:hello.
Inside the curly brackets {...}, we will specify the commands we want to write inside this MCFunction.
  say('Hello world!')
This line tells Sandstone that we want to write the /say command in the current MCFunction, with the Hello world! argument. It will result in the command say Hello world!.
Β