Skip to content

Commit 008ccb7

Browse files
committed
Write loading data
1 parent 198f117 commit 008ccb7

File tree

6 files changed

+54
-20
lines changed

6 files changed

+54
-20
lines changed

docs/introduction/datapacking/custom-recipes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Here's an example of adding a Farmer's Delight cutting board recipe, which defin
5454
});
5555
```
5656

57+
<!-- Note that you are effectively recreating the JSON file, and how mods handle recipes can vary from mod to mod, so no one bit of advice will apply to all mods. -->
5758

5859
### Looping
5960
Of course, this starts becoming powerful when you start to combine them with a [loop, function or otherwise](../saving-time/loops.md), allowing you to easily add tons of custom recipes without having to manage a single datapack file.
@@ -133,7 +134,7 @@ Here's a datapack example:
133134
}
134135
```
135136

136-
The field:
137+
Let's break it down into it's parts:
137138

138139
- An ItemStack `input` field
139140

@@ -214,4 +215,3 @@ Now for the fun part: Actually using it!
214215
1600000, 160000
215216
)
216217
```
217-

docs/introduction/datapacking/json-files.md

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
title: JsonIO
3+
---

docs/introduction/datapacking/loading-data.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,24 @@
22
title: Loading Data with KubeJS
33
---
44

5+
# Loading Data with KubeJS
6+
You can also use KubeJS to load assets from resource packs and data from datapacks!
7+
8+
---
9+
10+
## Loading Assets
11+
12+
[Resource pack](https://minecraft.wiki/w/Resource_pack) assets (custom textures, language files, etc.) can be placed in `kubejs/assets` to be loaded. This folder is loaded the same way as the `assets` folder in a resource pack. Assets in this folder will not appear as a separate resource pack and will be automatically loaded for every world.
13+
14+
If you already have a resource pack, you can simply copy the folder(s) from inside the resource pack’s `assets` folder into KubeJS’s `assets` folder.
15+
16+
## Loading Data
17+
18+
!!! note
19+
Consider looking into [JsonIO](jsonio.md) if you have to generate a generate a large amount of ([nonrecipe](custom-recipes.md)) datapack files, rather than manually writing them.
20+
21+
Datapack data can be placed in `kubejs/data` to be loaded. Data within this folder will not appear as a separate datapack. It is loaded the same way as the `data` folder in a datapack and will be automatically loaded for every world.
22+
23+
If you already have a datapack, you can simply copy the folder(s) from inside the datapack’s `data` folder into KubeJS’s `data` folder.
524

6-
# Header
725

8-
Page content here...

docs/introduction/saving-time/helpful-mods.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ Adds VSCode intellisense support for KubeJS.
1818
<figcaption>The curseforge page explains how to install.</figcaption>
1919
</figure>
2020

21+
## [KubeJS Offline Documenation](https://www.curseforge.com/minecraft/mc-mods/kubejs-offline)
22+
KubeJS Offline is a mod that dumps all class data at runtime into a single html file using a single command - `/kubejs_offline`.
23+
24+
Previews of these pages can be found on the curseforge mod page.
2125

2226
## [Almost Unified](https://www.curseforge.com/minecraft/mc-mods/almost-unified)
2327
Helps unify resources (ingots, etc) without having to do it manually.

docs/introduction/saving-time/loops.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ After reading the previous chapters, you might have started thinking about custo
1111

1212
---
1313

14-
# Arrays
14+
## Arrays
1515
Some events allow you to use an array instead of just a single item, enabling you to perform actions on multiple items rather than needing separate methods for each.
1616

1717
```js
@@ -22,8 +22,7 @@ JEIEvents.hideItems(event => {
2222

2323
1. Hides both the `ae2:inscriber` and the `ae2:vibration_chamber`
2424

25-
26-
# Loops
25+
## Loops
2726
Loops allow you to iterate over arrays and perform actions on each element. This is particularly useful when you have a list of items and want to apply the same logic to all of them.
2827

2928
Here's an example of using a `foreach` loop to define recipes for upgrading furnaces:
@@ -53,10 +52,29 @@ furnaces.forEach(([furnace, mat, base]) => { // (1)
5352
2. **Recipe Definition**: For each furnace, a shaped recipe for the output furnace (`furnace`) is defined using the provided material (`mat`) and base furnace (`base`).
5453

5554

56-
# Functions
55+
## Functions
5756
Functions allow you to reuse code by defining a function and repeatedly calling it with multiple arguments, even across different files! Knowing a little bit of [javascript](https://www.w3schools.com/js/default.asp) can go a very long way when working with functions.
5857

59-
## Helper Functions
58+
59+
```js
60+
let potting = (output, pottedInput) => { // (1)
61+
event.shaped(output, [
62+
'BIB',
63+
' B '
64+
], {
65+
B: 'minecraft:brick',
66+
I: pottedInput
67+
})
68+
}
69+
70+
potting('kubejs:potted_snowball', 'minecraft:snowball') // (2)
71+
potting('kubejs:potted_lava', 'minecraft:lava_bucket')
72+
potting('minecraft:blast_furnace', 'minecraft:furnace')
73+
```
74+
1. Defines helper function `potting` with the elements of of `output` and `pottedInput`
75+
2. Creating shaped recipes using the helper
76+
77+
### Helper Functions
6078
Using the knowledge that you can call constants across different files, you could create a helper file with various functions in it and simply call them from anywhere.
6179

6280
```js
@@ -89,7 +107,7 @@ donutCraft(event, "sophisticatedbackpacks:stack_upgrade_tier_1", "sophisticatedb
89107
### Applying knowledge
90108
Of course, functions aren't as rigid as the above examples imply. With a little bit of JavaScript knowledge, you can create pretty some nice things.
91109

92-
The function below is excerpted from [CABIN](https://github.com/ThePansmith/CABIN), and is used to generate the recipes used to turn machines into usable parts. If the fourth parameter is omitted, it defaults to creating a stonecutting recipe instead.
110+
The function below is excerpted from [CABIN](https://github.com/ThePansmith/CABIN), and is used to generate the recipes used to turn machines into usable parts. If the fourth parameter is omitted, it defaults to creating a stonecutting recipe instead.
93111

94112
```js
95113
const createMachine = (machineItem, event, outputIngredient, inputIngredient) => { // (1)
@@ -138,7 +156,7 @@ createMachine("minecraft:obsidian", event, Item.of("minecraft:crying_obsidian",
138156
```
139157

140158

141-
### Callback Functions
159+
#### Callback Functions
142160
Likewise, you can define functions that call other functions. For example:
143161

144162
```js
@@ -166,7 +184,7 @@ if (Platform.isLoaded("createdeco")) { // (1)
166184
2. Ifs, switches, and otherwise are not limited to just functions or mechanics!
167185

168186

169-
# Regex
187+
## Regex
170188
A **regex**, shorthand for "regular expression", is a pattern describing a certain amount of text. Essentially, it acts as a filter, allowing anything that matches to pass. Regex can be quite powerful, enabling you to search with surprisingly complex options. Getting into the nitty-gritty of regex is beyond this guide (consider looking [here](https://regexr.com/) for a starting place), but here are some practical examples:
171189

172190
```js

0 commit comments

Comments
 (0)