Crafting

The game's smithies and alchemy tables, who uses them, and your own crafting. At a game station, the player's game runs the minigame and the server follows it, with one player per station per dimension, and craftingStarting and craftingCompleting can refuse. For custom recipes and stations, the server does everything: it takes materials, runs progress by time or only through your calls, grants products, and refunds an unfinished craft. Events, with kind 'alchemy', 'smithing' or 'custom', are craftingStarting, craftingStarted, craftingCompleting, craftingCompleted, craftingRefunding, craftingEnded, craftingStationUsed and craftingRecipeLearned.

crafting.isAvailable()

Crafting.isAvailable(kind)

Whether the server itself runs this kind of crafting, which today is only 'custom'.

crafting.stations()

Crafting.stations(kind)

All stations of a kind, or all if left out. Game stations have { id, kind, level, layer, position, forward, placed }, with `placed` false for the level's own, and those SmartObject.remove took from all dimensions are not listed. Custom ones have their recipes.

crafting.recipes()

Crafting.recipes(player, kind)

Recipes of a kind, or both if left out, with ingredients and products: the game's, then those from resources' table patches and Crafting.defineRecipe, each with `source`, 'game', 'mod' or 'script'. It says nothing about what the player knows.

crafting.defineRecipe()

Crafting.defineRecipe(definition)

Adds an alchemy or smithing recipe to the game's book and smithy for the rest of the server's life, with fields matching a row of AlchemyRecipe.xml or BlacksmithRecipes.xml. All clients load it, including later joiners, and Crafting.recipes lists it with source 'script'. Items must be the game's class GUIDs, not from Items.register. Text appears as you give it. Repeating an identical registration does nothing. A TypeError means an invalid definition, an item not in the catalogue, an id taken by the game or another resource, or a different definition under an existing id. The icon is `iconImage` if given, a base64 PNG with 8 bits per channel, not interlaced, fitted onto the 64 x 64 square with its aspect kept and the rest transparent, otherwise the game item icon `icon` names. An alchemy recipe's two book pictures are `productImage`, fitted to 256 x 256, and `recipeImage`, 1024 x 1024, in the same format, or `bookPicturesFrom`, borrowing a game alchemy recipe's. Without these the book shows none. The table row with its texts can be at most 40 KiB.

crafting.session()

Crafting.session(player)

The player's crafting session, or null: { kind, id, station, dimension, phase, recipe, materials, progress, expiresInMs }.

crafting.occupancy()

Crafting.occupancy(stationKey, dimension = GLOBAL_WORLD)

Who holds a station in a dimension, or null.

crafting.cancel()

Crafting.cancel(player, options = {})

Ends the player's craft. A custom one returns the materials, and at a game station their game closes it. Returns false if there is nothing to end.

crafting.knowledge()

Crafting.knowledge(player)

The player's alchemy knowledge: each recipe id with a mask of the steps they know.

crafting.grantKnowledge()

Crafting.grantKnowledge(player, recipeId, mask)

Teaches an alchemy recipe with the whole mask, forgets it with 0, or teaches part of it for this session.

crafting.addRecipe()

Crafting.addRecipe(options)

Adds a custom recipe and returns it as { id, name, ingredients, products, duration, learn, sketch }.

crafting.removeRecipe()

Crafting.removeRecipe(id)

Removes a custom recipe.

crafting.recipe()

Crafting.recipe(id)

A custom recipe, { id, name, ingredients, products, duration, learn, sketch }, or null.

crafting.addStation()

Crafting.addStation(options)

Puts a custom station on a prop or place, with the game's 'press [key] to ...' hint, the animation the crafter plays, and its recipes. Using it fires craftingStationUsed. Returns its id.

crafting.removeStation()

Crafting.removeStation(id)

Removes a custom station and cancels any craft running there.

crafting.craft()

Crafting.craft(player, stationKey, recipeId)

Starts a custom craft, checking the recipe, taking materials and starting progress. Failure reasons are unknownStation, unknownRecipe, notLearned, busy and missing materials.

crafting.setProgress()

Crafting.setProgress(player, value)

Sets a custom craft's progress, 0 to 1, and reaching 1 completes it. Returns false if the player is not crafting at a custom station.

crafting.addProgress()

Crafting.addProgress(player, amount)

Adds to a custom craft's progress.

crafting.learnRecipe()

Crafting.learnRecipe(player, id)

Teaches a player a custom recipe, firing craftingRecipeLearned. Knowledge lasts while they are on the server.

crafting.forgetRecipe()

Crafting.forgetRecipe(player, id)

Makes a player forget a custom recipe.

crafting.knowsRecipe()

Crafting.knowsRecipe(player, id)

Whether a player can craft a custom recipe.

crafting.learnedRecipes()

Crafting.learnedRecipes(player)

The custom recipes a player has learned. Store them to restore with learnRecipe on their next visit.