Create framework for getting rid of global definitions of node/tool/item/whatever types

This commit is contained in:
Perttu Ahola 2011-11-14 00:19:48 +02:00
parent 5fc791ac9a
commit abceeee92f
60 changed files with 1017 additions and 743 deletions

@ -94,6 +94,7 @@ configure_file(
) )
set(common_SRCS set(common_SRCS
content_tool.cpp
tool.cpp tool.cpp
mapnode_contentfeatures.cpp mapnode_contentfeatures.cpp
luaentity_common.cpp luaentity_common.cpp

@ -449,7 +449,7 @@ void Camera::updateSettings()
m_wanted_frametime = 1.0 / wanted_fps; m_wanted_frametime = 1.0 / wanted_fps;
} }
void Camera::wield(const InventoryItem* item) void Camera::wield(const InventoryItem* item, ITextureSource *tsrc)
{ {
if (item != NULL) if (item != NULL)
{ {
@ -472,7 +472,7 @@ void Camera::wield(const InventoryItem* item)
// If that failed, make an extruded sprite. // If that failed, make an extruded sprite.
if (!isCube) if (!isCube)
{ {
m_wieldnode->setSprite(item->getImageRaw()); m_wieldnode->setSprite(item->getImageRaw(tsrc));
m_wieldnode->setScale(v3f(40)); m_wieldnode->setScale(v3f(40));
} }

@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
class LocalPlayer; class LocalPlayer;
class MapDrawControl; class MapDrawControl;
class ExtrudedSpriteSceneNode; class ExtrudedSpriteSceneNode;
class ITextureSource;
/* /*
Client camera class, manages the player and camera scene nodes, the viewing distance Client camera class, manages the player and camera scene nodes, the viewing distance
@ -115,7 +116,7 @@ public:
void updateSettings(); void updateSettings();
// Replace the wielded item mesh // Replace the wielded item mesh
void wield(const InventoryItem* item); void wield(const InventoryItem* item, ITextureSource *tsrc);
// Start digging animation // Start digging animation
// Pass 0 for left click, 1 for right click // Pass 0 for left click, 1 for right click

@ -160,7 +160,7 @@ void * MeshUpdateThread::Thread()
ScopeProfiler sp(g_profiler, "Client: Mesh making"); ScopeProfiler sp(g_profiler, "Client: Mesh making");
scene::SMesh *mesh_new = NULL; scene::SMesh *mesh_new = NULL;
mesh_new = makeMapBlockMesh(q->data); mesh_new = makeMapBlockMesh(q->data, m_tsrc);
MeshUpdateResult r; MeshUpdateResult r;
r.p = q->p; r.p = q->p;
@ -185,13 +185,18 @@ Client::Client(
IrrlichtDevice *device, IrrlichtDevice *device,
const char *playername, const char *playername,
std::string password, std::string password,
MapDrawControl &control): MapDrawControl &control,
m_mesh_update_thread(), ITextureSource *tsrc,
IToolDefManager *toolmgr):
m_tsrc(tsrc),
m_toolmgr(toolmgr),
m_mesh_update_thread(tsrc),
m_env( m_env(
new ClientMap(this, control, new ClientMap(this, this, control,
device->getSceneManager()->getRootSceneNode(), device->getSceneManager()->getRootSceneNode(),
device->getSceneManager(), 666), device->getSceneManager(), 666),
device->getSceneManager() device->getSceneManager(),
tsrc, this
), ),
m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, this), m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, this),
m_device(device), m_device(device),
@ -863,7 +868,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
Update an existing block Update an existing block
*/ */
//infostream<<"Updating"<<std::endl; //infostream<<"Updating"<<std::endl;
block->deSerialize(istr, ser_version); block->deSerialize(istr, ser_version, this);
} }
else else
{ {
@ -872,7 +877,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
*/ */
//infostream<<"Creating new"<<std::endl; //infostream<<"Creating new"<<std::endl;
block = new MapBlock(&m_env.getMap(), p); block = new MapBlock(&m_env.getMap(), p);
block->deSerialize(istr, ser_version); block->deSerialize(istr, ser_version, this);
sector->insertBlock(block); sector->insertBlock(block);
//DEBUG //DEBUG
@ -1157,7 +1162,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
//t4.stop(); //t4.stop();
//TimeTaker t1("inventory.deSerialize()", m_device); //TimeTaker t1("inventory.deSerialize()", m_device);
player->inventory.deSerialize(is); player->inventory.deSerialize(is, this);
//t1.stop(); //t1.stop();
m_inventory_updated = true; m_inventory_updated = true;
@ -1464,7 +1469,8 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
<< peer_id << std::endl; << peer_id << std::endl;
} else { } else {
std::istringstream iss(itemstring); std::istringstream iss(itemstring);
delete inv->changeItem(0, InventoryItem::deSerialize(iss)); delete inv->changeItem(0,
InventoryItem::deSerialize(iss, this));
infostream<<"Client: player item for peer " << peer_id << ": "; infostream<<"Client: player item for peer " << peer_id << ": ";
player->getWieldItem()->serialize(infostream); player->getWieldItem()->serialize(infostream);
infostream<<std::endl; infostream<<std::endl;
@ -2041,7 +2047,7 @@ void Client::setTempMod(v3s16 p, NodeMod mod)
i = affected_blocks.getIterator(); i = affected_blocks.getIterator();
i.atEnd() == false; i++) i.atEnd() == false; i++)
{ {
i.getNode()->getValue()->updateMesh(m_env.getDayNightRatio()); i.getNode()->getValue()->updateMesh(m_env.getDayNightRatio(), m_tsrc);
} }
} }
@ -2058,7 +2064,7 @@ void Client::clearTempMod(v3s16 p)
i = affected_blocks.getIterator(); i = affected_blocks.getIterator();
i.atEnd() == false; i++) i.atEnd() == false; i++)
{ {
i.getNode()->getValue()->updateMesh(m_env.getDayNightRatio()); i.getNode()->getValue()->updateMesh(m_env.getDayNightRatio(), m_tsrc);
} }
} }

@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <ostream> #include <ostream>
#include "clientobject.h" #include "clientobject.h"
#include "utility.h" // For IntervalLimiter #include "utility.h" // For IntervalLimiter
#include "gamedef.h"
struct MeshMakeData; struct MeshMakeData;
@ -98,7 +99,8 @@ class MeshUpdateThread : public SimpleThread
{ {
public: public:
MeshUpdateThread() MeshUpdateThread(ITextureSource *tsrc):
m_tsrc(tsrc)
{ {
} }
@ -107,6 +109,8 @@ public:
MeshUpdateQueue m_queue_in; MeshUpdateQueue m_queue_in;
MutexedQueue<MeshUpdateResult> m_queue_out; MutexedQueue<MeshUpdateResult> m_queue_out;
ITextureSource *m_tsrc;
}; };
enum ClientEventType enum ClientEventType
@ -139,7 +143,7 @@ struct ClientEvent
}; };
}; };
class Client : public con::PeerHandler, public InventoryManager class Client : public con::PeerHandler, public InventoryManager, public IGameDef
{ {
public: public:
/* /*
@ -150,7 +154,9 @@ public:
IrrlichtDevice *device, IrrlichtDevice *device,
const char *playername, const char *playername,
std::string password, std::string password,
MapDrawControl &control MapDrawControl &control,
ITextureSource *tsrc,
IToolDefManager *toolmgr
); );
~Client(); ~Client();
@ -303,6 +309,13 @@ public:
float getRTT(void); float getRTT(void);
// IGameDef interface
// Under envlock
virtual IToolDefManager* getToolDefManager()
{ return m_toolmgr; }
virtual INodeDefManager* getNodeDefManager()
{ assert(0); return NULL; } // TODO
private: private:
// Virtual methods from con::PeerHandler // Virtual methods from con::PeerHandler
@ -325,44 +338,31 @@ private:
float m_ignore_damage_timer; // Used after server moves player float m_ignore_damage_timer; // Used after server moves player
IntervalLimiter m_map_timer_and_unload_interval; IntervalLimiter m_map_timer_and_unload_interval;
ITextureSource *m_tsrc;
IToolDefManager *m_toolmgr;
MeshUpdateThread m_mesh_update_thread; MeshUpdateThread m_mesh_update_thread;
ClientEnvironment m_env; ClientEnvironment m_env;
con::Connection m_con; con::Connection m_con;
IrrlichtDevice *m_device; IrrlichtDevice *m_device;
// Server serialization version // Server serialization version
u8 m_server_ser_ver; u8 m_server_ser_ver;
// This is behind m_env_mutex. // This is behind m_env_mutex.
bool m_inventory_updated; bool m_inventory_updated;
core::map<v3s16, bool> m_active_blocks; core::map<v3s16, bool> m_active_blocks;
PacketCounter m_packetcounter; PacketCounter m_packetcounter;
// Received from the server. 0-23999 // Received from the server. 0-23999
u32 m_time_of_day; u32 m_time_of_day;
// 0 <= m_daynight_i < DAYNIGHT_CACHE_COUNT // 0 <= m_daynight_i < DAYNIGHT_CACHE_COUNT
//s32 m_daynight_i; //s32 m_daynight_i;
//u32 m_daynight_ratio; //u32 m_daynight_ratio;
Queue<std::wstring> m_chat_queue; Queue<std::wstring> m_chat_queue;
// The seed returned by the server in TOCLIENT_INIT is stored here // The seed returned by the server in TOCLIENT_INIT is stored here
u64 m_map_seed; u64 m_map_seed;
std::string m_password; std::string m_password;
bool m_access_denied; bool m_access_denied;
std::wstring m_access_denied_reason; std::wstring m_access_denied_reason;
InventoryContext m_inventory_context; InventoryContext m_inventory_context;
Queue<ClientEvent> m_client_event_queue; Queue<ClientEvent> m_client_event_queue;
friend class FarMesh; friend class FarMesh;
}; };

@ -26,8 +26,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
ClientActiveObject ClientActiveObject
*/ */
ClientActiveObject::ClientActiveObject(u16 id): ClientActiveObject::ClientActiveObject(u16 id, IGameDef *gamedef):
ActiveObject(id) ActiveObject(id),
m_gamedef(gamedef)
{ {
} }
@ -36,7 +37,7 @@ ClientActiveObject::~ClientActiveObject()
removeFromScene(); removeFromScene();
} }
ClientActiveObject* ClientActiveObject::create(u8 type) ClientActiveObject* ClientActiveObject::create(u8 type, IGameDef *gamedef)
{ {
// Find factory function // Find factory function
core::map<u16, Factory>::Node *n; core::map<u16, Factory>::Node *n;
@ -50,7 +51,7 @@ ClientActiveObject* ClientActiveObject::create(u8 type)
} }
Factory f = n->getValue(); Factory f = n->getValue();
ClientActiveObject *object = (*f)(); ClientActiveObject *object = (*f)(gamedef);
return object; return object;
} }

