-
Notifications
You must be signed in to change notification settings - Fork 127
[EN] Dev Cheat Sheet
Redeix edited this page Jul 6, 2025
·
21 revisions
The purpose of this page is for developers to document helpful functions for future use. If you have any JavaScript or java code that would be nice to share please put it here.
Here is an example of turning an item tag into an array, you can omit any part as necessary.
const tag_array = Ingredient.of('#forge:tag').itemIds.toArray().map(String);
- .itemIds This accesses the list of item ids from that ingredient tag. The result is a Java Set.
- .toArray() This converts the list (which is a Java Set) into a JavaScript array.
- .map(String) This converts each item ID in the array to a string. Required for most js functions, but not all.
Here is an example of using an array in a recipe to produce the same array, except the original item. Useful for stonecutters, dyeing, etc.
const tag_array = Ingredient.of('#forge:tag').itemIds.toArray().map(String);
tag_array.forEach(item => {
event.stonecutting(item,
Ingredient.of('#forge:tag').subtract(item)
).id(`tfg:stonecutter/${item.replace(/:/g, "/")}`)
})
The example below is used in the armor trim builder.
materials.forEach(material => {
const trimfilepaths = [
`kubejs/data/minecraft/trim_material/${material.materialName}.json`,
`kubejs/data/tfc/trim_material/${material.materialName}.json`
];
const newtrimdata = {
asset_name: material.materialName,
description: {
color: material.nameColor,
translate: `trim_material.tfc.${material.materialName}`
},
ingredient: material.itemName,
item_model_index: material.indexNumber
};
trimfilepaths.forEach(trimfilepaths => {
const existingData = JsonIO.read(trimfilepaths);
// Only write if the file is missing or contents are different
if (JSON.stringify(existingData) !== JSON.stringify(newtrimdata)) {
JsonIO.write(trimfilepaths, newtrimdata);
}
});
});
- Declare the file paths. (example above:
trimfilepaths
) - Create a const version of the json information. (example above:
newtrimdata
) - For each file path, read its contents, and write new data if missing. (example above: existingData)
If you want to use a fluid tag; use the example below. Instead of Fluid.of()
JsonIO.of({ amount: int, value: { tag: "forge:fluid_tag" }})