KubeJS 6.1 Update

For script and pack developers

For addon mod developers

Update Primer (sorted by topics, still incomplete):

Recipe Schemas

From the announcement:

This is the big one. Recipe schemas completely change the way custom recipe handlers are registered in KubeJS, and should hopefully also mean a lot less boilerplate code down the line for you. Each recipe is now defined by a schema containing a set of recipe components, with those components acting as "codecs" for the underlying values. For you, this means the following:
- Instead of primarily using RecipeJS subclasses, you will now have to define a RecipeSchema
  - Each schema uses a set of RecipeKeys, which are named RecipeComponents with some additional properties like optional default values and settings for automatic constructor and method generation
  - A RecipeComponent is a reusable definition of a recipe element (such as an in/output item, a fluid, or even just a number value) that has a role (input, output, other), a description (for use in addon mods like ProbeJS) and contains logic for (de)serialisation and bulk recipe operations (i.e. recipe filtering and replacement). There are lots of standard components provided in the dev.latvian.mods.kubejs.recipe.component package, including blocks, items and fluids, generic group and logic components (array, map, and, or), and all kinds of primitives (including specialised ones such as number ranges and characters)
  - While the recipe schema will generate constructors by default, you can override this behaviour by defining one yourself using constructor(factory, keys). Note that this will stop the default constructor from being generated, so if you want to keep that, you will have to define it yourself again.
  (A good example of complex custom recipe constructors is `ShapedRecipeSchema`)
- While schemas replace RecipeJS on the java side, on the JS side, the user is still passed a RecipeJS object after creation, with additional autogenerated "builder" methods for each component to allow for the user to set e.g. optional values after recipe creation  (e.g. event.smelting(...).xp(20).cookingTime(100)). and you can add even more properties or do additional after-load validation by overriding the recipe factory entirely!


You can download KubeJS 6.1 at https://kubejs.com/downloads!

Revision #19
Created 24 June 2023 17:16:27 by Lat
Updated 18 July 2023 10:23:36 by Max