mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-21 01:49:44 +00:00
add can_be_placed block event
can_be_placed(x, y, z, playerid, rotation) is called before a player places the block, after the built-in checks (replaceability, grounded, entities). The block is placed only if the function returns true. rotation is the rotation the block is going to be placed with, so blocks like ladders can check the block they are attached to. The event is not called for block.place / block.set. Closes #909
This commit is contained in:
parent
1dd1af1a72
commit
2a01cfc5b1
6 changed files with 68 additions and 0 deletions
|
|
@ -451,6 +451,23 @@ static bool on_block_common(
|
|||
return result;
|
||||
}
|
||||
|
||||
bool scripting::can_block_be_placed(
|
||||
Player* player, const Block& block, const glm::ivec3& pos, int rotation
|
||||
) {
|
||||
if (!block.rt.funcsset.canbeplaced) {
|
||||
return true;
|
||||
}
|
||||
std::string name = block.name + ".canbeplaced";
|
||||
return lua::emit_event(
|
||||
lua::get_main_state(), name, [pos, player, rotation](auto L) {
|
||||
lua::pushivec_stack(L, pos);
|
||||
lua::pushinteger(L, player ? player->getId() : -1);
|
||||
lua::pushinteger(L, rotation);
|
||||
return 5;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void scripting::on_block_placed(
|
||||
Player* player, const Block& block, const glm::ivec3& pos
|
||||
) {
|
||||
|
|
@ -717,6 +734,8 @@ void scripting::load_content_script(
|
|||
register_event(env, "on_breaking", prefix + ".breaking");
|
||||
funcsset.onbroken = register_event(env, "on_broken", prefix + ".broken");
|
||||
funcsset.onplaced = register_event(env, "on_placed", prefix + ".placed");
|
||||
funcsset.canbeplaced =
|
||||
register_event(env, "can_be_placed", prefix + ".canbeplaced");
|
||||
funcsset.onreplaced =
|
||||
register_event(env, "on_replaced", prefix + ".replaced");
|
||||
funcsset.oninteract =
|
||||
|
|
|
|||
|
|
@ -92,6 +92,9 @@ namespace scripting {
|
|||
void on_blocks_tick(const Block& block, int tps);
|
||||
void update_block(const Block& block, const glm::ivec3& pos);
|
||||
void random_update_block(const Block& block, const glm::ivec3& pos);
|
||||
bool can_block_be_placed(
|
||||
Player* player, const Block& block, const glm::ivec3& pos, int rotation
|
||||
);
|
||||
void on_block_placed(
|
||||
Player* player, const Block& block, const glm::ivec3& pos
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue