Skip to content

Instantly share code, notes, and snippets.

@mackthehobbit
Last active August 29, 2015 14:23
Show Gist options
  • Save mackthehobbit/a28285a9b3d4bf7d418f to your computer and use it in GitHub Desktop.
Save mackthehobbit/a28285a9b3d4bf7d418f to your computer and use it in GitHub Desktop.
Addon Recipes example
#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);
}
#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&);
};
@rekmolly
Copy link

What the "/#/", "#/#", "/#/"?

@mackthehobbit
Copy link
Author

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