scripting: on_interact (right click on block) callback
This commit is contained in:
@@ -266,6 +266,10 @@ void PlayerController::updateInteraction(){
|
|||||||
blocksController->breakBlock(player, block, x, y, z);
|
blocksController->breakBlock(player, block, x, y, z);
|
||||||
}
|
}
|
||||||
if (rclick){
|
if (rclick){
|
||||||
|
if (block->rt.funcsset.oninteract) {
|
||||||
|
scripting::on_block_interact(player, block, x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (block->model != BlockModel::xsprite){
|
if (block->model != BlockModel::xsprite){
|
||||||
x = (iend.x)+(norm.x);
|
x = (iend.x)+(norm.x);
|
||||||
y = (iend.y)+(norm.y);
|
y = (iend.y)+(norm.y);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "../../voxels/Block.h"
|
#include "../../voxels/Block.h"
|
||||||
#include "../../voxels/Chunks.h"
|
#include "../../voxels/Chunks.h"
|
||||||
#include "../../voxels/voxel.h"
|
#include "../../voxels/voxel.h"
|
||||||
|
#include "../../lighting/Lighting.h"
|
||||||
|
|
||||||
int l_block_name(lua_State* L) {
|
int l_block_name(lua_State* L) {
|
||||||
int id = lua_tointeger(L, 1);
|
int id = lua_tointeger(L, 1);
|
||||||
@@ -39,6 +40,7 @@ int l_set_block(lua_State* L) {
|
|||||||
int z = lua_tointeger(L, 3);
|
int z = lua_tointeger(L, 3);
|
||||||
int id = lua_tointeger(L, 4);
|
int id = lua_tointeger(L, 4);
|
||||||
scripting::level->chunks->set(x, y, z, id, 0);
|
scripting::level->chunks->set(x, y, z, id, 0);
|
||||||
|
scripting::level->lighting->onBlockSet(x,y,z, id);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -116,6 +116,15 @@ void scripting::on_block_broken(Player* player, const Block* block, int x, int y
|
|||||||
call_func(L, 3, name);
|
call_func(L, 3, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void scripting::on_block_interact(Player* player, const Block* block, int x, int y, int z) {
|
||||||
|
std::string name = block->name+".oninteract";
|
||||||
|
lua_getglobal(L, name.c_str());
|
||||||
|
lua_pushinteger(L, x);
|
||||||
|
lua_pushinteger(L, y);
|
||||||
|
lua_pushinteger(L, z);
|
||||||
|
call_func(L, 3, name);
|
||||||
|
}
|
||||||
|
|
||||||
void scripting::load_block_script(std::string prefix, fs::path file, block_funcs_set* funcsset) {
|
void scripting::load_block_script(std::string prefix, fs::path file, block_funcs_set* funcsset) {
|
||||||
std::string src = files::read_string(file);
|
std::string src = files::read_string(file);
|
||||||
std::cout << "loading script " << file.u8string() << std::endl;
|
std::cout << "loading script " << file.u8string() << std::endl;
|
||||||
@@ -129,6 +138,7 @@ void scripting::load_block_script(std::string prefix, fs::path file, block_funcs
|
|||||||
funcsset->randupdate=rename_global(L, "on_random_update", (prefix+".randupdate").c_str());
|
funcsset->randupdate=rename_global(L, "on_random_update", (prefix+".randupdate").c_str());
|
||||||
funcsset->onbroken=rename_global(L, "on_broken", (prefix+".broken").c_str());
|
funcsset->onbroken=rename_global(L, "on_broken", (prefix+".broken").c_str());
|
||||||
funcsset->onplaced=rename_global(L, "on_placed", (prefix+".placed").c_str());
|
funcsset->onplaced=rename_global(L, "on_placed", (prefix+".placed").c_str());
|
||||||
|
funcsset->oninteract=rename_global(L, "on_interact", (prefix+".oninteract").c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void scripting::close() {
|
void scripting::close() {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ namespace scripting {
|
|||||||
void random_update_block(const Block* block, int x, int y, int z);
|
void random_update_block(const Block* block, int x, int y, int z);
|
||||||
void on_block_placed(Player* player, const Block* block, int x, int y, int z);
|
void on_block_placed(Player* player, const Block* block, int x, int y, int z);
|
||||||
void on_block_broken(Player* player, const Block* block, int x, int y, int z);
|
void on_block_broken(Player* player, const Block* block, int x, int y, int z);
|
||||||
|
void on_block_interact(Player* player, const Block* block, int x, int y, int z);
|
||||||
void load_block_script(std::string prefix, fs::path file, block_funcs_set* funcsset);
|
void load_block_script(std::string prefix, fs::path file, block_funcs_set* funcsset);
|
||||||
void close();
|
void close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ struct block_funcs_set {
|
|||||||
bool update: 1;
|
bool update: 1;
|
||||||
bool onplaced: 1;
|
bool onplaced: 1;
|
||||||
bool onbroken: 1;
|
bool onbroken: 1;
|
||||||
|
bool oninteract: 1;
|
||||||
bool randupdate: 1;
|
bool randupdate: 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user