player.get_selected_block
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user