Skip to content

Commit 88b36fe

Browse files
bluffconSilabear
andauthored
updated getting started guide for 1.21.10 (#118)
* update for 1.21.10 * t * a few changes --------- Co-authored-by: Silabear <[email protected]>
1 parent a9b64fa commit 88b36fe

File tree

1 file changed

+63
-40
lines changed

1 file changed

+63
-40
lines changed

src/routes/guide/getting-started/+page.svx

Lines changed: 63 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description:
66
step-by-step tutorial will help you understand the basics of datapack
77
creation, even if you have little coding knowledge. Start enhancing your
88
Minecraft experience today!
9-
version: 1.21.8
9+
version: 1.21.10
1010
---
1111

1212
<script lang="ts">
@@ -65,19 +65,25 @@ or more difficult to work with. https://vscode.dev/
6565

6666
The first step when creating a datapack is to **make a new world** to test it
6767
in. Go ahead and do that now - make sure that your world has **cheats enabled**
68-
and it is set to **creative mode**. Once you've created the world, the next step
69-
is to find and open your world folder:
68+
and it is set to **creative mode**. In the world, you will need to run the `/datapack create` command -
69+
it will create your datapack folder as well as the necessary metadata for you, which saves you a bunch of time.
70+
71+
For example, to make a datapack with the ID `ExampleDatapack` and the
72+
description "This is an example datapack", you would run the following command:
73+
74+
```
75+
/datapack create ExampleDatapack "This is an example datapack"
76+
```
77+
78+
Once you've created your empty datapack, the next step is to find and open the
79+
world folder:
7080

7181
1. Save and quit your world
7282
2. Go to your world in the Singleplayer menu and hit "Edit"
7383
3. Press "Open World Folder"
7484

75-
The folder that opens contains all the data in your Minecraft world. You should
76-
see that there's lots of other subfolders in this folder. Find the one which is
77-
called `datapacks`, and open it. This folder is where the world's datapacks are
78-
stored. Create a folder - this will be the root folder of your datapack project.
79-
The name doesn't matter. I'm just going to call it `Example Datapack`. **Open
80-
this new folder**. Inside this folder is where all the data starts from.
85+
The folder that opens contains your Minecraft world's data. There will be loads of subfolders in
86+
this folder: find the one which is called `datapacks`, and open it. This folder is where the world's datapacks are stored. If you used `/datapack create`, you should see your datapack's folder here already. (If not, you'll have to create it yourself. This is explained in the "NOTE" box below)
8187

8288
:::tip
8389

@@ -88,15 +94,16 @@ datapack will be _so much easier_!
8894

8995
:::
9096

91-
The first file we want to create is the `pack.mcmeta` file. This file will tell
92-
Minecraft that the folder is a datapack, as well as holding the basic
93-
information of the pack. **Create `pack.mcmeta`, and put this inside it**:
97+
The datapack folder will contain `pack.mcmeta` and a folder called `data`.
98+
`pack.mcmeta` tells Minecraft that the folder is a datapack,
99+
as well as containing the basic information about the pack, such
100+
as what versions it works in. `/datapack create` made this file automatically, but you can open the file like normal and view it if you want:
94101

95-
```json
102+
```json:pack.mcmeta
96103
{
97104
"pack": {
98-
"description": "DATAPACK NAME HERE",
99-
"pack_format": 81
105+
"description": "This is an example datapack",
106+
"pack_format": 88
100107
}
101108
}
102109
```
@@ -106,8 +113,18 @@ If you're interested, here's what this file means:
106113
- `pack` is an object containing the metadata of the file.
107114
- `description` is the name of your datapack, usually along with a short
108115
description of what your pack does.
109-
- `pack_format` tells Minecraft what versions this datapack works in. `81` is
110-
the latest for 1.21.8
116+
- `pack_format` tells Minecraft what versions this datapack works in. `88`
117+
(or 88.0) is the latest for 1.21.10
118+
119+
120+
121+
:::note
122+
123+
If you're in a version earlier than 1.21.6, you may notice that `/datapack create` doesn't
124+
exist. You will have to create your datapack folder (inside `datapacks`) yourself. Just make
125+
a folder, and then inside that folder, create `pack.mcmeta` (as shown above) and the `data` folder.
126+
127+
:::
111128

112129
## Writing your first function
113130

@@ -123,18 +140,18 @@ as an entity (or as the Server) and at a position
123140
Let's get started by writing one simple function. In traditional programming
124141
fashion, let's make a function which sends "Hello World" to chat.
125142

126-
1. Create a folder in your datapack called `data`.
143+
1. Open your empty `data` folder.
127144
2. In the `data` folder, create a new folder. This folder is your
128145
**namespace** - it will contain all the data specific to your datapack.
129146
Usually this needs to have a **unique name** (one which other people would
130147
not have picked), but for this tutorial just call it `example`.
131148
3. In the `example` folder, create a folder called `function`. This folder will
132-
contain all the **mcfunction** files.
149+
contain all the **.mcfunction** files.
133150

134151
You should now have a folder structure that looks something like this:
135152

136153
```
137-
/world/datapacks/Example Datapack/data/example/function
154+
/world/datapacks/ExampleDatapack/data/example/function
138155
```
139156

140157
:::warning
@@ -146,7 +163,7 @@ due to some pesky name changes Mojang introduced in a recent update.
146163

147164
Once you're sure that's correct, you can start writing the actual function.
148165

149-
In the `function` folder, create an empty file called `hello_world.mcfunction`.
166+
In the `function` folder, create an empty text file called `hello_world.mcfunction`.
150167
Open this file with any text editor (we recommend Visual Studio Code)
151168

152169
Inside `hello_world.mcfunction`, put the following:
@@ -159,9 +176,15 @@ title @s title "Hello World!"
159176
give @s diamond
160177
```
161178

162-
It's that simple! Once you **save that file**, **rejoin your world** and then
163-
run `/reload`, you should be able to use the following command to run the
164-
function:
179+
:::info
180+
181+
Commands in functions shouldn't have the default slash `/` symbol which in-world
182+
commands have! Having the `/` before a command will make the mcfunction invalid
183+
and fail when it tries to run
184+
185+
:::
186+
187+
It's that simple! Once you **save that file**, and then run `/reload` (or if that doesn't work, rejoin your world), you should be able to use the following command to run the function:
165188

166189
```mcfunction
167190
/function example:hello_world
@@ -211,7 +234,12 @@ Minecraft "run this command every tick" (every tick = 20 times per second)
211234
1. In the `data` folder, create the `minecraft` folder.
212235
2. In the `minecraft` folder, create a `tags` folder
213236
3. In the `tags` folder, create a `function` folder
214-
4. In the new `function` folder, create a new file: `tick.json`
237+
4. In the new `function` folder, create a new text file: `tick.json`
238+
239+
The final path would look like this:
240+
```
241+
/world/datapacks/ExampleDatapack/data/minecraft/tags/function/tick.json
242+
```
215243

216244
**`tick.json` is NOT a function**. In `tick.json`, we are going to put a **list
217245
of functions** which we want to run every tick. If you put any commands in
@@ -258,7 +286,7 @@ world. They all start with an `@` symbol. There are 6 base target selectors:
258286

259287
| Target Selector | Description |
260288
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
261-
| `@e` | **All Entities** - By itself, this selector will select every single entity which is currently loaded in the world |
289+
| `@e` | **All Entities** - By itself, this selector will select every single entity which is currently loaded in the world. |
262290
| `@s` | **This Entity** - This selector will select the entity which is currently running the command. For example, if I run a command as @s, then it will run the commands as me. |
263291
| `@a` | **All Players** - This selects all currently online players. (All players are always loaded in the world). |
264292
| `@r` | **Random Player** - This selects one random player. |
@@ -282,7 +310,7 @@ basic ones which you might see quite often:
282310
| `[type=minecraft:arrow]` | **Entity Type** - This criteria will narrow down the selection to only include entities of a certain type. For good pack optimisation, you should use this often. |
283311
| `[distance=..5]` | **Distance to entity** - This criteria will only include entities based on their distance to their distance to the current position. `..` can be used to represent a greater/less than symbol - for example, `..5` means less than 5 blocks away. |
284312
| `[limit=2]` | **Limit selection** - Using the `limit` criteria, you can make specify a max amount of entities to be selected. This is often used in conjunction with the `sort` criteria. For example, `@e[sort=nearest,limit=1]` would select the nearest entity of any type. |
285-
| `[nbt={key:value}]` | **Entity Data** - This criteria will select entities if their NBT (entity data) matches a pattern. |
313+
| `[nbt={key:value}]` | **Entity Data** - This criteria will select entities if their NBT (entity data) matches a pattern. (note: if you do this loads of times, it might start to be a bit laggy!) |
286314

287315
### How are we going to use them?
288316

@@ -295,10 +323,10 @@ This target selector can be used in an `execute` command to run a command as the
295323
entity. Try putting this in your `loop.mcfunction`:
296324

297325
```mcfunction:loop.mcfunction
298-
execute as @e[type=arrow,nbt={inGround:1b}] at @s run say I'm an arrow, I'm in the ground!
326+
execute as @e[type=arrow,nbt={inGround:1b}] run say I'm an arrow, I'm in the ground!
299327
```
300328

301-
Reload your datapack and fire an arrow at at a block. You should see that your
329+
`/reload` your datapack and fire an arrow at at a block. You should see that your
302330
chat is spammed with messages, meaning that we successfully selected arrows in
303331
the ground, and executed a command as them!
304332

@@ -308,33 +336,28 @@ Now we can move onto the fun part! We have a simple command which will run
308336
another command as any arrow in the ground. We only need to do two things with
309337
this command:
310338

339+
- Get the arrow's position
311340
- Spawn an explosion at the position of the arrow
312341
- Kill the arrow so that it only explodes once
313342

314-
To create an explosion in Minecraft, we can simply summon a TNT entity. When a
315-
TNT entity is summoned, it will explode instantly.
343+
To create an explosion in Minecraft, we can simply summon a TNT entity that has an instant fuse length - we can do this by summoning `tnt` with the data `{fuse:0}` at the position of the arrow. We can do this using the `execute at` command, which tells the game that the `summon` command should be ran at the position of the entity, instead of at the world spawn (because all commands are run at a position in the world). This way, when we summon an entity at `~ ~ ~`, the game knows that it's referring to the position of the arrow. *This sounds complicated, but in reality, its a really easy and intuitive system when you understand it :P*
316344

317345
```mcfunction
318-
execute as @e[type=arrow,nbt={inGround:1b}] at @s run summon tnt
346+
execute at @e[type=arrow,nbt={inGround:1b}] run summon tnt ~ ~ ~ {fuse:0}
319347
```
320348

321349
Then, we just need to copy this command and make it kill the arrow after the
322350
explosion has happened. This is as simple as it sounds - we can use `/kill` to
323351
remove the arrow. Your finished `loop.mcfunction` should look like this:
324352

325353
```mcfunction:loop.mcfunction
326-
execute as @e[type=arrow,nbt={inGround:1b}] at @s run summon tnt
354+
execute as @e[type=arrow,nbt={inGround:1b}] at @s run summon tnt ~ ~ ~ {fuse:0}
327355
kill @e[type=arrow,nbt={inGround:1b}]
328356
```
329357

330-
:::info
358+
:::note
331359

332-
In reality, this method isn't the best one to use. Instead of having two
333-
commands for this, you can just execute a function as the arrow which will
334-
summon the TNT at @s's position, and then kill @s. By only using the @e selector
335-
once and then referring to @s, you remove extra stress from the computer. For
336-
now, it doesn't matter - this guide is designed to give you a better idea of the
337-
logic rather than the little details.
360+
In reality, this method might be a bit laggy if there are a lot of `arrow`s in the world. A better system would involve creating a function which referenced `@s` (the "current" entity) instead of `@e[...]`, and then runnning that function as all `arrow`s in the ground. This way, we only use `@e[...]` once, which is a lot more efficient. However, for the purposes of this tutorial, it doesn't matter at all.
338361

339362
:::
340363

0 commit comments

Comments
 (0)