mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
move logic to avoid need of public LuaABM definiton or reinterpret_cast
This commit is contained in:
parent
22fc23fc51
commit
636c603946
3 changed files with 93 additions and 111 deletions
|
@ -17,68 +17,82 @@
|
|||
LuaABM & LuaLBM
|
||||
*/
|
||||
|
||||
LuaABM::LuaABM(int id,
|
||||
const std::string &name,
|
||||
const std::vector<std::string> &trigger_contents,
|
||||
const std::vector<std::string> &required_neighbors,
|
||||
const std::vector<std::string> &without_neighbors,
|
||||
float trigger_interval, u32 trigger_chance, bool simple_catch_up,
|
||||
s16 min_y, s16 max_y):
|
||||
m_id(id),
|
||||
m_name(name),
|
||||
m_trigger_contents(trigger_contents),
|
||||
m_required_neighbors(required_neighbors),
|
||||
m_without_neighbors(without_neighbors),
|
||||
m_trigger_interval(trigger_interval),
|
||||
m_trigger_chance(trigger_chance),
|
||||
m_simple_catch_up(simple_catch_up),
|
||||
m_min_y(min_y),
|
||||
m_max_y(max_y)
|
||||
{
|
||||
}
|
||||
const std::string &LuaABM::getName() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
const std::vector<std::string> &LuaABM::getTriggerContents() const
|
||||
{
|
||||
return m_trigger_contents;
|
||||
}
|
||||
const std::vector<std::string> &LuaABM::getRequiredNeighbors() const
|
||||
{
|
||||
return m_required_neighbors;
|
||||
}
|
||||
const std::vector<std::string> &LuaABM::getWithoutNeighbors() const
|
||||
{
|
||||
return m_without_neighbors;
|
||||
}
|
||||
float LuaABM::getTriggerInterval()
|
||||
{
|
||||
return m_trigger_interval;
|
||||
}
|
||||
u32 LuaABM::getTriggerChance()
|
||||
{
|
||||
return m_trigger_chance;
|
||||
}
|
||||
bool LuaABM::getSimpleCatchUp()
|
||||
{
|
||||
return m_simple_catch_up;
|
||||
}
|
||||
s16 LuaABM::getMinY()
|
||||
{
|
||||
return m_min_y;
|
||||
}
|
||||
s16 LuaABM::getMaxY()
|
||||
{
|
||||
return m_max_y;
|
||||
}
|
||||
class LuaABM : public ActiveBlockModifier {
|
||||
private:
|
||||
const int m_id;
|
||||
|
||||
void LuaABM::trigger(ServerEnvironment *env, v3s16 p, MapNode n,
|
||||
u32 active_object_count, u32 active_object_count_wider)
|
||||
{
|
||||
auto *script = env->getScriptIface();
|
||||
script->triggerABM(m_id, p, n, active_object_count, active_object_count_wider);
|
||||
}
|
||||
std::string m_name;
|
||||
std::vector<std::string> m_trigger_contents;
|
||||
std::vector<std::string> m_required_neighbors;
|
||||
std::vector<std::string> m_without_neighbors;
|
||||
float m_trigger_interval;
|
||||
u32 m_trigger_chance;
|
||||
bool m_simple_catch_up;
|
||||
s16 m_min_y;
|
||||
s16 m_max_y;
|
||||
public:
|
||||
LuaABM(int id,
|
||||
const std::string name,
|
||||
const std::vector<std::string> &trigger_contents,
|
||||
const std::vector<std::string> &required_neighbors,
|
||||
const std::vector<std::string> &without_neighbors,
|
||||
float trigger_interval, u32 trigger_chance, bool simple_catch_up,
|
||||
s16 min_y, s16 max_y):
|
||||
m_id(id),
|
||||
m_name(name),
|
||||
m_trigger_contents(trigger_contents),
|
||||
m_required_neighbors(required_neighbors),
|
||||
m_without_neighbors(without_neighbors),
|
||||
m_trigger_interval(trigger_interval),
|
||||
m_trigger_chance(trigger_chance),
|
||||
m_simple_catch_up(simple_catch_up),
|
||||
m_min_y(min_y),
|
||||
m_max_y(max_y)
|
||||
{
|
||||
}
|
||||
virtual const std::string &getName() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
virtual const std::vector<std::string> &getTriggerContents() const
|
||||
{
|
||||
return m_trigger_contents;
|
||||
}
|
||||
virtual const std::vector<std::string> &getRequiredNeighbors() const
|
||||
{
|
||||
return m_required_neighbors;
|
||||
}
|
||||
virtual const std::vector<std::string> &getWithoutNeighbors() const
|
||||
{
|
||||
return m_without_neighbors;
|
||||
}
|
||||
virtual float getTriggerInterval()
|
||||
{
|
||||
return m_trigger_interval;
|
||||
}
|
||||
virtual u32 getTriggerChance()
|
||||
{
|
||||
return m_trigger_chance;
|
||||
}
|
||||
virtual bool getSimpleCatchUp()
|
||||
{
|
||||
return m_simple_catch_up;
|
||||
}
|
||||
virtual s16 getMinY()
|
||||
{
|
||||
return m_min_y;
|
||||
}
|
||||
virtual s16 getMaxY()
|
||||
{
|
||||
return m_max_y;
|
||||
}
|
||||
virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n,
|
||||
u32 active_object_count, u32 active_object_count_wider)
|
||||
{
|
||||
auto *script = env->getScriptIface();
|
||||
script->triggerABM(m_id, p, n, active_object_count, active_object_count_wider);
|
||||
}
|
||||
};
|
||||
|
||||
class LuaLBM : public LoadingBlockModifierDef
|
||||
{
|
||||
|
@ -184,6 +198,18 @@ bool ScriptApiEnv::read_nodenames(lua_State *L, int idx, std::vector<std::string
|
|||
return true;
|
||||
}
|
||||
|
||||
int ScriptApiEnv::override_abm(lua_State *L, ServerEnvironment *env)
|
||||
{
|
||||
int abm_id = lua_tonumber(L, 1);
|
||||
|
||||
LuaABM *abm = ScriptApiEnv::readABM(L, 2, abm_id);
|
||||
if (abm != nullptr) {
|
||||
env->replaceActiveBlockModifier(abm);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
LuaABM *ScriptApiEnv::readABM(lua_State *L, int abm_index, int id)
|
||||
{
|
||||
std::string name;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue