3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2013-2020 Minetest core developers & community
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 class LuaEntitySAO : public UnitSAO
28 LuaEntitySAO() = delete;
29 // Used by the environment to load SAO
30 LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &data);
31 // Used by the Lua API
32 LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &name,
33 const std::string &state) :
35 m_init_name(name), m_init_state(state)
40 ActiveObjectType getType() const { return ACTIVEOBJECT_TYPE_LUAENTITY; }
41 ActiveObjectType getSendType() const { return ACTIVEOBJECT_TYPE_GENERIC; }
42 virtual void addedToEnvironment(u32 dtime_s);
43 void step(float dtime, bool send_recommended);
44 std::string getClientInitializationData(u16 protocol_version);
46 bool isStaticAllowed() const { return m_prop.static_save; }
47 bool shouldUnload() const { return true; }
48 void getStaticData(std::string *result) const;
50 u32 punch(v3f dir, const ToolCapabilities *toolcap = nullptr,
51 ServerActiveObject *puncher = nullptr,
52 float time_from_last_punch = 1000000.0f,
53 u16 initial_wear = 0);
55 void rightClick(ServerActiveObject *clicker);
57 void setPos(const v3f &pos);
58 void moveTo(v3f pos, bool continuous);
59 float getMinimumSavedMovement();
61 std::string getDescription();
63 void setHP(s32 hp, const PlayerHPChangeReason &reason);
66 /* LuaEntitySAO-specific */
67 void setVelocity(v3f velocity);
68 void addVelocity(v3f velocity) { m_velocity += velocity; }
70 void setAcceleration(v3f acceleration);
71 v3f getAcceleration();
73 void setTextureMod(const std::string &mod);
74 std::string getTextureMod() const;
75 void setSprite(v2s16 p, int num_frames, float framelength,
76 bool select_horiz_by_yawpitch);
77 std::string getName();
78 bool getCollisionBox(aabb3f *toset) const;
79 bool getSelectionBox(aabb3f *toset) const;
80 bool collideWithObjects() const;
83 void dispatchScriptDeactivate(bool removal);
84 virtual void onMarkedForDeactivation() { dispatchScriptDeactivate(false); }
85 virtual void onMarkedForRemoval() { dispatchScriptDeactivate(true); }
88 std::string getPropertyPacket();
89 void sendPosition(bool do_interpolate, bool is_movement_end);
90 std::string generateSetTextureModCommand() const;
91 static std::string generateSetSpriteCommand(v2s16 p, u16 num_frames,
92 f32 framelength, bool select_horiz_by_yawpitch);
94 std::string m_init_name;
95 std::string m_init_state;
96 bool m_registered = false;
101 v3f m_last_sent_position;
102 v3f m_last_sent_velocity;
103 v3f m_last_sent_rotation;
104 float m_last_sent_position_timer = 0.0f;
105 float m_last_sent_move_precision = 0.0f;
106 std::string m_current_texture_modifier = "";