Skip to content

[EN] Dev Cheat Sheet

Pyritie edited this page Jul 6, 2025 · 21 revisions

Cheat Sheet

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.


JavaScript:

Tag to array

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.

Tag Subtraction

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, "/")}`)
	})

JavaScript to JSON

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);
      }
    });
  });
  1. Declare the file paths. (example above: trimfilepaths)
  2. Create a const version of the json information. (example above: newtrimdata)
  3. For each file path, read its contents, and write new data if missing. (example above: existingData)

Using Fluid Tags

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" }})

Java:


JSON:


Greate:

Documentation

If you want to generate a recipe for a gregtech machine without greate generating a recipe (for example, a bender recipe that you don't want in the mech press), put _electric_only or _manual_only on the end of the recipe ID. (_manual_only is inspired by base create, where this suffix stops create from generating a bulk blasting recipe from a smelting recipe, etc)

Home
  │
  ├─ Upgrade Guides
  │     │
  │     ├─ 0.7 to 0.9  [EN] [CN]
  │     │
  │     ├─ 0.9 to 0.10  [EN] [CN]
  │     │
  │     └─ 0.10 to 0.11  [EN] [CN]
  │
  │
  ├─ Major Changelogs
  │     │
  │     ├─ Update 0.10  [EN] [CN]
  │     │
  │     └─ Update 0.11  [EN] [CN]
  │
  │
  ├─ Developer Information
  │     │
  │     ├─ Cheat Sheet  [EN] [CN]
  │     │
  │     ├─ Pixel Comp.  [EN] [CN]
  │     │
  │     ├─ Kubejs Scripts  [EN] [CN]
  │     │
  │     └─ Worldgen  [EN] [CN]
  │
  │
  └─ Modpack Information
         │
         └─ Mod Addons  [EN] [CN]
Clone this wiki locally