player.get_selected_block

This commit is contained in:
MihailRis
2024-05-31 08:33:37 +03:00
parent 29ca6e969c
commit 74042b5c2a
13 changed files with 32 additions and 18 deletions
+3 -3
View File
@@ -166,7 +166,6 @@ void CameraControl::update(const PlayerInput& input, float delta, Chunks* chunks
}
}
glm::vec3 PlayerController::selectedBlockPosition;
glm::vec3 PlayerController::selectedPointPosition;
glm::ivec3 PlayerController::selectedBlockNormal;
int PlayerController::selectedBlockId = -1;
@@ -362,11 +361,11 @@ void PlayerController::updateInteraction(){
maxDistance,
end, norm, iend
);
if (vox != nullptr){
if (vox != nullptr) {
player->selectedVoxel = *vox;
selectedBlockId = vox->id;
selectedBlockRotation = vox->rotation();
selectedBlockPosition = iend;
player->selectedBlockPosition = iend;
selectedPointPosition = end;
selectedBlockNormal = norm;
int x = iend.x;
@@ -443,6 +442,7 @@ void PlayerController::updateInteraction(){
} else {
selectedBlockId = -1;
selectedBlockRotation = 0;
player->selectedVoxel.id = BLOCK_VOID;
}
if (rclick) {
if (item->rt.funcsset.on_use) {
-1
View File
@@ -77,7 +77,6 @@ class PlayerController {
void onFootstep();
void updateFootsteps(float delta);
public:
static glm::vec3 selectedBlockPosition;
static glm::ivec3 selectedBlockNormal;
static glm::vec3 selectedPointPosition;
static int selectedBlockId;
+15
View File
@@ -132,6 +132,20 @@ static int l_player_set_noclip(lua_State* L) {
return 0;
}
static int l_player_get_selected_block(lua_State* L) {
if (auto player = get_player(L, 1)) {
if (player->selectedVoxel.id == BLOCK_VOID) {
return 0;
}
const glm::ivec3 pos = player->selectedBlockPosition;
lua_pushinteger(L, pos.x);
lua_pushinteger(L, pos.y);
lua_pushinteger(L, pos.z);
return 3;
}
return 0;
}
const luaL_Reg playerlib [] = {
{"get_pos", lua_wrap_errors<l_player_get_pos>},
{"set_pos", lua_wrap_errors<l_player_set_pos>},
@@ -144,5 +158,6 @@ const luaL_Reg playerlib [] = {
{"set_flight", lua_wrap_errors<l_player_set_flight>},
{"is_noclip", lua_wrap_errors<l_player_is_noclip>},
{"set_noclip", lua_wrap_errors<l_player_set_noclip>},
{"get_selected_block", lua_wrap_errors<l_player_get_selected_block>},
{NULL, NULL}
};