Last active
August 29, 2015 14:23
-
-
Save mackthehobbit/a28285a9b3d4bf7d418f to your computer and use it in GitHub Desktop.
Addon Recipes example
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 <jni.h> | |
#include "substrate.h" | |
#include "minecraftpe/recipes/Recipes.h" | |
#include "minecraftpe/item/Item.h" | |
#include "minecraftpe/tile/Tile.h" | |
static void (*_ToolRecipes$addRecipes)(Recipes* self); | |
static void ToolRecipes$addRecipes(Recipes* self) { | |
self->addShapedRecipe(ItemInstance(Item::diamond), "/#/", "#/#", "/#/", { | |
Recipes::Type('/', Item::stick); | |
Recipes::Type('#', Tile::dirt); | |
}); | |
_ToolRecipes$addRecipes(self); | |
} | |
JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) { | |
void* handle = dlopen("libminecraftpe.so", RTLD_LAZY); | |
MSHookFunction((void*) dlsym(handle, "_ZN11ToolRecipes10addRecipesEP7Recipes"), (void*) &ToolRecipes$addRecipes, (void**) &_ToolRecipes$addRecipes); | |
} |
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 | |
// this goes in minecraftpe/recipes/ !!! | |
#include <vector> | |
#include <string> | |
#include "minecraftpe/item/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* i) : c(c), item(i) {} | |
Type(char c, Tile* t) : c(c), tile(t) {} | |
Type(char c, Item* i, int damage) : c(c), item(NULL), tile(NULL), itemInstance(i, 1, damage) {} | |
Type(char c, Tile* t, int damage) : c(c), item(NULL), tile(NULL), itemInstance(t, 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&); | |
void addShapedRecipe(std::vector<ItemInstance> const&, std::vector<std::string> const&, std::vector<Recipes::Type> const&); | |
void addSingleIngredientRecipeItem(ItemInstance const&, ItemInstance const&); | |
}; |
It's the same system as Minecraft PC recipes. Those are the shape strings (here '/' denotes a stick, and '#' is dirt).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What the "/#/", "#/#", "/#/"?