3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef CLIENTOBJECT_HEADER
21 #define CLIENTOBJECT_HEADER
23 #include "irrlichttypes_extrabloated.h"
24 #include "activeobject.h"
26 #include "util/cpp11_container.h"
28 class ClientEnvironment;
34 class WieldMeshSceneNode;
36 class ClientActiveObject : public ActiveObject
39 ClientActiveObject(u16 id, Client *client, ClientEnvironment *env);
40 virtual ~ClientActiveObject();
42 virtual void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
43 IrrlichtDevice *irr){}
44 virtual void removeFromScene(bool permanent){}
45 // 0 <= light_at_pos <= LIGHT_SUN
46 virtual void updateLight(u8 light_at_pos){}
47 virtual void updateLightNoCheck(u8 light_at_pos){}
48 virtual v3s16 getLightPosition(){return v3s16(0,0,0);}
49 virtual aabb3f *getSelectionBox() { return NULL; }
50 virtual bool getCollisionBox(aabb3f *toset) const { return false; }
51 virtual bool collideWithObjects() const { return false; }
52 virtual v3f getPosition(){ return v3f(0,0,0); }
53 virtual float getYaw() const { return 0; }
54 virtual scene::ISceneNode *getSceneNode() { return NULL; }
55 virtual scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode() { return NULL; }
56 virtual bool isLocalPlayer() const {return false;}
57 virtual void setAttachments() {}
58 virtual bool doShowSelectionBox(){return true;}
60 // Step object in time
61 virtual void step(float dtime, ClientEnvironment *env){}
63 // Process a message sent by the server side object
64 virtual void processMessage(const std::string &data){}
66 virtual std::string infoText() {return "";}
67 virtual std::string debugInfoText() {return "";}
70 This takes the return value of
71 ServerActiveObject::getClientInitializationData
73 virtual void initialize(const std::string &data){}
75 // Create a certain type of ClientActiveObject
76 static ClientActiveObject* create(ActiveObjectType type, Client *client,
77 ClientEnvironment *env);
79 // If returns true, punch will not be sent to the server
80 virtual bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
81 float time_from_last_punch=1000000)
85 // Used for creating objects based on type
86 typedef ClientActiveObject* (*Factory)(Client *client, ClientEnvironment *env);
87 static void registerType(u16 type, Factory f);
89 ClientEnvironment *m_env;
91 // Used for creating objects based on type
92 static UNORDERED_MAP<u16, Factory> m_types;
95 struct DistanceSortedActiveObject
97 ClientActiveObject *obj;
100 DistanceSortedActiveObject(ClientActiveObject *a_obj, f32 a_d)
106 bool operator < (const DistanceSortedActiveObject &other) const