Delete irrlichttypes_extrabloated.h (#15723)
[minetest.git] / src / server / luaentity_sao.h
blob9ea1d3f228407337ec7082c43f8b147b0480eecb
1 // Luanti
2 // SPDX-License-Identifier: LGPL-2.1-or-later
3 // Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 // Copyright (C) 2013-2020 Minetest core developers & community
6 #pragma once
8 #include "unit_sao.h"
10 class LuaEntitySAO : public UnitSAO
12 public:
13 LuaEntitySAO() = delete;
14 // Used by the environment to load SAO
15 LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &data);
16 // Used by the Lua API
17 LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &name,
18 const std::string &state) :
19 UnitSAO(env, pos),
20 m_init_name(name), m_init_state(state)
23 ~LuaEntitySAO();
25 ActiveObjectType getType() const { return ACTIVEOBJECT_TYPE_LUAENTITY; }
26 ActiveObjectType getSendType() const { return ACTIVEOBJECT_TYPE_GENERIC; }
27 virtual void addedToEnvironment(u32 dtime_s);
28 void step(float dtime, bool send_recommended);
29 std::string getClientInitializationData(u16 protocol_version);
31 bool isStaticAllowed() const { return m_prop.static_save; }
32 bool shouldUnload() const { return true; }
33 void getStaticData(std::string *result) const;
35 u32 punch(v3f dir, const ToolCapabilities *toolcap = nullptr,
36 ServerActiveObject *puncher = nullptr,
37 float time_from_last_punch = 1000000.0f,
38 u16 initial_wear = 0);
40 void rightClick(ServerActiveObject *clicker);
42 void setPos(const v3f &pos);
43 void moveTo(v3f pos, bool continuous);
44 float getMinimumSavedMovement();
46 std::string getDescription();
48 void setHP(s32 hp, const PlayerHPChangeReason &reason);
49 u16 getHP() const;
51 /* LuaEntitySAO-specific */
52 void setVelocity(v3f velocity);
53 void addVelocity(v3f velocity) { m_velocity += velocity; }
54 v3f getVelocity();
55 void setAcceleration(v3f acceleration);
56 v3f getAcceleration();
58 void setTextureMod(const std::string &mod);
59 std::string getTextureMod() const;
60 void setSprite(v2s16 p, int num_frames, float framelength,
61 bool select_horiz_by_yawpitch);
62 std::string getName();
63 bool getCollisionBox(aabb3f *toset) const;
64 bool getSelectionBox(aabb3f *toset) const;
65 bool collideWithObjects() const;
67 protected:
68 void dispatchScriptDeactivate(bool removal);
69 virtual void onMarkedForDeactivation() {
70 UnitSAO::onMarkedForDeactivation();
71 dispatchScriptDeactivate(false);
73 virtual void onMarkedForRemoval() {
74 UnitSAO::onMarkedForRemoval();
75 dispatchScriptDeactivate(true);
78 private:
79 std::string getPropertyPacket();
80 void sendPosition(bool do_interpolate, bool is_movement_end);
81 std::string generateSetTextureModCommand() const;
82 static std::string generateSetSpriteCommand(v2s16 p, u16 num_frames,
83 f32 framelength, bool select_horiz_by_yawpitch);
85 std::string m_init_name;
86 std::string m_init_state;
87 bool m_registered = false;
89 v3f m_velocity;
90 v3f m_acceleration;
92 v3f m_last_sent_position;
93 v3f m_last_sent_velocity;
94 v3f m_last_sent_rotation;
95 float m_last_sent_position_timer = 0.0f;
96 float m_last_sent_move_precision = 0.0f;
98 std::string m_texture_modifier;
99 bool m_texture_modifier_sent = false;