add 'on_block_tick' event
This commit is contained in:
@@ -707,6 +707,25 @@ static int l_has_tag(lua::State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_pull_register_events(lua::State* L) {
|
||||
auto events = blocks_agent::pull_register_events();
|
||||
if (events.empty())
|
||||
return 0;
|
||||
|
||||
lua::createtable(L, events.size() * 4, 0);
|
||||
for (int i = 0; i < events.size(); i++) {
|
||||
const auto& event = events[i];
|
||||
lua::pushinteger(L, static_cast<int>(event.type) | event.id << 16);
|
||||
lua::rawseti(L, i * 4 + 1);
|
||||
|
||||
for (int j = 0; j < 3; j++) {
|
||||
lua::pushinteger(L, event.coord[j]);
|
||||
lua::rawseti(L, i * 4 + j + 2);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
const luaL_Reg blocklib[] = {
|
||||
{"index", lua::wrap<l_index>},
|
||||
{"name", lua::wrap<l_get_def>},
|
||||
@@ -747,5 +766,6 @@ const luaL_Reg blocklib[] = {
|
||||
{"set_field", lua::wrap<l_set_field>},
|
||||
{"reload_script", lua::wrap<l_reload_script>},
|
||||
{"has_tag", lua::wrap<l_has_tag>},
|
||||
{"__pull_register_events", lua::wrap<l_pull_register_events>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "util/timeutil.hpp"
|
||||
#include "voxels/Block.hpp"
|
||||
#include "voxels/Chunk.hpp"
|
||||
#include "voxels/blocks_agent.hpp"
|
||||
#include "world/Level.hpp"
|
||||
#include "world/World.hpp"
|
||||
#include "interfaces/Process.hpp"
|
||||
@@ -464,6 +465,7 @@ void scripting::on_chunk_present(const Chunk& chunk, bool loaded) {
|
||||
);
|
||||
}
|
||||
}
|
||||
blocks_agent::on_chunk_present(*content->getIndices(), chunk);
|
||||
}
|
||||
|
||||
void scripting::on_chunk_remove(const Chunk& chunk) {
|
||||
@@ -478,6 +480,7 @@ void scripting::on_chunk_remove(const Chunk& chunk) {
|
||||
);
|
||||
}
|
||||
}
|
||||
blocks_agent::on_chunk_remove(*content->getIndices(), chunk);
|
||||
}
|
||||
|
||||
void scripting::on_inventory_open(const Player* player, const Inventory& inventory) {
|
||||
@@ -648,6 +651,8 @@ void scripting::load_content_script(
|
||||
register_event(env, "on_replaced", prefix + ".replaced");
|
||||
funcsset.oninteract =
|
||||
register_event(env, "on_interact", prefix + ".interact");
|
||||
funcsset.onblocktick =
|
||||
register_event(env, "on_block_tick", prefix + ".blocktick");
|
||||
funcsset.onblockstick =
|
||||
register_event(env, "on_blocks_tick", prefix + ".blockstick");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user