@ -36,14 +36,16 @@ Some planning
*/ */
class ClientEnvironment; class ClientEnvironment;
class ITextureSource;
class IGameDef;
class ClientActiveObject : public ActiveObject class ClientActiveObject : public ActiveObject
{ {
public: public:
ClientActiveObject(u16 id); ClientActiveObject(u16 id, IGameDef *gamedef);
virtual ~ClientActiveObject(); virtual ~ClientActiveObject();
virtual void addToScene(scene::ISceneManager *smgr){} virtual void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc){}
virtual void removeFromScene(){} virtual void removeFromScene(){}
// 0 <= light_at_pos <= LIGHT_SUN // 0 <= light_at_pos <= LIGHT_SUN
virtual void updateLight(u8 light_at_pos){} virtual void updateLight(u8 light_at_pos){}
@ -68,7 +70,7 @@ public:
virtual void initialize(const std::string &data){} virtual void initialize(const std::string &data){}
// Create a certain type of ClientActiveObject // Create a certain type of ClientActiveObject
static ClientActiveObject* create(u8 type); static ClientActiveObject* create(u8 type, IGameDef *gamedef);
// If returns true, punch will not be sent to the server // If returns true, punch will not be sent to the server
virtual bool directReportPunch(const std::string &toolname, v3f dir) virtual bool directReportPunch(const std::string &toolname, v3f dir)
@ -76,8 +78,9 @@ public:
protected: protected:
// Used for creating objects based on type // Used for creating objects based on type
typedef ClientActiveObject* (*Factory)(); typedef ClientActiveObject* (*Factory)(IGameDef *gamedef);
static void registerType(u16 type, Factory f); static void registerType(u16 type, Factory f);
IGameDef *m_gamedef;
private: private:
// Used for creating objects based on type // Used for creating objects based on type
static core::map<u16, Factory> m_types; static core::map<u16, Factory> m_types;

@ -30,10 +30,10 @@ core::map<u16, ClientActiveObject::Factory> ClientActiveObject::m_types;
*/ */
// Prototype // Prototype
TestCAO proto_TestCAO; TestCAO proto_TestCAO(NULL);
TestCAO::TestCAO(): TestCAO::TestCAO(IGameDef *gamedef):
ClientActiveObject(0), ClientActiveObject(0, gamedef),
m_node(NULL), m_node(NULL),
m_position(v3f(0,10*BS,0)) m_position(v3f(0,10*BS,0))
{ {
@ -44,12 +44,12 @@ TestCAO::~TestCAO()
{ {
} }
ClientActiveObject* TestCAO::create() ClientActiveObject* TestCAO::create(IGameDef *gamedef)
{ {
return new TestCAO(); return new TestCAO(gamedef);
} }
void TestCAO::addToScene(scene::ISceneManager *smgr) void TestCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
{ {
if(m_node != NULL) if(m_node != NULL)
return; return;
@ -146,10 +146,10 @@ void TestCAO::processMessage(const std::string &data)
#include "inventory.h" #include "inventory.h"
// Prototype // Prototype
ItemCAO proto_ItemCAO; ItemCAO proto_ItemCAO(NULL);
ItemCAO::ItemCAO(): ItemCAO::ItemCAO(IGameDef *gamedef):
ClientActiveObject(0), ClientActiveObject(0, gamedef),
m_selection_box(-BS/3.,0.0,-BS/3., BS/3.,BS*2./3.,BS/3.), m_selection_box(-BS/3.,0.0,-BS/3., BS/3.,BS*2./3.,BS/3.),
m_node(NULL), m_node(NULL),
m_position(v3f(0,10*BS,0)) m_position(v3f(0,10*BS,0))
@ -161,12 +161,12 @@ ItemCAO::~ItemCAO()
{ {
} }
ClientActiveObject* ItemCAO::create() ClientActiveObject* ItemCAO::create(IGameDef *gamedef)
{ {
return new ItemCAO(); return new ItemCAO(gamedef);
} }
void ItemCAO::addToScene(scene::ISceneManager *smgr) void ItemCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
{ {
if(m_node != NULL) if(m_node != NULL)
return; return;
@ -218,13 +218,13 @@ void ItemCAO::addToScene(scene::ISceneManager *smgr)
video::ITexture *texture = NULL; video::ITexture *texture = NULL;
try{ try{
InventoryItem *item = NULL; InventoryItem *item = NULL;
item = InventoryItem::deSerialize(is); item = InventoryItem::deSerialize(is, m_gamedef);
infostream<<__FUNCTION_NAME<<": m_inventorystring=\"" infostream<<__FUNCTION_NAME<<": m_inventorystring=\""
<<m_inventorystring<<"\" -> item="<<item <<m_inventorystring<<"\" -> item="<<item
<<std::endl; <<std::endl;
if(item) if(item)
{ {
texture = item->getImage(); texture = item->getImage(tsrc);
delete item; delete item;
} }
} }
@ -327,10 +327,10 @@ void ItemCAO::initialize(const std::string &data)
#include "inventory.h" #include "inventory.h"
// Prototype // Prototype
RatCAO proto_RatCAO; RatCAO proto_RatCAO(NULL);
RatCAO::RatCAO(): RatCAO::RatCAO(IGameDef *gamedef):
ClientActiveObject(0), ClientActiveObject(0, gamedef),
m_selection_box(-BS/3.,0.0,-BS/3., BS/3.,BS/2.,BS/3.), m_selection_box(-BS/3.,0.0,-BS/3., BS/3.,BS/2.,BS/3.),
m_node(NULL), m_node(NULL),
m_position(v3f(0,10*BS,0)), m_position(v3f(0,10*BS,0)),
@ -343,12 +343,12 @@ RatCAO::~RatCAO()
{ {
} }
ClientActiveObject* RatCAO::create() ClientActiveObject* RatCAO::create(IGameDef *gamedef)
{ {
return new RatCAO(); return new RatCAO(gamedef);
} }
void RatCAO::addToScene(scene::ISceneManager *smgr) void RatCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
{ {
if(m_node != NULL) if(m_node != NULL)
return; return;
@ -473,10 +473,10 @@ void RatCAO::initialize(const std::string &data)
#include "inventory.h" #include "inventory.h"
// Prototype // Prototype
Oerkki1CAO proto_Oerkki1CAO; Oerkki1CAO proto_Oerkki1CAO(NULL);
Oerkki1CAO::Oerkki1CAO(): Oerkki1CAO::Oerkki1CAO(IGameDef *gamedef):
ClientActiveObject(0), ClientActiveObject(0, gamedef),
m_selection_box(-BS/3.,0.0,-BS/3., BS/3.,BS*2.,BS/3.), m_selection_box(-BS/3.,0.0,-BS/3., BS/3.,BS*2.,BS/3.),
m_node(NULL), m_node(NULL),
m_position(v3f(0,10*BS,0)), m_position(v3f(0,10*BS,0)),
@ -491,12 +491,12 @@ Oerkki1CAO::~Oerkki1CAO()
{ {
} }
ClientActiveObject* Oerkki1CAO::create() ClientActiveObject* Oerkki1CAO::create(IGameDef *gamedef)
{ {
return new Oerkki1CAO(); return new Oerkki1CAO(gamedef);
} }
void Oerkki1CAO::addToScene(scene::ISceneManager *smgr) void Oerkki1CAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
{ {
if(m_node != NULL) if(m_node != NULL)
return; return;
@ -712,10 +712,10 @@ bool Oerkki1CAO::directReportPunch(const std::string &toolname, v3f dir)
*/ */
// Prototype // Prototype
FireflyCAO proto_FireflyCAO; FireflyCAO proto_FireflyCAO(NULL);
FireflyCAO::FireflyCAO(): FireflyCAO::FireflyCAO(IGameDef *gamedef):
ClientActiveObject(0), ClientActiveObject(0, gamedef),
m_selection_box(-BS/3.,0.0,-BS/3., BS/3.,BS/2.,BS/3.), m_selection_box(-BS/3.,0.0,-BS/3., BS/3.,BS/2.,BS/3.),
m_node(NULL), m_node(NULL),
m_position(v3f(0,10*BS,0)), m_position(v3f(0,10*BS,0)),
@ -728,12 +728,12 @@ FireflyCAO::~FireflyCAO()
{ {
} }
ClientActiveObject* FireflyCAO::create() ClientActiveObject* FireflyCAO::create(IGameDef *gamedef)
{ {
return new FireflyCAO(); return new FireflyCAO(gamedef);
} }
void FireflyCAO::addToScene(scene::ISceneManager *smgr) void FireflyCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
{ {
if(m_node != NULL) if(m_node != NULL)
return; return;
@ -856,10 +856,10 @@ void FireflyCAO::initialize(const std::string &data)
*/ */
// Prototype // Prototype
MobV2CAO proto_MobV2CAO; MobV2CAO proto_MobV2CAO(NULL);
MobV2CAO::MobV2CAO(): MobV2CAO::MobV2CAO(IGameDef *gamedef):
ClientActiveObject(0), ClientActiveObject(0, gamedef),
m_selection_box(-0.4*BS,-0.4*BS,-0.4*BS, 0.4*BS,0.8*BS,0.4*BS), m_selection_box(-0.4*BS,-0.4*BS,-0.4*BS, 0.4*BS,0.8*BS,0.4*BS),
m_node(NULL), m_node(NULL),
m_position(v3f(0,10*BS,0)), m_position(v3f(0,10*BS,0)),
@ -888,12 +888,12 @@ MobV2CAO::~MobV2CAO()
delete m_properties; delete m_properties;
} }
ClientActiveObject* MobV2CAO::create() ClientActiveObject* MobV2CAO::create(IGameDef *gamedef)
{ {
return new MobV2CAO(); return new MobV2CAO(gamedef);
} }
void MobV2CAO::addToScene(scene::ISceneManager *smgr) void MobV2CAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
{ {
if(m_node != NULL) if(m_node != NULL)
return; return;
@ -905,7 +905,7 @@ void MobV2CAO::addToScene(scene::ISceneManager *smgr)
scene::MyBillboardSceneNode *bill = new scene::MyBillboardSceneNode( scene::MyBillboardSceneNode *bill = new scene::MyBillboardSceneNode(
smgr->getRootSceneNode(), smgr, -1, v3f(0,0,0), v2f(1,1)); smgr->getRootSceneNode(), smgr, -1, v3f(0,0,0), v2f(1,1));
bill->setMaterialTexture(0, g_texturesource->getTextureRaw(texture_string)); bill->setMaterialTexture(0, tsrc->getTextureRaw(texture_string));
bill->setMaterialFlag(video::EMF_LIGHTING, false); bill->setMaterialFlag(video::EMF_LIGHTING, false);
bill->setMaterialFlag(video::EMF_BILINEAR_FILTER, false); bill->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
bill->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF); bill->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
@ -1271,10 +1271,10 @@ void MobV2CAO::setLooks(const std::string &looks)
#include "luaentity_common.h" #include "luaentity_common.h"
// Prototype // Prototype
LuaEntityCAO proto_LuaEntityCAO; LuaEntityCAO proto_LuaEntityCAO(NULL);
LuaEntityCAO::LuaEntityCAO(): LuaEntityCAO::LuaEntityCAO(IGameDef *gamedef):
ClientActiveObject(0), ClientActiveObject(0, gamedef),
m_selection_box(-BS/3.,-BS/3.,-BS/3., BS/3.,BS/3.,BS/3.), m_selection_box(-BS/3.,-BS/3.,-BS/3., BS/3.,BS/3.,BS/3.),
m_meshnode(NULL), m_meshnode(NULL),
m_spritenode(NULL), m_spritenode(NULL),
@ -1290,12 +1290,12 @@ LuaEntityCAO::~LuaEntityCAO()
delete m_prop; delete m_prop;
} }
ClientActiveObject* LuaEntityCAO::create() ClientActiveObject* LuaEntityCAO::create(IGameDef *gamedef)
{ {
return new LuaEntityCAO(); return new LuaEntityCAO(gamedef);
} }
void LuaEntityCAO::addToScene(scene::ISceneManager *smgr) void LuaEntityCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
{ {
if(m_meshnode != NULL || m_spritenode != NULL) if(m_meshnode != NULL || m_spritenode != NULL)
return; return;
@ -1310,7 +1310,7 @@ void LuaEntityCAO::addToScene(scene::ISceneManager *smgr)
if(m_prop->textures.size() >= 1) if(m_prop->textures.size() >= 1)
texturestring = m_prop->textures[0]; texturestring = m_prop->textures[0];
m_spritenode->setMaterialTexture(0, m_spritenode->setMaterialTexture(0,
g_texturesource->getTextureRaw(texturestring)); tsrc->getTextureRaw(texturestring));
m_spritenode->setMaterialFlag(video::EMF_LIGHTING, false); m_spritenode->setMaterialFlag(video::EMF_LIGHTING, false);
m_spritenode->setMaterialFlag(video::EMF_BILINEAR_FILTER, false); m_spritenode->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
m_spritenode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF); m_spritenode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
@ -1389,7 +1389,7 @@ void LuaEntityCAO::addToScene(scene::ISceneManager *smgr)
std::string texturestring = "unknown_block.png"; std::string texturestring = "unknown_block.png";
if(m_prop->textures.size() > i) if(m_prop->textures.size() > i)
texturestring = m_prop->textures[i]; texturestring = m_prop->textures[i];
AtlasPointer ap = g_texturesource->getTexture(texturestring); AtlasPointer ap = tsrc->getTexture(texturestring);
// Get the tile texture and atlas transformation // Get the tile texture and atlas transformation
video::ITexture* atlas = ap.atlas; video::ITexture* atlas = ap.atlas;

@ -115,7 +115,7 @@ struct SmoothTranslator
class TestCAO : public ClientActiveObject class TestCAO : public ClientActiveObject
{ {
public: public:
TestCAO(); TestCAO(IGameDef *gamedef);
virtual ~TestCAO(); virtual ~TestCAO();
u8 getType() const u8 getType() const
@ -123,9 +123,9 @@ public:
return ACTIVEOBJECT_TYPE_TEST; return ACTIVEOBJECT_TYPE_TEST;
} }
static ClientActiveObject* create(); static ClientActiveObject* create(IGameDef *gamedef);
void addToScene(scene::ISceneManager *smgr); void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
void removeFromScene(); void removeFromScene();
void updateLight(u8 light_at_pos); void updateLight(u8 light_at_pos);
v3s16 getLightPosition(); v3s16 getLightPosition();
@ -147,7 +147,7 @@ private:
class ItemCAO : public ClientActiveObject class ItemCAO : public ClientActiveObject
{ {
public: public:
ItemCAO(); ItemCAO(IGameDef *gamedef);
virtual ~ItemCAO(); virtual ~ItemCAO();
u8 getType() const u8 getType() const
@ -155,9 +155,9 @@ public:
return ACTIVEOBJECT_TYPE_ITEM; return ACTIVEOBJECT_TYPE_ITEM;
} }
static ClientActiveObject* create(); static ClientActiveObject* create(IGameDef *gamedef);
void addToScene(scene::ISceneManager *smgr); void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
void removeFromScene(); void removeFromScene();
void updateLight(u8 light_at_pos); void updateLight(u8 light_at_pos);
v3s16 getLightPosition(); v3s16 getLightPosition();
@ -188,7 +188,7 @@ private:
class RatCAO : public ClientActiveObject class RatCAO : public ClientActiveObject
{ {
public: public:
RatCAO(); RatCAO(IGameDef *gamedef);
virtual ~RatCAO(); virtual ~RatCAO();
u8 getType() const u8 getType() const
@ -196,9 +196,9 @@ public:
return ACTIVEOBJECT_TYPE_RAT; return ACTIVEOBJECT_TYPE_RAT;
} }
static ClientActiveObject* create(); static ClientActiveObject* create(IGameDef *gamedef);
void addToScene(scene::ISceneManager *smgr); void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
void removeFromScene(); void removeFromScene();
void updateLight(u8 light_at_pos); void updateLight(u8 light_at_pos);
v3s16 getLightPosition(); v3s16 getLightPosition();
@ -231,7 +231,7 @@ private:
class Oerkki1CAO : public ClientActiveObject class Oerkki1CAO : public ClientActiveObject
{ {
public: public:
Oerkki1CAO(); Oerkki1CAO(IGameDef *gamedef);
virtual ~Oerkki1CAO(); virtual ~Oerkki1CAO();
u8 getType() const u8 getType() const
@ -239,9 +239,9 @@ public:
return ACTIVEOBJECT_TYPE_OERKKI1; return ACTIVEOBJECT_TYPE_OERKKI1;
} }
static ClientActiveObject* create(); static ClientActiveObject* create(IGameDef *gamedef);
void addToScene(scene::ISceneManager *smgr); void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
void removeFromScene(); void removeFromScene();
void updateLight(u8 light_at_pos); void updateLight(u8 light_at_pos);
v3s16 getLightPosition(); v3s16 getLightPosition();
@ -280,7 +280,7 @@ private:
class FireflyCAO : public ClientActiveObject class FireflyCAO : public ClientActiveObject
{ {
public: public:
FireflyCAO(); FireflyCAO(IGameDef *gamedef);
virtual ~FireflyCAO(); virtual ~FireflyCAO();
u8 getType() const u8 getType() const
@ -288,9 +288,9 @@ public:
return ACTIVEOBJECT_TYPE_FIREFLY; return ACTIVEOBJECT_TYPE_FIREFLY;
} }
static ClientActiveObject* create(); static ClientActiveObject* create(IGameDef *gamedef);
void addToScene(scene::ISceneManager *smgr); void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
void removeFromScene(); void removeFromScene();
void updateLight(u8 light_at_pos); void updateLight(u8 light_at_pos);
v3s16 getLightPosition(); v3s16 getLightPosition();
@ -322,7 +322,7 @@ private:
class MobV2CAO : public ClientActiveObject class MobV2CAO : public ClientActiveObject
{ {
public: public:
MobV2CAO(); MobV2CAO(IGameDef *gamedef);
virtual ~MobV2CAO(); virtual ~MobV2CAO();
u8 getType() const u8 getType() const
@ -330,9 +330,9 @@ public:
return ACTIVEOBJECT_TYPE_MOBV2; return ACTIVEOBJECT_TYPE_MOBV2;
} }
static ClientActiveObject* create(); static ClientActiveObject* create(IGameDef *gamedef);
void addToScene(scene::ISceneManager *smgr); void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
void removeFromScene(); void removeFromScene();
void updateLight(u8 light_at_pos); void updateLight(u8 light_at_pos);
v3s16 getLightPosition(); v3s16 getLightPosition();
@ -396,7 +396,7 @@ struct LuaEntityProperties;
class LuaEntityCAO : public ClientActiveObject class LuaEntityCAO : public ClientActiveObject
{ {
public: public:
LuaEntityCAO(); LuaEntityCAO(IGameDef *gamedef);
virtual ~LuaEntityCAO(); virtual ~LuaEntityCAO();
u8 getType() const u8 getType() const
@ -404,9 +404,9 @@ public:
return ACTIVEOBJECT_TYPE_LUAENTITY; return ACTIVEOBJECT_TYPE_LUAENTITY;
} }
static ClientActiveObject* create(); static ClientActiveObject* create(IGameDef *gamedef);
void addToScene(scene::ISceneManager *smgr); void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
void removeFromScene(); void removeFromScene();
void updateLight(u8 light_at_pos); void updateLight(u8 light_at_pos);
v3s16 getLightPosition(); v3s16 getLightPosition();

@ -27,7 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
items: actually *items[9] items: actually *items[9]
return value: allocates a new item, or returns NULL. return value: allocates a new item, or returns NULL.
*/ */
InventoryItem *craft_get_result(InventoryItem **items) InventoryItem *craft_get_result(InventoryItem **items, IGameDef *gamedef)
{ {
// Wood // Wood
{ {
@ -35,7 +35,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_TREE); specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_TREE);
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new MaterialItem(CONTENT_WOOD, 4); return new MaterialItem(gamedef, CONTENT_WOOD, 4);
} }
} }
@ -45,7 +45,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new CraftItem("Stick", 4); return new CraftItem(gamedef, "Stick", 4);
} }
} }
@ -60,7 +60,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[8] = ItemSpec(ITEM_CRAFT, "Stick"); specs[8] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new MaterialItem(CONTENT_FENCE, 2); return new MaterialItem(gamedef, CONTENT_FENCE, 2);
} }
} }
@ -76,8 +76,8 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick"); specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
//return new MapBlockObjectItem("Sign"); //return new MapBlockObjectItem(gamedef, "Sign");
return new MaterialItem(CONTENT_SIGN_WALL, 1); return new MaterialItem(gamedef, CONTENT_SIGN_WALL, 1);
} }
} }
@ -88,7 +88,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[3] = ItemSpec(ITEM_CRAFT, "Stick"); specs[3] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new MaterialItem(CONTENT_TORCH, 4); return new MaterialItem(gamedef, CONTENT_TORCH, 4);
} }
} }
@ -102,7 +102,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick"); specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new ToolItem("WPick", 0); return new ToolItem(gamedef, "WPick", 0);
} }
} }
@ -116,7 +116,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick"); specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new ToolItem("STPick", 0); return new ToolItem(gamedef, "STPick", 0);
} }
} }
@ -130,7 +130,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick"); specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new ToolItem("SteelPick", 0); return new ToolItem(gamedef, "SteelPick", 0);
} }
} }
@ -144,7 +144,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick"); specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new ToolItem("MesePick", 0); return new ToolItem(gamedef, "MesePick", 0);
} }
} }
@ -156,7 +156,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick"); specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new ToolItem("WShovel", 0); return new ToolItem(gamedef, "WShovel", 0);
} }
} }
@ -168,7 +168,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick"); specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new ToolItem("STShovel", 0); return new ToolItem(gamedef, "STShovel", 0);
} }
} }
@ -180,7 +180,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick"); specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new ToolItem("SteelShovel", 0); return new ToolItem(gamedef, "SteelShovel", 0);
} }
} }
@ -194,7 +194,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick"); specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new ToolItem("WAxe", 0); return new ToolItem(gamedef, "WAxe", 0);
} }
} }
@ -208,7 +208,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick"); specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new ToolItem("STAxe", 0); return new ToolItem(gamedef, "STAxe", 0);
} }
} }
@ -222,7 +222,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick"); specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new ToolItem("SteelAxe", 0); return new ToolItem(gamedef, "SteelAxe", 0);
} }
} }
@ -234,7 +234,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick"); specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new ToolItem("WSword", 0); return new ToolItem(gamedef, "WSword", 0);
} }
} }
@ -246,7 +246,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick"); specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new ToolItem("STSword", 0); return new ToolItem(gamedef, "STSword", 0);
} }
} }
@ -258,7 +258,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "Stick"); specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new ToolItem("SteelSword", 0); return new ToolItem(gamedef, "SteelSword", 0);
} }
} }
@ -276,7 +276,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[8] = ItemSpec(ITEM_CRAFT, "steel_ingot"); specs[8] = ItemSpec(ITEM_CRAFT, "steel_ingot");
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new MaterialItem(CONTENT_RAIL, 15); return new MaterialItem(gamedef, CONTENT_RAIL, 15);
} }
} }
@ -293,7 +293,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new MaterialItem(CONTENT_CHEST, 1); return new MaterialItem(gamedef, CONTENT_CHEST, 1);
} }
} }
@ -311,7 +311,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new MaterialItem(CONTENT_LOCKABLE_CHEST, 1); return new MaterialItem(gamedef, CONTENT_LOCKABLE_CHEST, 1);
} }
} }
@ -328,7 +328,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE); specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new MaterialItem(CONTENT_FURNACE, 1); return new MaterialItem(gamedef, CONTENT_FURNACE, 1);
} }
} }
@ -346,7 +346,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[8] = ItemSpec(ITEM_CRAFT, "steel_ingot"); specs[8] = ItemSpec(ITEM_CRAFT, "steel_ingot");
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new MaterialItem(CONTENT_STEEL, 1); return new MaterialItem(gamedef, CONTENT_STEEL, 1);
} }
} }
@ -359,7 +359,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_SAND); specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_SAND);
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new MaterialItem(CONTENT_SANDSTONE, 1); return new MaterialItem(gamedef, CONTENT_SANDSTONE, 1);
} }
} }
@ -372,7 +372,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "lump_of_clay"); specs[7] = ItemSpec(ITEM_CRAFT, "lump_of_clay");
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new MaterialItem(CONTENT_CLAY, 1); return new MaterialItem(gamedef, CONTENT_CLAY, 1);
} }
} }
@ -385,7 +385,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "clay_brick"); specs[7] = ItemSpec(ITEM_CRAFT, "clay_brick");
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new MaterialItem(CONTENT_BRICK, 1); return new MaterialItem(gamedef, CONTENT_BRICK, 1);
} }
} }
@ -397,7 +397,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_PAPYRUS); specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_PAPYRUS);
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new CraftItem("paper", 1); return new CraftItem(gamedef, "paper", 1);
} }
} }
@ -409,7 +409,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "paper"); specs[7] = ItemSpec(ITEM_CRAFT, "paper");
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new CraftItem("book", 1); return new CraftItem(gamedef, "book", 1);
} }
} }
@ -427,7 +427,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new MaterialItem(CONTENT_BOOKSHELF, 1); return new MaterialItem(gamedef, CONTENT_BOOKSHELF, 1);
} }
} }
@ -443,7 +443,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[8] = ItemSpec(ITEM_CRAFT, "Stick"); specs[8] = ItemSpec(ITEM_CRAFT, "Stick");
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new MaterialItem(CONTENT_LADDER, 1); return new MaterialItem(gamedef, CONTENT_LADDER, 1);
} }
} }
@ -457,35 +457,35 @@ InventoryItem *craft_get_result(InventoryItem **items)
specs[7] = ItemSpec(ITEM_CRAFT, "steel_ingot"); specs[7] = ItemSpec(ITEM_CRAFT, "steel_ingot");
if(checkItemCombination(items, specs)) if(checkItemCombination(items, specs))
{ {
return new CraftItem("apple_iron", 1); return new CraftItem(gamedef, "apple_iron", 1);
} }
} }
return NULL; return NULL;
} }
void craft_set_creative_inventory(Player *player) void craft_set_creative_inventory(Player *player, IGameDef *gamedef)
{ {
player->resetInventory(); player->resetInventory();
// Give some good tools // Give some good tools
{ {
InventoryItem *item = new ToolItem("MesePick", 0); InventoryItem *item = new ToolItem(gamedef, "MesePick", 0);
void* r = player->inventory.addItem("main", item); void* r = player->inventory.addItem("main", item);
assert(r == NULL); assert(r == NULL);
} }
{ {
InventoryItem *item = new ToolItem("SteelPick", 0); InventoryItem *item = new ToolItem(gamedef, "SteelPick", 0);
void* r = player->inventory.addItem("main", item); void* r = player->inventory.addItem("main", item);
assert(r == NULL); assert(r == NULL);
} }
{ {
InventoryItem *item = new ToolItem("SteelAxe", 0); InventoryItem *item = new ToolItem(gamedef, "SteelAxe", 0);
void* r = player->inventory.addItem("main", item); void* r = player->inventory.addItem("main", item);
assert(r == NULL); assert(r == NULL);
} }
{ {
InventoryItem *item = new ToolItem("SteelShovel", 0); InventoryItem *item = new ToolItem(gamedef, "SteelShovel", 0);
void* r = player->inventory.addItem("main", item); void* r = player->inventory.addItem("main", item);
assert(r == NULL); assert(r == NULL);
} }
@ -528,7 +528,7 @@ void craft_set_creative_inventory(Player *player)
if(*mip == CONTENT_IGNORE) if(*mip == CONTENT_IGNORE)
break; break;
InventoryItem *item = new MaterialItem(*mip, 1); InventoryItem *item = new MaterialItem(gamedef, *mip, 1);
player->inventory.addItem("main", item); player->inventory.addItem("main", item);
mip++; mip++;
@ -538,7 +538,7 @@ void craft_set_creative_inventory(Player *player)
assert(USEFUL_CONTENT_COUNT <= PLAYER_INVENTORY_SIZE); assert(USEFUL_CONTENT_COUNT <= PLAYER_INVENTORY_SIZE);
// add torch first // add torch first
InventoryItem *item = new MaterialItem(CONTENT_TORCH, 1); InventoryItem *item = new MaterialItem(gamedef, CONTENT_TORCH, 1);
player->inventory.addItem("main", item); player->inventory.addItem("main", item);
// Then others // Then others
@ -549,86 +549,86 @@ void craft_set_creative_inventory(Player *player)
|| i == CONTENT_COALSTONE) || i == CONTENT_COALSTONE)
continue; continue;
InventoryItem *item = new MaterialItem(i, 1); InventoryItem *item = new MaterialItem(gamedef, i, 1);
player->inventory.addItem("main", item); player->inventory.addItem("main", item);
} }
#endif #endif
/*// Sign /*// Sign
{ {
InventoryItem *item = new MapBlockObjectItem("Sign Example text"); InventoryItem *item = new MapBlockObjectItem(gamedef, "Sign Example text");
void* r = player->inventory.addItem("main", item); void* r = player->inventory.addItem("main", item);
assert(r == NULL); assert(r == NULL);
}*/ }*/
} }
void craft_give_initial_stuff(Player *player) void craft_give_initial_stuff(Player *player, IGameDef *gamedef)
{ {
{ {
InventoryItem *item = new ToolItem("SteelPick", 0); InventoryItem *item = new ToolItem(gamedef, "SteelPick", 0);
void* r = player->inventory.addItem("main", item); void* r = player->inventory.addItem("main", item);
assert(r == NULL); assert(r == NULL);
} }
{ {
InventoryItem *item = new MaterialItem(CONTENT_TORCH, 99); InventoryItem *item = new MaterialItem(gamedef, CONTENT_TORCH, 99);
void* r = player->inventory.addItem("main", item); void* r = player->inventory.addItem("main", item);
assert(r == NULL); assert(r == NULL);
} }
{ {
InventoryItem *item = new ToolItem("SteelAxe", 0); InventoryItem *item = new ToolItem(gamedef, "SteelAxe", 0);
void* r = player->inventory.addItem("main", item); void* r = player->inventory.addItem("main", item);
assert(r == NULL); assert(r == NULL);
} }
{ {
InventoryItem *item = new ToolItem("SteelShovel", 0); InventoryItem *item = new ToolItem(gamedef, "SteelShovel", 0);
void* r = player->inventory.addItem("main", item); void* r = player->inventory.addItem("main", item);
assert(r == NULL); assert(r == NULL);
} }
{ {
InventoryItem *item = new MaterialItem(CONTENT_COBBLE, 99); InventoryItem *item = new MaterialItem(gamedef, CONTENT_COBBLE, 99);
void* r = player->inventory.addItem("main", item); void* r = player->inventory.addItem("main", item);
assert(r == NULL); assert(r == NULL);
} }
/*{ /*{
InventoryItem *item = new MaterialItem(CONTENT_MESE, 6); InventoryItem *item = new MaterialItem(gamedef, CONTENT_MESE, 6);
void* r = player->inventory.addItem("main", item); void* r = player->inventory.addItem("main", item);
assert(r == NULL); assert(r == NULL);
} }
{ {
InventoryItem *item = new MaterialItem(CONTENT_COALSTONE, 6); InventoryItem *item = new MaterialItem(gamedef, CONTENT_COALSTONE, 6);
void* r = player->inventory.addItem("main", item); void* r = player->inventory.addItem("main", item);
assert(r == NULL); assert(r == NULL);
} }
{ {
InventoryItem *item = new MaterialItem(CONTENT_WOOD, 6); InventoryItem *item = new MaterialItem(gamedef, CONTENT_WOOD, 6);
void* r = player->inventory.addItem("main", item); void* r = player->inventory.addItem("main", item);
assert(r == NULL); assert(r == NULL);
} }
{ {
InventoryItem *item = new CraftItem("Stick", 4); InventoryItem *item = new CraftItem(gamedef, "Stick", 4);
void* r = player->inventory.addItem("main", item); void* r = player->inventory.addItem("main", item);
assert(r == NULL); assert(r == NULL);
} }
{ {
InventoryItem *item = new ToolItem("WPick", 32000); InventoryItem *item = new ToolItem(gamedef, "WPick", 32000);
void* r = player->inventory.addItem("main", item); void* r = player->inventory.addItem("main", item);
assert(r == NULL); assert(r == NULL);
} }
{ {
InventoryItem *item = new ToolItem("STPick", 32000); InventoryItem *item = new ToolItem(gamedef, "STPick", 32000);
void* r = player->inventory.addItem("main", item); void* r = player->inventory.addItem("main", item);
assert(r == NULL); assert(r == NULL);
}*/ }*/
/*// and some signs /*// and some signs
for(u16 i=0; i<4; i++) for(u16 i=0; i<4; i++)
{ {
InventoryItem *item = new MapBlockObjectItem("Sign Example text"); InventoryItem *item = new MapBlockObjectItem(gamedef, "Sign Example text");
bool r = player->inventory.addItem("main", item); bool r = player->inventory.addItem("main", item);
assert(r == true); assert(r == true);
}*/ }*/
/*// Give some other stuff /*// Give some other stuff
{ {
InventoryItem *item = new MaterialItem(CONTENT_TREE, 999); InventoryItem *item = new MaterialItem(gamedef, CONTENT_TREE, 999);
bool r = player->inventory.addItem("main", item); bool r = player->inventory.addItem("main", item);
assert(r == true); assert(r == true);
}*/ }*/

@ -22,17 +22,18 @@ with this program; if not, write to the Free Software Foundation, Inc.,
class InventoryItem; class InventoryItem;
class Player; class Player;
class IGameDef;
/* /*
items: actually *items[9] items: actually *items[9]
return value: allocates a new item, or returns NULL. return value: allocates a new item, or returns NULL.
*/ */
InventoryItem *craft_get_result(InventoryItem **items); InventoryItem *craft_get_result(InventoryItem **items, IGameDef *gamedef);
void craft_set_creative_inventory(Player *player); void craft_set_creative_inventory(Player *player, IGameDef *gamedef);
// Called when give_initial_stuff setting is used // Called when give_initial_stuff setting is used
void craft_give_initial_stuff(Player *player); void craft_give_initial_stuff(Player *player, IGameDef *gamedef);
#endif #endif

@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
//#include "serverobject.h" //#include "serverobject.h"
#include "content_sao.h" #include "content_sao.h"
bool item_material_is_cookable(content_t content) bool item_material_is_cookable(content_t content, IGameDef *gamedef)
{ {
if(content == CONTENT_TREE) if(content == CONTENT_TREE)
return true; return true;
@ -34,18 +34,20 @@ bool item_material_is_cookable(content_t content)
return false; return false;
} }
InventoryItem* item_material_create_cook_result(content_t content) InventoryItem* item_material_create_cook_result(content_t content,
IGameDef *gamedef)
{ {
if(content == CONTENT_TREE) if(content == CONTENT_TREE)
return new CraftItem("lump_of_coal", 1); return new CraftItem(gamedef, "lump_of_coal", 1);
else if(content == CONTENT_COBBLE) else if(content == CONTENT_COBBLE)
return new MaterialItem(CONTENT_STONE, 1); return new MaterialItem(gamedef, CONTENT_STONE, 1);
else if(content == CONTENT_SAND) else if(content == CONTENT_SAND)
return new MaterialItem(CONTENT_GLASS, 1); return new MaterialItem(gamedef, CONTENT_GLASS, 1);
return NULL; return NULL;
} }
std::string item_craft_get_image_name(const std::string &subname) std::string item_craft_get_image_name(const std::string &subname,
IGameDef *gamedef)
{ {
if(subname == "Stick") if(subname == "Stick")
return "stick.png"; return "stick.png";
@ -103,7 +105,7 @@ ServerActiveObject* item_craft_create_object(const std::string &subname,
return NULL; return NULL;
} }
s16 item_craft_get_drop_count(const std::string &subname) s16 item_craft_get_drop_count(const std::string &subname, IGameDef *gamedef)
{ {
if(subname == "rat" || subname == "firefly" || subname == "testobject1") if(subname == "rat" || subname == "firefly" || subname == "testobject1")
return 1; return 1;
@ -111,7 +113,7 @@ s16 item_craft_get_drop_count(const std::string &subname)
return -1; return -1;
} }
bool item_craft_is_cookable(const std::string &subname) bool item_craft_is_cookable(const std::string &subname, IGameDef *gamedef)
{ {
if(subname == "lump_of_iron" || subname == "lump_of_clay" || subname == "rat" || subname == "cooked_rat") if(subname == "lump_of_iron" || subname == "lump_of_clay" || subname == "rat" || subname == "cooked_rat")
return true; return true;
@ -119,21 +121,22 @@ bool item_craft_is_cookable(const std::string &subname)
return false; return false;
} }
InventoryItem* item_craft_create_cook_result(const std::string &subname) InventoryItem* item_craft_create_cook_result(const std::string &subname,
IGameDef *gamedef)
{ {
if(subname == "lump_of_iron") if(subname == "lump_of_iron")
return new CraftItem("steel_ingot", 1); return new CraftItem(gamedef, "steel_ingot", 1);
else if(subname == "lump_of_clay") else if(subname == "lump_of_clay")
return new CraftItem("clay_brick", 1); return new CraftItem(gamedef, "clay_brick", 1);
else if(subname == "rat") else if(subname == "rat")
return new CraftItem("cooked_rat", 1); return new CraftItem(gamedef, "cooked_rat", 1);
else if(subname == "cooked_rat") else if(subname == "cooked_rat")
return new CraftItem("scorched_stuff", 1); return new CraftItem(gamedef, "scorched_stuff", 1);
return NULL; return NULL;
} }
bool item_craft_is_eatable(const std::string &subname) bool item_craft_is_eatable(const std::string &subname, IGameDef *gamedef)
{ {
if(subname == "cooked_rat") if(subname == "cooked_rat")
return true; return true;
@ -144,7 +147,7 @@ bool item_craft_is_eatable(const std::string &subname)
return false; return false;
} }
s16 item_craft_eat_hp_change(const std::string &subname) s16 item_craft_eat_hp_change(const std::string &subname, IGameDef *gamedef)
{ {
if(subname == "cooked_rat") if(subname == "cooked_rat")
return 6; // 3 hearts return 6; // 3 hearts

@ -27,18 +27,26 @@ with this program; if not, write to the Free Software Foundation, Inc.,
class InventoryItem; class InventoryItem;
class ServerActiveObject; class ServerActiveObject;
class ServerEnvironment; class ServerEnvironment;
class IGameDef;
bool item_material_is_cookable(content_t content); bool item_material_is_cookable(content_t content, IGameDef *gamedef);
InventoryItem* item_material_create_cook_result(content_t content); InventoryItem* item_material_create_cook_result(content_t content,
IGameDef *gamedef);
std::string item_craft_get_image_name(const std::string &subname); std::string item_craft_get_image_name(const std::string &subname,
IGameDef *gamedef);
ServerActiveObject* item_craft_create_object(const std::string &subname, ServerActiveObject* item_craft_create_object(const std::string &subname,
ServerEnvironment *env, v3f pos); ServerEnvironment *env, v3f pos);
s16 item_craft_get_drop_count(const std::string &subname); s16 item_craft_get_drop_count(const std::string &subname,
bool item_craft_is_cookable(const std::string &subname); IGameDef *gamedef);
InventoryItem* item_craft_create_cook_result(const std::string &subname); bool item_craft_is_cookable(const std::string &subname,
bool item_craft_is_eatable(const std::string &subname); IGameDef *gamedef);
s16 item_craft_eat_hp_change(const std::string &subname); InventoryItem* item_craft_create_cook_result(const std::string &subname,
IGameDef *gamedef);
bool item_craft_is_eatable(const std::string &subname,
IGameDef *gamedef);
s16 item_craft_eat_hp_change(const std::string &subname,
IGameDef *gamedef);
#endif #endif

@ -19,7 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "content_mapblock.h" #include "content_mapblock.h"
#include "content_mapnode.h" #include "content_mapnode.h"
#include "main.h" // For g_settings and g_texturesource #include "main.h" // For g_settings
#include "mineral.h" #include "mineral.h"
#include "mapblock_mesh.h" // For MapBlock_LightColor() #include "mapblock_mesh.h" // For MapBlock_LightColor()
#include "settings.h" #include "settings.h"
@ -122,7 +122,7 @@ void makeCuboid(video::SMaterial &material, MeshCollector *collector,
#ifndef SERVER #ifndef SERVER
void mapblock_mesh_generate_special(MeshMakeData *data, void mapblock_mesh_generate_special(MeshMakeData *data,
MeshCollector &collector) MeshCollector &collector, ITextureSource *tsrc)
{ {
// 0ms // 0ms
//TimeTaker timer("mapblock_mesh_generate_special()"); //TimeTaker timer("mapblock_mesh_generate_special()");
@ -147,8 +147,8 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
material_leaves1.setFlag(video::EMF_BILINEAR_FILTER, false); material_leaves1.setFlag(video::EMF_BILINEAR_FILTER, false);
material_leaves1.setFlag(video::EMF_FOG_ENABLE, true); material_leaves1.setFlag(video::EMF_FOG_ENABLE, true);
material_leaves1.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; material_leaves1.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
AtlasPointer pa_leaves1 = g_texturesource->getTexture( AtlasPointer pa_leaves1 = tsrc->getTexture(
g_texturesource->getTextureId("leaves.png")); tsrc->getTextureId("leaves.png"));
material_leaves1.setTexture(0, pa_leaves1.atlas); material_leaves1.setTexture(0, pa_leaves1.atlas);
// Glass material // Glass material
@ -157,8 +157,8 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
material_glass.setFlag(video::EMF_BILINEAR_FILTER, false); material_glass.setFlag(video::EMF_BILINEAR_FILTER, false);
material_glass.setFlag(video::EMF_FOG_ENABLE, true); material_glass.setFlag(video::EMF_FOG_ENABLE, true);
material_glass.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; material_glass.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
AtlasPointer pa_glass = g_texturesource->getTexture( AtlasPointer pa_glass = tsrc->getTexture(
g_texturesource->getTextureId("glass.png")); tsrc->getTextureId("glass.png"));
material_glass.setTexture(0, pa_glass.atlas); material_glass.setTexture(0, pa_glass.atlas);
// Wood material // Wood material
@ -167,8 +167,8 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
material_wood.setFlag(video::EMF_BILINEAR_FILTER, false); material_wood.setFlag(video::EMF_BILINEAR_FILTER, false);
material_wood.setFlag(video::EMF_FOG_ENABLE, true); material_wood.setFlag(video::EMF_FOG_ENABLE, true);
material_wood.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; material_wood.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
AtlasPointer pa_wood = g_texturesource->getTexture( AtlasPointer pa_wood = tsrc->getTexture(
g_texturesource->getTextureId("wood.png")); tsrc->getTextureId("wood.png"));
material_wood.setTexture(0, pa_wood.atlas); material_wood.setTexture(0, pa_wood.atlas);
// General ground material for special output // General ground material for special output
@ -186,8 +186,8 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
material_papyrus.setFlag(video::EMF_BILINEAR_FILTER, false); material_papyrus.setFlag(video::EMF_BILINEAR_FILTER, false);
material_papyrus.setFlag(video::EMF_FOG_ENABLE, true); material_papyrus.setFlag(video::EMF_FOG_ENABLE, true);
material_papyrus.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; material_papyrus.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
AtlasPointer pa_papyrus = g_texturesource->getTexture( AtlasPointer pa_papyrus = tsrc->getTexture(
g_texturesource->getTextureId("papyrus.png")); tsrc->getTextureId("papyrus.png"));
material_papyrus.setTexture(0, pa_papyrus.atlas); material_papyrus.setTexture(0, pa_papyrus.atlas);
// Apple material // Apple material
@ -196,8 +196,8 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
material_apple.setFlag(video::EMF_BILINEAR_FILTER, false); material_apple.setFlag(video::EMF_BILINEAR_FILTER, false);
material_apple.setFlag(video::EMF_FOG_ENABLE, true); material_apple.setFlag(video::EMF_FOG_ENABLE, true);
material_apple.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; material_apple.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
AtlasPointer pa_apple = g_texturesource->getTexture( AtlasPointer pa_apple = tsrc->getTexture(
g_texturesource->getTextureId("apple.png")); tsrc->getTextureId("apple.png"));
material_apple.setTexture(0, pa_apple.atlas); material_apple.setTexture(0, pa_apple.atlas);
@ -207,8 +207,8 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
material_sapling.setFlag(video::EMF_BILINEAR_FILTER, false); material_sapling.setFlag(video::EMF_BILINEAR_FILTER, false);
material_sapling.setFlag(video::EMF_FOG_ENABLE, true); material_sapling.setFlag(video::EMF_FOG_ENABLE, true);
material_sapling.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; material_sapling.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
AtlasPointer pa_sapling = g_texturesource->getTexture( AtlasPointer pa_sapling = tsrc->getTexture(
g_texturesource->getTextureId("sapling.png")); tsrc->getTextureId("sapling.png"));
material_sapling.setTexture(0, pa_sapling.atlas); material_sapling.setTexture(0, pa_sapling.atlas);
@ -218,8 +218,8 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
material_junglegrass.setFlag(video::EMF_BILINEAR_FILTER, false); material_junglegrass.setFlag(video::EMF_BILINEAR_FILTER, false);
material_junglegrass.setFlag(video::EMF_FOG_ENABLE, true); material_junglegrass.setFlag(video::EMF_FOG_ENABLE, true);
material_junglegrass.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; material_junglegrass.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
AtlasPointer pa_junglegrass = g_texturesource->getTexture( AtlasPointer pa_junglegrass = tsrc->getTexture(
g_texturesource->getTextureId("junglegrass.png")); tsrc->getTextureId("junglegrass.png"));
material_junglegrass.setTexture(0, pa_junglegrass.atlas); material_junglegrass.setTexture(0, pa_junglegrass.atlas);
for(s16 z=0; z<MAP_BLOCKSIZE; z++) for(s16 z=0; z<MAP_BLOCKSIZE; z++)
@ -249,7 +249,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
texturename = "torch.png"; texturename = "torch.png";
} }
AtlasPointer ap = g_texturesource->getTexture(texturename); AtlasPointer ap = tsrc->getTexture(texturename);
// Set material // Set material
video::SMaterial material; video::SMaterial material;
@ -304,7 +304,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
*/ */
else if(n.getContent() == CONTENT_SIGN_WALL) else if(n.getContent() == CONTENT_SIGN_WALL)
{ {
AtlasPointer ap = g_texturesource->getTexture("sign_wall.png"); AtlasPointer ap = tsrc->getTexture("sign_wall.png");
// Set material // Set material
video::SMaterial material; video::SMaterial material;
@ -923,7 +923,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
video::SColor c = MapBlock_LightColor(255, l); video::SColor c = MapBlock_LightColor(255, l);
// Get the right texture // Get the right texture
TileSpec ts = n.getTile(dir); TileSpec ts = n.getTile(dir, tsrc);
AtlasPointer ap = ts.texture; AtlasPointer ap = ts.texture;
material_general.setTexture(0, ap.atlas); material_general.setTexture(0, ap.atlas);
@ -1110,7 +1110,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
else if(adjacencies == 4) else if(adjacencies == 4)
texturename = "rail_crossing.png"; texturename = "rail_crossing.png";
AtlasPointer ap = g_texturesource->getTexture(texturename); AtlasPointer ap = tsrc->getTexture(texturename);
video::SMaterial material_rail; video::SMaterial material_rail;
material_rail.setFlag(video::EMF_LIGHTING, false); material_rail.setFlag(video::EMF_LIGHTING, false);
@ -1182,7 +1182,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
collector.append(material_rail, vertices, 4, indices, 6); collector.append(material_rail, vertices, 4, indices, 6);
} }
else if (n.getContent() == CONTENT_LADDER) { else if (n.getContent() == CONTENT_LADDER) {
AtlasPointer ap = g_texturesource->getTexture("ladder.png"); AtlasPointer ap = tsrc->getTexture("ladder.png");
// Set material // Set material
video::SMaterial material_ladder; video::SMaterial material_ladder;

@ -23,8 +23,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef SERVER #ifndef SERVER
#include "mapblock_mesh.h" #include "mapblock_mesh.h"
#include "utility.h" #include "utility.h"
class ITextureSource;
void mapblock_mesh_generate_special(MeshMakeData *data, void mapblock_mesh_generate_special(MeshMakeData *data,
MeshCollector &collector); MeshCollector &collector, ITextureSource *tsrc);
#endif #endif
#endif #endif

@ -156,16 +156,16 @@ MapNode mapnode_translate_to_internal(MapNode n_from, u8 version)
} }
// See header for description // See header for description
void content_mapnode_init() void content_mapnode_init(ITextureSource *tsrc)
{ {
if(g_texturesource == NULL) if(tsrc == NULL)
dstream<<"INFO: Initial run of content_mapnode_init with " dstream<<"INFO: Initial run of content_mapnode_init with "
"g_texturesource=NULL. If this segfaults, " "tsrc=NULL. If this segfaults, "
"there is a bug with something not checking for " "there is a bug with something not checking for "
"the NULL value."<<std::endl; "the NULL value."<<std::endl;
else else
dstream<<"INFO: Full run of content_mapnode_init with " dstream<<"INFO: Full run of content_mapnode_init with "
"g_texturesource!=NULL"<<std::endl; "tsrc!=NULL"<<std::endl;
// Read some settings // Read some settings
bool new_style_water = g_settings->getBool("new_style_water"); bool new_style_water = g_settings->getBool("new_style_water");
@ -178,8 +178,8 @@ void content_mapnode_init()
i = CONTENT_STONE; i = CONTENT_STONE;
f = &content_features(i); f = &content_features(i);
f->setAllTextures("stone.png"); f->setAllTextures(tsrc, "stone.png");
f->setInventoryTextureCube("stone.png", "stone.png", "stone.png"); f->setInventoryTextureCube("stone.png", "stone.png", "stone.png", tsrc);
f->param_type = CPT_MINERAL; f->param_type = CPT_MINERAL;
f->is_ground_content = true; f->is_ground_content = true;
f->often_contains_mineral = true; f->often_contains_mineral = true;
@ -190,9 +190,9 @@ void content_mapnode_init()
i = CONTENT_GRASS; i = CONTENT_GRASS;
f = &content_features(i); f = &content_features(i);
f->setAllTextures("mud.png^grass_side.png"); f->setAllTextures(tsrc, "mud.png^grass_side.png");
f->setTexture(0, "grass.png"); f->setTexture(tsrc, 0, "grass.png");
f->setTexture(1, "mud.png"); f->setTexture(tsrc, 1, "mud.png");
f->param_type = CPT_MINERAL; f->param_type = CPT_MINERAL;
f->is_ground_content = true; f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(CONTENT_MUD)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(CONTENT_MUD)+" 1";
@ -200,9 +200,9 @@ void content_mapnode_init()
i = CONTENT_GRASS_FOOTSTEPS; i = CONTENT_GRASS_FOOTSTEPS;
f = &content_features(i); f = &content_features(i);
f->setAllTextures("mud.png^grass_side.png"); f->setAllTextures(tsrc, "mud.png^grass_side.png");
f->setTexture(0, "grass_footsteps.png"); f->setTexture(tsrc, 0, "grass_footsteps.png");
f->setTexture(1, "mud.png"); f->setTexture(tsrc, 1, "mud.png");
f->param_type = CPT_MINERAL; f->param_type = CPT_MINERAL;
f->is_ground_content = true; f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(CONTENT_MUD)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(CONTENT_MUD)+" 1";
@ -210,8 +210,8 @@ void content_mapnode_init()
i = CONTENT_MUD; i = CONTENT_MUD;
f = &content_features(i); f = &content_features(i);
f->setAllTextures("mud.png"); f->setAllTextures(tsrc, "mud.png");
f->setInventoryTextureCube("mud.png", "mud.png", "mud.png"); f->setInventoryTextureCube("mud.png", "mud.png", "mud.png", tsrc);
f->param_type = CPT_MINERAL; f->param_type = CPT_MINERAL;
f->is_ground_content = true; f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
@ -219,8 +219,8 @@ void content_mapnode_init()
i = CONTENT_SAND; i = CONTENT_SAND;
f = &content_features(i); f = &content_features(i);
f->setAllTextures("sand.png"); f->setAllTextures(tsrc, "sand.png");
f->setInventoryTextureCube("sand.png", "sand.png", "sand.png"); f->setInventoryTextureCube("sand.png", "sand.png", "sand.png", tsrc);
f->param_type = CPT_MINERAL; f->param_type = CPT_MINERAL;
f->is_ground_content = true; f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
@ -228,8 +228,8 @@ void content_mapnode_init()
i = CONTENT_GRAVEL; i = CONTENT_GRAVEL;
f = &content_features(i); f = &content_features(i);
f->setAllTextures("gravel.png"); f->setAllTextures(tsrc, "gravel.png");
f->setInventoryTextureCube("gravel.png", "gravel.png", "gravel.png"); f->setInventoryTextureCube("gravel.png", "gravel.png", "gravel.png", tsrc);
f->param_type = CPT_MINERAL; f->param_type = CPT_MINERAL;
f->is_ground_content = true; f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
@ -237,8 +237,8 @@ void content_mapnode_init()
i = CONTENT_SANDSTONE; i = CONTENT_SANDSTONE;
f = &content_features(i); f = &content_features(i);
f->setAllTextures("sandstone.png"); f->setAllTextures(tsrc, "sandstone.png");
f->setInventoryTextureCube("sandstone.png", "sandstone.png", "sandstone.png"); f->setInventoryTextureCube("sandstone.png", "sandstone.png", "sandstone.png", tsrc);
f->param_type = CPT_MINERAL; f->param_type = CPT_MINERAL;
f->is_ground_content = true; f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(CONTENT_SAND)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(CONTENT_SAND)+" 1";
@ -246,8 +246,8 @@ void content_mapnode_init()
i = CONTENT_CLAY; i = CONTENT_CLAY;
f = &content_features(i); f = &content_features(i);
f->setAllTextures("clay.png"); f->setAllTextures(tsrc, "clay.png");
f->setInventoryTextureCube("clay.png", "clay.png", "clay.png"); f->setInventoryTextureCube("clay.png", "clay.png", "clay.png", tsrc);
f->param_type = CPT_MINERAL; f->param_type = CPT_MINERAL;
f->is_ground_content = true; f->is_ground_content = true;
f->dug_item = std::string("CraftItem lump_of_clay 4"); f->dug_item = std::string("CraftItem lump_of_clay 4");
@ -255,8 +255,8 @@ void content_mapnode_init()
i = CONTENT_BRICK; i = CONTENT_BRICK;
f = &content_features(i); f = &content_features(i);
f->setAllTextures("brick.png"); f->setAllTextures(tsrc, "brick.png");
f->setInventoryTextureCube("brick.png", "brick.png", "brick.png"); f->setInventoryTextureCube("brick.png", "brick.png", "brick.png", tsrc);
f->param_type = CPT_MINERAL; f->param_type = CPT_MINERAL;
f->is_ground_content = true; f->is_ground_content = true;
f->dug_item = std::string("CraftItem clay_brick 4"); f->dug_item = std::string("CraftItem clay_brick 4");
@ -264,9 +264,9 @@ void content_mapnode_init()
i = CONTENT_TREE; i = CONTENT_TREE;
f = &content_features(i); f = &content_features(i);
f->setAllTextures("tree.png"); f->setAllTextures(tsrc, "tree.png");
f->setTexture(0, "tree_top.png"); f->setTexture(tsrc, 0, "tree_top.png");
f->setTexture(1, "tree_top.png"); f->setTexture(tsrc, 1, "tree_top.png");
f->param_type = CPT_MINERAL; f->param_type = CPT_MINERAL;
f->is_ground_content = true; f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
@ -274,9 +274,9 @@ void content_mapnode_init()
i = CONTENT_JUNGLETREE; i = CONTENT_JUNGLETREE;
f = &content_features(i); f = &content_features(i);
f->setAllTextures("jungletree.png"); f->setAllTextures(tsrc, "jungletree.png");
f->setTexture(0, "jungletree_top.png"); f->setTexture(tsrc, 0, "jungletree_top.png");
f->setTexture(1, "jungletree_top.png"); f->setTexture(tsrc, 1, "jungletree_top.png");
f->param_type = CPT_MINERAL; f->param_type = CPT_MINERAL;
//f->is_ground_content = true; //f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
@ -284,7 +284,7 @@ void content_mapnode_init()
i = CONTENT_JUNGLEGRASS; i = CONTENT_JUNGLEGRASS;
f = &content_features(i); f = &content_features(i);
f->setInventoryTexture("junglegrass.png"); f->setInventoryTexture("junglegrass.png", tsrc);
f->used_texturenames["junglegrass.png"] = true; f->used_texturenames["junglegrass.png"] = true;
f->light_propagates = true; f->light_propagates = true;
f->param_type = CPT_LIGHT; f->param_type = CPT_LIGHT;
@ -305,12 +305,12 @@ void content_mapnode_init()
{ {
f->solidness = 0; // drawn separately, makes no faces f->solidness = 0; // drawn separately, makes no faces
f->visual_solidness = 1; f->visual_solidness = 1;
f->setAllTextures("leaves.png"); f->setAllTextures(tsrc, "leaves.png");
f->setInventoryTextureCube("leaves.png", "leaves.png", "leaves.png"); f->setInventoryTextureCube("leaves.png", "leaves.png", "leaves.png", tsrc);
} }
else else
{ {
f->setAllTextures("[noalpha:leaves.png"); f->setAllTextures(tsrc, "[noalpha:leaves.png");
} }
f->extra_dug_item = std::string("MaterialItem2 ")+itos(CONTENT_SAPLING)+" 1"; f->extra_dug_item = std::string("MaterialItem2 ")+itos(CONTENT_SAPLING)+" 1";
f->extra_dug_item_rarity = 20; f->extra_dug_item_rarity = 20;
@ -319,10 +319,10 @@ void content_mapnode_init()
i = CONTENT_CACTUS; i = CONTENT_CACTUS;
f = &content_features(i); f = &content_features(i);
f->setAllTextures("cactus_side.png"); f->setAllTextures(tsrc, "cactus_side.png");
f->setTexture(0, "cactus_top.png"); f->setTexture(tsrc, 0, "cactus_top.png");
f->setTexture(1, "cactus_top.png"); f->setTexture(tsrc, 1, "cactus_top.png");
f->setInventoryTextureCube("cactus_top.png", "cactus_side.png", "cactus_side.png"); f->setInventoryTextureCube("cactus_top.png", "cactus_side.png", "cactus_side.png", tsrc);
f->param_type = CPT_MINERAL; f->param_type = CPT_MINERAL;
f->is_ground_content = true; f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
@ -330,7 +330,7 @@ void content_mapnode_init()
i = CONTENT_PAPYRUS; i = CONTENT_PAPYRUS;
f = &content_features(i); f = &content_features(i);
f->setInventoryTexture("papyrus.png"); f->setInventoryTexture("papyrus.png", tsrc);
f->used_texturenames["papyrus.png"] = true; f->used_texturenames["papyrus.png"] = true;
f->light_propagates = true; f->light_propagates = true;
f->param_type = CPT_LIGHT; f->param_type = CPT_LIGHT;
@ -342,12 +342,12 @@ void content_mapnode_init()
i = CONTENT_BOOKSHELF; i = CONTENT_BOOKSHELF;
f = &content_features(i); f = &content_features(i);
f->setAllTextures("bookshelf.png"); f->setAllTextures(tsrc, "bookshelf.png");
f->setTexture(0, "wood.png"); f->setTexture(tsrc, 0, "wood.png");
f->setTexture(1, "wood.png"); f->setTexture(tsrc, 1, "wood.png");
// FIXME: setInventoryTextureCube() only cares for the first texture // FIXME: setInventoryTextureCube() only cares for the first texture
f->setInventoryTextureCube("bookshelf.png", "bookshelf.png", "bookshelf.png"); f->setInventoryTextureCube("bookshelf.png", "bookshelf.png", "bookshelf.png", tsrc);
//f->setInventoryTextureCube("wood.png", "bookshelf.png", "bookshelf.png"); //f->setInventoryTextureCube("wood.png", "bookshelf.png", "bookshelf.png", tsrc);
f->param_type = CPT_MINERAL; f->param_type = CPT_MINERAL;
f->is_ground_content = true; f->is_ground_content = true;
setWoodLikeMaterialProperties(f->material, 0.75); setWoodLikeMaterialProperties(f->material, 0.75);
@ -361,8 +361,8 @@ void content_mapnode_init()
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
f->solidness = 0; // drawn separately, makes no faces f->solidness = 0; // drawn separately, makes no faces
f->visual_solidness = 1; f->visual_solidness = 1;
f->setAllTextures("glass.png"); f->setAllTextures(tsrc, "glass.png");
f->setInventoryTextureCube("glass.png", "glass.png", "glass.png"); f->setInventoryTextureCube("glass.png", "glass.png", "glass.png", tsrc);
setGlassLikeMaterialProperties(f->material, 1.0); setGlassLikeMaterialProperties(f->material, 1.0);
i = CONTENT_FENCE; i = CONTENT_FENCE;
@ -373,13 +373,13 @@ void content_mapnode_init()
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
f->solidness = 0; // drawn separately, makes no faces f->solidness = 0; // drawn separately, makes no faces
f->air_equivalent = true; // grass grows underneath f->air_equivalent = true; // grass grows underneath
f->setInventoryTexture("fence.png"); f->setInventoryTexture("fence.png", tsrc);
f->used_texturenames["fence.png"] = true; f->used_texturenames["fence.png"] = true;
setWoodLikeMaterialProperties(f->material, 0.75); setWoodLikeMaterialProperties(f->material, 0.75);
i = CONTENT_RAIL; i = CONTENT_RAIL;
f = &content_features(i); f = &content_features(i);
f->setInventoryTexture("rail.png"); f->setInventoryTexture("rail.png", tsrc);
f->used_texturenames["rail.png"] = true; f->used_texturenames["rail.png"] = true;
f->light_propagates = true; f->light_propagates = true;
f->param_type = CPT_LIGHT; f->param_type = CPT_LIGHT;
@ -393,7 +393,7 @@ void content_mapnode_init()
i = CONTENT_LADDER; i = CONTENT_LADDER;
f = &content_features(i); f = &content_features(i);
f->setInventoryTexture("ladder.png"); f->setInventoryTexture("ladder.png", tsrc);
f->used_texturenames["ladder.png"] = true; f->used_texturenames["ladder.png"] = true;
f->light_propagates = true; f->light_propagates = true;
f->param_type = CPT_LIGHT; f->param_type = CPT_LIGHT;
@ -410,30 +410,30 @@ void content_mapnode_init()
// Deprecated // Deprecated
i = CONTENT_COALSTONE; i = CONTENT_COALSTONE;
f = &content_features(i); f = &content_features(i);
f->setAllTextures("stone.png^mineral_coal.png"); f->setAllTextures(tsrc, "stone.png^mineral_coal.png");
f->is_ground_content = true; f->is_ground_content = true;
setStoneLikeMaterialProperties(f->material, 1.5); setStoneLikeMaterialProperties(f->material, 1.5);
i = CONTENT_WOOD; i = CONTENT_WOOD;
f = &content_features(i); f = &content_features(i);
f->setAllTextures("wood.png"); f->setAllTextures(tsrc, "wood.png");
f->setInventoryTextureCube("wood.png", "wood.png", "wood.png"); f->setInventoryTextureCube("wood.png", "wood.png", "wood.png", tsrc);
f->is_ground_content = true; f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
setWoodLikeMaterialProperties(f->material, 0.75); setWoodLikeMaterialProperties(f->material, 0.75);
i = CONTENT_MESE; i = CONTENT_MESE;
f = &content_features(i); f = &content_features(i);
f->setAllTextures("mese.png"); f->setAllTextures(tsrc, "mese.png");
f->setInventoryTextureCube("mese.png", "mese.png", "mese.png"); f->setInventoryTextureCube("mese.png", "mese.png", "mese.png", tsrc);
f->is_ground_content = true; f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
setStoneLikeMaterialProperties(f->material, 0.5); setStoneLikeMaterialProperties(f->material, 0.5);
i = CONTENT_CLOUD; i = CONTENT_CLOUD;
f = &content_features(i); f = &content_features(i);
f->setAllTextures("cloud.png"); f->setAllTextures(tsrc, "cloud.png");
f->setInventoryTextureCube("cloud.png", "cloud.png", "cloud.png"); f->setInventoryTextureCube("cloud.png", "cloud.png", "cloud.png", tsrc);
f->is_ground_content = true; f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
@ -451,7 +451,7 @@ void content_mapnode_init()
i = CONTENT_WATER; i = CONTENT_WATER;
f = &content_features(i); f = &content_features(i);
f->setInventoryTextureCube("water.png", "water.png", "water.png"); f->setInventoryTextureCube("water.png", "water.png", "water.png", tsrc);
f->param_type = CPT_LIGHT; f->param_type = CPT_LIGHT;
f->light_propagates = true; f->light_propagates = true;
f->solidness = 0; // Drawn separately, makes no faces f->solidness = 0; // Drawn separately, makes no faces
@ -468,7 +468,7 @@ void content_mapnode_init()
if(!opaque_water) if(!opaque_water)
f->vertex_alpha = WATER_ALPHA; f->vertex_alpha = WATER_ALPHA;
f->post_effect_color = video::SColor(64, 100, 100, 200); f->post_effect_color = video::SColor(64, 100, 100, 200);
if(f->special_material == NULL && g_texturesource) if(f->special_material == NULL && tsrc)
{ {
// Flowing water material // Flowing water material
f->special_material = new video::SMaterial; f->special_material = new video::SMaterial;
@ -478,8 +478,8 @@ void content_mapnode_init()
f->special_material->setFlag(video::EMF_FOG_ENABLE, true); f->special_material->setFlag(video::EMF_FOG_ENABLE, true);
if(!opaque_water) if(!opaque_water)
f->special_material->MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA; f->special_material->MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
AtlasPointer *pa_water1 = new AtlasPointer(g_texturesource->getTexture( AtlasPointer *pa_water1 = new AtlasPointer(tsrc->getTexture(
g_texturesource->getTextureId("water.png"))); tsrc->getTextureId("water.png")));
f->special_material->setTexture(0, pa_water1->atlas); f->special_material->setTexture(0, pa_water1->atlas);
// Flowing water material, backface culled // Flowing water material, backface culled
@ -493,8 +493,8 @@ void content_mapnode_init()
i = CONTENT_WATERSOURCE; i = CONTENT_WATERSOURCE;
f = &content_features(i); f = &content_features(i);
//f->setInventoryTexture("water.png"); //f->setInventoryTexture("water.png", tsrc);
f->setInventoryTextureCube("water.png", "water.png", "water.png"); f->setInventoryTextureCube("water.png", "water.png", "water.png", tsrc);
if(new_style_water) if(new_style_water)
{ {
f->solidness = 0; // drawn separately, makes no faces f->solidness = 0; // drawn separately, makes no faces
@ -504,8 +504,8 @@ void content_mapnode_init()
f->solidness = 1; f->solidness = 1;
#ifndef SERVER #ifndef SERVER
TileSpec t; TileSpec t;
if(g_texturesource) if(tsrc)
t.texture = g_texturesource->getTexture("water.png"); t.texture = tsrc->getTexture("water.png");
if(!opaque_water){ if(!opaque_water){
t.alpha = WATER_ALPHA; t.alpha = WATER_ALPHA;
@ -530,7 +530,7 @@ void content_mapnode_init()
if(!opaque_water) if(!opaque_water)
f->vertex_alpha = WATER_ALPHA; f->vertex_alpha = WATER_ALPHA;
f->post_effect_color = video::SColor(64, 100, 100, 200); f->post_effect_color = video::SColor(64, 100, 100, 200);
if(f->special_material == NULL && g_texturesource) if(f->special_material == NULL && tsrc)
{ {
// New-style water source material (mostly unused) // New-style water source material (mostly unused)
f->special_material = new video::SMaterial; f->special_material = new video::SMaterial;
@ -539,8 +539,8 @@ void content_mapnode_init()
f->special_material->setFlag(video::EMF_BILINEAR_FILTER, false); f->special_material->setFlag(video::EMF_BILINEAR_FILTER, false);
f->special_material->setFlag(video::EMF_FOG_ENABLE, true); f->special_material->setFlag(video::EMF_FOG_ENABLE, true);
f->special_material->MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA; f->special_material->MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
AtlasPointer *pa_water1 = new AtlasPointer(g_texturesource->getTexture( AtlasPointer *pa_water1 = new AtlasPointer(tsrc->getTexture(
g_texturesource->getTextureId("water.png"))); tsrc->getTextureId("water.png")));
f->special_material->setTexture(0, pa_water1->atlas); f->special_material->setTexture(0, pa_water1->atlas);
f->special_atlas = pa_water1; f->special_atlas = pa_water1;
} }
@ -548,7 +548,7 @@ void content_mapnode_init()
i = CONTENT_LAVA; i = CONTENT_LAVA;
f = &content_features(i); f = &content_features(i);
f->setInventoryTextureCube("lava.png", "lava.png", "lava.png"); f->setInventoryTextureCube("lava.png", "lava.png", "lava.png", tsrc);
f->used_texturenames["lava.png"] = true; f->used_texturenames["lava.png"] = true;
f->param_type = CPT_LIGHT; f->param_type = CPT_LIGHT;
f->light_propagates = false; f->light_propagates = false;
@ -566,7 +566,7 @@ void content_mapnode_init()
f->damage_per_second = 4*2; f->damage_per_second = 4*2;
#ifndef SERVER #ifndef SERVER
f->post_effect_color = video::SColor(192, 255, 64, 0); f->post_effect_color = video::SColor(192, 255, 64, 0);
if(f->special_material == NULL && g_texturesource) if(f->special_material == NULL && tsrc)
{ {
// Flowing lava material // Flowing lava material
f->special_material = new video::SMaterial; f->special_material = new video::SMaterial;
@ -577,8 +577,8 @@ void content_mapnode_init()
f->special_material->MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; f->special_material->MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
AtlasPointer *pa_lava1 = new AtlasPointer( AtlasPointer *pa_lava1 = new AtlasPointer(
g_texturesource->getTexture( tsrc->getTexture(
g_texturesource->getTextureId("lava.png"))); tsrc->getTextureId("lava.png")));
f->special_material->setTexture(0, pa_lava1->atlas); f->special_material->setTexture(0, pa_lava1->atlas);
// Flowing lava material, backface culled // Flowing lava material, backface culled
@ -592,7 +592,7 @@ void content_mapnode_init()
i = CONTENT_LAVASOURCE; i = CONTENT_LAVASOURCE;
f = &content_features(i); f = &content_features(i);
f->setInventoryTextureCube("lava.png", "lava.png", "lava.png"); f->setInventoryTextureCube("lava.png", "lava.png", "lava.png", tsrc);
f->used_texturenames["ladder.png"] = true; f->used_texturenames["ladder.png"] = true;
if(new_style_water) if(new_style_water)
{ {
@ -603,8 +603,8 @@ void content_mapnode_init()
f->solidness = 2; f->solidness = 2;
#ifndef SERVER #ifndef SERVER
TileSpec t; TileSpec t;
if(g_texturesource) if(tsrc)
t.texture = g_texturesource->getTexture("lava.png"); t.texture = tsrc->getTexture("lava.png");
//t.alpha = 255; //t.alpha = 255;
//t.material_type = MATERIAL_ALPHA_VERTEX; //t.material_type = MATERIAL_ALPHA_VERTEX;
@ -627,7 +627,7 @@ void content_mapnode_init()
f->damage_per_second = 4*2; f->damage_per_second = 4*2;
#ifndef SERVER #ifndef SERVER
f->post_effect_color = video::SColor(192, 255, 64, 0); f->post_effect_color = video::SColor(192, 255, 64, 0);
if(f->special_material == NULL && g_texturesource) if(f->special_material == NULL && tsrc)
{ {
// New-style lava source material (mostly unused) // New-style lava source material (mostly unused)
f->special_material = new video::SMaterial; f->special_material = new video::SMaterial;
@ -637,8 +637,8 @@ void content_mapnode_init()
f->special_material->setFlag(video::EMF_FOG_ENABLE, true); f->special_material->setFlag(video::EMF_FOG_ENABLE, true);
f->special_material->MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; f->special_material->MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
AtlasPointer *pa_lava1 = new AtlasPointer( AtlasPointer *pa_lava1 = new AtlasPointer(
g_texturesource->getTexture( tsrc->getTexture(
g_texturesource->getTextureId("lava.png"))); tsrc->getTextureId("lava.png")));
f->special_material->setTexture(0, pa_lava1->atlas); f->special_material->setTexture(0, pa_lava1->atlas);
f->special_atlas = pa_lava1; f->special_atlas = pa_lava1;
@ -647,7 +647,7 @@ void content_mapnode_init()
i = CONTENT_TORCH; i = CONTENT_TORCH;
f = &content_features(i); f = &content_features(i);
f->setInventoryTexture("torch_on_floor.png"); f->setInventoryTexture("torch_on_floor.png", tsrc);
f->used_texturenames["torch_on_floor.png"] = true; f->used_texturenames["torch_on_floor.png"] = true;
f->used_texturenames["torch_on_ceiling.png"] = true; f->used_texturenames["torch_on_ceiling.png"] = true;
f->used_texturenames["torch_on_floor.png"] = true; f->used_texturenames["torch_on_floor.png"] = true;
@ -672,7 +672,7 @@ void content_mapnode_init()
i = CONTENT_SIGN_WALL; i = CONTENT_SIGN_WALL;
f = &content_features(i); f = &content_features(i);
f->setInventoryTexture("sign_wall.png"); f->setInventoryTexture("sign_wall.png", tsrc);
f->used_texturenames["sign_wall.png"] = true; f->used_texturenames["sign_wall.png"] = true;
f->param_type = CPT_LIGHT; f->param_type = CPT_LIGHT;
f->light_propagates = true; f->light_propagates = true;
@ -683,54 +683,54 @@ void content_mapnode_init()
f->air_equivalent = true; f->air_equivalent = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
if(f->initial_metadata == NULL) if(f->initial_metadata == NULL)
f->initial_metadata = new SignNodeMetadata("Some sign"); f->initial_metadata = new SignNodeMetadata(NULL, "Some sign");
setConstantMaterialProperties(f->material, 0.5); setConstantMaterialProperties(f->material, 0.5);
f->selection_box.type = NODEBOX_WALLMOUNTED; f->selection_box.type = NODEBOX_WALLMOUNTED;
i = CONTENT_CHEST; i = CONTENT_CHEST;
f = &content_features(i); f = &content_features(i);
f->param_type = CPT_FACEDIR_SIMPLE; f->param_type = CPT_FACEDIR_SIMPLE;
f->setAllTextures("chest_side.png"); f->setAllTextures(tsrc, "chest_side.png");
f->setTexture(0, "chest_top.png"); f->setTexture(tsrc, 0, "chest_top.png");
f->setTexture(1, "chest_top.png"); f->setTexture(tsrc, 1, "chest_top.png");
f->setTexture(5, "chest_front.png"); // Z- f->setTexture(tsrc, 5, "chest_front.png"); // Z-
f->setInventoryTexture("chest_top.png"); f->setInventoryTexture("chest_top.png", tsrc);
//f->setInventoryTextureCube("chest_top.png", "chest_side.png", "chest_side.png"); //f->setInventoryTextureCube("chest_top.png", "chest_side.png", "chest_side.png", tsrc);
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
if(f->initial_metadata == NULL) if(f->initial_metadata == NULL)
f->initial_metadata = new ChestNodeMetadata(); f->initial_metadata = new ChestNodeMetadata(NULL);
setWoodLikeMaterialProperties(f->material, 1.0); setWoodLikeMaterialProperties(f->material, 1.0);
i = CONTENT_LOCKABLE_CHEST; i = CONTENT_LOCKABLE_CHEST;
f = &content_features(i); f = &content_features(i);
f->param_type = CPT_FACEDIR_SIMPLE; f->param_type = CPT_FACEDIR_SIMPLE;
f->setAllTextures("chest_side.png"); f->setAllTextures(tsrc, "chest_side.png");
f->setTexture(0, "chest_top.png"); f->setTexture(tsrc, 0, "chest_top.png");
f->setTexture(1, "chest_top.png"); f->setTexture(tsrc, 1, "chest_top.png");
f->setTexture(5, "chest_lock.png"); // Z- f->setTexture(tsrc, 5, "chest_lock.png"); // Z-
f->setInventoryTexture("chest_lock.png"); f->setInventoryTexture("chest_lock.png", tsrc);
//f->setInventoryTextureCube("chest_top.png", "chest_side.png", "chest_side.png"); //f->setInventoryTextureCube("chest_top.png", "chest_side.png", "chest_side.png", tsrc);
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
if(f->initial_metadata == NULL) if(f->initial_metadata == NULL)
f->initial_metadata = new LockingChestNodeMetadata(); f->initial_metadata = new LockingChestNodeMetadata(NULL);
setWoodLikeMaterialProperties(f->material, 1.0); setWoodLikeMaterialProperties(f->material, 1.0);
i = CONTENT_FURNACE; i = CONTENT_FURNACE;
f = &content_features(i); f = &content_features(i);
f->param_type = CPT_FACEDIR_SIMPLE; f->param_type = CPT_FACEDIR_SIMPLE;
f->setAllTextures("furnace_side.png"); f->setAllTextures(tsrc, "furnace_side.png");
f->setTexture(5, "furnace_front.png"); // Z- f->setTexture(tsrc, 5, "furnace_front.png"); // Z-
f->setInventoryTexture("furnace_front.png"); f->setInventoryTexture("furnace_front.png", tsrc);
//f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; //f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
f->dug_item = std::string("MaterialItem2 ")+itos(CONTENT_COBBLE)+" 6"; f->dug_item = std::string("MaterialItem2 ")+itos(CONTENT_COBBLE)+" 6";
if(f->initial_metadata == NULL) if(f->initial_metadata == NULL)
f->initial_metadata = new FurnaceNodeMetadata(); f->initial_metadata = new FurnaceNodeMetadata(NULL);
setStoneLikeMaterialProperties(f->material, 3.0); setStoneLikeMaterialProperties(f->material, 3.0);
i = CONTENT_COBBLE; i = CONTENT_COBBLE;
f = &content_features(i); f = &content_features(i);
f->setAllTextures("cobble.png"); f->setAllTextures(tsrc, "cobble.png");
f->setInventoryTextureCube("cobble.png", "cobble.png", "cobble.png"); f->setInventoryTextureCube("cobble.png", "cobble.png", "cobble.png", tsrc);
f->param_type = CPT_NONE; f->param_type = CPT_NONE;
f->is_ground_content = true; f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
@ -738,8 +738,8 @@ void content_mapnode_init()
i = CONTENT_MOSSYCOBBLE; i = CONTENT_MOSSYCOBBLE;
f = &content_features(i); f = &content_features(i);
f->setAllTextures("mossycobble.png"); f->setAllTextures(tsrc, "mossycobble.png");
f->setInventoryTextureCube("mossycobble.png", "mossycobble.png", "mossycobble.png"); f->setInventoryTextureCube("mossycobble.png", "mossycobble.png", "mossycobble.png", tsrc);
f->param_type = CPT_NONE; f->param_type = CPT_NONE;
f->is_ground_content = true; f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
@ -747,9 +747,9 @@ void content_mapnode_init()
i = CONTENT_STEEL; i = CONTENT_STEEL;
f = &content_features(i); f = &content_features(i);
f->setAllTextures("steel_block.png"); f->setAllTextures(tsrc, "steel_block.png");
f->setInventoryTextureCube("steel_block.png", "steel_block.png", f->setInventoryTextureCube("steel_block.png", "steel_block.png",
"steel_block.png"); "steel_block.png", tsrc);
f->param_type = CPT_NONE; f->param_type = CPT_NONE;
f->is_ground_content = true; f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
@ -758,25 +758,25 @@ void content_mapnode_init()
i = CONTENT_NC; i = CONTENT_NC;
f = &content_features(i); f = &content_features(i);
f->param_type = CPT_FACEDIR_SIMPLE; f->param_type = CPT_FACEDIR_SIMPLE;
f->setAllTextures("nc_side.png"); f->setAllTextures(tsrc, "nc_side.png");
f->setTexture(5, "nc_front.png"); // Z- f->setTexture(tsrc, 5, "nc_front.png"); // Z-
f->setTexture(4, "nc_back.png"); // Z+ f->setTexture(tsrc, 4, "nc_back.png"); // Z+
f->setInventoryTexture("nc_front.png"); f->setInventoryTexture("nc_front.png", tsrc);
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
setStoneLikeMaterialProperties(f->material, 3.0); setStoneLikeMaterialProperties(f->material, 3.0);
i = CONTENT_NC_RB; i = CONTENT_NC_RB;
f = &content_features(i); f = &content_features(i);
f->setAllTextures("nc_rb.png"); f->setAllTextures(tsrc, "nc_rb.png");
f->setInventoryTexture("nc_rb.png"); f->setInventoryTexture("nc_rb.png", tsrc);
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
setStoneLikeMaterialProperties(f->material, 3.0); setStoneLikeMaterialProperties(f->material, 3.0);
i = CONTENT_SAPLING; i = CONTENT_SAPLING;
f = &content_features(i); f = &content_features(i);
f->param_type = CPT_LIGHT; f->param_type = CPT_LIGHT;
f->setAllTextures("sapling.png"); f->setAllTextures(tsrc, "sapling.png");
f->setInventoryTexture("sapling.png"); f->setInventoryTexture("sapling.png", tsrc);
f->used_texturenames["sapling.png"] = true; f->used_texturenames["sapling.png"] = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
f->light_propagates = true; f->light_propagates = true;
@ -787,7 +787,7 @@ void content_mapnode_init()
i = CONTENT_APPLE; i = CONTENT_APPLE;
f = &content_features(i); f = &content_features(i);
f->setInventoryTexture("apple.png"); f->setInventoryTexture("apple.png", tsrc);
f->used_texturenames["apple.png"] = true; f->used_texturenames["apple.png"] = true;
f->param_type = CPT_LIGHT; f->param_type = CPT_LIGHT;
f->light_propagates = true; f->light_propagates = true;

@ -21,20 +21,21 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define CONTENT_MAPNODE_HEADER #define CONTENT_MAPNODE_HEADER
#include "mapnode.h" #include "mapnode.h"
class ITextureSource;
/* /*
Fills stuff to the global ContentFeatures lookup table. Fills stuff to the global ContentFeatures lookup table.
This accesses g_texturesource; if it is non-NULL, textures are set This accesses tsrc; if it is non-NULL, textures are set
for the nodes. for the nodes.
Client first calls this with g_texturesource=NULL to run some Client first calls this with tsrc=NULL to run some
unit tests and stuff, then it runs this again with g_texturesource unit tests and stuff, then it runs this again with tsrc
defined to get the textures. defined to get the textures.
Server only calls this once with g_texturesource=NULL. Server only calls this once with tsrc=NULL.
*/ */
void content_mapnode_init(); void content_mapnode_init(ITextureSource *tsrc);
// Backwards compatibility for non-extended content types in v19 // Backwards compatibility for non-extended content types in v19
extern content_t trans_table_19[21][2]; extern content_t trans_table_19[21][2];

@ -27,9 +27,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/ */
// Prototype // Prototype
SignNodeMetadata proto_SignNodeMetadata(""); SignNodeMetadata proto_SignNodeMetadata(NULL, "");
SignNodeMetadata::SignNodeMetadata(std::string text): SignNodeMetadata::SignNodeMetadata(IGameDef *gamedef, std::string text):
NodeMetadata(gamedef),
m_text(text) m_text(text)
{ {
NodeMetadata::registerType(typeId(), create); NodeMetadata::registerType(typeId(), create);
@ -38,14 +39,14 @@ u16 SignNodeMetadata::typeId() const
{ {
return CONTENT_SIGN_WALL; return CONTENT_SIGN_WALL;
} }
NodeMetadata* SignNodeMetadata::create(std::istream &is) NodeMetadata* SignNodeMetadata::create(std::istream &is, IGameDef *gamedef)
{ {
std::string text = deSerializeString(is); std::string text = deSerializeString(is);
return new SignNodeMetadata(text); return new SignNodeMetadata(gamedef, text);
} }
NodeMetadata* SignNodeMetadata::clone() NodeMetadata* SignNodeMetadata::clone(IGameDef *gamedef)
{ {
return new SignNodeMetadata(m_text); return new SignNodeMetadata(gamedef, m_text);
} }
void SignNodeMetadata::serializeBody(std::ostream &os) void SignNodeMetadata::serializeBody(std::ostream &os)
{ {
@ -61,9 +62,10 @@ std::string SignNodeMetadata::infoText()
*/ */
// Prototype // Prototype
ChestNodeMetadata proto_ChestNodeMetadata; ChestNodeMetadata proto_ChestNodeMetadata(NULL);
ChestNodeMetadata::ChestNodeMetadata() ChestNodeMetadata::ChestNodeMetadata(IGameDef *gamedef):
NodeMetadata(gamedef)
{ {
NodeMetadata::registerType(typeId(), create); NodeMetadata::registerType(typeId(), create);
@ -78,15 +80,15 @@ u16 ChestNodeMetadata::typeId() const
{ {
return CONTENT_CHEST; return CONTENT_CHEST;
} }
NodeMetadata* ChestNodeMetadata::create(std::istream &is) NodeMetadata* ChestNodeMetadata::create(std::istream &is, IGameDef *gamedef)
{ {
ChestNodeMetadata *d = new ChestNodeMetadata(); ChestNodeMetadata *d = new ChestNodeMetadata(gamedef);
d->m_inventory->deSerialize(is); d->m_inventory->deSerialize(is, gamedef);
return d; return d;
} }
NodeMetadata* ChestNodeMetadata::clone() NodeMetadata* ChestNodeMetadata::clone(IGameDef *gamedef)
{ {
ChestNodeMetadata *d = new ChestNodeMetadata(); ChestNodeMetadata *d = new ChestNodeMetadata(gamedef);
*d->m_inventory = *m_inventory; *d->m_inventory = *m_inventory;
return d; return d;
} }
@ -123,9 +125,10 @@ std::string ChestNodeMetadata::getInventoryDrawSpecString()
*/ */
// Prototype // Prototype
LockingChestNodeMetadata proto_LockingChestNodeMetadata; LockingChestNodeMetadata proto_LockingChestNodeMetadata(NULL);
LockingChestNodeMetadata::LockingChestNodeMetadata() LockingChestNodeMetadata::LockingChestNodeMetadata(IGameDef *gamedef):
NodeMetadata(gamedef)
{ {
NodeMetadata::registerType(typeId(), create); NodeMetadata::registerType(typeId(), create);
@ -140,16 +143,16 @@ u16 LockingChestNodeMetadata::typeId() const
{ {
return CONTENT_LOCKABLE_CHEST; return CONTENT_LOCKABLE_CHEST;
} }
NodeMetadata* LockingChestNodeMetadata::create(std::istream &is) NodeMetadata* LockingChestNodeMetadata::create(std::istream &is, IGameDef *gamedef)
{ {
LockingChestNodeMetadata *d = new LockingChestNodeMetadata(); LockingChestNodeMetadata *d = new LockingChestNodeMetadata(gamedef);
d->setOwner(deSerializeString(is)); d->setOwner(deSerializeString(is));
d->m_inventory->deSerialize(is); d->m_inventory->deSerialize(is, gamedef);
return d; return d;
} }
NodeMetadata* LockingChestNodeMetadata::clone() NodeMetadata* LockingChestNodeMetadata::clone(IGameDef *gamedef)
{ {
LockingChestNodeMetadata *d = new LockingChestNodeMetadata(); LockingChestNodeMetadata *d = new LockingChestNodeMetadata(gamedef);
*d->m_inventory = *m_inventory; *d->m_inventory = *m_inventory;
return d; return d;
} }
@ -187,9 +190,10 @@ std::string LockingChestNodeMetadata::getInventoryDrawSpecString()
*/ */
// Prototype // Prototype
FurnaceNodeMetadata proto_FurnaceNodeMetadata; FurnaceNodeMetadata proto_FurnaceNodeMetadata(NULL);
FurnaceNodeMetadata::FurnaceNodeMetadata() FurnaceNodeMetadata::FurnaceNodeMetadata(IGameDef *gamedef):
NodeMetadata(gamedef)
{ {
NodeMetadata::registerType(typeId(), create); NodeMetadata::registerType(typeId(), create);
@ -212,17 +216,17 @@ u16 FurnaceNodeMetadata::typeId() const
{ {
return CONTENT_FURNACE; return CONTENT_FURNACE;
} }
NodeMetadata* FurnaceNodeMetadata::clone() NodeMetadata* FurnaceNodeMetadata::clone(IGameDef *gamedef)
{ {
FurnaceNodeMetadata *d = new FurnaceNodeMetadata(); FurnaceNodeMetadata *d = new FurnaceNodeMetadata(m_gamedef);
*d->m_inventory = *m_inventory; *d->m_inventory = *m_inventory;
return d; return d;
} }
NodeMetadata* FurnaceNodeMetadata::create(std::istream &is) NodeMetadata* FurnaceNodeMetadata::create(std::istream &is, IGameDef *gamedef)
{ {
FurnaceNodeMetadata *d = new FurnaceNodeMetadata(); FurnaceNodeMetadata *d = new FurnaceNodeMetadata(gamedef);
d->m_inventory->deSerialize(is); d->m_inventory->deSerialize(is, gamedef);
int temp; int temp;
is>>temp; is>>temp;

@ -27,12 +27,12 @@ class Inventory;
class SignNodeMetadata : public NodeMetadata class SignNodeMetadata : public NodeMetadata
{ {
public: public:
SignNodeMetadata(std::string text); SignNodeMetadata(IGameDef *gamedef, std::string text);
//~SignNodeMetadata(); //~SignNodeMetadata();
virtual u16 typeId() const; virtual u16 typeId() const;
static NodeMetadata* create(std::istream &is); static NodeMetadata* create(std::istream &is, IGameDef *gamedef);
virtual NodeMetadata* clone(); virtual NodeMetadata* clone(IGameDef *gamedef);
virtual void serializeBody(std::ostream &os); virtual void serializeBody(std::ostream &os);
virtual std::string infoText(); virtual std::string infoText();
@ -47,12 +47,12 @@ private:
class ChestNodeMetadata : public NodeMetadata class ChestNodeMetadata : public NodeMetadata
{ {
public: public:
ChestNodeMetadata(); ChestNodeMetadata(IGameDef *gamedef);
~ChestNodeMetadata(); ~ChestNodeMetadata();
virtual u16 typeId() const; virtual u16 typeId() const;
static NodeMetadata* create(std::istream &is); static NodeMetadata* create(std::istream &is, IGameDef *gamedef);
virtual NodeMetadata* clone(); virtual NodeMetadata* clone(IGameDef *gamedef);
virtual void serializeBody(std::ostream &os); virtual void serializeBody(std::ostream &os);
virtual std::string infoText(); virtual std::string infoText();
virtual Inventory* getInventory() {return m_inventory;} virtual Inventory* getInventory() {return m_inventory;}
@ -66,12 +66,12 @@ private:
class LockingChestNodeMetadata : public NodeMetadata class LockingChestNodeMetadata : public NodeMetadata
{ {
public: public:
LockingChestNodeMetadata(); LockingChestNodeMetadata(IGameDef *gamedef);
~LockingChestNodeMetadata(); ~LockingChestNodeMetadata();
virtual u16 typeId() const; virtual u16 typeId() const;
static NodeMetadata* create(std::istream &is); static NodeMetadata* create(std::istream &is, IGameDef *gamedef);
virtual NodeMetadata* clone(); virtual NodeMetadata* clone(IGameDef *gamedef);
virtual void serializeBody(std::ostream &os); virtual void serializeBody(std::ostream &os);
virtual std::string infoText(); virtual std::string infoText();
virtual Inventory* getInventory() {return m_inventory;} virtual Inventory* getInventory() {return m_inventory;}
@ -89,12 +89,12 @@ private:
class FurnaceNodeMetadata : public NodeMetadata class FurnaceNodeMetadata : public NodeMetadata
{ {
public: public:
FurnaceNodeMetadata(); FurnaceNodeMetadata(IGameDef *gamedef);
~FurnaceNodeMetadata(); ~FurnaceNodeMetadata();
virtual u16 typeId() const; virtual u16 typeId() const;
virtual NodeMetadata* clone(); virtual NodeMetadata* clone(IGameDef *gamedef);
static NodeMetadata* create(std::istream &is); static NodeMetadata* create(std::istream &is, IGameDef *gamedef);
virtual void serializeBody(std::ostream &os); virtual void serializeBody(std::ostream &os);
virtual std::string infoText(); virtual std::string infoText();
virtual Inventory* getInventory() {return m_inventory;} virtual Inventory* getInventory() {return m_inventory;}

@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "collision.h" #include "collision.h"
#include "environment.h" #include "environment.h"
#include "settings.h" #include "settings.h"
#include "main.h" // For g_profiler
#include "profiler.h" #include "profiler.h"
core::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types; core::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types;
@ -223,7 +224,8 @@ InventoryItem * ItemSAO::createInventoryItem()
{ {
try{ try{
std::istringstream is(m_inventorystring, std::ios_base::binary); std::istringstream is(m_inventorystring, std::ios_base::binary);
InventoryItem *item = InventoryItem::deSerialize(is); IGameDef *gamedef = m_env->getGameDef();
InventoryItem *item = InventoryItem::deSerialize(is, gamedef);
infostream<<__FUNCTION_NAME<<": m_inventorystring=\"" infostream<<__FUNCTION_NAME<<": m_inventorystring=\""
<<m_inventorystring<<"\" -> item="<<item <<m_inventorystring<<"\" -> item="<<item
<<std::endl; <<std::endl;
@ -448,7 +450,8 @@ std::string RatSAO::getStaticData()
void RatSAO::punch(ServerActiveObject *puncher) void RatSAO::punch(ServerActiveObject *puncher)
{ {
std::istringstream is("CraftItem rat 1", std::ios_base::binary); std::istringstream is("CraftItem rat 1", std::ios_base::binary);
InventoryItem *item = InventoryItem::deSerialize(is); IGameDef *gamedef = m_env->getGameDef();
InventoryItem *item = InventoryItem::deSerialize(is, gamedef);
bool fits = puncher->addToInventory(item); bool fits = puncher->addToInventory(item);
if(fits) if(fits)
m_removed = true; m_removed = true;
@ -932,7 +935,8 @@ std::string FireflySAO::getStaticData()
InventoryItem* FireflySAO::createPickedUpItem() InventoryItem* FireflySAO::createPickedUpItem()
{ {
std::istringstream is("CraftItem firefly 1", std::ios_base::binary); std::istringstream is("CraftItem firefly 1", std::ios_base::binary);
InventoryItem *item = InventoryItem::deSerialize(is); IGameDef *gamedef = m_env->getGameDef();
InventoryItem *item = InventoryItem::deSerialize(is, gamedef);
return item; return item;
} }
@ -1563,13 +1567,14 @@ LuaEntitySAO::~LuaEntitySAO()
delete m_prop; delete m_prop;
} }
void LuaEntitySAO::addedToEnvironment(u16 id) void LuaEntitySAO::addedToEnvironment()
{ {
ServerActiveObject::addedToEnvironment(id); ServerActiveObject::addedToEnvironment();
// Create entity from name and state // Create entity from name and state
lua_State *L = m_env->getLua(); lua_State *L = m_env->getLua();
m_registered = scriptapi_luaentity_add(L, id, m_init_name.c_str(), m_init_state.c_str()); m_registered = scriptapi_luaentity_add(L, m_id, m_init_name.c_str(),
m_init_state.c_str());
if(m_registered){ if(m_registered){
// Get properties // Get properties
@ -1660,7 +1665,8 @@ std::string LuaEntitySAO::getStaticData()
InventoryItem* LuaEntitySAO::createPickedUpItem() InventoryItem* LuaEntitySAO::createPickedUpItem()
{ {
std::istringstream is("CraftItem testobject1 1", std::ios_base::binary); std::istringstream is("CraftItem testobject1 1", std::ios_base::binary);
InventoryItem *item = InventoryItem::deSerialize(is); IGameDef *gamedef = m_env->getGameDef();
InventoryItem *item = InventoryItem::deSerialize(is, gamedef);
return item; return item;
} }

@ -204,7 +204,7 @@ public:
~LuaEntitySAO(); ~LuaEntitySAO();
u8 getType() const u8 getType() const
{return ACTIVEOBJECT_TYPE_LUAENTITY;} {return ACTIVEOBJECT_TYPE_LUAENTITY;}
virtual void addedToEnvironment(u16 id); virtual void addedToEnvironment();
static ServerActiveObject* create(ServerEnvironment *env, v3f pos, static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
const std::string &data); const std::string &data);
void step(float dtime, bool send_recommended); void step(float dtime, bool send_recommended);

68
src/content_tool.cpp Normal file

@ -0,0 +1,68 @@
/*
Minetest-c55
Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "content_tool.h"
#include "tool.h"
void content_tool_init(IToolDefManager *mgr)
{
mgr->registerTool("WPick",
ToolDefinition("tool_woodpick.png",
ToolDiggingProperties(2.0, 0,-1,2,0, 50, 0,0,0,0)));
mgr->registerTool("STPick",
ToolDefinition("tool_stonepick.png",
ToolDiggingProperties(1.5, 0,-1,2,0, 100, 0,0,0,0)));
mgr->registerTool("SteelPick",
ToolDefinition("tool_steelpick.png",
ToolDiggingProperties(1.0, 0,-1,2,0, 300, 0,0,0,0)));
mgr->registerTool("MesePick",
ToolDefinition("tool_mesepick.png",
ToolDiggingProperties(0, 0,0,0,0, 1337, 0,0,0,0)));
mgr->registerTool("WShovel",
ToolDefinition("tool_woodshovel.png",
ToolDiggingProperties(2.0, 0.5,2,-1.5,0.3, 50, 0,0,0,0)));
mgr->registerTool("STShovel",
ToolDefinition("tool_stoneshovel.png",
ToolDiggingProperties(1.5, 0.5,2,-1.5,0.1, 100, 0,0,0,0)));
mgr->registerTool("SteelShovel",
ToolDefinition("tool_steelshovel.png",
ToolDiggingProperties(1.0, 0.5,2,-1.5,0.0, 300, 0,0,0,0)));
mgr->registerTool("WAxe",
ToolDefinition("tool_woodaxe.png",
ToolDiggingProperties(2.0, 0.5,-0.2,1,-0.5, 50, 0,0,0,0)));
mgr->registerTool("STAxe",
ToolDefinition("tool_stoneaxe.png",
ToolDiggingProperties(1.5, 0.5,-0.2,1,-0.5, 100, 0,0,0,0)));
mgr->registerTool("SteelAxe",
ToolDefinition("tool_steelaxe.png",
ToolDiggingProperties(1.0, 0.5,-0.2,1,-0.5, 300, 0,0,0,0)));
mgr->registerTool("WSword",
ToolDefinition("tool_woodsword.png",
ToolDiggingProperties(3.0, 3,0,1,-1, 50, 0,0,0,0)));
mgr->registerTool("STSword",
ToolDefinition("tool_stonesword.png",
ToolDiggingProperties(2.5, 3,0,1,-1, 100, 0,0,0,0)));
mgr->registerTool("SteelSword",
ToolDefinition("tool_steelsword.png",
ToolDiggingProperties(2.0, 3,0,1,-1, 300, 0,0,0,0)));
mgr->registerTool("",
ToolDefinition("tool_hand.png",
ToolDiggingProperties(0.5, 1,0,-1,0, 50, 0,0,0,0)));
}

24
src/content_tool.h Normal file

@ -0,0 +1,24 @@
/*
Minetest-c55
Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
class IToolDefManager;
// Add default tools to manager
void content_tool_init(IToolDefManager *mgr);

@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "scriptapi.h" #include "scriptapi.h"
#include "mapnode_contentfeatures.h" #include "mapnode_contentfeatures.h"
#include "nodemetadata.h" #include "nodemetadata.h"
#include "main.h" // For g_settings, g_profiler
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
@ -270,9 +271,11 @@ void ActiveBlockList::update(core::list<v3s16> &active_positions,
ServerEnvironment ServerEnvironment
*/ */
ServerEnvironment::ServerEnvironment(ServerMap *map, lua_State *L): ServerEnvironment::ServerEnvironment(ServerMap *map, lua_State *L,
IGameDef *gamedef):
m_map(map), m_map(map),
m_lua(L), m_lua(L),
m_gamedef(gamedef),
m_random_spawn_timer(3), m_random_spawn_timer(3),
m_send_recommended_timer(0), m_send_recommended_timer(0),
m_game_time(0), m_game_time(0),
@ -312,7 +315,7 @@ void ServerEnvironment::serializePlayers(const std::string &savedir)
//infostream<<"Checking player file "<<path<<std::endl; //infostream<<"Checking player file "<<path<<std::endl;
// Load player to see what is its name // Load player to see what is its name
ServerRemotePlayer testplayer; ServerRemotePlayer testplayer(this);
{ {
// Open file and deserialize // Open file and deserialize
std::ifstream is(path.c_str(), std::ios_base::binary); std::ifstream is(path.c_str(), std::ios_base::binary);
@ -321,7 +324,7 @@ void ServerEnvironment::serializePlayers(const std::string &savedir)
infostream<<"Failed to read "<<path<<std::endl; infostream<<"Failed to read "<<path<<std::endl;
continue; continue;
} }
testplayer.deSerialize(is); testplayer.deSerialize(is, m_gamedef);
} }
//infostream<<"Loaded test player with name "<<testplayer.getName()<<std::endl; //infostream<<"Loaded test player with name "<<testplayer.getName()<<std::endl;
@ -426,7 +429,7 @@ void ServerEnvironment::deSerializePlayers(const std::string &savedir)
infostream<<"Checking player file "<<path<<std::endl; infostream<<"Checking player file "<<path<<std::endl;
// Load player to see what is its name // Load player to see what is its name
ServerRemotePlayer testplayer; ServerRemotePlayer testplayer(this);
{ {
// Open file and deserialize // Open file and deserialize
std::ifstream is(path.c_str(), std::ios_base::binary); std::ifstream is(path.c_str(), std::ios_base::binary);
@ -435,7 +438,7 @@ void ServerEnvironment::deSerializePlayers(const std::string &savedir)
infostream<<"Failed to read "<<path<<std::endl; infostream<<"Failed to read "<<path<<std::endl;
continue; continue;
} }
testplayer.deSerialize(is); testplayer.deSerialize(is, m_gamedef);
} }
if(!string_allowed(testplayer.getName(), PLAYERNAME_ALLOWED_CHARS)) if(!string_allowed(testplayer.getName(), PLAYERNAME_ALLOWED_CHARS))
@ -454,7 +457,7 @@ void ServerEnvironment::deSerializePlayers(const std::string &savedir)
if(player == NULL) if(player == NULL)
{ {
infostream<<"Is a new player"<<std::endl; infostream<<"Is a new player"<<std::endl;
player = new ServerRemotePlayer(); player = new ServerRemotePlayer(this);
newplayer = true; newplayer = true;
} }
@ -469,7 +472,7 @@ void ServerEnvironment::deSerializePlayers(const std::string &savedir)
infostream<<"Failed to read "<<path<<std::endl; infostream<<"Failed to read "<<path<<std::endl;
continue; continue;
} }
player->deSerialize(is); player->deSerialize(is, m_gamedef);
} }
if(newplayer) if(newplayer)
@ -1507,7 +1510,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
// Register reference in scripting api (must be done before post-init) // Register reference in scripting api (must be done before post-init)
scriptapi_add_object_reference(m_lua, object); scriptapi_add_object_reference(m_lua, object);
// Post-initialize object // Post-initialize object
object->addedToEnvironment(object->getId()); object->addedToEnvironment();
return object->getId(); return object->getId();
} }
@ -1862,9 +1865,12 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
ClientEnvironment ClientEnvironment
*/ */
ClientEnvironment::ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr): ClientEnvironment::ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr,
ITextureSource *texturesource, IGameDef *gamedef):
m_map(map), m_map(map),
m_smgr(smgr) m_smgr(smgr),
m_texturesource(texturesource),
m_gamedef(gamedef)
{ {
assert(m_map); assert(m_map);
assert(m_smgr); assert(m_smgr);
@ -2166,9 +2172,9 @@ void ClientEnvironment::step(float dtime)
} }
} }
void ClientEnvironment::updateMeshes(v3s16 blockpos) void ClientEnvironment::updateMeshes(v3s16 blockpos, ITextureSource *tsrc)
{ {
m_map->updateMeshes(blockpos, getDayNightRatio()); m_map->updateMeshes(blockpos, getDayNightRatio(), tsrc);
} }
void ClientEnvironment::expireMeshes(bool only_daynight_diffed) void ClientEnvironment::expireMeshes(bool only_daynight_diffed)
@ -2242,14 +2248,15 @@ u16 ClientEnvironment::addActiveObject(ClientActiveObject *object)
infostream<<"ClientEnvironment::addActiveObject(): " infostream<<"ClientEnvironment::addActiveObject(): "
<<"added (id="<<object->getId()<<")"<<std::endl; <<"added (id="<<object->getId()<<")"<<std::endl;
m_active_objects.insert(object->getId(), object); m_active_objects.insert(object->getId(), object);
object->addToScene(m_smgr); // TODO: Make g_texturesource non-global
object->addToScene(m_smgr, m_texturesource);
return object->getId(); return object->getId();
} }
void ClientEnvironment::addActiveObject(u16 id, u8 type, void ClientEnvironment::addActiveObject(u16 id, u8 type,
const std::string &init_data) const std::string &init_data)
{ {
ClientActiveObject* obj = ClientActiveObject::create(type); ClientActiveObject* obj = ClientActiveObject::create(type, m_gamedef);
if(obj == NULL) if(obj == NULL)
{ {
infostream<<"ClientEnvironment::addActiveObject(): " infostream<<"ClientEnvironment::addActiveObject(): "

@ -26,7 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
- The map - The map
- Players - Players
- Other objects - Other objects
- The current time in the game (actually it only contains the brightness) - The current time in the game
- etc. - etc.
*/ */
@ -42,6 +42,8 @@ class Server;
class ActiveBlockModifier; class ActiveBlockModifier;
class ServerActiveObject; class ServerActiveObject;
typedef struct lua_State lua_State; typedef struct lua_State lua_State;
class ITextureSource;
class IGameDef;
class Environment class Environment
{ {
@ -127,23 +129,20 @@ private:
class ServerEnvironment : public Environment class ServerEnvironment : public Environment
{ {
public: public:
ServerEnvironment(ServerMap *map, lua_State *L); ServerEnvironment(ServerMap *map, lua_State *L, IGameDef *gamedef);
~ServerEnvironment(); ~ServerEnvironment();
Map & getMap() Map & getMap()
{ { return *m_map; }
return *m_map;
}
ServerMap & getServerMap() ServerMap & getServerMap()
{ { return *m_map; }
return *m_map;
}
lua_State* getLua() lua_State* getLua()
{ { return m_lua; }
return m_lua;
} IGameDef *getGameDef()
{ return m_gamedef; }
float getSendRecommendedInterval() float getSendRecommendedInterval()
{ {
@ -218,6 +217,7 @@ public:
/* /*
ActiveBlockModifiers (TODO) ActiveBlockModifiers (TODO)
------------------------------------------- -------------------------------------------
NOTE: Not used currently (TODO: Use or remove)
*/ */
void addActiveBlockModifier(ActiveBlockModifier *abm); void addActiveBlockModifier(ActiveBlockModifier *abm);
@ -277,6 +277,8 @@ private:
ServerMap *m_map; ServerMap *m_map;
// Lua state // Lua state
lua_State *m_lua; lua_State *m_lua;
// Game definition
IGameDef *m_gamedef;
// Active object list // Active object list
core::map<u16, ServerActiveObject*> m_active_objects; core::map<u16, ServerActiveObject*> m_active_objects;
// Outgoing network message buffer for active objects // Outgoing network message buffer for active objects
@ -302,6 +304,8 @@ private:
These are fed into ServerEnvironment at initialization time; These are fed into ServerEnvironment at initialization time;
ServerEnvironment handles deleting them. ServerEnvironment handles deleting them.
NOTE: Not used currently (TODO: Use or remove)
*/ */
class ActiveBlockModifier class ActiveBlockModifier
@ -353,7 +357,8 @@ struct ClientEnvEvent
class ClientEnvironment : public Environment class ClientEnvironment : public Environment
{ {
public: public:
ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr); ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr,
ITextureSource *texturesource, IGameDef *gamedef);
~ClientEnvironment(); ~ClientEnvironment();
Map & getMap() Map & getMap()
@ -371,7 +376,8 @@ public:
virtual void addPlayer(Player *player); virtual void addPlayer(Player *player);
LocalPlayer * getLocalPlayer(); LocalPlayer * getLocalPlayer();
void updateMeshes(v3s16 blockpos); // Slightly deprecated
void updateMeshes(v3s16 blockpos, ITextureSource *tsrc);
void expireMeshes(bool only_daynight_diffed); void expireMeshes(bool only_daynight_diffed);
void setTimeOfDay(u32 time) void setTimeOfDay(u32 time)
@ -382,8 +388,8 @@ public:
if(getDayNightRatio() != old_dr) if(getDayNightRatio() != old_dr)
{ {
dout_client<<DTIME<<"ClientEnvironment: DayNightRatio changed" /*infostream<<"ClientEnvironment: DayNightRatio changed"
<<" -> expiring meshes"<<std::endl; <<" -> expiring meshes"<<std::endl;*/
expireMeshes(true); expireMeshes(true);
} }
} }
@ -429,6 +435,8 @@ public:
private: private:
ClientMap *m_map; ClientMap *m_map;
scene::ISceneManager *m_smgr; scene::ISceneManager *m_smgr;
ITextureSource *m_texturesource;
IGameDef *m_gamedef;
core::map<u16, ClientActiveObject*> m_active_objects; core::map<u16, ClientActiveObject*> m_active_objects;
Queue<ClientEnvEvent> m_client_event_queue; Queue<ClientEnvEvent> m_client_event_queue;
IntervalLimiter m_active_object_light_update_interval; IntervalLimiter m_active_object_light_update_interval;

@ -46,6 +46,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
// Needed for determining pointing to nodes // Needed for determining pointing to nodes
#include "mapnode_contentfeatures.h" #include "mapnode_contentfeatures.h"
#include "nodemetadata.h" #include "nodemetadata.h"
#include "main.h" // For g_settings
#include "content_mapnode.h" // For content_mapnode_init
#include "tool.h"
#include "content_tool.h" // For content_tool_init
/* /*
Setting this to 1 enables a special camera mode that forces Setting this to 1 enables a special camera mode that forces
@ -153,6 +157,7 @@ private:
Hotbar draw routine Hotbar draw routine
*/ */
void draw_hotbar(video::IVideoDriver *driver, gui::IGUIFont *font, void draw_hotbar(video::IVideoDriver *driver, gui::IGUIFont *font,
ITextureSource *tsrc,
v2s32 centerlowerpos, s32 imgsize, s32 itemcount, v2s32 centerlowerpos, s32 imgsize, s32 itemcount,
Inventory *inventory, s32 halfheartcount) Inventory *inventory, s32 halfheartcount)
{ {
@ -244,7 +249,7 @@ void draw_hotbar(video::IVideoDriver *driver, gui::IGUIFont *font,
if(item != NULL) if(item != NULL)
{ {
drawInventoryItem(driver, font, item, rect, NULL); drawInventoryItem(driver, font, item, rect, NULL, tsrc);
} }
} }
@ -587,6 +592,21 @@ void the_game(
draw_load_screen(L"Loading...", driver, font); draw_load_screen(L"Loading...", driver, font);
// Create tool manager
IToolDefManager *toolmgr = createToolDefManager();
// Create texture source
TextureSource *tsrc = new TextureSource(device);
// Initialize mapnode again to enable changed graphics settings
// Initialize content feature table with textures
init_contentfeatures(tsrc);
// Fill content feature table with default definitions
content_mapnode_init(tsrc);
// Initialize default tool definitions
content_tool_init(toolmgr);
/* /*
Create server. Create server.
SharedPtr will delete it when it goes out of scope. SharedPtr will delete it when it goes out of scope.
@ -606,7 +626,8 @@ void the_game(
draw_load_screen(L"Creating client...", driver, font); draw_load_screen(L"Creating client...", driver, font);
infostream<<"Creating client"<<std::endl; infostream<<"Creating client"<<std::endl;
MapDrawControl draw_control; MapDrawControl draw_control;
Client client(device, playername.c_str(), password, draw_control); Client client(device, playername.c_str(), password, draw_control,
tsrc, toolmgr);
draw_load_screen(L"Resolving address...", driver, font); draw_load_screen(L"Resolving address...", driver, font);
Address connect_address(0,0,0,0, port); Address connect_address(0,0,0,0, port);
@ -883,7 +904,7 @@ void the_game(
/* /*
Process TextureSource's queue Process TextureSource's queue
*/ */
((TextureSource*)g_texturesource)->processQueue(); tsrc->processQueue();
/* /*
Random calculations Random calculations
@ -1113,7 +1134,7 @@ void the_game(
new GUIInventoryMenu(guienv, guiroot, -1, new GUIInventoryMenu(guienv, guiroot, -1,
&g_menumgr, v2s16(8,7), &g_menumgr, v2s16(8,7),
client.getInventoryContext(), client.getInventoryContext(),
&client); &client, tsrc);
core::array<GUIInventoryMenu::DrawSpec> draw_spec; core::array<GUIInventoryMenu::DrawSpec> draw_spec;
draw_spec.push_back(GUIInventoryMenu::DrawSpec( draw_spec.push_back(GUIInventoryMenu::DrawSpec(
@ -1672,8 +1693,10 @@ void the_game(
// Get digging properties for material and tool // Get digging properties for material and tool
content_t material = n.getContent(); content_t material = n.getContent();
ToolDiggingProperties tp =
toolmgr->getDiggingProperties(toolname);
DiggingProperties prop = DiggingProperties prop =
getDiggingProperties(material, toolname); getDiggingProperties(material, &tp);
float dig_time_complete = 0.0; float dig_time_complete = 0.0;
@ -1775,7 +1798,7 @@ void the_game(
new GUIInventoryMenu(guienv, guiroot, -1, new GUIInventoryMenu(guienv, guiroot, -1,
&g_menumgr, invsize, &g_menumgr, invsize,
client.getInventoryContext(), client.getInventoryContext(),
&client); &client, tsrc);
menu->setDrawSpec(draw_spec); menu->setDrawSpec(draw_spec);
menu->drop(); menu->drop();
} }
@ -2079,7 +2102,7 @@ void the_game(
InventoryItem *item = NULL; InventoryItem *item = NULL;
if(mlist != NULL) if(mlist != NULL)
item = mlist->getItem(g_selected_item); item = mlist->getItem(g_selected_item);
camera.wield(item); camera.wield(item, tsrc);
} }
/* /*
@ -2202,7 +2225,8 @@ void the_game(
Draw hotbar Draw hotbar
*/ */
{ {
draw_hotbar(driver, font, v2s32(displaycenter.X, screensize.Y), draw_hotbar(driver, font, tsrc,
v2s32(displaycenter.X, screensize.Y),
hotbar_imagesize, hotbar_itemcount, &local_inventory, hotbar_imagesize, hotbar_itemcount, &local_inventory,
client.getHP()); client.getHP());
} }
@ -2269,6 +2293,9 @@ void the_game(
driver->endScene(); driver->endScene();
gui_shuttingdowntext->remove();*/ gui_shuttingdowntext->remove();*/
} }
delete toolmgr;
delete tsrc;
} }

42
src/gamedef.h Normal file

@ -0,0 +1,42 @@
/*
Minetest-c55
Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef GAMEDEF_HEADER
#define GAMEDEF_HEADER
class IToolDefManager;
class INodeDefManager; //TODO
//class IItemDefManager; //TODO
// Mineral too?
/*
An interface for fetching game-global definitions like tool and
mapnode properties
*/
class IGameDef
{
public:
virtual IToolDefManager* getToolDefManager()=0;
virtual INodeDefManager* getNodeDefManager()=0;
//virtual IItemDefManager* getItemDefManager()=0;
};
#endif

@ -32,13 +32,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
void drawInventoryItem(video::IVideoDriver *driver, void drawInventoryItem(video::IVideoDriver *driver,
gui::IGUIFont *font, gui::IGUIFont *font,
InventoryItem *item, core::rect<s32> rect, InventoryItem *item, core::rect<s32> rect,
const core::rect<s32> *clip) const core::rect<s32> *clip,
ITextureSource *tsrc)
{ {
if(item == NULL) if(item == NULL)
return; return;
video::ITexture *texture = NULL; video::ITexture *texture = NULL;
texture = item->getImage(); texture = item->getImage(tsrc);
if(texture != NULL) if(texture != NULL)
{ {
@ -89,12 +90,14 @@ GUIInventoryMenu::GUIInventoryMenu(gui::IGUIEnvironment* env,
IMenuManager *menumgr, IMenuManager *menumgr,
v2s16 menu_size, v2s16 menu_size,
InventoryContext *c, InventoryContext *c,
InventoryManager *invmgr InventoryManager *invmgr,
ITextureSource *tsrc
): ):
GUIModalMenu(env, parent, id, menumgr), GUIModalMenu(env, parent, id, menumgr),
m_menu_size(menu_size), m_menu_size(menu_size),
m_c(c), m_c(c),
m_invmgr(invmgr) m_invmgr(invmgr),
m_tsrc(tsrc)
{ {
m_selected_item = NULL; m_selected_item = NULL;
} }
@ -218,7 +221,7 @@ GUIInventoryMenu::ItemSpec GUIInventoryMenu::getItemAtPos(v2s32 p) const
return ItemSpec("", "", -1); return ItemSpec("", "", -1);
} }
void GUIInventoryMenu::drawList(const ListDrawSpec &s) void GUIInventoryMenu::drawList(const ListDrawSpec &s, ITextureSource *tsrc)
{ {
video::IVideoDriver* driver = Environment->getVideoDriver(); video::IVideoDriver* driver = Environment->getVideoDriver();
@ -269,7 +272,7 @@ void GUIInventoryMenu::drawList(const ListDrawSpec &s)
if(item) if(item)
{ {
drawInventoryItem(driver, font, item, drawInventoryItem(driver, font, item,
rect, &AbsoluteClippingRect); rect, &AbsoluteClippingRect, tsrc);
} }
} }
@ -292,7 +295,7 @@ void GUIInventoryMenu::drawMenu()
for(u32 i=0; i<m_draw_spec.size(); i++) for(u32 i=0; i<m_draw_spec.size(); i++)
{ {
ListDrawSpec &s = m_draw_spec[i]; ListDrawSpec &s = m_draw_spec[i];
drawList(s); drawList(s, m_tsrc);
} }
/* /*

@ -26,10 +26,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "utility.h" #include "utility.h"
#include "modalMenu.h" #include "modalMenu.h"
class ITextureSource;
void drawInventoryItem(video::IVideoDriver *driver, void drawInventoryItem(video::IVideoDriver *driver,
gui::IGUIFont *font, gui::IGUIFont *font,
InventoryItem *item, core::rect<s32> rect, InventoryItem *item, core::rect<s32> rect,
const core::rect<s32> *clip); const core::rect<s32> *clip,
ITextureSource *tsrc);
class GUIInventoryMenu : public GUIModalMenu class GUIInventoryMenu : public GUIModalMenu
{ {
@ -114,7 +117,8 @@ public:
IMenuManager *menumgr, IMenuManager *menumgr,
v2s16 menu_size, v2s16 menu_size,
InventoryContext *c, InventoryContext *c,
InventoryManager *invmgr InventoryManager *invmgr,
ITextureSource *tsrc
); );
~GUIInventoryMenu(); ~GUIInventoryMenu();
@ -130,7 +134,7 @@ public:
void regenerateGui(v2u32 screensize); void regenerateGui(v2u32 screensize);
ItemSpec getItemAtPos(v2s32 p) const; ItemSpec getItemAtPos(v2s32 p) const;
void drawList(const ListDrawSpec &s); void drawList(const ListDrawSpec &s, ITextureSource *tsrc);
void drawMenu(); void drawMenu();
bool OnEvent(const SEvent& event); bool OnEvent(const SEvent& event);
@ -149,6 +153,7 @@ protected:
InventoryContext *m_c; InventoryContext *m_c;
InventoryManager *m_invmgr; InventoryManager *m_invmgr;
ITextureSource *m_tsrc;
core::array<DrawSpec> m_init_draw_spec; core::array<DrawSpec> m_init_draw_spec;
core::array<ListDrawSpec> m_draw_spec; core::array<ListDrawSpec> m_draw_spec;

@ -1,6 +1,6 @@
/* /*
Minetest-c55 Minetest-c55
Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com> Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -17,16 +17,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
/*
(c) 2010 Perttu Ahola <celeron55@gmail.com>
*/
#include "inventory.h" #include "inventory.h"
#include "serialization.h" #include "serialization.h"
#include "utility.h" #include "utility.h"
#include "debug.h" #include "debug.h"
#include <sstream> #include <sstream>
#include "main.h" #include "main.h" // For tsrc, g_toolmanager
#include "serverobject.h" #include "serverobject.h"
#include "content_mapnode.h" #include "content_mapnode.h"
#include "content_inventory.h" #include "content_inventory.h"
@ -35,14 +31,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "log.h" #include "log.h"
#include "mapnode_contentfeatures.h" #include "mapnode_contentfeatures.h"
#include "tool.h" #include "tool.h"
#include "gamedef.h"
/* /*
InventoryItem InventoryItem
*/ */
InventoryItem::InventoryItem(u16 count) InventoryItem::InventoryItem(IGameDef *gamedef, u16 count):
m_gamedef(gamedef),
m_count(count)
{ {
m_count = count; assert(m_gamedef);
} }
InventoryItem::~InventoryItem() InventoryItem::~InventoryItem()
@ -61,7 +60,7 @@ content_t content_translate_from_19_to_internal(content_t c_from)
return c_from; return c_from;
} }
InventoryItem* InventoryItem::deSerialize(std::istream &is) InventoryItem* InventoryItem::deSerialize(std::istream &is, IGameDef *gamedef)
{ {
DSTACK(__FUNCTION_NAME); DSTACK(__FUNCTION_NAME);
@ -84,7 +83,7 @@ InventoryItem* InventoryItem::deSerialize(std::istream &is)
} }
if(material > MAX_CONTENT) if(material > MAX_CONTENT)
throw SerializationError("Too large material number"); throw SerializationError("Too large material number");
return new MaterialItem(material, count); return new MaterialItem(gamedef, material, count);
} }
else if(name == "MaterialItem2") else if(name == "MaterialItem2")
{ {
@ -94,7 +93,7 @@ InventoryItem* InventoryItem::deSerialize(std::istream &is)
is>>count; is>>count;
if(material > MAX_CONTENT) if(material > MAX_CONTENT)
throw SerializationError("Too large material number"); throw SerializationError("Too large material number");
return new MaterialItem(material, count); return new MaterialItem(gamedef, material, count);
} }
else if(name == "MBOItem") else if(name == "MBOItem")
{ {
@ -108,7 +107,7 @@ InventoryItem* InventoryItem::deSerialize(std::istream &is)
std::getline(is, subname, ' '); std::getline(is, subname, ' ');
u16 count; u16 count;
is>>count; is>>count;
return new CraftItem(subname, count); return new CraftItem(gamedef, subname, count);
} }
else if(name == "ToolItem") else if(name == "ToolItem")
{ {
@ -116,7 +115,7 @@ InventoryItem* InventoryItem::deSerialize(std::istream &is)
std::getline(is, toolname, ' '); std::getline(is, toolname, ' ');
u16 wear; u16 wear;
is>>wear; is>>wear;
return new ToolItem(toolname, wear); return new ToolItem(gamedef, toolname, wear);
} }
else else
{ {
@ -151,7 +150,7 @@ ServerActiveObject* InventoryItem::createSAO(ServerEnvironment *env, u16 id, v3f
*/ */
#ifndef SERVER #ifndef SERVER
video::ITexture * MaterialItem::getImage() const video::ITexture * MaterialItem::getImage(ITextureSource *tsrc) const
{ {
return content_features(m_content).inventory_texture; return content_features(m_content).inventory_texture;
} }
@ -159,12 +158,12 @@ video::ITexture * MaterialItem::getImage() const
bool MaterialItem::isCookable() const bool MaterialItem::isCookable() const
{ {
return item_material_is_cookable(m_content); return item_material_is_cookable(m_content, m_gamedef);
} }
InventoryItem *MaterialItem::createCookResult() const InventoryItem *MaterialItem::createCookResult() const
{ {
return item_material_create_cook_result(m_content); return item_material_create_cook_result(m_content, m_gamedef);
} }
/* /*
@ -173,23 +172,54 @@ InventoryItem *MaterialItem::createCookResult() const
std::string ToolItem::getImageBasename() const std::string ToolItem::getImageBasename() const
{ {
return tool_get_imagename(m_toolname); return m_gamedef->getToolDefManager()->getImagename(m_toolname);
} }
#ifndef SERVER
video::ITexture * ToolItem::getImage(ITextureSource *tsrc) const
{
if(tsrc == NULL)
return NULL;
std::string basename = getImageBasename();
/*
Calculate a progress value with sane amount of
maximum states
*/
u32 maxprogress = 30;
u32 toolprogress = (65535-m_wear)/(65535/maxprogress);
float value_f = (float)toolprogress / (float)maxprogress;
std::ostringstream os;
os<<basename<<"^[progressbar"<<value_f;
return tsrc->getTextureRaw(os.str());
}
video::ITexture * ToolItem::getImageRaw(ITextureSource *tsrc) const
{
if(tsrc == NULL)
return NULL;
return tsrc->getTextureRaw(getImageBasename());
}
#endif
/* /*
CraftItem CraftItem
*/ */
#ifndef SERVER #ifndef SERVER
video::ITexture * CraftItem::getImage() const video::ITexture * CraftItem::getImage(ITextureSource *tsrc) const
{ {
if(g_texturesource == NULL) if(tsrc == NULL)
return NULL; return NULL;
std::string name = item_craft_get_image_name(m_subname); std::string name = item_craft_get_image_name(m_subname, m_gamedef);
// Get such a texture // Get such a texture
return g_texturesource->getTextureRaw(name); return tsrc->getTextureRaw(name);
} }
#endif #endif
@ -206,7 +236,7 @@ ServerActiveObject* CraftItem::createSAO(ServerEnvironment *env, u16 id, v3f pos
u16 CraftItem::getDropCount() const u16 CraftItem::getDropCount() const
{ {
// Special cases // Special cases
s16 dc = item_craft_get_drop_count(m_subname); s16 dc = item_craft_get_drop_count(m_subname, m_gamedef);
if(dc != -1) if(dc != -1)
return dc; return dc;
// Default // Default
@ -215,21 +245,21 @@ u16 CraftItem::getDropCount() const
bool CraftItem::isCookable() const bool CraftItem::isCookable() const
{ {
return item_craft_is_cookable(m_subname); return item_craft_is_cookable(m_subname, m_gamedef);
} }
InventoryItem *CraftItem::createCookResult() const InventoryItem *CraftItem::createCookResult() const
{ {
return item_craft_create_cook_result(m_subname); return item_craft_create_cook_result(m_subname, m_gamedef);
} }
bool CraftItem::use(ServerEnvironment *env, ServerActiveObject *user) bool CraftItem::use(ServerEnvironment *env, ServerActiveObject *user)
{ {
if(!item_craft_is_eatable(m_subname)) if(!item_craft_is_eatable(m_subname, m_gamedef))
return false; return false;
u16 result_count = getCount() - 1; // Eat one at a time u16 result_count = getCount() - 1; // Eat one at a time
s16 hp_change = item_craft_eat_hp_change(m_subname); s16 hp_change = item_craft_eat_hp_change(m_subname, m_gamedef);
s16 hp = user->getHP(); s16 hp = user->getHP();
hp += hp_change; hp += hp_change;
if(hp < 0) if(hp < 0)
@ -304,7 +334,7 @@ void InventoryList::serialize(std::ostream &os) const
os<<"EndInventoryList\n"; os<<"EndInventoryList\n";
} }
void InventoryList::deSerialize(std::istream &is) void InventoryList::deSerialize(std::istream &is, IGameDef *gamedef)
{ {
//is.imbue(std::locale("C")); //is.imbue(std::locale("C"));
@ -335,7 +365,7 @@ void InventoryList::deSerialize(std::istream &is)
{ {
if(item_i > getSize() - 1) if(item_i > getSize() - 1)
throw SerializationError("too many items"); throw SerializationError("too many items");
InventoryItem *item = InventoryItem::deSerialize(iss); InventoryItem *item = InventoryItem::deSerialize(iss, gamedef);
m_items[item_i++] = item; m_items[item_i++] = item;
} }
else if(name == "Empty") else if(name == "Empty")
@ -655,7 +685,7 @@ void Inventory::serialize(std::ostream &os) const
os<<"EndInventory\n"; os<<"EndInventory\n";
} }
void Inventory::deSerialize(std::istream &is) void Inventory::deSerialize(std::istream &is, IGameDef *gamedef)
{ {
clear(); clear();
@ -687,7 +717,7 @@ void Inventory::deSerialize(std::istream &is)
iss>>listsize; iss>>listsize;
InventoryList *list = new InventoryList(listname, listsize); InventoryList *list = new InventoryList(listname, listsize);
list->deSerialize(is); list->deSerialize(is, gamedef);
m_lists.push_back(list); m_lists.push_back(list);
} }

@ -1,6 +1,6 @@
/* /*
Minetest-c55 Minetest-c55
Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com> Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -17,10 +17,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
/*
(c) 2010 Perttu Ahola <celeron55@gmail.com>
*/
#ifndef INVENTORY_HEADER #ifndef INVENTORY_HEADER
#define INVENTORY_HEADER #define INVENTORY_HEADER
@ -29,34 +25,37 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <string> #include <string>
#include "common_irrlicht.h" #include "common_irrlicht.h"
#include "debug.h" #include "debug.h"
#include "main.h" // For g_materials
#include "mapnode.h" // For content_t #include "mapnode.h" // For content_t
#define QUANTITY_ITEM_MAX_COUNT 99 #define QUANTITY_ITEM_MAX_COUNT 99
class ServerActiveObject; class ServerActiveObject;
class ServerEnvironment; class ServerEnvironment;
class ITextureSource;
class IGameDef;
class InventoryItem class InventoryItem
{ {
public: public:
InventoryItem(u16 count); InventoryItem(IGameDef *gamedef, u16 count);
virtual ~InventoryItem(); virtual ~InventoryItem();
static InventoryItem* deSerialize(std::istream &is); static InventoryItem* deSerialize(std::istream &is, IGameDef *gamedef);
virtual const char* getName() const = 0; virtual const char* getName() const = 0;
// Shall write the name and the parameters // Shall write the name and the parameters
virtual void serialize(std::ostream &os) const = 0; virtual void serialize(std::ostream &os) const = 0;
// Shall make an exact clone of the item // Shall make an exact clone of the item
virtual InventoryItem* clone() = 0; virtual InventoryItem* clone() = 0;
#ifndef SERVER
// Return the name of the image for this item // Return the name of the image for this item
virtual std::string getImageBasename() const { return ""; } virtual std::string getImageBasename() const { return ""; }
#ifndef SERVER
// Shall return an image of the item (or NULL) // Shall return an image of the item (or NULL)
virtual video::ITexture * getImage() const { return NULL; } virtual video::ITexture * getImage(ITextureSource *tsrc) const
{ return NULL; }
// Shall return an image of the item without embellishments (or NULL) // Shall return an image of the item without embellishments (or NULL)
virtual video::ITexture * getImageRaw() const { return getImage(); } virtual video::ITexture * getImageRaw(ITextureSource *tsrc) const
{ return getImage(tsrc); }
#endif #endif
// Shall return a text to show in the GUI // Shall return a text to show in the GUI
virtual std::string getText() { return ""; } virtual std::string getText() { return ""; }
@ -119,14 +118,15 @@ public:
ServerActiveObject *user){return false;} ServerActiveObject *user){return false;}
protected: protected:
IGameDef *m_gamedef;
u16 m_count; u16 m_count;
}; };
class MaterialItem : public InventoryItem class MaterialItem : public InventoryItem
{ {
public: public:
MaterialItem(content_t content, u16 count): MaterialItem(IGameDef *gamedef, content_t content, u16 count):
InventoryItem(count) InventoryItem(gamedef, count)
{ {
m_content = content; m_content = content;
} }
@ -148,10 +148,10 @@ public:
} }
virtual InventoryItem* clone() virtual InventoryItem* clone()
{ {
return new MaterialItem(m_content, m_count); return new MaterialItem(m_gamedef, m_content, m_count);
} }
#ifndef SERVER #ifndef SERVER
video::ITexture * getImage() const; video::ITexture * getImage(ITextureSource *tsrc) const;
#endif #endif
std::string getText() std::string getText()
{ {
@ -199,8 +199,8 @@ private:
class CraftItem : public InventoryItem class CraftItem : public InventoryItem
{ {
public: public:
CraftItem(std::string subname, u16 count): CraftItem(IGameDef *gamedef, std::string subname, u16 count):
InventoryItem(count) InventoryItem(gamedef, count)
{ {
m_subname = subname; m_subname = subname;
} }
@ -221,10 +221,10 @@ public:
} }
virtual InventoryItem* clone() virtual InventoryItem* clone()
{ {
return new CraftItem(m_subname, m_count); return new CraftItem(m_gamedef, m_subname, m_count);
} }
#ifndef SERVER #ifndef SERVER
video::ITexture * getImage() const; video::ITexture * getImage(ITextureSource *tsrc) const;
#endif #endif
std::string getText() std::string getText()
{ {
@ -275,8 +275,8 @@ private:
class ToolItem : public InventoryItem class ToolItem : public InventoryItem
{ {
public: public:
ToolItem(std::string toolname, u16 wear): ToolItem(IGameDef *gamedef, std::string toolname, u16 wear):
InventoryItem(1) InventoryItem(gamedef, 1)
{ {
m_toolname = toolname; m_toolname = toolname;
m_wear = wear; m_wear = wear;
@ -298,41 +298,15 @@ public:
} }
virtual InventoryItem* clone() virtual InventoryItem* clone()
{ {
return new ToolItem(m_toolname, m_wear); return new ToolItem(m_gamedef, m_toolname, m_wear);
} }
std::string getImageBasename() const; std::string getImageBasename() const;
#ifndef SERVER #ifndef SERVER
video::ITexture * getImage() const video::ITexture * getImage(ITextureSource *tsrc) const;
{ video::ITexture * getImageRaw(ITextureSource *tsrc) const;
if(g_texturesource == NULL)
return NULL;
std::string basename = getImageBasename();
/*
Calculate a progress value with sane amount of
maximum states
*/
u32 maxprogress = 30;
u32 toolprogress = (65535-m_wear)/(65535/maxprogress);
float value_f = (float)toolprogress / (float)maxprogress;
std::ostringstream os;
os<<basename<<"^[progressbar"<<value_f;
return g_texturesource->getTextureRaw(os.str());
}
video::ITexture * getImageRaw() const
{
if(g_texturesource == NULL)
return NULL;
return g_texturesource->getTextureRaw(getImageBasename());
}
#endif #endif
std::string getText() std::string getText()
{ {
return ""; return "";
@ -390,7 +364,7 @@ public:
~InventoryList(); ~InventoryList();
void clearItems(); void clearItems();
void serialize(std::ostream &os) const; void serialize(std::ostream &os) const;
void deSerialize(std::istream &is); void deSerialize(std::istream &is, IGameDef *gamedef);
InventoryList(const InventoryList &other); InventoryList(const InventoryList &other);
InventoryList & operator = (const InventoryList &other); InventoryList & operator = (const InventoryList &other);
@ -460,7 +434,7 @@ public:
Inventory & operator = (const Inventory &other); Inventory & operator = (const Inventory &other);
void serialize(std::ostream &os) const; void serialize(std::ostream &os) const;
void deSerialize(std::istream &is); void deSerialize(std::istream &is, IGameDef *gamedef);
InventoryList * addList(const std::string &name, u32 size); InventoryList * addList(const std::string &name, u32 size);
InventoryList * getList(const std::string &name); InventoryList * getList(const std::string &name);

@ -385,11 +385,11 @@ Doing currently:
*/ */
#ifdef NDEBUG #ifdef NDEBUG
#ifdef _WIN32 /*#ifdef _WIN32
#pragma message ("Disabling unit tests") #pragma message ("Disabling unit tests")
#else #else
#warning "Disabling unit tests" #warning "Disabling unit tests"
#endif #endif*/
// Disable unit tests // Disable unit tests
#define ENABLE_TESTS 0 #define ENABLE_TESTS 0
#else #else
@ -437,9 +437,6 @@ Doing currently:
#include "mapnode_contentfeatures.h" // For init_contentfeatures #include "mapnode_contentfeatures.h" // For init_contentfeatures
#include "content_mapnode.h" // For content_mapnode_init #include "content_mapnode.h" // For content_mapnode_init
// This makes textures
ITextureSource *g_texturesource = NULL;
/* /*
Settings. Settings.
These are loaded from the config file. These are loaded from the config file.
@ -1275,11 +1272,11 @@ int main(int argc, char *argv[])
These are needed for unit tests at least. These are needed for unit tests at least.
*/ */
// Initialize content feature table // Initialize content feature table without textures
init_contentfeatures(); init_contentfeatures(NULL);
// Initialize mapnode content without textures (with g_texturesource=NULL) // Initialize mapnode content without textures
content_mapnode_init(); content_mapnode_init(NULL);
// Must be called before g_texturesource is created // Must be called before texturesource is created
// (for texture atlas making) // (for texture atlas making)
init_mineral(); init_mineral();
@ -1430,9 +1427,6 @@ int main(int argc, char *argv[])
// Create game callback for menus // Create game callback for menus
g_gamecallback = new MainGameCallback(device); g_gamecallback = new MainGameCallback(device);
// Create texture source
g_texturesource = new TextureSource(device);
/* /*
Speed tests (done after irrlicht is loaded to get timer) Speed tests (done after irrlicht is loaded to get timer)
*/ */
@ -1477,13 +1471,6 @@ int main(int argc, char *argv[])
skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255,0,0,0)); skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255,0,0,0));
skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(255,0,0,0)); skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(255,0,0,0));
/*
Preload some textures and stuff
*/
// Initialize mapnode content with textures (with g_texturesource!=NULL)
content_mapnode_init();
/* /*
GUI stuff GUI stuff
*/ */
@ -1657,12 +1644,6 @@ int main(int argc, char *argv[])
if(device->run() == false) if(device->run() == false)
break; break;
// Initialize mapnode again to enable changed graphics settings
// Initialize content feature table
init_contentfeatures();
// Initialize mapnode content with textures (with g_texturesource!=NULL)
content_mapnode_init();
/* /*
Run game Run game
*/ */

@ -24,10 +24,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
class Settings; class Settings;
extern Settings *g_settings; extern Settings *g_settings;
// This makes and maps textures
class ITextureSource;
extern ITextureSource *g_texturesource;
// Global profiler // Global profiler
class Profiler; class Profiler;
extern Profiler *g_profiler; extern Profiler *g_profiler;

@ -62,8 +62,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Map Map
*/ */
Map::Map(std::ostream &dout): Map::Map(std::ostream &dout, IGameDef *gamedef):
m_dout(dout), m_dout(dout),
m_gamedef(gamedef),
m_sector_cache(NULL) m_sector_cache(NULL)
{ {
/*m_sector_mutex.Init(); /*m_sector_mutex.Init();
@ -1025,7 +1026,7 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
NodeMetadata *meta_proto = content_features(n).initial_metadata; NodeMetadata *meta_proto = content_features(n).initial_metadata;
if(meta_proto) if(meta_proto)
{ {
NodeMetadata *meta = meta_proto->clone(); NodeMetadata *meta = meta_proto->clone(m_gamedef);
meta->setOwner(player_name); meta->setOwner(player_name);
setNodeMetadata(p, meta); setNodeMetadata(p, meta);
} }
@ -1906,8 +1907,8 @@ void Map::nodeMetadataStep(float dtime,
ServerMap ServerMap
*/ */
ServerMap::ServerMap(std::string savedir): ServerMap::ServerMap(std::string savedir, IGameDef *gamedef):
Map(dout_server), Map(dout_server, gamedef),
m_seed(0), m_seed(0),
m_map_metadata_changed(true), m_map_metadata_changed(true),
m_database(NULL), m_database(NULL),
@ -3309,7 +3310,7 @@ void ServerMap::loadBlock(std::string sectordir, std::string blockfile, MapSecto
} }
// Read basic data // Read basic data
block->deSerialize(is, version); block->deSerialize(is, version, m_gamedef);
// Read extra data stored on disk // Read extra data stored on disk
block->deSerializeDiskExtra(is, version); block->deSerializeDiskExtra(is, version);
@ -3379,7 +3380,7 @@ void ServerMap::loadBlock(std::string *blob, v3s16 p3d, MapSector *sector, bool
} }
// Read basic data // Read basic data
block->deSerialize(is, version); block->deSerialize(is, version, m_gamedef);
// Read extra data stored on disk // Read extra data stored on disk
block->deSerializeDiskExtra(is, version); block->deSerializeDiskExtra(is, version);
@ -3522,12 +3523,13 @@ void ServerMap::PrintInfo(std::ostream &out)
ClientMap::ClientMap( ClientMap::ClientMap(
Client *client, Client *client,
IGameDef *gamedef,
MapDrawControl &control, MapDrawControl &control,
scene::ISceneNode* parent, scene::ISceneNode* parent,
scene::ISceneManager* mgr, scene::ISceneManager* mgr,
s32 id s32 id
): ):
Map(dout_client), Map(dout_client, gamedef),
scene::ISceneNode(parent, mgr, id), scene::ISceneNode(parent, mgr, id),
m_client(client), m_client(client),
m_control(control), m_control(control),
@ -4168,14 +4170,15 @@ void ClientMap::expireMeshes(bool only_daynight_diffed)
} }
} }
void ClientMap::updateMeshes(v3s16 blockpos, u32 daynight_ratio) void ClientMap::updateMeshes(v3s16 blockpos, u32 daynight_ratio,
ITextureSource *tsrc)
{ {
assert(mapType() == MAPTYPE_CLIENT); assert(mapType() == MAPTYPE_CLIENT);
try{ try{
v3s16 p = blockpos + v3s16(0,0,0); v3s16 p = blockpos + v3s16(0,0,0);
MapBlock *b = getBlockNoCreate(p); MapBlock *b = getBlockNoCreate(p);
b->updateMesh(daynight_ratio); b->updateMesh(daynight_ratio, tsrc);
//b->setMeshExpired(true); //b->setMeshExpired(true);
} }
catch(InvalidPositionException &e){} catch(InvalidPositionException &e){}
@ -4183,21 +4186,21 @@ void ClientMap::updateMeshes(v3s16 blockpos, u32 daynight_ratio)
try{ try{
v3s16 p = blockpos + v3s16(-1,0,0); v3s16 p = blockpos + v3s16(-1,0,0);
MapBlock *b = getBlockNoCreate(p); MapBlock *b = getBlockNoCreate(p);
b->updateMesh(daynight_ratio); b->updateMesh(daynight_ratio, tsrc);
//b->setMeshExpired(true); //b->setMeshExpired(true);
} }
catch(InvalidPositionException &e){} catch(InvalidPositionException &e){}
try{ try{
v3s16 p = blockpos + v3s16(0,-1,0); v3s16 p = blockpos + v3s16(0,-1,0);
MapBlock *b = getBlockNoCreate(p); MapBlock *b = getBlockNoCreate(p);
b->updateMesh(daynight_ratio); b->updateMesh(daynight_ratio, tsrc);
//b->setMeshExpired(true); //b->setMeshExpired(true);
} }
catch(InvalidPositionException &e){} catch(InvalidPositionException &e){}
try{ try{
v3s16 p = blockpos + v3s16(0,0,-1); v3s16 p = blockpos + v3s16(0,0,-1);
MapBlock *b = getBlockNoCreate(p); MapBlock *b = getBlockNoCreate(p);
b->updateMesh(daynight_ratio); b->updateMesh(daynight_ratio, tsrc);
//b->setMeshExpired(true); //b->setMeshExpired(true);
} }
catch(InvalidPositionException &e){} catch(InvalidPositionException &e){}

@ -41,6 +41,7 @@ class ServerMapSector;
class ClientMapSector; class ClientMapSector;
class MapBlock; class MapBlock;
class NodeMetadata; class NodeMetadata;
class IGameDef;
namespace mapgen{ namespace mapgen{
struct BlockMakeData; struct BlockMakeData;
@ -109,7 +110,7 @@ class Map /*: public NodeContainer*/
{ {
public: public:
Map(std::ostream &dout); Map(std::ostream &dout, IGameDef *gamedef);
virtual ~Map(); virtual ~Map();
/*virtual u16 nodeContainerId() const /*virtual u16 nodeContainerId() const
@ -289,7 +290,9 @@ public:
protected: protected:
std::ostream &m_dout; std::ostream &m_dout; // A bit deprecated, could be removed
IGameDef *m_gamedef;
core::map<MapEventReceiver*, bool> m_event_receivers; core::map<MapEventReceiver*, bool> m_event_receivers;
@ -315,7 +318,7 @@ public:
/* /*
savedir: directory to which map data should be saved savedir: directory to which map data should be saved
*/ */
ServerMap(std::string savedir); ServerMap(std::string savedir, IGameDef *gamedef);
~ServerMap(); ~ServerMap();
s32 mapType() const s32 mapType() const
@ -435,7 +438,7 @@ public:
u64 getSeed(){ return m_seed; } u64 getSeed(){ return m_seed; }
private: private:
// Seed used for all kinds of randomness // Seed used for all kinds of randomness in generation
u64 m_seed; u64 m_seed;
std::string m_savedir; std::string m_savedir;
@ -496,6 +499,7 @@ struct MapDrawControl
}; };
class Client; class Client;
class ITextureSource;
/* /*
ClientMap ClientMap
@ -508,6 +512,7 @@ class ClientMap : public Map, public scene::ISceneNode
public: public:
ClientMap( ClientMap(
Client *client, Client *client,
IGameDef *gamedef,
MapDrawControl &control, MapDrawControl &control,
scene::ISceneNode* parent, scene::ISceneNode* parent,
scene::ISceneManager* mgr, scene::ISceneManager* mgr,
@ -583,9 +588,10 @@ public:
/* /*
Update the faces of the given block and blocks on the Update the faces of the given block and blocks on the
leading edge. leading edge, without threading. Rarely used.
*/ */
void updateMeshes(v3s16 blockpos, u32 daynight_ratio); void updateMeshes(v3s16 blockpos, u32 daynight_ratio,
ITextureSource *tsrc);
// Update meshes that touch the node // Update meshes that touch the node
//void updateNodeMeshes(v3s16 nodepos, u32 daynight_ratio); //void updateNodeMeshes(v3s16 nodepos, u32 daynight_ratio);

@ -138,7 +138,7 @@ MapNode MapBlock::getNodeParentNoEx(v3s16 p)
#ifndef SERVER #ifndef SERVER
#if 1 #if 1
void MapBlock::updateMesh(u32 daynight_ratio) void MapBlock::updateMesh(u32 daynight_ratio, ITextureSource *tsrc)
{ {
#if 0 #if 0
/* /*
@ -154,7 +154,7 @@ void MapBlock::updateMesh(u32 daynight_ratio)
MeshMakeData data; MeshMakeData data;
data.fill(daynight_ratio, this); data.fill(daynight_ratio, this);
scene::SMesh *mesh_new = makeMapBlockMesh(&data); scene::SMesh *mesh_new = makeMapBlockMesh(&data, tsrc);
/* /*
Replace the mesh Replace the mesh
@ -655,7 +655,7 @@ void MapBlock::serialize(std::ostream &os, u8 version)
} }
} }
void MapBlock::deSerialize(std::istream &is, u8 version) void MapBlock::deSerialize(std::istream &is, u8 version, IGameDef *gamedef)
{ {
if(!ser_ver_supported(version)) if(!ser_ver_supported(version))
throw VersionMismatchException("ERROR: MapBlock format not supported"); throw VersionMismatchException("ERROR: MapBlock format not supported");
@ -786,7 +786,7 @@ void MapBlock::deSerialize(std::istream &is, u8 version)
{ {
std::string data = deSerializeString(is); std::string data = deSerializeString(is);
std::istringstream iss(data, std::ios_base::binary); std::istringstream iss(data, std::ios_base::binary);
m_node_metadata->deSerialize(iss); m_node_metadata->deSerialize(iss, gamedef);
} }
else else
{ {
@ -794,7 +794,7 @@ void MapBlock::deSerialize(std::istream &is, u8 version)
std::ostringstream oss(std::ios_base::binary); std::ostringstream oss(std::ios_base::binary);
decompressZlib(is, oss); decompressZlib(is, oss);
std::istringstream iss(oss.str(), std::ios_base::binary); std::istringstream iss(oss.str(), std::ios_base::binary);
m_node_metadata->deSerialize(iss); m_node_metadata->deSerialize(iss, gamedef);
} }
} }
catch(SerializationError &e) catch(SerializationError &e)

@ -38,6 +38,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
class Map; class Map;
class NodeMetadataList; class NodeMetadataList;
class ITextureSource;
class IGameDef;
#define BLOCK_TIMESTAMP_UNDEFINED 0xffffffff #define BLOCK_TIMESTAMP_UNDEFINED 0xffffffff
@ -407,7 +409,7 @@ public:
NOTE: Prefer generating the mesh separately and then using NOTE: Prefer generating the mesh separately and then using
replaceMesh(). replaceMesh().
*/ */
void updateMesh(u32 daynight_ratio); void updateMesh(u32 daynight_ratio, ITextureSource *tsrc);
#endif #endif
// Replace the mesh with a new one // Replace the mesh with a new one
void replaceMesh(scene::SMesh *mesh_new); void replaceMesh(scene::SMesh *mesh_new);
@ -537,7 +539,7 @@ public:
// These don't write or read version by itself // These don't write or read version by itself
void serialize(std::ostream &os, u8 version); void serialize(std::ostream &os, u8 version);
void deSerialize(std::istream &is, u8 version); void deSerialize(std::istream &is, u8 version, IGameDef *gamedef);
// Used after the basic ones when writing on disk (serverside) // Used after the basic ones when writing on disk (serverside)
void serializeDiskExtra(std::ostream &os, u8 version); void serializeDiskExtra(std::ostream &os, u8 version);
void deSerializeDiskExtra(std::istream &is, u8 version); void deSerializeDiskExtra(std::istream &is, u8 version);

@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "settings.h" #include "settings.h"
#include "profiler.h" #include "profiler.h"
#include "mapnode_contentfeatures.h" #include "mapnode_contentfeatures.h"
#include "tile.h"
void MeshMakeData::fill(u32 daynight_ratio, MapBlock *block) void MeshMakeData::fill(u32 daynight_ratio, MapBlock *block)
{ {
@ -252,10 +253,10 @@ void makeFastFace(TileSpec tile, u8 li0, u8 li1, u8 li2, u8 li3, v3f p,
Returns TILE_NODE if doesn't exist or should not be drawn. Returns TILE_NODE if doesn't exist or should not be drawn.
*/ */
TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir, TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir,
NodeModMap &temp_mods) NodeModMap &temp_mods, ITextureSource *tsrc)
{ {
TileSpec spec; TileSpec spec;
spec = mn.getTile(face_dir); spec = mn.getTile(face_dir, tsrc);
/* /*
Check temporary modifications on this node Check temporary modifications on this node
@ -272,7 +273,7 @@ TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir,
if(mod.type == NODEMOD_CHANGECONTENT) if(mod.type == NODEMOD_CHANGECONTENT)
{ {
MapNode mn2(mod.param); MapNode mn2(mod.param);
spec = mn2.getTile(face_dir); spec = mn2.getTile(face_dir, tsrc);
} }
if(mod.type == NODEMOD_CRACK) if(mod.type == NODEMOD_CRACK)
{ {
@ -283,20 +284,20 @@ TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir,
// Get original texture name // Get original texture name
u32 orig_id = spec.texture.id; u32 orig_id = spec.texture.id;
std::string orig_name = g_texturesource->getTextureName(orig_id); std::string orig_name = tsrc->getTextureName(orig_id);
// Create new texture name // Create new texture name
std::ostringstream os; std::ostringstream os;
os<<orig_name<<"^[crack"<<mod.param; os<<orig_name<<"^[crack"<<mod.param;
// Get new texture // Get new texture
u32 new_id = g_texturesource->getTextureId(os.str()); u32 new_id = tsrc->getTextureId(os.str());
/*dstream<<"MapBlock::getNodeTile(): Switching from " /*dstream<<"MapBlock::getNodeTile(): Switching from "
<<orig_name<<" to "<<os.str()<<" (" <<orig_name<<" to "<<os.str()<<" ("
<<orig_id<<" to "<<new_id<<")"<<std::endl;*/ <<orig_id<<" to "<<new_id<<")"<<std::endl;*/
spec.texture = g_texturesource->getTexture(new_id); spec.texture = tsrc->getTexture(new_id);
} }
} }
@ -412,6 +413,7 @@ void getTileInfo(
VoxelManipulator &vmanip, VoxelManipulator &vmanip,
NodeModMap &temp_mods, NodeModMap &temp_mods,
bool smooth_lighting, bool smooth_lighting,
ITextureSource *tsrc,
// Output: // Output:
bool &makes_face, bool &makes_face,
v3s16 &p_corrected, v3s16 &p_corrected,
@ -422,8 +424,8 @@ void getTileInfo(
{ {
MapNode n0 = vmanip.getNodeNoEx(blockpos_nodes + p); MapNode n0 = vmanip.getNodeNoEx(blockpos_nodes + p);
MapNode n1 = vmanip.getNodeNoEx(blockpos_nodes + p + face_dir); MapNode n1 = vmanip.getNodeNoEx(blockpos_nodes + p + face_dir);
TileSpec tile0 = getNodeTile(n0, p, face_dir, temp_mods); TileSpec tile0 = getNodeTile(n0, p, face_dir, temp_mods, tsrc);
TileSpec tile1 = getNodeTile(n1, p + face_dir, -face_dir, temp_mods); TileSpec tile1 = getNodeTile(n1, p + face_dir, -face_dir, temp_mods, tsrc);
// This is hackish // This is hackish
content_t content0 = getNodeContent(p, n0, temp_mods); content_t content0 = getNodeContent(p, n0, temp_mods);
@ -493,7 +495,8 @@ void updateFastFaceRow(
NodeModMap &temp_mods, NodeModMap &temp_mods,
VoxelManipulator &vmanip, VoxelManipulator &vmanip,
v3s16 blockpos_nodes, v3s16 blockpos_nodes,
bool smooth_lighting) bool smooth_lighting,
ITextureSource *tsrc)
{ {
v3s16 p = startpos; v3s16 p = startpos;
@ -505,7 +508,7 @@ void updateFastFaceRow(
u8 lights[4] = {0,0,0,0}; u8 lights[4] = {0,0,0,0};
TileSpec tile; TileSpec tile;
getTileInfo(blockpos_nodes, p, face_dir, daynight_ratio, getTileInfo(blockpos_nodes, p, face_dir, daynight_ratio,
vmanip, temp_mods, smooth_lighting, vmanip, temp_mods, smooth_lighting, tsrc,
makes_face, p_corrected, face_dir_corrected, lights, tile); makes_face, p_corrected, face_dir_corrected, lights, tile);
for(u16 j=0; j<length; j++) for(u16 j=0; j<length; j++)
@ -528,7 +531,7 @@ void updateFastFaceRow(
p_next = p + translate_dir; p_next = p + translate_dir;
getTileInfo(blockpos_nodes, p_next, face_dir, daynight_ratio, getTileInfo(blockpos_nodes, p_next, face_dir, daynight_ratio,
vmanip, temp_mods, smooth_lighting, vmanip, temp_mods, smooth_lighting, tsrc,
next_makes_face, next_p_corrected, next_makes_face, next_p_corrected,
next_face_dir_corrected, next_lights, next_face_dir_corrected, next_lights,
next_tile); next_tile);
@ -641,7 +644,7 @@ void updateFastFaceRow(
} }
} }
scene::SMesh* makeMapBlockMesh(MeshMakeData *data) scene::SMesh* makeMapBlockMesh(MeshMakeData *data, ITextureSource *tsrc)
{ {
// 4-21ms for MAP_BLOCKSIZE=16 // 4-21ms for MAP_BLOCKSIZE=16
// 24-155ms for MAP_BLOCKSIZE=32 // 24-155ms for MAP_BLOCKSIZE=32
@ -688,7 +691,8 @@ scene::SMesh* makeMapBlockMesh(MeshMakeData *data)
data->m_temp_mods, data->m_temp_mods,
data->m_vmanip, data->m_vmanip,
blockpos_nodes, blockpos_nodes,
smooth_lighting); smooth_lighting,
tsrc);
} }
} }
/* /*
@ -706,7 +710,8 @@ scene::SMesh* makeMapBlockMesh(MeshMakeData *data)
data->m_temp_mods, data->m_temp_mods,
data->m_vmanip, data->m_vmanip,
blockpos_nodes, blockpos_nodes,
smooth_lighting); smooth_lighting,
tsrc);
} }
} }
/* /*
@ -724,7 +729,8 @@ scene::SMesh* makeMapBlockMesh(MeshMakeData *data)
data->m_temp_mods, data->m_temp_mods,
data->m_vmanip, data->m_vmanip,
blockpos_nodes, blockpos_nodes,
smooth_lighting); smooth_lighting,
tsrc);
} }
} }
} }
@ -789,7 +795,7 @@ scene::SMesh* makeMapBlockMesh(MeshMakeData *data)
- whatever - whatever
*/ */
mapblock_mesh_generate_special(data, collector); mapblock_mesh_generate_special(data, collector, tsrc);
/* /*
Add stuff from collector to mesh Add stuff from collector to mesh

@ -141,7 +141,7 @@ struct MeshMakeData
}; };
// This is the highest-level function in here // This is the highest-level function in here
scene::SMesh* makeMapBlockMesh(MeshMakeData *data); scene::SMesh* makeMapBlockMesh(MeshMakeData *data, ITextureSource *tsrc);
#endif #endif

@ -220,7 +220,7 @@ u8 MapNode::getLightBanksWithSource()
} }
#ifndef SERVER #ifndef SERVER
TileSpec MapNode::getTile(v3s16 dir) TileSpec MapNode::getTile(v3s16 dir, ITextureSource *tsrc)
{ {
if(content_features(*this).param_type == CPT_FACEDIR_SIMPLE) if(content_features(*this).param_type == CPT_FACEDIR_SIMPLE)
dir = facedir_rotate(param1, dir); dir = facedir_rotate(param1, dir);
@ -253,19 +253,19 @@ TileSpec MapNode::getTile(v3s16 dir)
/* /*
If it contains some mineral, change texture id If it contains some mineral, change texture id
*/ */
if(content_features(*this).param_type == CPT_MINERAL && g_texturesource) if(content_features(*this).param_type == CPT_MINERAL && tsrc)
{ {
u8 mineral = getMineral(); u8 mineral = getMineral();
std::string mineral_texture_name = mineral_block_texture(mineral); std::string mineral_texture_name = mineral_block_texture(mineral);
if(mineral_texture_name != "") if(mineral_texture_name != "")
{ {
u32 orig_id = spec.texture.id; u32 orig_id = spec.texture.id;
std::string texture_name = g_texturesource->getTextureName(orig_id); std::string texture_name = tsrc->getTextureName(orig_id);
//texture_name += "^blit:"; //texture_name += "^blit:";
texture_name += "^"; texture_name += "^";
texture_name += mineral_texture_name; texture_name += mineral_texture_name;
u32 new_id = g_texturesource->getTextureId(texture_name); u32 new_id = tsrc->getTextureId(texture_name);
spec.texture = g_texturesource->getTexture(new_id); spec.texture = tsrc->getTexture(new_id);
} }
} }

@ -226,7 +226,7 @@ struct MapNode
Returns: TileSpec. Can contain miscellaneous texture coordinates, Returns: TileSpec. Can contain miscellaneous texture coordinates,
which must be obeyed so that the texture atlas can be used. which must be obeyed so that the texture atlas can be used.
*/ */
TileSpec getTile(v3s16 dir); TileSpec getTile(v3s16 dir, ITextureSource *tsrc);
#endif #endif
/* /*

@ -19,8 +19,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapnode_contentfeatures.h" #include "mapnode_contentfeatures.h"
#include "main.h" // For g_settings and g_texturesource #include "main.h" // For g_settings
#include "nodemetadata.h" #include "nodemetadata.h"
#ifndef SERVER
#include "tile.h"
#endif
struct ContentFeatures g_content_features[MAX_CONTENT+1]; struct ContentFeatures g_content_features[MAX_CONTENT+1];
@ -29,7 +32,7 @@ struct ContentFeatures g_content_features[MAX_CONTENT+1];
Must be called before accessing the table. Must be called before accessing the table.
*/ */
void init_contentfeatures() void init_contentfeatures(ITextureSource *tsrc)
{ {
#ifndef SERVER #ifndef SERVER
/* /*
@ -64,7 +67,7 @@ void init_contentfeatures()
if(i == CONTENT_IGNORE || i == CONTENT_AIR) if(i == CONTENT_IGNORE || i == CONTENT_AIR)
continue; continue;
ContentFeatures *f = &g_content_features[i]; ContentFeatures *f = &g_content_features[i];
f->setAllTextures("unknown_block.png"); f->setAllTextures(tsrc, "unknown_block.png");
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
} }
@ -83,13 +86,14 @@ ContentFeatures::~ContentFeatures()
} }
#ifndef SERVER #ifndef SERVER
void ContentFeatures::setTexture(u16 i, std::string name, u8 alpha) void ContentFeatures::setTexture(ITextureSource *tsrc,
u16 i, std::string name, u8 alpha)
{ {
used_texturenames[name] = true; used_texturenames[name] = true;
if(g_texturesource) if(tsrc)
{ {
tiles[i].texture = g_texturesource->getTexture(name); tiles[i].texture = tsrc->getTexture(name);
} }
if(alpha != 255) if(alpha != 255)
@ -99,23 +103,24 @@ void ContentFeatures::setTexture(u16 i, std::string name, u8 alpha)
} }
if(inventory_texture == NULL) if(inventory_texture == NULL)
setInventoryTexture(name); setInventoryTexture(name, tsrc);
} }
void ContentFeatures::setInventoryTexture(std::string imgname) void ContentFeatures::setInventoryTexture(std::string imgname,
ITextureSource *tsrc)
{ {
if(g_texturesource == NULL) if(tsrc == NULL)
return; return;
imgname += "^[forcesingle"; imgname += "^[forcesingle";
inventory_texture = g_texturesource->getTextureRaw(imgname); inventory_texture = tsrc->getTextureRaw(imgname);
} }
void ContentFeatures::setInventoryTextureCube(std::string top, void ContentFeatures::setInventoryTextureCube(std::string top,
std::string left, std::string right) std::string left, std::string right, ITextureSource *tsrc)
{ {
if(g_texturesource == NULL) if(tsrc == NULL)
return; return;
str_replace_char(top, '^', '&'); str_replace_char(top, '^', '&');
@ -129,7 +134,7 @@ void ContentFeatures::setInventoryTextureCube(std::string top,
imgname_full += left; imgname_full += left;
imgname_full += "{"; imgname_full += "{";
imgname_full += right; imgname_full += right;
inventory_texture = g_texturesource->getTextureRaw(imgname_full); inventory_texture = tsrc->getTextureRaw(imgname_full);
} }
#endif #endif

@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "tile.h" #include "tile.h"
#endif #endif
#include "materials.h" // MaterialProperties #include "materials.h" // MaterialProperties
class ITextureSource;
/* /*
Content feature list Content feature list
@ -40,7 +41,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Must be called before accessing the table. Must be called before accessing the table.
*/ */
void init_contentfeatures(); void init_contentfeatures(ITextureSource *tsrc);
enum ContentParamType enum ContentParamType
{ {
@ -232,21 +233,24 @@ struct ContentFeatures
*/ */
#ifdef SERVER #ifdef SERVER
void setTexture(u16 i, std::string name, u8 alpha=255) void setTexture(ITextureSource *tsrc, u16 i, std::string name,
u8 alpha=255)
{} {}
void setAllTextures(std::string name, u8 alpha=255) void setAllTextures(ITextureSource *tsrc, std::string name, u8 alpha=255)
{} {}
#else #else
void setTexture(u16 i, std::string name, u8 alpha=255); void setTexture(ITextureSource *tsrc,
u16 i, std::string name, u8 alpha=255);
void setAllTextures(std::string name, u8 alpha=255) void setAllTextures(ITextureSource *tsrc,
std::string name, u8 alpha=255)
{ {
for(u16 i=0; i<6; i++) for(u16 i=0; i<6; i++)
{ {
setTexture(i, name, alpha); setTexture(tsrc, i, name, alpha);
} }
// Force inventory texture too // Force inventory texture too
setInventoryTexture(name); setInventoryTexture(name, tsrc);
} }
#endif #endif
@ -265,16 +269,17 @@ struct ContentFeatures
#endif #endif
#ifdef SERVER #ifdef SERVER
void setInventoryTexture(std::string imgname) void setInventoryTexture(std::string imgname,
ITextureSource *tsrc)
{} {}
void setInventoryTextureCube(std::string top, void setInventoryTextureCube(std::string top,
std::string left, std::string right) std::string left, std::string right, ITextureSource *tsrc)
{} {}
#else #else
void setInventoryTexture(std::string imgname); void setInventoryTexture(std::string imgname, ITextureSource *tsrc);
void setInventoryTextureCube(std::string top, void setInventoryTextureCube(std::string top,
std::string left, std::string right); std::string left, std::string right, ITextureSource *tsrc);
#endif #endif
}; };

@ -3,29 +3,28 @@
#include "mapnode_contentfeatures.h" #include "mapnode_contentfeatures.h"
#include "tool.h" #include "tool.h"
DiggingProperties getDiggingProperties(u16 material, const std::string &tool) DiggingProperties getDiggingProperties(u16 material, ToolDiggingProperties *tp)
{ {
assert(tp);
MaterialProperties &mp = content_features(material).material; MaterialProperties &mp = content_features(material).material;
if(mp.diggability == DIGGABLE_NOT) if(mp.diggability == DIGGABLE_NOT)
return DiggingProperties(false, 0, 0); return DiggingProperties(false, 0, 0);
if(mp.diggability == DIGGABLE_CONSTANT) if(mp.diggability == DIGGABLE_CONSTANT)
return DiggingProperties(true, mp.constant_time, 0); return DiggingProperties(true, mp.constant_time, 0);
ToolDiggingProperties tp = tool_get_digging_properties(tool); float time = tp->basetime;
time += tp->dt_weight * mp.weight;
float time = tp.basetime; time += tp->dt_crackiness * mp.crackiness;
time += tp.dt_weight * mp.weight; time += tp->dt_crumbliness * mp.crumbliness;
time += tp.dt_crackiness * mp.crackiness; time += tp->dt_cuttability * mp.cuttability;
time += tp.dt_crumbliness * mp.crumbliness;
time += tp.dt_cuttability * mp.cuttability;
if(time < 0.2) if(time < 0.2)
time = 0.2; time = 0.2;
float durability = tp.basedurability; float durability = tp->basedurability;
durability += tp.dd_weight * mp.weight; durability += tp->dd_weight * mp.weight;
durability += tp.dd_crackiness * mp.crackiness; durability += tp->dd_crackiness * mp.crackiness;
durability += tp.dd_crumbliness * mp.crumbliness; durability += tp->dd_crumbliness * mp.crumbliness;
durability += tp.dd_cuttability * mp.cuttability; durability += tp->dd_cuttability * mp.cuttability;
if(durability < 1) if(durability < 1)
durability = 1; durability = 1;

@ -88,8 +88,9 @@ struct DiggingProperties
u16 wear; u16 wear;
}; };
// Tool "" is bare hands class ToolDiggingProperties;
DiggingProperties getDiggingProperties(u16 material, const std::string &tool);
DiggingProperties getDiggingProperties(u16 material, ToolDiggingProperties *tp);
#endif #endif

@ -40,12 +40,14 @@ void init_mineral();
std::string mineral_block_texture(u8 mineral); std::string mineral_block_texture(u8 mineral);
inline CraftItem * getDiggedMineralItem(u8 mineral) class IGameDef;
inline CraftItem * getDiggedMineralItem(u8 mineral, IGameDef *gamedef)
{ {
if(mineral == MINERAL_COAL) if(mineral == MINERAL_COAL)
return new CraftItem("lump_of_coal", 1); return new CraftItem(gamedef, "lump_of_coal", 1);
else if(mineral == MINERAL_IRON) else if(mineral == MINERAL_IRON)
return new CraftItem("lump_of_iron", 1); return new CraftItem(gamedef, "lump_of_iron", 1);
return NULL; return NULL;
} }

@ -32,7 +32,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
core::map<u16, NodeMetadata::Factory> NodeMetadata::m_types; core::map<u16, NodeMetadata::Factory> NodeMetadata::m_types;
NodeMetadata::NodeMetadata() NodeMetadata::NodeMetadata(IGameDef *gamedef):
m_gamedef(gamedef)
{ {
} }
@ -40,7 +41,7 @@ NodeMetadata::~NodeMetadata()
{ {
} }
NodeMetadata* NodeMetadata::deSerialize(std::istream &is) NodeMetadata* NodeMetadata::deSerialize(std::istream &is, IGameDef *gamedef)
{ {
// Read id // Read id
u8 buf[2]; u8 buf[2];
@ -67,7 +68,7 @@ NodeMetadata* NodeMetadata::deSerialize(std::istream &is)
std::istringstream iss(data, std::ios_base::binary); std::istringstream iss(data, std::ios_base::binary);
Factory f = n->getValue(); Factory f = n->getValue();
NodeMetadata *meta = (*f)(iss); NodeMetadata *meta = (*f)(iss, gamedef);
return meta; return meta;
} }
catch(SerializationError &e) catch(SerializationError &e)
@ -128,7 +129,7 @@ void NodeMetadataList::serialize(std::ostream &os)
} }
} }
void NodeMetadataList::deSerialize(std::istream &is) void NodeMetadataList::deSerialize(std::istream &is, IGameDef *gamedef)
{ {
m_data.clear(); m_data.clear();
@ -159,7 +160,7 @@ void NodeMetadataList::deSerialize(std::istream &is)
p16 -= p.Y * MAP_BLOCKSIZE; p16 -= p.Y * MAP_BLOCKSIZE;
p.X += p16; p.X += p16;
NodeMetadata *data = NodeMetadata::deSerialize(is); NodeMetadata *data = NodeMetadata::deSerialize(is, gamedef);
if(data == NULL) if(data == NULL)
continue; continue;

@ -34,21 +34,22 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/ */
class Inventory; class Inventory;
class IGameDef;
class NodeMetadata class NodeMetadata
{ {
public: public:
typedef NodeMetadata* (*Factory)(std::istream&); typedef NodeMetadata* (*Factory)(std::istream&, IGameDef *gamedef);
NodeMetadata(); NodeMetadata(IGameDef *gamedef);
virtual ~NodeMetadata(); virtual ~NodeMetadata();
static NodeMetadata* deSerialize(std::istream &is); static NodeMetadata* deSerialize(std::istream &is, IGameDef *gamedef);
void serialize(std::ostream &os); void serialize(std::ostream &os);
// This usually is the CONTENT_ value // This usually is the CONTENT_ value
virtual u16 typeId() const = 0; virtual u16 typeId() const = 0;
virtual NodeMetadata* clone() = 0; virtual NodeMetadata* clone(IGameDef *gamedef) = 0;
virtual void serializeBody(std::ostream &os) = 0; virtual void serializeBody(std::ostream &os) = 0;
virtual std::string infoText() {return "";} virtual std::string infoText() {return "";}
virtual Inventory* getInventory() {return NULL;} virtual Inventory* getInventory() {return NULL;}
@ -69,6 +70,7 @@ public:
virtual void setText(const std::string &t){} virtual void setText(const std::string &t){}
protected: protected:
static void registerType(u16 id, Factory f); static void registerType(u16 id, Factory f);
IGameDef *m_gamedef;
private: private:
static core::map<u16, Factory> m_types; static core::map<u16, Factory> m_types;
}; };
@ -83,7 +85,7 @@ public:
~NodeMetadataList(); ~NodeMetadataList();
void serialize(std::ostream &os); void serialize(std::ostream &os);
void deSerialize(std::istream &is); void deSerialize(std::istream &is, IGameDef *gamedef);
// Get pointer to data // Get pointer to data
NodeMetadata* get(v3s16 p); NodeMetadata* get(v3s16 p);

@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef SERVER #ifndef SERVER
#include <ITextSceneNode.h> #include <ITextSceneNode.h>
#endif #endif
#include "main.h" // For g_settings
#include "settings.h" #include "settings.h"
#include "mapnode_contentfeatures.h" #include "mapnode_contentfeatures.h"
@ -128,7 +129,7 @@ void Player::serialize(std::ostream &os)
inventory.serialize(os); inventory.serialize(os);
} }
void Player::deSerialize(std::istream &is) void Player::deSerialize(std::istream &is, IGameDef *gamedef)
{ {
Settings args; Settings args;
@ -162,7 +163,7 @@ void Player::deSerialize(std::istream &is)
hp = 20; hp = 20;
} }
inventory.deSerialize(is); inventory.deSerialize(is, gamedef);
} }
/* /*

@ -141,7 +141,7 @@ public:
deSerialize stops reading exactly at the right point. deSerialize stops reading exactly at the right point.
*/ */
void serialize(std::ostream &os); void serialize(std::ostream &os);
void deSerialize(std::istream &is); void deSerialize(std::istream &is, IGameDef *gamedef);
bool touching_ground; bool touching_ground;
// This oscillates so that the player jumps a bit above the surface // This oscillates so that the player jumps a bit above the surface
@ -185,8 +185,8 @@ public:
class ServerRemotePlayer : public Player, public ServerActiveObject class ServerRemotePlayer : public Player, public ServerActiveObject
{ {
public: public:
ServerRemotePlayer(): ServerRemotePlayer(ServerEnvironment *env):
ServerActiveObject(NULL, v3f(0,0,0)) ServerActiveObject(env, v3f(0,0,0))
{ {
} }
ServerRemotePlayer(ServerEnvironment *env, v3f pos_, u16 peer_id_, ServerRemotePlayer(ServerEnvironment *env, v3f pos_, u16 peer_id_,

@ -478,7 +478,11 @@ private:
<<" itemstring=\""<<itemstring<<"\""<<std::endl; <<" itemstring=\""<<itemstring<<"\""<<std::endl;
// Do it // Do it
std::istringstream is(itemstring, std::ios::binary); std::istringstream is(itemstring, std::ios::binary);
InventoryItem *item = InventoryItem::deSerialize(is); ServerEnvironment *env = co->getEnv();
assert(env);
IGameDef *gamedef = env->getGameDef();
InventoryItem *item = InventoryItem::deSerialize(is, gamedef);
infostream<<"item="<<env<<std::endl;
bool fits = co->addToInventory(item); bool fits = co->addToInventory(item);
// Return // Return
lua_pushboolean(L, fits); lua_pushboolean(L, fits);
@ -557,7 +561,8 @@ const luaL_reg ObjectRef::methods[] = {
}; };
// Creates a new anonymous reference if id=0 // Creates a new anonymous reference if id=0
static void objectref_get_or_create(lua_State *L, ServerActiveObject *cobj) static void objectref_get_or_create(lua_State *L,
ServerActiveObject *cobj)
{ {
if(cobj->getId() == 0){ if(cobj->getId() == 0){
ObjectRef::create(L, cobj); ObjectRef::create(L, cobj);

@ -28,6 +28,7 @@ class ServerEnvironment;
class ServerActiveObject; class ServerActiveObject;
typedef struct lua_State lua_State; typedef struct lua_State lua_State;
struct LuaEntityProperties; struct LuaEntityProperties;
//class IGameDef;
void scriptapi_export(lua_State *L, Server *server); void scriptapi_export(lua_State *L, Server *server);
void scriptapi_add_environment(lua_State *L, ServerEnvironment *env); void scriptapi_add_environment(lua_State *L, ServerEnvironment *env);
@ -48,7 +49,7 @@ void scriptapi_luaentity_get_properties(lua_State *L, u16 id,
LuaEntityProperties *prop); LuaEntityProperties *prop);
void scriptapi_luaentity_step(lua_State *L, u16 id, float dtime); void scriptapi_luaentity_step(lua_State *L, u16 id, float dtime);
void scriptapi_luaentity_punch(lua_State *L, u16 id, void scriptapi_luaentity_punch(lua_State *L, u16 id,
ServerActiveObject *clicker); ServerActiveObject *puncher);
void scriptapi_luaentity_rightclick(lua_State *L, u16 id, void scriptapi_luaentity_rightclick(lua_State *L, u16 id,
ServerActiveObject *clicker); ServerActiveObject *clicker);

@ -42,6 +42,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "script.h" #include "script.h"
#include "scriptapi.h" #include "scriptapi.h"
#include "mapnode_contentfeatures.h" #include "mapnode_contentfeatures.h"
#include "tool.h"
#include "content_tool.h" // For content_tool_init
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
@ -956,7 +958,7 @@ Server::Server(
m_authmanager(mapsavedir+DIR_DELIM+"auth.txt"), m_authmanager(mapsavedir+DIR_DELIM+"auth.txt"),
m_banmanager(mapsavedir+DIR_DELIM+"ipban.txt"), m_banmanager(mapsavedir+DIR_DELIM+"ipban.txt"),
m_lua(NULL), m_lua(NULL),
//m_scriptapi(NULL), m_toolmgr(createToolDefManager()),
m_thread(this), m_thread(this),
m_emergethread(this), m_emergethread(this),
m_time_counter(0), m_time_counter(0),
@ -982,6 +984,9 @@ Server::Server(
JMutexAutoLock envlock(m_env_mutex); JMutexAutoLock envlock(m_env_mutex);
JMutexAutoLock conlock(m_con_mutex); JMutexAutoLock conlock(m_con_mutex);
// Initialize default tool definitions
content_tool_init(m_toolmgr);
// Initialize scripting // Initialize scripting
infostream<<"Server: Initializing scripting"<<std::endl; infostream<<"Server: Initializing scripting"<<std::endl;
@ -1001,7 +1006,7 @@ Server::Server(
// Initialize Environment // Initialize Environment
m_env = new ServerEnvironment(new ServerMap(mapsavedir), m_lua); m_env = new ServerEnvironment(new ServerMap(mapsavedir, this), m_lua, this);
// Give environment reference to scripting api // Give environment reference to scripting api
scriptapi_add_environment(m_lua, m_env); scriptapi_add_environment(m_lua, m_env);
@ -1101,6 +1106,8 @@ Server::~Server()
// Delete Environment // Delete Environment
delete m_env; delete m_env;
delete m_toolmgr;
// Deinitialize scripting // Deinitialize scripting
infostream<<"Server: Deinitializing scripting"<<std::endl; infostream<<"Server: Deinitializing scripting"<<std::endl;
script_deinit(m_lua); script_deinit(m_lua);
@ -2574,8 +2581,10 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
std::string toolname = titem->getToolName(); std::string toolname = titem->getToolName();
// Get digging properties for material and tool // Get digging properties for material and tool
ToolDiggingProperties tp =
m_toolmgr->getDiggingProperties(toolname);
DiggingProperties prop = DiggingProperties prop =
getDiggingProperties(material, toolname); getDiggingProperties(material, &tp);
if(prop.diggable == false) if(prop.diggable == false)
{ {
@ -2600,7 +2609,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
InventoryItem *item = NULL; InventoryItem *item = NULL;
if(mineral != MINERAL_NONE) if(mineral != MINERAL_NONE)
item = getDiggedMineralItem(mineral); item = getDiggedMineralItem(mineral, this);
// If not mineral // If not mineral
if(item == NULL) if(item == NULL)
@ -2609,7 +2618,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
if(dug_s != "") if(dug_s != "")
{ {
std::istringstream is(dug_s, std::ios::binary); std::istringstream is(dug_s, std::ios::binary);
item = InventoryItem::deSerialize(is); item = InventoryItem::deSerialize(is, this);
} }
} }
@ -2626,7 +2635,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
item = NULL; item = NULL;
if(mineral != MINERAL_NONE) if(mineral != MINERAL_NONE)
item = getDiggedMineralItem(mineral); item = getDiggedMineralItem(mineral, this);
// If not mineral // If not mineral
if(item == NULL) if(item == NULL)
@ -2637,7 +2646,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
&& myrand() % extra_rarity == 0) && myrand() % extra_rarity == 0)
{ {
std::istringstream is(extra_dug_s, std::ios::binary); std::istringstream is(extra_dug_s, std::ios::binary);
item = InventoryItem::deSerialize(is); item = InventoryItem::deSerialize(is, this);
} }
} }
@ -4108,7 +4117,7 @@ void Server::UpdateCrafting(u16 peer_id)
} }
// Get result of crafting grid // Get result of crafting grid
InventoryItem *result = craft_get_result(items); InventoryItem *result = craft_get_result(items, this);
if(result) if(result)
rlist->addItem(result); rlist->addItem(result);
} }
@ -4272,7 +4281,7 @@ Player *Server::emergePlayer(const char *name, const char *password, u16 peer_id
player->inventory_backup = new Inventory(); player->inventory_backup = new Inventory();
*(player->inventory_backup) = player->inventory; *(player->inventory_backup) = player->inventory;
// Set creative inventory // Set creative inventory
craft_set_creative_inventory(player); craft_set_creative_inventory(player, this);
} }
return player; return player;
@ -4326,11 +4335,11 @@ Player *Server::emergePlayer(const char *name, const char *password, u16 peer_id
player->inventory_backup = new Inventory(); player->inventory_backup = new Inventory();
*(player->inventory_backup) = player->inventory; *(player->inventory_backup) = player->inventory;
// Set creative inventory // Set creative inventory
craft_set_creative_inventory(player); craft_set_creative_inventory(player, this);
} }
else if(g_settings->getBool("give_initial_stuff")) else if(g_settings->getBool("give_initial_stuff"))
{ {
craft_give_initial_stuff(player); craft_give_initial_stuff(player, this);
} }
return player; return player;

@ -29,8 +29,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "inventory.h" #include "inventory.h"
#include "auth.h" #include "auth.h"
#include "ban.h" #include "ban.h"
#include "gamedef.h"
struct LuaState; struct LuaState;
typedef struct lua_State lua_State; typedef struct lua_State lua_State;
class IToolDefManager;
/* /*
Some random functions Some random functions
@ -361,7 +363,7 @@ private:
}; };
class Server : public con::PeerHandler, public MapEventReceiver, class Server : public con::PeerHandler, public MapEventReceiver,
public InventoryManager public InventoryManager, public IGameDef
{ {
public: public:
/* /*
@ -482,6 +484,13 @@ public:
// Envlock and conlock should be locked when using Lua // Envlock and conlock should be locked when using Lua
lua_State *getLua(){ return m_lua; } lua_State *getLua(){ return m_lua; }
// IGameDef interface
// Under envlock
virtual IToolDefManager* getToolDefManager()
{ return m_toolmgr; }
virtual INodeDefManager* getNodeDefManager()
{ assert(0); return NULL; } // TODO
private: private:
// con::PeerHandler implementation. // con::PeerHandler implementation.
@ -606,6 +615,9 @@ private:
// Envlock and conlock should be locked when using Lua // Envlock and conlock should be locked when using Lua
lua_State *m_lua; lua_State *m_lua;
// Tool definition manager
IToolDefManager *m_toolmgr;
/* /*
Threads Threads
*/ */
@ -692,8 +704,6 @@ private:
*/ */
u16 m_ignore_map_edit_events_peer_id; u16 m_ignore_map_edit_events_peer_id;
Profiler *m_profiler;
friend class EmergeThread; friend class EmergeThread;
friend class RemoteClient; friend class RemoteClient;
}; };

@ -19,6 +19,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "servercommand.h" #include "servercommand.h"
#include "utility.h" #include "utility.h"
#include "settings.h" #include "settings.h"
#include "main.h" // For g_settings
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"

@ -88,9 +88,6 @@ Settings *g_settings = &main_settings;
Profiler main_profiler; Profiler main_profiler;
Profiler *g_profiler = &main_profiler; Profiler *g_profiler = &main_profiler;
// A dummy thing
ITextureSource *g_texturesource = NULL;
/* /*
Debug streams Debug streams
*/ */
@ -305,10 +302,10 @@ int main(int argc, char *argv[])
// Initialize stuff // Initialize stuff
// Initialize content feature table // Initialize content feature table without textures
init_contentfeatures(); init_contentfeatures(NULL);
// Initialize mapnode content without textures (with g_texturesource=NULL) // Initialize mapnode content without textures
content_mapnode_init(); content_mapnode_init(NULL);
init_mineral(); init_mineral();

@ -37,9 +37,8 @@ ServerActiveObject::~ServerActiveObject()
{ {
} }
void ServerActiveObject::addedToEnvironment(u16 id) void ServerActiveObject::addedToEnvironment()
{ {
setId(id);
} }
ServerActiveObject* ServerActiveObject::create(u8 type, ServerActiveObject* ServerActiveObject::create(u8 type,

@ -54,7 +54,8 @@ public:
ServerActiveObject(ServerEnvironment *env, v3f pos); ServerActiveObject(ServerEnvironment *env, v3f pos);
virtual ~ServerActiveObject(); virtual ~ServerActiveObject();
virtual void addedToEnvironment(u16 id); // Call after id has been set and has been inserted in environment
virtual void addedToEnvironment();
// Create a certain type of ServerActiveObject // Create a certain type of ServerActiveObject
static ServerActiveObject* create(u8 type, static ServerActiveObject* create(u8 type,

@ -18,76 +18,70 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/ */
#include "tool.h" #include "tool.h"
#include "irrlichttypes.h"
#include "log.h"
#include <ostream>
std::string tool_get_imagename(const std::string &toolname) class CToolDefManager: public IToolDefManager
{ {
if(toolname == "WPick") public:
return "tool_woodpick.png"; virtual ~CToolDefManager()
else if(toolname == "STPick") {
return "tool_stonepick.png"; for(core::map<std::string, ToolDefinition*>::Iterator
else if(toolname == "SteelPick") i = m_tool_definitions.getIterator();
return "tool_steelpick.png"; i.atEnd() == false; i++){
else if(toolname == "MesePick") delete i.getNode()->getValue();
return "tool_mesepick.png"; }
else if(toolname == "WShovel") }
return "tool_woodshovel.png"; virtual bool registerTool(std::string toolname, const ToolDefinition &def)
else if(toolname == "STShovel") {
return "tool_stoneshovel.png"; infostream<<"registerTool: registering tool \""<<toolname<<"\""<<std::endl;
else if(toolname == "SteelShovel") core::map<std::string, ToolDefinition*>::Node *n;
return "tool_steelshovel.png"; n = m_tool_definitions.find(toolname);
else if(toolname == "WAxe") if(n != NULL){
return "tool_woodaxe.png"; errorstream<<"registerTool: registering tool \""<<toolname
else if(toolname == "STAxe") <<"\" failed: name is already registered"<<std::endl;
return "tool_stoneaxe.png"; return false;
else if(toolname == "SteelAxe") }
return "tool_steelaxe.png"; m_tool_definitions[toolname] = new ToolDefinition(def);
else if(toolname == "WSword") return true;
return "tool_woodsword.png"; }
else if(toolname == "STSword") virtual ToolDefinition* getToolDefinition(const std::string &toolname)
return "tool_stonesword.png"; {
else if(toolname == "SteelSword") core::map<std::string, ToolDefinition*>::Node *n;
return "tool_steelsword.png"; n = m_tool_definitions.find(toolname);
else if(n == NULL)
return "cloud.png"; return NULL;
return n->getValue();
}
virtual std::string getImagename(const std::string &toolname)
{
ToolDefinition *def = getToolDefinition(toolname);
if(def == NULL)
return "";
return def->imagename;
}
virtual ToolDiggingProperties getDiggingProperties(
const std::string &toolname)
{
ToolDefinition *def = getToolDefinition(toolname);
// If tool does not exist, just return an impossible
if(def == NULL){
// If tool does not exist, try empty name
ToolDefinition *def = getToolDefinition("");
if(def == NULL) // If that doesn't exist either, return default
return ToolDiggingProperties();
return def->properties;
}
return def->properties;
}
private:
// Key is name
core::map<std::string, ToolDefinition*> m_tool_definitions;
};
IToolDefManager* createToolDefManager()
{
return new CToolDefManager();
} }
ToolDiggingProperties tool_get_digging_properties(const std::string &toolname)
{
// weight, crackiness, crumbleness, cuttability
if(toolname == "WPick")
return ToolDiggingProperties(2.0, 0,-1,2,0, 50, 0,0,0,0);
else if(toolname == "STPick")
return ToolDiggingProperties(1.5, 0,-1,2,0, 100, 0,0,0,0);
else if(toolname == "SteelPick")
return ToolDiggingProperties(1.0, 0,-1,2,0, 300, 0,0,0,0);
else if(toolname == "MesePick")
return ToolDiggingProperties(0, 0,0,0,0, 1337, 0,0,0,0);
else if(toolname == "WShovel")
return ToolDiggingProperties(2.0, 0.5,2,-1.5,0.3, 50, 0,0,0,0);
else if(toolname == "STShovel")
return ToolDiggingProperties(1.5, 0.5,2,-1.5,0.1, 100, 0,0,0,0);
else if(toolname == "SteelShovel")
return ToolDiggingProperties(1.0, 0.5,2,-1.5,0.0, 300, 0,0,0,0);
// weight, crackiness, crumbleness, cuttability
else if(toolname == "WAxe")
return ToolDiggingProperties(2.0, 0.5,-0.2,1,-0.5, 50, 0,0,0,0);
else if(toolname == "STAxe")
return ToolDiggingProperties(1.5, 0.5,-0.2,1,-0.5, 100, 0,0,0,0);
else if(toolname == "SteelAxe")
return ToolDiggingProperties(1.0, 0.5,-0.2,1,-0.5, 300, 0,0,0,0);
else if(toolname == "WSword")
return ToolDiggingProperties(3.0, 3,0,1,-1, 50, 0,0,0,0);
else if(toolname == "STSword")
return ToolDiggingProperties(2.5, 3,0,1,-1, 100, 0,0,0,0);
else if(toolname == "SteelSword")
return ToolDiggingProperties(2.0, 3,0,1,-1, 300, 0,0,0,0);
// Properties of hand
return ToolDiggingProperties(0.5, 1,0,-1,0, 50, 0,0,0,0);
}

@ -51,9 +51,32 @@ struct ToolDiggingProperties
{} {}
}; };
std::string tool_get_imagename(const std::string &toolname); struct ToolDefinition
{
std::string imagename;
ToolDiggingProperties properties;
ToolDiggingProperties tool_get_digging_properties(const std::string &toolname); ToolDefinition(){}
ToolDefinition(const std::string &imagename_,
ToolDiggingProperties properties_):
imagename(imagename_),
properties(properties_)
{}
};
class IToolDefManager
{
public:
IToolDefManager(){}
virtual ~IToolDefManager(){}
virtual bool registerTool(std::string toolname, const ToolDefinition &def)=0;
virtual ToolDefinition* getToolDefinition(const std::string &toolname)=0;
virtual std::string getImagename(const std::string &toolname)=0;
virtual ToolDiggingProperties getDiggingProperties(
const std::string &toolname)=0;
};
IToolDefManager* createToolDefManager();
#endif #endif