Last active
August 29, 2015 14:25
-
-
Save mackthehobbit/899642f193517431f6db to your computer and use it in GitHub Desktop.
Return multiple items from a recipe in an addon (like buckets from a cake)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Recipes.h" | |
... | |
/* Any existing recipes function. Try hooking ToolRecipes::addRecipes(Recipes*), etc. */ | |
void addSomeRecipes(Recipes* recipes) { | |
... | |
std::vector<Recipes::Type> ingredients; | |
std::vector<std::string> shape; | |
std::vector<ItemInstance> results; | |
ingredients.push_back(Recipes::Type('U', Item::bucket, 10)); // 'U' = bucket of lava | |
ingredients.push_back(Recipes::Type('/', Item::stick)); // '/' = stick | |
results.push_back(ItemInstance(Tile::torch, 64)); // create 64 torches... | |
results.push_back(ItemInstance(Item::bucket)); // ... and an empty bucket! | |
shape.push_back("U"); // define shape | |
shape.push_back("/"); | |
recipes->addShapedRecipe(results, shape, ingredients); | |
... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <vector> | |
#include <string> | |
#include "../ItemInstance.h" | |
class Recipe; | |
class Tile; | |
class Recipes { | |
public: | |
std::vector<Recipe*> recipes; | |
class Type { | |
public: | |
Item* item; | |
Tile* tile; | |
ItemInstance itemInstance; | |
char c; | |
Type(char c, Item* item) : c(c), item(item) {} | |
Type(char c, Tile* tile) : c(c), tile(tile) {} | |
Type(char c, Item* item, int damage) : c(c), item(NULL), tile(NULL), itemInstance(item, 1, damage) {} | |
Type(char c, Tile* tile, int damage) : c(c), item(NULL), tile(NULL), itemInstance(tile, 1, damage) {} | |
}; | |
static Recipes* getInstance(); | |
void addShapedRecipe(ItemInstance const&, std::string const&, std::vector<Recipes::Type> const&); | |
void addShapedRecipe(ItemInstance const&, std::string const&, std::string const&, std::vector<Recipes::Type> const&); | |
void addShapedRecipe(ItemInstance const&, std::string const&, std::string const&, std::string const&, std::vector<Recipes::Type> const&); | |
void addShapedRecipe(ItemInstance const&, std::vector<std::string> const&, std::vector<Recipes::Type> const&); | |
/* ================================================================================== */ | |
/* This is the important function: the first argument is a vector of crafting results */ | |
void addShapedRecipe(std::vector<ItemInstance> const&, std::vector<std::string> const&, std::vector<Recipes::Type> const&); | |
/* ================================================================================== */ | |
void addSingleIngredientRecipeItem(ItemInstance const&, ItemInstance const&); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment