-
Notifications
You must be signed in to change notification settings - Fork 1
/
recipes.js
47 lines (35 loc) · 1.53 KB
/
recipes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var craftingrecipes = require('craftingrecipes');
var ItemPile = require('itempile');
module.exports = function(game, opts) {
return new RecipesPlugin(game, opts);
};
function RecipesPlugin(game, opts) {
this.craftList = new craftingrecipes.RecipeList();
this.smeltMap = {};
this.thesaurus = new craftingrecipes.CraftingThesaurus();
}
RecipesPlugin.prototype.register = function(recipe) {
return this.craftList.register(recipe);
};
RecipesPlugin.prototype.registerAmorphous = function(ingredients, result) {
return this.register(new craftingrecipes.AmorphousRecipe(ingredients, ItemPile.fromArrayIfArray(result)));
};
RecipesPlugin.prototype.registerPositional = function(ingredients, result) {
return this.register(new craftingrecipes.PositionalRecipe(ingredients, ItemPile.fromArrayIfArray(result)));
};
RecipesPlugin.prototype.find = function(inventory) {
return this.craftList.find(inventory);
};
RecipesPlugin.prototype.craft = function(inventory) {
return this.craftList.craft(inventory);
};
RecipesPlugin.prototype.registerSmelting = function(input, output) {
if (input in this.craftList)
console.log('WARNING: voxel-recipes registerSmelting overwriting recipes '+input+' -> '+output); // TODO: do we care?
this.craftList[input] = ItemPile.fromArrayIfArray(output);
};
RecipesPlugin.prototype.smelt = function(input) {
if (!input || !input.item) return undefined;
var output = this.craftList[input.item]; // TODO: smelting inputs of different stack sizes? (vs always 1)
return output ? output.clone() : undefined;
};