refactor lua scripting a bit

This commit is contained in:
MihailRis
2024-08-19 00:49:28 +03:00
parent 706cabeebd
commit 71f56334cb
7 changed files with 158 additions and 147 deletions
+9 -9
View File
@@ -225,14 +225,14 @@ void scripting::on_blocks_tick(const Block& block, int tps) {
void scripting::update_block(const Block& block, int x, int y, int z) {
std::string name = block.name + ".update";
lua::emit_event(lua::get_main_thread(), name, [x, y, z](auto L) {
return lua::pushivec3_stack(L, x, y, z);
return lua::pushivec_stack(L, glm::ivec3(x, y, z));
});
}
void scripting::random_update_block(const Block& block, int x, int y, int z) {
std::string name = block.name + ".randupdate";
lua::emit_event(lua::get_main_thread(), name, [x, y, z](auto L) {
return lua::pushivec3_stack(L, x, y, z);
return lua::pushivec_stack(L, glm::ivec3(x, y, z));
});
}
@@ -241,13 +241,13 @@ void scripting::on_block_placed(
) {
std::string name = block.name + ".placed";
lua::emit_event(lua::get_main_thread(), name, [x, y, z, player](auto L) {
lua::pushivec3_stack(L, x, y, z);
lua::pushivec_stack(L, glm::ivec3(x, y, z));
lua::pushinteger(L, player ? player->getId() : -1);
return 4;
});
auto world_event_args = [&](lua::State* L) {
lua::pushinteger(L, block.rt.id);
lua::pushivec3_stack(L, x, y, z);
lua::pushivec_stack(L, glm::ivec3(x, y, z));
lua::pushinteger(L, player ? player->getId() : -1);
return 5;
};
@@ -271,7 +271,7 @@ void scripting::on_block_broken(
lua::get_main_thread(),
name,
[x, y, z, player](auto L) {
lua::pushivec3_stack(L, x, y, z);
lua::pushivec_stack(L, glm::ivec3(x, y, z));
lua::pushinteger(L, player ? player->getId() : -1);
return 4;
}
@@ -279,7 +279,7 @@ void scripting::on_block_broken(
}
auto world_event_args = [&](lua::State* L) {
lua::pushinteger(L, block.rt.id);
lua::pushivec3_stack(L, x, y, z);
lua::pushivec_stack(L, glm::ivec3(x, y, z));
lua::pushinteger(L, player ? player->getId() : -1);
return 5;
};
@@ -299,7 +299,7 @@ bool scripting::on_block_interact(
) {
std::string name = block.name + ".interact";
return lua::emit_event(lua::get_main_thread(), name, [pos, player](auto L) {
lua::pushivec3_stack(L, pos.x, pos.y, pos.z);
lua::pushivec_stack(L, pos);
lua::pushinteger(L, player->getId());
return 4;
});
@@ -322,7 +322,7 @@ bool scripting::on_item_use_on_block(
lua::get_main_thread(),
name,
[ipos, normal, player](auto L) {
lua::pushivec3_stack(L, ipos.x, ipos.y, ipos.z);
lua::pushivec_stack(L, ipos);
lua::pushinteger(L, player->getId());
lua::pushivec(L, normal);
return 5;
@@ -338,7 +338,7 @@ bool scripting::on_item_break_block(
lua::get_main_thread(),
name,
[x, y, z, player](auto L) {
lua::pushivec3_stack(L, x, y, z);
lua::pushivec_stack(L, glm::ivec3(x, y, z));
lua::pushinteger(L, player->getId());
return 4;
}