forked from Kolyah35/minecraft-pe-0.6.1
the whole game
This commit is contained in:
53
src/world/item/crafting/ArmorRecipes.cpp
Executable file
53
src/world/item/crafting/ArmorRecipes.cpp
Executable file
@@ -0,0 +1,53 @@
|
||||
#include "ArmorRecipes.h"
|
||||
#include "Recipes.h"
|
||||
#include "../../level/tile/Tile.h"
|
||||
|
||||
static RowList shapes[] = {
|
||||
// Helmet
|
||||
Recipes::Shape(
|
||||
"XXX", //
|
||||
"X X"),//
|
||||
|
||||
// Chest plate
|
||||
Recipes::Shape(
|
||||
"X X",//
|
||||
"XXX",//
|
||||
"XXX"),//
|
||||
|
||||
// Leggings
|
||||
Recipes::Shape(
|
||||
"XXX",//
|
||||
"X X",//
|
||||
"X X"),//
|
||||
|
||||
// Boots
|
||||
Recipes::Shape(
|
||||
"X X",//
|
||||
"X X")//
|
||||
};
|
||||
|
||||
void ArmorRecipes::addRecipes( Recipes* r )
|
||||
{
|
||||
int materialIds[] = {Item::leather->id, /*((Tile*)Tile::fire)->id,*/ Item::ironIngot->id, Item::emerald->id, Item::goldIngot->id};
|
||||
|
||||
const int NumMaterials = sizeof(materialIds) / sizeof(int);
|
||||
const int NumRecipes = sizeof(shapes) / sizeof(RowList);
|
||||
|
||||
Item* map[NumRecipes][NumMaterials] = {
|
||||
{Item::helmet_cloth, /*Item::helmet_chain,*/ Item::helmet_iron, Item::helmet_diamond, Item::helmet_gold},
|
||||
{Item::chestplate_cloth, /*Item::chestplate_chain,*/ Item::chestplate_iron, Item::chestplate_diamond, Item::chestplate_gold},
|
||||
{Item::leggings_cloth, /*Item::leggings_chain,*/ Item::leggings_iron, Item::leggings_diamond, Item::leggings_gold},
|
||||
{Item::boots_cloth, /*Item::boots_chain,*/ Item::boots_iron, Item::boots_diamond, Item::boots_gold},
|
||||
};
|
||||
|
||||
//const int OVERRIDDEN_MaterialCount = 2;
|
||||
for (int m = 0; m < NumMaterials; m++) {
|
||||
int materialId = materialIds[m];
|
||||
for (int t = 0; t < NumRecipes; t++) {
|
||||
Item* target = (Item*) map[t][m];
|
||||
|
||||
r->addShapedRecipe( ItemInstance(target), shapes[t],
|
||||
definition('X', Item::items[materialId]) );
|
||||
}
|
||||
}
|
||||
}
|
||||
14
src/world/item/crafting/ArmorRecipes.h
Executable file
14
src/world/item/crafting/ArmorRecipes.h
Executable file
@@ -0,0 +1,14 @@
|
||||
#ifndef NET_MINECRAFT_WORLD_ITEM_CRAFTING__ArmorRecipes_H__
|
||||
#define NET_MINECRAFT_WORLD_ITEM_CRAFTING__ArmorRecipes_H__
|
||||
|
||||
//package net.minecraft.world.item.crafting;
|
||||
|
||||
class Recipes;
|
||||
|
||||
class ArmorRecipes
|
||||
{
|
||||
public:
|
||||
static void addRecipes(Recipes* r);
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_WORLD_ITEM_CRAFTING__ArmorRecipes_H__*/
|
||||
73
src/world/item/crafting/ClothDyeRecipes.h
Executable file
73
src/world/item/crafting/ClothDyeRecipes.h
Executable file
@@ -0,0 +1,73 @@
|
||||
#ifndef NET_MINECRAFT_WORLD_ITEM_CRAFTING__ClothDyeRecipes_H__
|
||||
#define NET_MINECRAFT_WORLD_ITEM_CRAFTING__ClothDyeRecipes_H__
|
||||
|
||||
//package net.minecraft.world.item.crafting;
|
||||
|
||||
#include "Recipes.h"
|
||||
#include "../DyePowderItem.h"
|
||||
#include "../Item.h"
|
||||
#include "../ItemInstance.h"
|
||||
#include "../../level/tile/ClothTile.h"
|
||||
#include "../../level/tile/Tile.h"
|
||||
|
||||
class ClothDyeRecipes
|
||||
{
|
||||
public:
|
||||
static void addRecipes(Recipes* r){
|
||||
// recipes for converting cloth to colored cloth using dye
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if (i == DyePowderItem::BLACK
|
||||
|| i == DyePowderItem::BROWN
|
||||
|| i == DyePowderItem::SILVER
|
||||
|| i == DyePowderItem::GRAY
|
||||
|| i == DyePowderItem::WHITE)
|
||||
continue;
|
||||
|
||||
r->addShapelessRecipe(ItemInstance(Tile::cloth, 1, ClothTile::getTileDataForItemAuxValue(i)),
|
||||
definition(0, ItemInstance(Item::dye_powder, 1, i), 0, ItemInstance(Item::items[Tile::cloth->id], 1, 0)));
|
||||
}
|
||||
// White cloth/wool-block from any cloth block (including white...)
|
||||
/*
|
||||
r->addShapelessRecipe(ItemInstance(Tile::cloth, 1, 15-DyePowderItem::WHITE),
|
||||
definition(0, ItemInstance(Tile::cloth, 1, Recipe::ANY_AUX_VALUE)));
|
||||
*/
|
||||
|
||||
// some dye recipes
|
||||
r->addShapelessRecipe(ItemInstance(Item::dye_powder, 2, DyePowderItem::YELLOW),
|
||||
definition(0, Tile::flower));
|
||||
//r->addShapelessRecipe(ItemInstance(Item::dye_powder, 2, DyePowderItem::RED),
|
||||
//definition(Tile*)Tile::rose));
|
||||
r->addShapelessRecipe(ItemInstance(Item::dye_powder, 3, DyePowderItem::WHITE),
|
||||
definition(0, Item::bone));
|
||||
r->addShapelessRecipe(ItemInstance(Item::dye_powder, 2, DyePowderItem::PINK), //
|
||||
definition(0, ItemInstance(Item::dye_powder, 1, DyePowderItem::RED), 0, ItemInstance(Item::dye_powder, 1, DyePowderItem::WHITE)));
|
||||
r->addShapelessRecipe(ItemInstance(Item::dye_powder, 2, DyePowderItem::ORANGE), //
|
||||
definition(0, ItemInstance(Item::dye_powder, 1, DyePowderItem::RED), 0, ItemInstance(Item::dye_powder, 1, DyePowderItem::YELLOW)));
|
||||
r->addShapelessRecipe(ItemInstance(Item::dye_powder, 2, DyePowderItem::LIME), //
|
||||
definition(0, ItemInstance(Item::dye_powder, 1, DyePowderItem::GREEN), 0, ItemInstance(Item::dye_powder, 1, DyePowderItem::WHITE)));
|
||||
// r->addShapelessRecipe(ItemInstance(Item::dye_powder, 2, DyePowderItem::GRAY), //
|
||||
// definition(0, ItemInstance(Item::dye_powder, 1, DyePowderItem::BLACK), 0, ItemInstance(Item::dye_powder, 1, DyePowderItem::WHITE)));
|
||||
// r->addShapelessRecipe(ItemInstance(Item::dye_powder, 2, DyePowderItem::SILVER), //
|
||||
// definition(0, ItemInstance(Item::dye_powder, 1, DyePowderItem::GRAY), 0, ItemInstance(Item::dye_powder, 1, DyePowderItem::WHITE)));
|
||||
// r->addShapelessRecipe(ItemInstance(Item::dye_powder, 3, DyePowderItem::SILVER), //
|
||||
// definition(0, ItemInstance(Item::dye_powder, 1, DyePowderItem::BLACK), 0, ItemInstance(Item::dye_powder, 1, DyePowderItem::WHITE), 0, ItemInstance(Item::dye_powder, 1, DyePowderItem::WHITE)));
|
||||
// r->addShapelessRecipe(ItemInstance(Item::dye_powder, 2, DyePowderItem::BROWN), //
|
||||
// definition(0, ItemInstance(Item::dye_powder, 1, DyePowderItem::BLACK), 0, ItemInstance(Item::dye_powder, 1, DyePowderItem::ORANGE)));
|
||||
// r->addShapelessRecipe(ItemInstance(Item::dye_powder, 3, DyePowderItem::BROWN), //
|
||||
// definition(0, ItemInstance(Item::dye_powder, 1, DyePowderItem::BLACK), 0, ItemInstance(Item::dye_powder, 1, DyePowderItem::RED), 0, ItemInstance(Item::dye_powder, 1, DyePowderItem::YELLOW)));
|
||||
r->addShapelessRecipe(ItemInstance(Item::dye_powder, 2, DyePowderItem::LIGHT_BLUE), //
|
||||
definition(0, ItemInstance(Item::dye_powder, 1, DyePowderItem::BLUE), 0, ItemInstance(Item::dye_powder, 1, DyePowderItem::WHITE)));
|
||||
r->addShapelessRecipe(ItemInstance(Item::dye_powder, 2, DyePowderItem::CYAN), //
|
||||
definition(0, ItemInstance(Item::dye_powder, 1, DyePowderItem::BLUE), 0, ItemInstance(Item::dye_powder, 1, DyePowderItem::GREEN)));
|
||||
r->addShapelessRecipe(ItemInstance(Item::dye_powder, 2, DyePowderItem::PURPLE), //
|
||||
definition(0, ItemInstance(Item::dye_powder, 1, DyePowderItem::BLUE), 0, ItemInstance(Item::dye_powder, 1, DyePowderItem::RED)));
|
||||
//r->addShapelessRecipe(ItemInstance(Item::dye_powder, 2, DyePowderItem::MAGENTA), //
|
||||
// definition(0, ItemInstance(Item::dye_powder, 1, DyePowderItem::PURPLE), 0, ItemInstance(Item::dye_powder, 1, DyePowderItem::PINK)));
|
||||
//r->addShapelessRecipe(ItemInstance(Item::dye_powder, 3, DyePowderItem::MAGENTA), //
|
||||
// definition(0, ItemInstance(Item::dye_powder, 1, DyePowderItem::BLUE), 0, ItemInstance(Item::dye_powder, 1, DyePowderItem::RED), 0, ItemInstance(Item::dye_powder, 1, DyePowderItem::PINK)));
|
||||
r->addShapelessRecipe(ItemInstance(Item::dye_powder, 4, DyePowderItem::MAGENTA), //
|
||||
definition(0, ItemInstance(Item::dye_powder, 1, DyePowderItem::BLUE), 0, ItemInstance(Item::dye_powder, 1, DyePowderItem::RED), 0, ItemInstance(Item::dye_powder, 1, DyePowderItem::RED), 0, ItemInstance(Item::dye_powder, 1, DyePowderItem::WHITE)));
|
||||
}
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_WORLD_ITEM_CRAFTING__ClothDyeRecipes_H__*/
|
||||
54
src/world/item/crafting/FoodRecipes.h
Executable file
54
src/world/item/crafting/FoodRecipes.h
Executable file
@@ -0,0 +1,54 @@
|
||||
#ifndef NET_MINECRAFT_WORLD_ITEM_CRAFTING__FoodRecipes_H__
|
||||
#define NET_MINECRAFT_WORLD_ITEM_CRAFTING__FoodRecipes_H__
|
||||
|
||||
//package net.minecraft.world.item.crafting;
|
||||
|
||||
#include "Recipes.h"
|
||||
#include "../Item.h"
|
||||
#include "../ItemInstance.h"
|
||||
#include "../DyePowderItem.h"
|
||||
#include "../../level/tile/Tile.h"
|
||||
|
||||
class FoodRecipes {
|
||||
public:
|
||||
static void addRecipes(Recipes* r) {
|
||||
r->addShapelessRecipe(ItemInstance(Item::mushroomStew), //
|
||||
definition(0, Tile::mushroom1, 0, Tile::mushroom2, 0, Item::bowl));
|
||||
|
||||
//r->addShapedRecipe(/*new*/ ItemInstance(Item::cookie, 8), //
|
||||
// "#X#", //
|
||||
|
||||
// definition('X', /*new*/ ItemInstance(Item::dye_powder, 1, DyePowderItem::BROWN), '#', Item::wheat));
|
||||
|
||||
r->addShapedRecipe(/*new*/ ItemInstance(Tile::melon), //
|
||||
"MMM", //
|
||||
"MMM", //
|
||||
"MMM", //
|
||||
|
||||
definition('M', Item::melon));
|
||||
|
||||
r->addShapedRecipe(/*new*/ ItemInstance(Item::seeds_melon), //
|
||||
"M", //
|
||||
|
||||
definition('M', Item::melon));
|
||||
|
||||
//r->addShapedRecipe(/*new*/ ItemInstance(Item::seeds_pumpkin, 4), //
|
||||
// "M", //
|
||||
|
||||
// definition('M', Tile::pumpkin));
|
||||
|
||||
//r->addShapelessRecipe(/*new*/ ItemInstance(Item::fermentedSpiderEye), //
|
||||
// definition(0,Item::spiderEye, 0,Tile::mushroom1, 0,Item::sugar));
|
||||
|
||||
//r->addShapelessRecipe(/*new*/ ItemInstance(Item::speckledMelon), //
|
||||
// definition(0,Item::melon, 0,Item::goldNugget));
|
||||
|
||||
//r->addShapelessRecipe(/*new*/ ItemInstance(Item::blazePowder, 2), //
|
||||
// definition(0,Item::blazeRod));
|
||||
|
||||
//r->addShapelessRecipe(/*new*/ ItemInstance(Item::magmaCream), //
|
||||
// definition(0,Item::blazePowder, 0,Item::slimeBall));
|
||||
}
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_WORLD_ITEM_CRAFTING__FoodRecipes_H__*/
|
||||
66
src/world/item/crafting/FurnaceRecipes.cpp
Executable file
66
src/world/item/crafting/FurnaceRecipes.cpp
Executable file
@@ -0,0 +1,66 @@
|
||||
#include "FurnaceRecipes.h"
|
||||
#include "../../level/tile/Tile.h"
|
||||
#include "../DyePowderItem.h"
|
||||
#include "../CoalItem.h"
|
||||
|
||||
/*static*/
|
||||
FurnaceRecipes* FurnaceRecipes::instance = NULL;
|
||||
|
||||
const FurnaceRecipes* FurnaceRecipes::getInstance()
|
||||
{
|
||||
if (!instance) instance = new FurnaceRecipes();
|
||||
return instance;
|
||||
}
|
||||
|
||||
void FurnaceRecipes::addFurnaceRecipe( int itemId, const ItemInstance& result )
|
||||
{
|
||||
recipes.insert(std::make_pair(itemId, result));
|
||||
}
|
||||
|
||||
bool FurnaceRecipes::isFurnaceItem( int itemId ) const
|
||||
{
|
||||
return recipes.find(itemId) != recipes.end();
|
||||
}
|
||||
|
||||
ItemInstance FurnaceRecipes::getResult( int itemId ) const
|
||||
{
|
||||
Map::const_iterator cit = recipes.find(itemId);
|
||||
return (cit != recipes.end())? cit->second : ItemInstance();
|
||||
}
|
||||
|
||||
const FurnaceRecipes::Map& FurnaceRecipes::getRecipes() const
|
||||
{
|
||||
return recipes;
|
||||
}
|
||||
|
||||
FurnaceRecipes::FurnaceRecipes()
|
||||
{
|
||||
addFurnaceRecipe(Tile::ironOre->id, ItemInstance(Item::ironIngot));
|
||||
addFurnaceRecipe(Tile::goldOre->id, ItemInstance(Item::goldIngot));
|
||||
addFurnaceRecipe(Tile::emeraldOre->id, ItemInstance(Item::emerald));
|
||||
addFurnaceRecipe(Tile::sand->id, ItemInstance(Tile::glass));
|
||||
addFurnaceRecipe(Item::porkChop_raw->id,ItemInstance(Item::porkChop_cooked));
|
||||
addFurnaceRecipe(Item::beef_raw->id, ItemInstance(Item::beef_cooked));
|
||||
addFurnaceRecipe(Item::chicken_raw->id, ItemInstance(Item::chicken_cooked));
|
||||
//addFurnaceRecipe(Item::fish_raw->id, ItemInstance(Item::fish_cooked));
|
||||
addFurnaceRecipe(Tile::stoneBrick->id, ItemInstance(Tile::rock));
|
||||
addFurnaceRecipe(Item::clay->id, ItemInstance(Item::brick));
|
||||
addFurnaceRecipe(Tile::cactus->id, ItemInstance(Item::dye_powder, 1, DyePowderItem::GREEN));
|
||||
addFurnaceRecipe(Tile::mushroom2->id, ItemInstance(Item::dye_powder, 1, DyePowderItem::RED));
|
||||
addFurnaceRecipe(Tile::treeTrunk->id, ItemInstance(Item::coal, 1, CoalItem::CHAR_COAL));
|
||||
addFurnaceRecipe(Tile::netherrack->id, ItemInstance(Item::netherbrick));
|
||||
/*
|
||||
// special silk touch related recipes:
|
||||
addFurnaceRecipe(Tile::coalOre->id, ItemInstance(Item::coal));
|
||||
addFurnaceRecipe(Tile::redStoneOre->id, ItemInstance(Item::redStone));
|
||||
addFurnaceRecipe(Tile::lapisOre->id, ItemInstance(Item::dye_powder, 1, DyePowderItem::BLUE));
|
||||
*/
|
||||
}
|
||||
|
||||
void FurnaceRecipes::teardownFurnaceRecipes()
|
||||
{
|
||||
if (instance) {
|
||||
delete instance;
|
||||
instance = NULL;
|
||||
}
|
||||
}
|
||||
33
src/world/item/crafting/FurnaceRecipes.h
Executable file
33
src/world/item/crafting/FurnaceRecipes.h
Executable file
@@ -0,0 +1,33 @@
|
||||
#ifndef NET_MINECRAFT_WORLD_ITEM_CRAFTING__FurnaceRecipes_H__
|
||||
#define NET_MINECRAFT_WORLD_ITEM_CRAFTING__FurnaceRecipes_H__
|
||||
|
||||
//package net.minecraft.world.item.crafting;
|
||||
|
||||
#include "../ItemInstance.h"
|
||||
#include <map>
|
||||
|
||||
class FurnaceRecipes
|
||||
{
|
||||
public:
|
||||
typedef std::map<int, ItemInstance> Map;
|
||||
|
||||
static void teardownFurnaceRecipes();
|
||||
static const FurnaceRecipes* getInstance();
|
||||
|
||||
bool isFurnaceItem(int itemId) const;
|
||||
|
||||
ItemInstance getResult(int itemId) const;
|
||||
|
||||
const Map& getRecipes() const;
|
||||
|
||||
private:
|
||||
FurnaceRecipes();
|
||||
|
||||
void addFurnaceRecipe(int itemId, const ItemInstance& result);
|
||||
|
||||
static FurnaceRecipes* instance;
|
||||
|
||||
Map recipes;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_WORLD_ITEM_CRAFTING__FurnaceRecipes_H__*/
|
||||
45
src/world/item/crafting/OreRecipes.cpp
Executable file
45
src/world/item/crafting/OreRecipes.cpp
Executable file
@@ -0,0 +1,45 @@
|
||||
#include "OreRecipes.h"
|
||||
#include "Recipes.h"
|
||||
#include "../../level/tile/Tile.h"
|
||||
#include "../DyePowderItem.h"
|
||||
#include <utility>
|
||||
|
||||
void OreRecipes::addRecipes(Recipes* r)
|
||||
{
|
||||
typedef std::pair<Tile*, ItemInstance> Pair;
|
||||
Pair map[] = {
|
||||
std::make_pair(Tile::goldBlock, ItemInstance(Item::goldIngot, 9)),
|
||||
std::make_pair(Tile::ironBlock, ItemInstance(Item::ironIngot, 9)),
|
||||
std::make_pair(Tile::emeraldBlock, ItemInstance(Item::emerald, 9)),
|
||||
std::make_pair(Tile::lapisBlock, ItemInstance(Item::dye_powder, 9, DyePowderItem::BLUE))
|
||||
};
|
||||
const int NumItems = sizeof(map) / sizeof(Pair);
|
||||
|
||||
for (int i = 0; i < NumItems; i++) {
|
||||
Tile* from = map[i].first;
|
||||
ItemInstance to = map[i].second;
|
||||
|
||||
r->addShapedRecipe(ItemInstance(from), //
|
||||
"###", //
|
||||
"###", //
|
||||
"###", //
|
||||
|
||||
definition('#', to));
|
||||
|
||||
r->addShapedRecipe(to, //
|
||||
"#", //
|
||||
|
||||
definition('#', from));
|
||||
}
|
||||
|
||||
//r->addShapedRecipe(ItemInstance(Item::goldIngot), //
|
||||
// "###", //
|
||||
// "###", //
|
||||
// "###", //
|
||||
|
||||
// definition('#', Item::goldNugget));
|
||||
//r->addShapedRecipe(ItemInstance(Item::goldNugget, 9), //
|
||||
// "#", //
|
||||
|
||||
// definition('#', Item::goldIngot));
|
||||
}
|
||||
14
src/world/item/crafting/OreRecipes.h
Executable file
14
src/world/item/crafting/OreRecipes.h
Executable file
@@ -0,0 +1,14 @@
|
||||
#ifndef NET_MINECRAFT_WORLD_ITEM_CRAFTING__OreRecipies_H__
|
||||
#define NET_MINECRAFT_WORLD_ITEM_CRAFTING__OreRecipies_H__
|
||||
|
||||
//package net.minecraft.world.item.crafting;
|
||||
|
||||
class Recipes;
|
||||
|
||||
class OreRecipes
|
||||
{
|
||||
public:
|
||||
static void addRecipes(Recipes* r);
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_WORLD_ITEM_CRAFTING__OreRecipies_H__*/
|
||||
109
src/world/item/crafting/Recipe.cpp
Executable file
109
src/world/item/crafting/Recipe.cpp
Executable file
@@ -0,0 +1,109 @@
|
||||
#include "Recipe.h"
|
||||
#include "../../../util/Mth.h"
|
||||
#include "../../level/tile/Tile.h"
|
||||
|
||||
void ItemPack::add( int id, int count /* = 1 */ )
|
||||
{
|
||||
Map::iterator it = items.find(id);
|
||||
if (it == items.end()) {
|
||||
items.insert(std::make_pair(id, count));
|
||||
} else {
|
||||
it->second += count;
|
||||
}
|
||||
}
|
||||
|
||||
void ItemPack::print() const
|
||||
{
|
||||
Map::const_iterator it = items.begin();
|
||||
while (it != items.end()) {
|
||||
ItemInstance item = getItemInstanceForId(it->first);
|
||||
//LOGI("> %d - %d, %d\n", it->first, item.id, item.getAuxValue());
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
int ItemPack::getMaxMultipliesOf( ItemPack& v ) const
|
||||
{
|
||||
if (v.items.empty())
|
||||
return 0;
|
||||
int minCount = 99;
|
||||
|
||||
Map::iterator it = v.items.begin();
|
||||
while (it != v.items.end()) {
|
||||
if (it->first <= 0) {
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
|
||||
Map::const_iterator jt = items.find(it->first);
|
||||
if (jt == items.end()) {
|
||||
//LOGI("shotto: %d (%s) wasn't found!\n", it->first, getItemInstanceForId(it->first).toString().c_str());
|
||||
return 0;
|
||||
}
|
||||
if (it->second == 0) {
|
||||
//LOGE("getMaxMultipliesOf: Can't have count 0 of item: %d\n", it->first);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int count = jt->second / it->second;
|
||||
if (count == 0) return 0;
|
||||
minCount = Mth::Min(minCount, count);
|
||||
++it;
|
||||
}
|
||||
return minCount;
|
||||
}
|
||||
|
||||
std::vector<ItemInstance> ItemPack::getItemInstances() const
|
||||
{
|
||||
std::vector<ItemInstance> out;
|
||||
Map::const_iterator it = items.begin();
|
||||
while (it != items.end()) {
|
||||
int id = it->first;
|
||||
int count = it->second;
|
||||
|
||||
ItemInstance item = getItemInstanceForId(id);
|
||||
item.count = count;
|
||||
out.push_back(item);
|
||||
++it;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
int ItemPack::getIdForItemInstance( const ItemInstance* ii )
|
||||
{
|
||||
bool anyAuxValue = Recipe::isAnyAuxValue(ii);
|
||||
return ii->id * 512 + (anyAuxValue? -1/*Recipes::ANY_AUX_VALUE*/ : ii->getAuxValue());
|
||||
}
|
||||
int ItemPack::getIdForItemInstanceAnyAux( const ItemInstance* ii )
|
||||
{
|
||||
return ii->id * 512 - 1;
|
||||
}
|
||||
|
||||
ItemInstance ItemPack::getItemInstanceForId( int id )
|
||||
{
|
||||
id += 256;
|
||||
return ItemInstance(id / 512, 1, (id & 511) - 256);
|
||||
}
|
||||
|
||||
int ItemPack::getCount( int id ) const
|
||||
{
|
||||
Map::const_iterator it = items.find(id);
|
||||
if (it == items.end()) return 0;
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
||||
/*static*/
|
||||
const int Recipe::SIZE_2X2 = 0;
|
||||
const int Recipe::SIZE_3X3 = 1;
|
||||
|
||||
bool Recipe::isAnyAuxValue( int id )
|
||||
{
|
||||
bool isTile = id < 256;
|
||||
if (!isTile) return false;
|
||||
if (id == Tile::cloth->id
|
||||
|| id == Tile::stoneSlabHalf->id
|
||||
|| id == Tile::sandStone->id)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
61
src/world/item/crafting/Recipe.h
Executable file
61
src/world/item/crafting/Recipe.h
Executable file
@@ -0,0 +1,61 @@
|
||||
#ifndef NET_MINECRAFT_WORLD_ITEM_CRAFTING__Recipe_H__
|
||||
#define NET_MINECRAFT_WORLD_ITEM_CRAFTING__Recipe_H__
|
||||
|
||||
//package net.minecraft.world.item.crafting;
|
||||
|
||||
//#include "../../inventory/CraftingContainer.h"
|
||||
#include "../ItemInstance.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
class CraftingContainer;
|
||||
|
||||
class ItemPack {
|
||||
public:
|
||||
typedef std::map<int, int> Map;
|
||||
//typedef std::vector<std::pair<int, int> > TypeCountList;
|
||||
|
||||
void add(int id, int count = 1);
|
||||
int getCount(int id) const;
|
||||
void print() const;
|
||||
|
||||
int getMaxMultipliesOf(ItemPack& v) const;
|
||||
std::vector<ItemInstance> getItemInstances() const;
|
||||
|
||||
static int getIdForItemInstance(const ItemInstance* ii);
|
||||
static int getIdForItemInstanceAnyAux( const ItemInstance* ii );
|
||||
static ItemInstance getItemInstanceForId(int id);
|
||||
private:
|
||||
Map items;
|
||||
};
|
||||
|
||||
|
||||
class Recipe
|
||||
{
|
||||
public:
|
||||
static const int SIZE_2X2;// = 0;
|
||||
static const int SIZE_3X3;// = 1;
|
||||
static const int ANY_AUX_VALUE = -1;
|
||||
|
||||
virtual ~Recipe() {}
|
||||
virtual bool matches(CraftingContainer* craftSlots) = 0;
|
||||
virtual const ItemPack& getItemPack() { return myItems; }
|
||||
virtual int getMaxCraftCount(ItemPack& fromItems) = 0;
|
||||
|
||||
virtual int size() = 0;
|
||||
|
||||
virtual ItemInstance assemble(CraftingContainer* craftSlots) = 0;
|
||||
virtual ItemInstance getResultItem() const = 0;
|
||||
|
||||
static bool isAnyAuxValue(const ItemInstance* ii) {
|
||||
return isAnyAuxValue(ii->id);
|
||||
}
|
||||
|
||||
virtual int getCraftingSize() = 0;
|
||||
private:
|
||||
static bool isAnyAuxValue(int id);
|
||||
protected:
|
||||
ItemPack myItems;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_WORLD_ITEM_CRAFTING__Recipe_H__*/
|
||||
12
src/world/item/crafting/RecipeCategory.h
Executable file
12
src/world/item/crafting/RecipeCategory.h
Executable file
@@ -0,0 +1,12 @@
|
||||
#ifndef NET_MINECRAFT_WORLD_ITEM_CRAFTING__RecipeCategory_H__
|
||||
#define NET_MINECRAFT_WORLD_ITEM_CRAFTING__RecipeCategory_H__
|
||||
|
||||
enum RecipeCategory {
|
||||
RCAT_TOOL,
|
||||
RCAT_WEAPON,
|
||||
RCAT_ARMOR,
|
||||
RCAT_FOOD,
|
||||
RCAT_OTHER
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_WORLD_ITEM_CRAFTING__RecipeCategory_H__*/
|
||||
642
src/world/item/crafting/Recipes.cpp
Executable file
642
src/world/item/crafting/Recipes.cpp
Executable file
@@ -0,0 +1,642 @@
|
||||
#include "Recipes.h"
|
||||
#include "ShapedRecipe.h"
|
||||
#include "ShapelessRecipe.h"
|
||||
|
||||
#include "ClothDyeRecipes.h"
|
||||
#include "ToolRecipes.h"
|
||||
#include "WeaponRecipes.h"
|
||||
#include "StructureRecipes.h"
|
||||
#include "FoodRecipes.h"
|
||||
#include "FurnaceRecipes.h"
|
||||
#include "ArmorRecipes.h"
|
||||
#include "OreRecipes.h"
|
||||
#include "../CoalItem.h"
|
||||
#include "../../level/tile/StoneSlabTile.h"
|
||||
|
||||
/*static*/
|
||||
Recipes* Recipes::instance = NULL;
|
||||
|
||||
Recipes::Recipes()
|
||||
{
|
||||
ToolRecipes::addRecipes(this);
|
||||
WeaponRecipes::addRecipes(this);
|
||||
OreRecipes::addRecipes(this);
|
||||
FoodRecipes::addRecipes(this);
|
||||
StructureRecipes::addRecipes(this);
|
||||
ArmorRecipes::addRecipes(this);
|
||||
ClothDyeRecipes::addRecipes(this);
|
||||
|
||||
addShapedRecipe(ItemInstance(Item::paper, 3), //
|
||||
"###", //
|
||||
|
||||
definition('#', Item::reeds));
|
||||
|
||||
addShapedRecipe(ItemInstance(Item::book, 1), //
|
||||
"#", //
|
||||
"#", //
|
||||
"#", //
|
||||
|
||||
definition('#', Item::paper));
|
||||
|
||||
addShapedRecipe(ItemInstance(Tile::fence, 2), //
|
||||
"###", //
|
||||
"###", //
|
||||
|
||||
definition('#', Item::stick));
|
||||
|
||||
//addShapedRecipe(ItemInstance(Tile::netherFence, 6), //
|
||||
// "###", //
|
||||
// "###", //
|
||||
|
||||
// '#', Tile::netherBrick);
|
||||
|
||||
addShapedRecipe(ItemInstance(Tile::fenceGate, 1), //
|
||||
"#W#", //
|
||||
"#W#", //
|
||||
|
||||
definition('#', Item::stick, 'W', Tile::wood));
|
||||
|
||||
//addShapedRecipe(ItemInstance(Tile::recordPlayer, 1), //
|
||||
// "###", //
|
||||
// "#X#", //
|
||||
// "###", //
|
||||
|
||||
// definition('#', Tile::wood, 'X', Item::emerald));
|
||||
|
||||
//addShapedRecipe(ItemInstance(Tile::musicBlock, 1), //
|
||||
// "###", //
|
||||
// "#X#", //
|
||||
// "###", //
|
||||
|
||||
// definition('#', Tile::wood, 'X', Item::redStone));
|
||||
|
||||
addShapedRecipe(ItemInstance(Tile::bookshelf, 1), //
|
||||
"###", //
|
||||
"XXX", //
|
||||
"###", //
|
||||
|
||||
definition('#', Tile::wood, 'X', Item::book));
|
||||
|
||||
addShapedRecipe(ItemInstance(Tile::snow, 1), //
|
||||
"##", //
|
||||
"##", //
|
||||
|
||||
definition('#', Item::snowBall));
|
||||
|
||||
addShapedRecipe(ItemInstance(Tile::clay, 1), //
|
||||
"##", //
|
||||
"##", //
|
||||
|
||||
definition('#', Item::clay));
|
||||
|
||||
addShapedRecipe(ItemInstance(Tile::redBrick, 1), //
|
||||
"##", //
|
||||
"##", //
|
||||
|
||||
definition('#', Item::brick));
|
||||
|
||||
addShapedRecipe(ItemInstance(Tile::lightGem, 1), //
|
||||
"##", //
|
||||
"##", //
|
||||
|
||||
definition('#', Item::yellowDust));
|
||||
|
||||
addShapedRecipe(ItemInstance(Tile::cloth, 1), //
|
||||
"##", //
|
||||
"##", //
|
||||
|
||||
definition('#', Item::string));
|
||||
|
||||
addShapedRecipe(ItemInstance(Tile::tnt, 1), //
|
||||
"X#X", //
|
||||
"#X#", //
|
||||
"X#X", //
|
||||
|
||||
definition( 'X', Item::sulphur,
|
||||
'#', Tile::sand));
|
||||
|
||||
addShapedRecipe(ItemInstance(Tile::stoneSlabHalf, 6, StoneSlabTile::COBBLESTONE_SLAB), //
|
||||
"###", //
|
||||
|
||||
definition('#', Tile::stoneBrick));
|
||||
|
||||
addShapedRecipe(ItemInstance(Tile::stoneSlabHalf, 6, StoneSlabTile::STONE_SLAB), //
|
||||
"###", //
|
||||
|
||||
definition('#', Tile::rock));
|
||||
|
||||
addShapedRecipe(ItemInstance(Tile::stoneSlabHalf, 6, StoneSlabTile::SAND_SLAB), //
|
||||
"###", //
|
||||
definition('#', Tile::sandStone));
|
||||
|
||||
addShapedRecipe(ItemInstance(Tile::stoneSlabHalf, 6, StoneSlabTile::WOOD_SLAB), //
|
||||
"###", //
|
||||
|
||||
definition('#', Tile::wood));
|
||||
|
||||
addShapedRecipe(ItemInstance(Tile::stoneSlabHalf, 6, StoneSlabTile::BRICK_SLAB), //
|
||||
"###", //
|
||||
|
||||
definition('#', Tile::redBrick));
|
||||
|
||||
addShapedRecipe(ItemInstance(Tile::stoneSlabHalf, 6, StoneSlabTile::SMOOTHBRICK_SLAB), //
|
||||
"###", //
|
||||
definition('#', Tile::stoneBrickSmooth));
|
||||
|
||||
addShapedRecipe(ItemInstance(Tile::ladder, 2), //
|
||||
"# #", //
|
||||
"###", //
|
||||
"# #", //
|
||||
|
||||
definition('#', Item::stick));
|
||||
|
||||
addShapedRecipe(ItemInstance(Item::door_wood, 1), //
|
||||
"##", //
|
||||
"##", //
|
||||
"##", //
|
||||
|
||||
definition('#', Tile::wood));
|
||||
|
||||
addShapedRecipe(ItemInstance(Tile::trapdoor, 2), //
|
||||
"###", //
|
||||
"###", //
|
||||
|
||||
definition('#', Tile::wood));
|
||||
|
||||
//addShapedRecipe(ItemInstance(Item::door_iron, 1), //
|
||||
// "##", //
|
||||
// "##", //
|
||||
// "##", //
|
||||
|
||||
// definition('#', Item::ironIngot));
|
||||
|
||||
addShapedRecipe(ItemInstance(Item::sign, 1), //
|
||||
"###", //
|
||||
"###", //
|
||||
" X ", //
|
||||
|
||||
definition('#', Tile::wood, 'X', Item::stick));
|
||||
|
||||
//addShapedRecipe(ItemInstance(Item::cake, 1), //
|
||||
// "AAA", //
|
||||
// "BEB", //
|
||||
// "CCC", //
|
||||
|
||||
// definition( 'A', Item::milk,//
|
||||
// 'B', Item::sugar,//
|
||||
// 'C', Item::wheat, 'E', Item::egg));
|
||||
|
||||
addShapedRecipe(ItemInstance(Item::sugar, 1), //
|
||||
"#", //
|
||||
|
||||
definition('#', Item::reeds));
|
||||
|
||||
addShapedRecipe(ItemInstance(Tile::wood, 4), //
|
||||
"#", //
|
||||
|
||||
definition('#', Tile::treeTrunk));
|
||||
|
||||
addShapedRecipe(ItemInstance(Item::stick, 4), //
|
||||
"#", //
|
||||
"#", //
|
||||
|
||||
definition('#', Tile::wood));
|
||||
|
||||
addShapedRecipe(ItemInstance(Tile::torch, 4), //
|
||||
"X", //
|
||||
"#", //
|
||||
|
||||
definition( 'X', Item::coal,//
|
||||
'#', Item::stick));
|
||||
// torch made of charcoal
|
||||
addShapedRecipe(ItemInstance(Tile::torch, 4), //
|
||||
"X", //
|
||||
"#", //
|
||||
|
||||
definition( 'X', ItemInstance(Item::coal, 1, CoalItem::CHAR_COAL),//
|
||||
'#', Item::stick));
|
||||
|
||||
addShapedRecipe(ItemInstance(Item::bowl, 4), //
|
||||
"# #", //
|
||||
" # ", //
|
||||
|
||||
definition('#', Tile::wood));
|
||||
|
||||
//addShapedRecipe(ItemInstance(Item::glassBottle, 3), //
|
||||
// "# #", //
|
||||
// " # ", //
|
||||
|
||||
// '#', Tile::glass);
|
||||
|
||||
//addShapedRecipe(ItemInstance(Tile::rail, 16), //
|
||||
// "X X", //
|
||||
// "X#X", //
|
||||
// "X X", //
|
||||
|
||||
// definition( 'X', Item::ironIngot,//
|
||||
// '#', Item::stick));
|
||||
|
||||
//addShapedRecipe(ItemInstance(Tile::goldenRail, 6), //
|
||||
// "X X", //
|
||||
// "X#X", //
|
||||
// "XRX", //
|
||||
|
||||
// 'X', Item::goldIngot,//
|
||||
// 'R', Item::redStone,//
|
||||
// '#', Item::stick);
|
||||
|
||||
//addShapedRecipe(ItemInstance(Tile::detectorRail, 6), //
|
||||
// "X X", //
|
||||
// "X#X", //
|
||||
// "XRX", //
|
||||
|
||||
// 'X', Item::ironIngot,//
|
||||
// 'R', Item::redStone,//
|
||||
// '#', Tile::pressurePlate_stone);
|
||||
|
||||
//addShapedRecipe(ItemInstance(Item::minecart, 1), //
|
||||
// "# #", //
|
||||
// "###", //
|
||||
|
||||
// definition('#', Item::ironIngot));
|
||||
|
||||
//addShapedRecipe(ItemInstance(Item::cauldron, 1), //
|
||||
// "# #", //
|
||||
// "# #", //
|
||||
// "###", //
|
||||
|
||||
// '#', Item::ironIngot);
|
||||
|
||||
//addShapedRecipe(ItemInstance(Item::brewingStand, 1), //
|
||||
// " B ", //
|
||||
// "###", //
|
||||
|
||||
// '#', Tile::stoneBrick, 'B', Item::blazeRod);
|
||||
|
||||
//addShapedRecipe(ItemInstance(Tile::litPumpkin, 1), //
|
||||
// "A", //
|
||||
// "B", //
|
||||
|
||||
// definition('A', Tile::pumpkin, 'B', Tile::torch));
|
||||
|
||||
//addShapedRecipe(ItemInstance(Item::minecart_chest, 1), //
|
||||
// "A", //
|
||||
// "B", //
|
||||
|
||||
// definition('A', Tile::chest, 'B', Item::minecart));
|
||||
|
||||
//addShapedRecipe(ItemInstance(Item::minecart_furnace, 1), //
|
||||
// "A", //
|
||||
// "B", //
|
||||
|
||||
// definition('A', Tile::furnace, 'B', Item::minecart));
|
||||
|
||||
//addShapedRecipe(ItemInstance(Item::boat, 1), //
|
||||
// "# #", //
|
||||
// "###", //
|
||||
|
||||
// definition('#', Tile::wood));
|
||||
|
||||
//addShapedRecipe(ItemInstance(Item::bucket_empty, 1), //
|
||||
// "# #", //
|
||||
// " # ", //
|
||||
|
||||
// definition('#', Item::ironIngot));
|
||||
|
||||
addShapedRecipe(ItemInstance(Item::flintAndSteel, 1), //
|
||||
"A ", //
|
||||
" B", //
|
||||
|
||||
definition('A', Item::ironIngot, 'B', Item::flint));
|
||||
|
||||
addShapedRecipe(ItemInstance(Item::bread, 1), //
|
||||
"###", //
|
||||
|
||||
definition('#', Item::wheat));
|
||||
|
||||
addShapedRecipe(ItemInstance(Tile::stairs_wood, 4), //
|
||||
"# ", //
|
||||
"## ", //
|
||||
"###", //
|
||||
|
||||
definition('#', Tile::wood));
|
||||
|
||||
//addShapedRecipe(ItemInstance(Item::fishingRod, 1), //
|
||||
// " #", //
|
||||
// " #X", //
|
||||
// "# X", //
|
||||
|
||||
// definition('#', Item::stick, 'X', Item::string));
|
||||
|
||||
addShapedRecipe(ItemInstance(Tile::stairs_stone, 4), //
|
||||
"# ", //
|
||||
"## ", //
|
||||
"###", //
|
||||
|
||||
definition('#', Tile::stoneBrick));
|
||||
|
||||
addShapedRecipe(ItemInstance(Tile::stairs_brick, 4), //
|
||||
"# ", //
|
||||
"## ", //
|
||||
"###", //
|
||||
definition('#', Tile::redBrick));
|
||||
|
||||
addShapedRecipe(ItemInstance(Tile::stairs_stoneBrickSmooth, 4), //
|
||||
"# ", //
|
||||
"## ", //
|
||||
"###", //
|
||||
|
||||
definition('#', Tile::stoneBrickSmooth));
|
||||
|
||||
addShapedRecipe(ItemInstance(Tile::stairs_netherBricks, 4), //
|
||||
"# ", //
|
||||
"## ", //
|
||||
"###", //
|
||||
|
||||
definition('#', Tile::netherBrick));
|
||||
|
||||
addShapedRecipe(ItemInstance(Item::painting, 1), //
|
||||
"###", //
|
||||
"#X#", //
|
||||
"###", //
|
||||
|
||||
definition('#', Item::stick, 'X', Tile::cloth));
|
||||
|
||||
//addShapedRecipe(ItemInstance(Item::apple_gold, 1), //
|
||||
// "###", //
|
||||
// "#X#", //
|
||||
// "###", //
|
||||
|
||||
// definition('#', Tile::goldBlock, 'X', Item::apple));
|
||||
|
||||
//addShapedRecipe(ItemInstance(Tile::lever, 1), //
|
||||
// "X", //
|
||||
// "#", //
|
||||
|
||||
// definition('#', Tile::stoneBrick, 'X', Item::stick));
|
||||
|
||||
//addShapedRecipe(ItemInstance(Tile::notGate_on, 1), //
|
||||
// "X", //
|
||||
// "#", //
|
||||
|
||||
// definition('#', Item::stick, 'X', Item::redStone));
|
||||
|
||||
//addShapedRecipe(ItemInstance(Item::diode, 1), //
|
||||
// "#X#", //
|
||||
// "III", //
|
||||
|
||||
// definition('#', Tile::notGate_on, 'X', Item::redStone, 'I', Tile::rock));
|
||||
|
||||
|
||||
//addShapedRecipe(ItemInstance(Item::clock, 1), //
|
||||
// " # ", //
|
||||
// "#X#", //
|
||||
// " # ", //
|
||||
|
||||
// definition('#', Item::goldIngot, 'X', Item::redStone));
|
||||
|
||||
//addShapedRecipe(ItemInstance(Item::compass, 1), //
|
||||
// " # ", //
|
||||
// "#X#", //
|
||||
// " # ", //
|
||||
|
||||
// definition('#', Item::ironIngot, 'X', Item::redStone));
|
||||
|
||||
//addShapedRecipe(ItemInstance(Item::map, 1), //
|
||||
// "###", //
|
||||
// "#X#", //
|
||||
// "###", //
|
||||
|
||||
// '#', Item::paper, 'X', Item::compass);
|
||||
|
||||
//addShapedRecipe(ItemInstance(Tile::button, 1), //
|
||||
// "#", //
|
||||
// "#", //
|
||||
|
||||
// definition('#', Tile::rock));
|
||||
|
||||
|
||||
//addShapedRecipe(ItemInstance(Tile::pressurePlate_stone, 1), //
|
||||
// "##", //
|
||||
|
||||
// definition('#', Tile::rock));
|
||||
|
||||
//addShapedRecipe(ItemInstance(Tile::pressurePlate_wood, 1), //
|
||||
// "##", //
|
||||
|
||||
// definition('#', Tile::wood));
|
||||
|
||||
//addShapedRecipe(ItemInstance(Tile::dispenser, 1), //
|
||||
// "###", //
|
||||
// "#X#", //
|
||||
// "#R#", //
|
||||
|
||||
// definition('#', Tile::stoneBrick, 'X', Item::bow, 'R', Item::redStone));
|
||||
|
||||
//addShapedRecipe(ItemInstance(Tile::pistonBase, 1), //
|
||||
// "TTT", //
|
||||
// "#X#", //
|
||||
// "#R#", //
|
||||
|
||||
// '#', Tile::stoneBrick, 'X', Item::ironIngot, 'R', Item::redStone, 'T', Tile::wood);
|
||||
|
||||
//addShapedRecipe(ItemInstance(Tile::pistonStickyBase, 1), //
|
||||
// "S", //
|
||||
// "P", //
|
||||
|
||||
// 'S', Item::slimeBall, 'P', Tile::pistonBase);
|
||||
|
||||
addShapedRecipe(ItemInstance(Item::bed, 1), //
|
||||
"###", //
|
||||
"XXX", //
|
||||
definition('#', Tile::cloth, 'X', Tile::wood));
|
||||
|
||||
//addShapedRecipe(ItemInstance(Tile::enchantTable, 1), //
|
||||
// " B ", //
|
||||
// "D#D", //
|
||||
// "###", //
|
||||
|
||||
// '#', Tile::obsidian, 'B', Item::book, 'D', Item::emerald);
|
||||
|
||||
//addShapelessRecipe(ItemInstance(Item::eyeOfEnder, 1), //
|
||||
// Item::enderPearl, Item::blazePowder);
|
||||
addShapedRecipe(ItemInstance(Tile::netherReactor, 1), //
|
||||
"X#X", //
|
||||
"X#X", //
|
||||
"X#X", //
|
||||
|
||||
definition('#', Item::emerald, 'X', Item::ironIngot));
|
||||
|
||||
LOGI("%d recipes\n", (int)recipes.size());
|
||||
}
|
||||
|
||||
void Recipes::addShapedRecipe( const ItemInstance& result, const RowList& rows, const TypeList& types )
|
||||
{
|
||||
if (rows.empty()) {
|
||||
LOGE("Recipes::addShapedRecipe: adding an empty recipe!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string map = "";
|
||||
int width = rows[0].length();
|
||||
int height = rows.size();
|
||||
|
||||
for (unsigned int i = 0; i < rows.size(); ++i)
|
||||
map += rows[i];
|
||||
|
||||
typedef std::map<char, ItemInstance> Map;
|
||||
Map mappings;
|
||||
for (unsigned int i = 0; i < types.size(); i++) {
|
||||
const Type& type = types[i];
|
||||
char from = type.c;
|
||||
ItemInstance to;
|
||||
|
||||
if (type.item) {
|
||||
to = ItemInstance(type.item);
|
||||
} else if (type.tile) {
|
||||
to = ItemInstance(type.tile, 1, Recipe::ANY_AUX_VALUE);
|
||||
} else if (!type.itemInstance.isNull()) {
|
||||
to = type.itemInstance;
|
||||
}
|
||||
|
||||
mappings.insert(std::make_pair(from, to));
|
||||
}
|
||||
|
||||
ItemInstance* ids = new ItemInstance[width * height];
|
||||
|
||||
for (int i = 0; i < width * height; i++) {
|
||||
char ch = map[i];
|
||||
Map::iterator it = mappings.find(ch);
|
||||
if (it != mappings.end())
|
||||
ids[i] = it->second;
|
||||
}
|
||||
|
||||
// <ids> are deleted in ShapedRecipe
|
||||
recipes.push_back(new ShapedRecipe(width, height, ids, result));
|
||||
}
|
||||
|
||||
void Recipes::addShapedRecipe( const ItemInstance& result, const std::string& r0, const TypeList& types) {
|
||||
addShapedRecipe(result, Shape(r0), types);
|
||||
}
|
||||
|
||||
void Recipes::addShapedRecipe( const ItemInstance& result, const std::string& r0, const std::string& r1, const TypeList& types) {
|
||||
addShapedRecipe(result, Shape(r0, r1), types);
|
||||
}
|
||||
|
||||
void Recipes::addShapedRecipe( const ItemInstance& result, const std::string& r0, const std::string& r1, const std::string& r2, const TypeList& types) {
|
||||
addShapedRecipe(result, Shape(r0, r1, r2), types);
|
||||
}
|
||||
|
||||
void Recipes::addShapelessRecipe(const ItemInstance& result, const TypeList& types) {
|
||||
|
||||
std::vector<ItemInstance> ingredients;
|
||||
|
||||
for (unsigned int i = 0; i < types.size(); i++) {
|
||||
const Type& type = types[i];
|
||||
if (type.item) {
|
||||
ingredients.push_back( ItemInstance(type.item) );
|
||||
} else if (type.tile) {
|
||||
ingredients.push_back( ItemInstance(type.tile) );
|
||||
} else if (!type.itemInstance.isNull()) {
|
||||
ingredients.push_back( type.itemInstance );
|
||||
} else {
|
||||
LOGE("addShapeLessRecipe: Incorrect shapeless recipe!\n");
|
||||
}
|
||||
}
|
||||
|
||||
recipes.push_back(new ShapelessRecipe(result, ingredients));
|
||||
}
|
||||
|
||||
RowList Recipes::Shape( const std::string& r0 ) {
|
||||
RowList rows;
|
||||
rows.push_back(r0);
|
||||
return rows;
|
||||
}
|
||||
|
||||
RowList Recipes::Shape( const std::string& r0, const std::string& r1 ) {
|
||||
RowList rows;
|
||||
rows.push_back(r0);
|
||||
rows.push_back(r1);
|
||||
return rows;
|
||||
}
|
||||
|
||||
RowList Recipes::Shape( const std::string& r0, const std::string& r1, const std::string& r2 ) {
|
||||
RowList rows;
|
||||
rows.push_back(r0);
|
||||
rows.push_back(r1);
|
||||
rows.push_back(r2);
|
||||
return rows;
|
||||
}
|
||||
|
||||
Recipe* Recipes::getRecipeFor( const ItemInstance& result )
|
||||
{
|
||||
for (unsigned int i = 0; i < recipes.size(); ++i) {
|
||||
Recipe* recipe = recipes[i];
|
||||
ItemInstance res = recipe->getResultItem();
|
||||
if (result.id != res.id) continue;
|
||||
|
||||
if ( result.count == 0 && result.getAuxValue() == res.getAuxValue()
|
||||
|| (result.count == res.count && result.getAuxValue() == res.getAuxValue()))
|
||||
return recipe;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Recipes* Recipes::getInstance()
|
||||
{
|
||||
if (!instance)
|
||||
instance = new Recipes();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void Recipes::teardownRecipes()
|
||||
{
|
||||
if (instance) {
|
||||
delete instance;
|
||||
instance = NULL;
|
||||
}
|
||||
FurnaceRecipes::teardownFurnaceRecipes();
|
||||
}
|
||||
|
||||
const RecipeList& Recipes::getRecipes()
|
||||
{
|
||||
return recipes;
|
||||
}
|
||||
|
||||
ItemInstance Recipes::getItemFor( CraftingContainer* craftSlots )
|
||||
{
|
||||
int count = 0;
|
||||
ItemInstance* first;
|
||||
ItemInstance* second;
|
||||
for (int i = 0; i < craftSlots->getContainerSize(); i++) {
|
||||
ItemInstance* item = craftSlots->getItem(i);
|
||||
if (item) {
|
||||
if (count == 0) first = item;
|
||||
if (count == 1) second = item;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 2 && first->id == second->id && first->count == 1 && second->count == 1 && Item::items[first->id]->canBeDepleted()) {
|
||||
Item* item = Item::items[first->id];
|
||||
int remaining1 = item->getMaxDamage() - first->getDamageValue();
|
||||
int remaining2 = item->getMaxDamage() - second->getDamageValue();
|
||||
int remaining = (remaining1 + remaining2) + item->getMaxDamage() * 10 / 100;
|
||||
int resultDamage = item->getMaxDamage() - remaining;
|
||||
if (resultDamage < 0) resultDamage = 0;
|
||||
return ItemInstance(first->id, 1, resultDamage);
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < recipes.size(); i++) {
|
||||
Recipe* r = recipes[i];
|
||||
if (r->matches(craftSlots)) return r->assemble(craftSlots);
|
||||
}
|
||||
return ItemInstance();
|
||||
}
|
||||
|
||||
Recipes::~Recipes()
|
||||
{
|
||||
for (unsigned int i = 0; i < recipes.size(); ++i)
|
||||
delete recipes[i];
|
||||
}
|
||||
98
src/world/item/crafting/Recipes.h
Executable file
98
src/world/item/crafting/Recipes.h
Executable file
@@ -0,0 +1,98 @@
|
||||
#ifndef NET_MINECRAFT_WORLD_ITEM_CRAFTING__Recipes_H__
|
||||
#define NET_MINECRAFT_WORLD_ITEM_CRAFTING__Recipes_H__
|
||||
|
||||
//package net.minecraft.world.item.crafting;
|
||||
|
||||
#include "../Item.h"
|
||||
#include "../../inventory/CraftingContainer.h"
|
||||
#include "../../level/tile/Tile.h"
|
||||
|
||||
#include "Recipe.h"
|
||||
|
||||
typedef std::vector<std::string> RowList;
|
||||
typedef std::vector<Recipe*> RecipeList;
|
||||
|
||||
class Recipes
|
||||
{
|
||||
public:
|
||||
static Recipes* getInstance();
|
||||
const RecipeList& getRecipes();
|
||||
static void teardownRecipes();
|
||||
|
||||
class Type {
|
||||
public:
|
||||
Type(char c, Item* item)
|
||||
: c(c), item(item), tile(NULL) {}
|
||||
Type(char c, Tile* tile)
|
||||
: c(c), item(NULL), tile(tile) {}
|
||||
Type(char c, const ItemInstance& itemInstance)
|
||||
: c(c), item(NULL), tile(NULL), itemInstance(itemInstance) {}
|
||||
bool isItem() { return item != NULL; }
|
||||
Item* item;
|
||||
Tile* tile;
|
||||
ItemInstance itemInstance;
|
||||
char c;
|
||||
} ;//Type;
|
||||
|
||||
typedef std::vector<Type> TypeList;
|
||||
|
||||
static RowList Shape(const std::string& r0);
|
||||
static RowList Shape(const std::string& r0, const std::string& r1);
|
||||
static RowList Shape(const std::string& r0, const std::string& r1, const std::string& r2);
|
||||
|
||||
void addShapedRecipe(const ItemInstance& result, const std::string& r0, const TypeList& types);
|
||||
void addShapedRecipe(const ItemInstance& result, const std::string& r0, const std::string&, const TypeList& types);
|
||||
void addShapedRecipe(const ItemInstance& result, const std::string& r0, const std::string& r1, const std::string& r2, const TypeList& types);
|
||||
|
||||
void addShapedRecipe(const ItemInstance& result, const RowList& rows, const TypeList& types);
|
||||
|
||||
void addShapelessRecipe(const ItemInstance& result, const TypeList& types);
|
||||
|
||||
Recipe* getRecipeFor(const ItemInstance& result);
|
||||
private:
|
||||
Recipes();
|
||||
~Recipes();
|
||||
|
||||
ItemInstance getItemFor(CraftingContainer* craftSlots);
|
||||
private:
|
||||
static Recipes* instance;
|
||||
RecipeList recipes;
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
Recipes::TypeList definition(char c0, T t) {
|
||||
Recipes::TypeList list;
|
||||
list.push_back(Recipes::Type(c0, t));
|
||||
return list;
|
||||
}
|
||||
|
||||
template <class T, class U>
|
||||
Recipes::TypeList definition(char c0, T t, char c1, U u) {
|
||||
Recipes::TypeList list;
|
||||
list.push_back(Recipes::Type(c0, t));
|
||||
list.push_back(Recipes::Type(c1, u));
|
||||
return list;
|
||||
}
|
||||
|
||||
template <class T, class U, class V>
|
||||
Recipes::TypeList definition(char c0, T t, char c1, U u, char c2, V v) {
|
||||
Recipes::TypeList list;
|
||||
list.push_back(Recipes::Type(c0, t));
|
||||
list.push_back(Recipes::Type(c1, u));
|
||||
list.push_back(Recipes::Type(c2, v));
|
||||
return list;
|
||||
}
|
||||
|
||||
template <class T, class U, class V, class W>
|
||||
Recipes::TypeList definition(char c0, T t, char c1, U u, char c2, V v, char c3, W w) {
|
||||
Recipes::TypeList list;
|
||||
list.push_back(Recipes::Type(c0, t));
|
||||
list.push_back(Recipes::Type(c1, u));
|
||||
list.push_back(Recipes::Type(c2, v));
|
||||
list.push_back(Recipes::Type(c3, w));
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
#endif /*NET_MINECRAFT_WORLD_ITEM_CRAFTING__Recipes_H__*/
|
||||
105
src/world/item/crafting/ShapedRecipe.h
Executable file
105
src/world/item/crafting/ShapedRecipe.h
Executable file
@@ -0,0 +1,105 @@
|
||||
#ifndef NET_MINECRAFT_WORLD_ITEM_CRAFTING__ShapedRecipe_H__
|
||||
#define NET_MINECRAFT_WORLD_ITEM_CRAFTING__ShapedRecipe_H__
|
||||
|
||||
//package net.minecraft.world.item.crafting;
|
||||
|
||||
#include "../../inventory/CraftingContainer.h"
|
||||
#include "../ItemInstance.h"
|
||||
#include "Recipe.h"
|
||||
|
||||
class ShapedRecipe: public Recipe
|
||||
{
|
||||
public:
|
||||
ShapedRecipe(int width, int height, ItemInstance* recipeItems, const ItemInstance& result)
|
||||
: width(width),
|
||||
height(height),
|
||||
recipeItems(recipeItems),
|
||||
resultId(result.id),
|
||||
result(result)
|
||||
//@todo: move slots to upper left
|
||||
{
|
||||
for (int i = 0; i < width * height; ++i)
|
||||
if (!recipeItems[i].isNull())
|
||||
myItems.add( ItemPack::getIdForItemInstance(&recipeItems[i]));
|
||||
}
|
||||
|
||||
~ShapedRecipe() {
|
||||
delete[] recipeItems;
|
||||
}
|
||||
|
||||
int getMaxCraftCount(ItemPack& fromItems) {
|
||||
|
||||
int count = fromItems.getMaxMultipliesOf(myItems);
|
||||
return count;
|
||||
|
||||
|
||||
//return (int)(Mth::random() * Mth::random() * 5);
|
||||
}
|
||||
|
||||
ItemInstance getResultItem() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
bool matches(CraftingContainer* craftSlots) {
|
||||
for (int xOffs = 0; xOffs <= (3 - width); xOffs++) {
|
||||
for (int yOffs = 0; yOffs <= (3 - height); yOffs++) {
|
||||
if (matches(craftSlots, xOffs, yOffs, true)) return true;
|
||||
if (matches(craftSlots, xOffs, yOffs, false)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemInstance assemble(CraftingContainer* craftSlots) {
|
||||
return ItemInstance(result.id, result.count, result.getAuxValue());
|
||||
}
|
||||
|
||||
int size() {
|
||||
return width * height;
|
||||
}
|
||||
|
||||
virtual std::vector<ItemInstance> getItems() {
|
||||
std::vector<ItemInstance> out;
|
||||
return out;
|
||||
}
|
||||
|
||||
private:
|
||||
bool matches(CraftingContainer* craftSlots, int xOffs, int yOffs, bool xFlip) {
|
||||
for (int x = 0; x < 3; x++) {
|
||||
for (int y = 0; y < 3; y++) {
|
||||
int xs = x - xOffs;
|
||||
int ys = y - yOffs;
|
||||
ItemInstance expected;
|
||||
if (xs >= 0 && ys >= 0 && xs < width && ys < height) {
|
||||
if (xFlip) expected = recipeItems[(width - xs - 1) + ys * width];
|
||||
else expected = recipeItems[xs + ys * width];
|
||||
}
|
||||
ItemInstance* item = craftSlots->getItem(x, y);
|
||||
if (!item && expected.isNull())
|
||||
continue;
|
||||
if ((item == NULL) ^ expected.isNull())
|
||||
return false;
|
||||
if (expected.id != item->id)
|
||||
return false;
|
||||
if (expected.getAuxValue() != Recipe::ANY_AUX_VALUE && expected.getAuxValue() != item->getAuxValue())
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int getCraftingSize() {
|
||||
return (width <= 2 && height <= 2)? SIZE_2X2 : SIZE_3X3;
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
const int resultId;
|
||||
private:
|
||||
int width, height;
|
||||
ItemInstance* recipeItems;
|
||||
ItemInstance result;
|
||||
//ItemPack myItems;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_WORLD_ITEM_CRAFTING__ShapedRecipe_H__*/
|
||||
83
src/world/item/crafting/ShapelessRecipe.h
Executable file
83
src/world/item/crafting/ShapelessRecipe.h
Executable file
@@ -0,0 +1,83 @@
|
||||
#ifndef NET_MINECRAFT_WORLD_ITEM_CRAFTING__ShapelessRecipe_H__
|
||||
#define NET_MINECRAFT_WORLD_ITEM_CRAFTING__ShapelessRecipe_H__
|
||||
|
||||
//package net.minecraft.world.item.crafting;
|
||||
|
||||
#include "Recipe.h"
|
||||
#include "../ItemInstance.h"
|
||||
#include "../../inventory/CraftingContainer.h"
|
||||
|
||||
class ShapelessRecipe: public Recipe
|
||||
{
|
||||
typedef std::vector<ItemInstance> Ingredients;
|
||||
public:
|
||||
ShapelessRecipe(ItemInstance result, const Ingredients& ingredients)
|
||||
: result(result),
|
||||
ingredients(ingredients)
|
||||
{
|
||||
for (unsigned int i = 0; i < ingredients.size(); ++i)
|
||||
if (!ingredients[i].isNull())
|
||||
myItems.add( ItemPack::getIdForItemInstance(&ingredients[i]) );
|
||||
}
|
||||
|
||||
ItemInstance getResultItem() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
int getMaxCraftCount(ItemPack& fromItems) {
|
||||
int count = fromItems.getMaxMultipliesOf(myItems);
|
||||
return count;
|
||||
//return (int)(Mth::random() * Mth::random() * 5);
|
||||
}
|
||||
|
||||
bool matches(CraftingContainer* craftSlots) {
|
||||
|
||||
Ingredients tempList = ingredients;
|
||||
|
||||
for (int y = 0; y < 3; y++) {
|
||||
for (int x = 0; x < 3; x++) {
|
||||
ItemInstance* item = craftSlots->getItem(x, y);
|
||||
|
||||
if (item) {
|
||||
bool found = false;
|
||||
for (unsigned int i = 0; i < ingredients.size(); ++i) {
|
||||
const ItemInstance& ingredient = ingredients[i];
|
||||
if (item->id == ingredient.id && (ingredient.getAuxValue() == Recipe::ANY_AUX_VALUE || item->getAuxValue() == ingredient.getAuxValue())) {
|
||||
found = true;
|
||||
|
||||
Ingredients::iterator it = std::find(tempList.begin(), tempList.end(), ingredient);
|
||||
if (it != tempList.end())
|
||||
tempList.erase(it);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tempList.empty();
|
||||
}
|
||||
|
||||
ItemInstance assemble(CraftingContainer* craftSlots) {
|
||||
return result;
|
||||
}
|
||||
|
||||
int size() {
|
||||
return (int)ingredients.size();
|
||||
}
|
||||
|
||||
int getCraftingSize() {
|
||||
return (ingredients.size() > 4)? SIZE_3X3 : SIZE_2X2;
|
||||
}
|
||||
|
||||
private:
|
||||
const ItemInstance result;
|
||||
const Ingredients ingredients;
|
||||
//ItemPack myItems;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_WORLD_ITEM_CRAFTING__ShapelessRecipe_H__*/
|
||||
1
src/world/item/crafting/StructureRecipes.cpp
Executable file
1
src/world/item/crafting/StructureRecipes.cpp
Executable file
@@ -0,0 +1 @@
|
||||
#include "StructureRecipes.h"
|
||||
100
src/world/item/crafting/StructureRecipes.h
Executable file
100
src/world/item/crafting/StructureRecipes.h
Executable file
@@ -0,0 +1,100 @@
|
||||
#ifndef NET_MINECRAFT_WORLD_ITEM_CRAFTING__StructureRecipes_H__
|
||||
#define NET_MINECRAFT_WORLD_ITEM_CRAFTING__StructureRecipes_H__
|
||||
|
||||
//package net.minecraft.world.item.crafting;
|
||||
|
||||
/* import net.minecraft.world.item.* */
|
||||
#include "Recipes.h"
|
||||
#include "../../level/tile/Tile.h"
|
||||
#include "../../level/tile/SandStoneTile.h"
|
||||
#include "../../level/tile/StoneSlabTile.h"
|
||||
|
||||
class StructureRecipes
|
||||
{
|
||||
public:
|
||||
static void addRecipes(Recipes* r) {
|
||||
r->addShapedRecipe(ItemInstance(Tile::chest), //
|
||||
"###", //
|
||||
"# #", //
|
||||
"###", //
|
||||
|
||||
definition('#', Tile::wood));
|
||||
|
||||
r->addShapedRecipe(ItemInstance(Tile::furnace), //
|
||||
"###", //
|
||||
"# #", //
|
||||
"###", //
|
||||
|
||||
definition('#', Tile::stoneBrick));
|
||||
|
||||
r->addShapedRecipe(ItemInstance(Tile::workBench), //
|
||||
"##", //
|
||||
"##", //
|
||||
|
||||
definition('#', Tile::wood));
|
||||
|
||||
r->addShapedRecipe(ItemInstance(Tile::stonecutterBench), //
|
||||
"##", //
|
||||
"##", //
|
||||
|
||||
definition('#', Tile::stoneBrick));
|
||||
|
||||
|
||||
r->addShapedRecipe(ItemInstance(Tile::sandStone), //
|
||||
"##", //
|
||||
"##", //
|
||||
|
||||
definition('#', Tile::sand));
|
||||
|
||||
r->addShapedRecipe(ItemInstance(Tile::sandStone, 4, SandStoneTile::TYPE_SMOOTHSIDE), //
|
||||
"##", //
|
||||
"##", //
|
||||
|
||||
definition('#', Tile::sandStone));
|
||||
|
||||
r->addShapedRecipe(ItemInstance(Tile::sandStone, 1, SandStoneTile::TYPE_HEIROGLYPHS), //
|
||||
"#", //
|
||||
"#", //
|
||||
|
||||
definition('#', ItemInstance(Tile::stoneSlabHalf, 1, StoneSlabTile::SAND_SLAB)));
|
||||
|
||||
r->addShapedRecipe(ItemInstance(Tile::stoneBrickSmooth, 4), //
|
||||
"##", //
|
||||
"##", //
|
||||
|
||||
definition('#', Tile::rock));
|
||||
|
||||
//r->addShapedRecipe(ItemInstance(Tile::ironFence, 16), //
|
||||
// "###", //
|
||||
// "###", //
|
||||
|
||||
// definition('#', Item::ironIngot));
|
||||
|
||||
r->addShapedRecipe(ItemInstance(Tile::thinGlass, 16), //
|
||||
"###", //
|
||||
"###", //
|
||||
|
||||
definition('#', Tile::glass));
|
||||
|
||||
r->addShapedRecipe(ItemInstance(Tile::netherBrick, 1), //
|
||||
"NN", //
|
||||
"NN", //
|
||||
|
||||
definition('N', Item::netherbrick));
|
||||
|
||||
r->addShapedRecipe(ItemInstance(Tile::quartzBlock, 1), //
|
||||
"NN", //
|
||||
"NN", //
|
||||
|
||||
definition('N', Item::netherQuartz));
|
||||
|
||||
//r->addShapedRecipe(ItemInstance(Tile::redstoneLight, 1), //
|
||||
// " R ", //
|
||||
// "RGR", //
|
||||
// " R ", //
|
||||
|
||||
// definition('R', Item::redStone, 'G', Tile::lightGem));
|
||||
}
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_WORLD_ITEM_CRAFTING__StructureRecipes_H__*/
|
||||
59
src/world/item/crafting/ToolRecipes.cpp
Executable file
59
src/world/item/crafting/ToolRecipes.cpp
Executable file
@@ -0,0 +1,59 @@
|
||||
#include "ToolRecipes.h"
|
||||
#include "Recipes.h"
|
||||
#include "../ShearsItem.h"
|
||||
#include "../../level/tile/Tile.h"
|
||||
|
||||
|
||||
static RowList shapes[] = {
|
||||
Recipes::Shape( "XXX", //
|
||||
" # ",//
|
||||
" # "),//
|
||||
|
||||
Recipes::Shape( "X",//
|
||||
"#",//
|
||||
"#"),//
|
||||
|
||||
Recipes::Shape( "XX",//
|
||||
"X#",//
|
||||
" #"),//
|
||||
|
||||
Recipes::Shape( "XX",//
|
||||
" #",//
|
||||
" #")//
|
||||
};
|
||||
|
||||
void ToolRecipes::addRecipes( Recipes* r )
|
||||
{
|
||||
int materialIds[] = {Tile::wood->id, Tile::stoneBrick->id, Item::ironIngot->id, Item::emerald->id, Item::goldIngot->id};
|
||||
const int NumMaterials = sizeof(materialIds) / sizeof(int);
|
||||
const int NumRecipes = sizeof(shapes) / sizeof(RowList);
|
||||
|
||||
Item* map[NumRecipes][NumMaterials] = {
|
||||
{Item::pickAxe_wood, Item::pickAxe_stone, Item::pickAxe_iron, Item::pickAxe_emerald, Item::pickAxe_gold},
|
||||
{Item::shovel_wood, Item::shovel_stone, Item::shovel_iron, Item::shovel_emerald, Item::shovel_gold},
|
||||
{Item::hatchet_wood, Item::hatchet_stone, Item::hatchet_iron, Item::hatchet_emerald, Item::hatchet_gold},
|
||||
{Item::hoe_wood, Item::hoe_stone, Item::hoe_iron, Item::hoe_emerald, Item::hoe_gold},
|
||||
};
|
||||
|
||||
//const int OVERRIDDEN_MaterialCount = 2;
|
||||
for (int m = 0; m < NumMaterials; m++) {
|
||||
int mId = materialIds[m];
|
||||
for (int t = 0; t < NumRecipes; t++) {
|
||||
Item* target = (Item*) map[t][m];
|
||||
|
||||
if (mId < 256) { // Tile
|
||||
r->addShapedRecipe( ItemInstance(target), shapes[t],
|
||||
definition('#', Item::stick, 'X', Tile::tiles[mId]) );
|
||||
} else { // Item
|
||||
r->addShapedRecipe( ItemInstance(target), shapes[t],
|
||||
definition('#', Item::stick, 'X', Item::items[mId]) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
r->addShapedRecipe( ItemInstance(Item::shears), //
|
||||
" #", //
|
||||
"# ", //
|
||||
|
||||
definition('#', Item::ironIngot));
|
||||
}
|
||||
14
src/world/item/crafting/ToolRecipes.h
Executable file
14
src/world/item/crafting/ToolRecipes.h
Executable file
@@ -0,0 +1,14 @@
|
||||
#ifndef NET_MINECRAFT_WORLD_ITEM_CRAFTING__ToolRecipes_H__
|
||||
#define NET_MINECRAFT_WORLD_ITEM_CRAFTING__ToolRecipes_H__
|
||||
|
||||
//package net.minecraft.world.item.crafting;
|
||||
|
||||
class Recipes;
|
||||
|
||||
class ToolRecipes
|
||||
{
|
||||
public:
|
||||
static void addRecipes(Recipes* r);
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_WORLD_ITEM_CRAFTING__ToolRecipes_H__*/
|
||||
49
src/world/item/crafting/WeaponRecipes.cpp
Executable file
49
src/world/item/crafting/WeaponRecipes.cpp
Executable file
@@ -0,0 +1,49 @@
|
||||
#include "WeaponRecipes.h"
|
||||
|
||||
static RowList shapes[] = {
|
||||
Recipes::Shape( "X", //
|
||||
"X",//
|
||||
"#"),//
|
||||
};
|
||||
|
||||
void WeaponRecipes::addRecipes( Recipes* r )
|
||||
{
|
||||
int materialIds[] = {Tile::wood->id, Tile::stoneBrick->id, Item::ironIngot->id, Item::emerald->id, Item::goldIngot->id};
|
||||
const int NumMaterials = sizeof(materialIds) / sizeof(int);
|
||||
const int NumRecipes = sizeof(shapes) / sizeof(RowList);
|
||||
|
||||
Item* map[NumRecipes][NumMaterials] = {
|
||||
{Item::sword_wood, Item::sword_stone, Item::sword_iron, Item::sword_emerald, Item::sword_gold},
|
||||
};
|
||||
|
||||
//const int OVERRIDDEN_MaterialCount = 2;
|
||||
for (int m = 0; m < NumMaterials; m++) {
|
||||
int mId = materialIds[m];
|
||||
for (int t = 0; t < NumRecipes; t++) {
|
||||
Item* target = (Item*) map[t][m];
|
||||
|
||||
if (mId < 256) { // Tile
|
||||
r->addShapedRecipe( ItemInstance(target), shapes[t],
|
||||
definition('#', Item::stick, 'X', Tile::tiles[mId]) );
|
||||
} else { // Item
|
||||
r->addShapedRecipe( ItemInstance(target), shapes[t],
|
||||
definition('#', Item::stick, 'X', Item::items[mId]) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
r->addShapedRecipe(ItemInstance(Item::bow, 1), //
|
||||
" #X", //
|
||||
"# X", //
|
||||
" #X", //
|
||||
definition( 'X', Item::string,//
|
||||
'#', Item::stick));
|
||||
|
||||
r->addShapedRecipe(ItemInstance(Item::arrow, 4), //
|
||||
"X", //
|
||||
"#", //
|
||||
"Y", //
|
||||
definition( 'Y', Item::feather,//
|
||||
'X', Item::flint,//
|
||||
'#', Item::stick));
|
||||
}
|
||||
15
src/world/item/crafting/WeaponRecipes.h
Executable file
15
src/world/item/crafting/WeaponRecipes.h
Executable file
@@ -0,0 +1,15 @@
|
||||
#ifndef NET_MINECRAFT_WORLD_ITEM_CRAFTING__WeaponRecipes_H__
|
||||
#define NET_MINECRAFT_WORLD_ITEM_CRAFTING__WeaponRecipes_H__
|
||||
|
||||
//package net.minecraft.world.item.crafting;
|
||||
|
||||
#include "Recipes.h"
|
||||
#include "../../level/tile/Tile.h"
|
||||
|
||||
class WeaponRecipes
|
||||
{
|
||||
public:
|
||||
static void addRecipes( Recipes* r );
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_WORLD_ITEM_CRAFTING__WeaponRecipes_H__*/
|
||||
Reference in New Issue
Block a user