1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Created and moved stuff to content_nodemeta.{h,cpp}

This commit is contained in:
Perttu Ahola 2011-06-18 00:46:50 +03:00
parent e7580d2804
commit da692355e8
10 changed files with 938 additions and 851 deletions

View file

@ -32,6 +32,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "servercommand.h"
#include "filesys.h"
#include "content_mapnode.h"
#include "content_craft.h"
#include "content_nodemeta.h"
#define BLOCK_EMERGE_FLAG_FROMDISK (1<<0)
@ -3828,334 +3830,10 @@ void Server::UpdateCrafting(u16 peer_id)
items[i] = clist->getItem(i);
}
bool found = false;
// Wood
if(!found)
{
ItemSpec specs[9];
specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_TREE);
if(checkItemCombination(items, specs))
{
rlist->addItem(new MaterialItem(CONTENT_WOOD, 4));
found = true;
}
}
// Stick
if(!found)
{
ItemSpec specs[9];
specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
if(checkItemCombination(items, specs))
{
rlist->addItem(new CraftItem("Stick", 4));
found = true;
}
}
// Fence
if(!found)
{
ItemSpec specs[9];
specs[3] = ItemSpec(ITEM_CRAFT, "Stick");
specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
specs[5] = ItemSpec(ITEM_CRAFT, "Stick");
specs[6] = ItemSpec(ITEM_CRAFT, "Stick");
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
specs[8] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
rlist->addItem(new MaterialItem(CONTENT_FENCE, 2));
found = true;
}
}
// Sign
if(!found)
{
ItemSpec specs[9];
specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
specs[4] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
//rlist->addItem(new MapBlockObjectItem("Sign"));
rlist->addItem(new MaterialItem(CONTENT_SIGN_WALL, 1));
found = true;
}
}
// Torch
if(!found)
{
ItemSpec specs[9];
specs[0] = ItemSpec(ITEM_CRAFT, "lump_of_coal");
specs[3] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
rlist->addItem(new MaterialItem(CONTENT_TORCH, 4));
found = true;
}
}
// Wooden pick
if(!found)
{
ItemSpec specs[9];
specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
rlist->addItem(new ToolItem("WPick", 0));
found = true;
}
}
// Stone pick
if(!found)
{
ItemSpec specs[9];
specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
rlist->addItem(new ToolItem("STPick", 0));
found = true;
}
}
// Steel pick
if(!found)
{
ItemSpec specs[9];
specs[0] = ItemSpec(ITEM_CRAFT, "steel_ingot");
specs[1] = ItemSpec(ITEM_CRAFT, "steel_ingot");
specs[2] = ItemSpec(ITEM_CRAFT, "steel_ingot");
specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
rlist->addItem(new ToolItem("SteelPick", 0));
found = true;
}
}
// Mese pick
if(!found)
{
ItemSpec specs[9];
specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_MESE);
specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_MESE);
specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_MESE);
specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
rlist->addItem(new ToolItem("MesePick", 0));
found = true;
}
}
// Wooden shovel
if(!found)
{
ItemSpec specs[9];
specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
rlist->addItem(new ToolItem("WShovel", 0));
found = true;
}
}
// Stone shovel
if(!found)
{
ItemSpec specs[9];
specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
rlist->addItem(new ToolItem("STShovel", 0));
found = true;
}
}
// Steel shovel
if(!found)
{
ItemSpec specs[9];
specs[1] = ItemSpec(ITEM_CRAFT, "steel_ingot");
specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
rlist->addItem(new ToolItem("SteelShovel", 0));
found = true;
}
}
// Wooden axe
if(!found)
{
ItemSpec specs[9];
specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
rlist->addItem(new ToolItem("WAxe", 0));
found = true;
}
}
// Stone axe
if(!found)
{
ItemSpec specs[9];
specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
rlist->addItem(new ToolItem("STAxe", 0));
found = true;
}
}
// Steel axe
if(!found)
{
ItemSpec specs[9];
specs[0] = ItemSpec(ITEM_CRAFT, "steel_ingot");
specs[1] = ItemSpec(ITEM_CRAFT, "steel_ingot");
specs[3] = ItemSpec(ITEM_CRAFT, "steel_ingot");
specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
rlist->addItem(new ToolItem("SteelAxe", 0));
found = true;
}
}
// Wooden sword
if(!found)
{
ItemSpec specs[9];
specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
specs[4] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
rlist->addItem(new ToolItem("WSword", 0));
found = true;
}
}
// Stone sword
if(!found)
{
ItemSpec specs[9];
specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
specs[4] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
rlist->addItem(new ToolItem("STSword", 0));
found = true;
}
}
// Steel sword
if(!found)
{
ItemSpec specs[9];
specs[1] = ItemSpec(ITEM_CRAFT, "steel_ingot");
specs[4] = ItemSpec(ITEM_CRAFT, "steel_ingot");
specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs))
{
rlist->addItem(new ToolItem("SteelSword", 0));
found = true;
}
}
// Chest
if(!found)
{
ItemSpec specs[9];
specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
specs[6] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
if(checkItemCombination(items, specs))
{
rlist->addItem(new MaterialItem(CONTENT_CHEST, 1));
found = true;
}
}
// Furnace
if(!found)
{
ItemSpec specs[9];
specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
specs[6] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
if(checkItemCombination(items, specs))
{
rlist->addItem(new MaterialItem(CONTENT_FURNACE, 1));
found = true;
}
}
// Steel block
if(!found)
{
ItemSpec specs[9];
specs[0] = ItemSpec(ITEM_CRAFT, "steel_ingot");
specs[1] = ItemSpec(ITEM_CRAFT, "steel_ingot");
specs[2] = ItemSpec(ITEM_CRAFT, "steel_ingot");
specs[3] = ItemSpec(ITEM_CRAFT, "steel_ingot");
specs[4] = ItemSpec(ITEM_CRAFT, "steel_ingot");
specs[5] = ItemSpec(ITEM_CRAFT, "steel_ingot");
specs[6] = ItemSpec(ITEM_CRAFT, "steel_ingot");
specs[7] = ItemSpec(ITEM_CRAFT, "steel_ingot");
specs[8] = ItemSpec(ITEM_CRAFT, "steel_ingot");
if(checkItemCombination(items, specs))
{
rlist->addItem(new MaterialItem(CONTENT_STEEL, 1));
found = true;
}
}
// Get result of crafting grid
InventoryItem *result = craft_get_result(items);
if(result)
rlist->addItem(result);
}
} // if creative_mode == false
@ -4206,97 +3884,6 @@ std::wstring Server::getStatusString()
return os.str();
}
void setCreativeInventory(Player *player)
{
player->resetInventory();
// Give some good tools
{
InventoryItem *item = new ToolItem("MesePick", 0);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
{
InventoryItem *item = new ToolItem("SteelPick", 0);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
{
InventoryItem *item = new ToolItem("SteelAxe", 0);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
{
InventoryItem *item = new ToolItem("SteelShovel", 0);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
/*
Give materials
*/
// CONTENT_IGNORE-terminated list
u8 material_items[] = {
CONTENT_TORCH,
CONTENT_COBBLE,
CONTENT_MUD,
CONTENT_STONE,
CONTENT_SAND,
CONTENT_TREE,
CONTENT_LEAVES,
CONTENT_GLASS,
CONTENT_FENCE,
CONTENT_MESE,
CONTENT_WATERSOURCE,
CONTENT_CLOUD,
CONTENT_CHEST,
CONTENT_FURNACE,
CONTENT_SIGN_WALL,
CONTENT_IGNORE
};
u8 *mip = material_items;
for(u16 i=0; i<PLAYER_INVENTORY_SIZE; i++)
{
if(*mip == CONTENT_IGNORE)
break;
InventoryItem *item = new MaterialItem(*mip, 1);
player->inventory.addItem("main", item);
mip++;
}
#if 0
assert(USEFUL_CONTENT_COUNT <= PLAYER_INVENTORY_SIZE);
// add torch first
InventoryItem *item = new MaterialItem(CONTENT_TORCH, 1);
player->inventory.addItem("main", item);
// Then others
for(u16 i=0; i<USEFUL_CONTENT_COUNT; i++)
{
// Skip some materials
if(i == CONTENT_WATER || i == CONTENT_TORCH
|| i == CONTENT_COALSTONE)
continue;
InventoryItem *item = new MaterialItem(i, 1);
player->inventory.addItem("main", item);
}
#endif
/*// Sign
{
InventoryItem *item = new MapBlockObjectItem("Sign Example text");
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}*/
}
v3f findSpawnPos(ServerMap &map)
{
//return v3f(50,50,50)*BS;
@ -4366,7 +3953,7 @@ Player *Server::emergePlayer(const char *name, const char *password, u16 peer_id
// Reset inventory to creative if in creative mode
if(g_settings.getBool("creative_mode"))
{
setCreativeInventory(player);
craft_set_creative_inventory(player);
}
return player;
@ -4419,78 +4006,11 @@ Player *Server::emergePlayer(const char *name, const char *password, u16 peer_id
if(g_settings.getBool("creative_mode"))
{
setCreativeInventory(player);
craft_set_creative_inventory(player);
}
else if(g_settings.getBool("give_initial_stuff"))
{
{
InventoryItem *item = new ToolItem("SteelPick", 0);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
{
InventoryItem *item = new MaterialItem(CONTENT_TORCH, 99);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
{
InventoryItem *item = new ToolItem("SteelAxe", 0);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
{
InventoryItem *item = new ToolItem("SteelShovel", 0);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
{
InventoryItem *item = new MaterialItem(CONTENT_COBBLE, 99);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
/*{
InventoryItem *item = new MaterialItem(CONTENT_MESE, 6);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
{
InventoryItem *item = new MaterialItem(CONTENT_COALSTONE, 6);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
{
InventoryItem *item = new MaterialItem(CONTENT_WOOD, 6);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
{
InventoryItem *item = new CraftItem("Stick", 4);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
{
InventoryItem *item = new ToolItem("WPick", 32000);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}
{
InventoryItem *item = new ToolItem("STPick", 32000);
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
}*/
/*// and some signs
for(u16 i=0; i<4; i++)
{
InventoryItem *item = new MapBlockObjectItem("Sign Example text");
bool r = player->inventory.addItem("main", item);
assert(r == true);
}*/
/*// Give some other stuff
{
InventoryItem *item = new MaterialItem(CONTENT_TREE, 999);
bool r = player->inventory.addItem("main", item);
assert(r == true);
}*/
craft_give_initial_stuff(player);
}
return player;