This commit is contained in:
alexei-zebra 2024-01-03 23:57:50 +03:00
parent 3c7f46987a
commit 405f8b3d14
8 changed files with 36 additions and 29 deletions

View file

@ -57,7 +57,7 @@ void BlocksController::updateSides(int x, int y, int z) {
}
void BlocksController::breakBlock(Player* player, const Block* def, int x, int y, int z) {
chunks->set(x,y,z, 0, 0);
chunks->set(x,y,z, voxel{0,0});
lighting->onBlockSet(x,y,z, 0);
if (def->rt.funcsset.onbroken) {
scripting::on_block_broken(player, def, x, y, z);

View file

@ -236,27 +236,27 @@ void PlayerController::updateInteraction(){
int x = iend.x;
int y = iend.y;
int z = iend.z;
uint8_t states = 0;
voxel voxel;
Block* def = contentIds->getBlockDef(player->chosenBlock);
if (def->rotatable){
const std::string& name = def->rotations.name;
if (name == "pipe") {
if (norm.x < 0.0f) states = BLOCK_DIR_WEST;
else if (norm.x > 0.0f) states = BLOCK_DIR_EAST;
else if (norm.y > 0.0f) states = BLOCK_DIR_UP;
else if (norm.y < 0.0f) states = BLOCK_DIR_DOWN;
else if (norm.z > 0.0f) states = BLOCK_DIR_NORTH;
else if (norm.z < 0.0f) states = BLOCK_DIR_SOUTH;
if (norm.x < 0.0f) voxel.setDir(BLOCK_DIR_WEST);
else if (norm.x > 0.0f) voxel.setDir(BLOCK_DIR_EAST);
else if (norm.y > 0.0f) voxel.setDir(BLOCK_DIR_UP);
else if (norm.y < 0.0f) voxel.setDir(BLOCK_DIR_DOWN);
else if (norm.z > 0.0f) voxel.setDir(BLOCK_DIR_NORTH);
else if (norm.z < 0.0f) voxel.setDir(BLOCK_DIR_SOUTH);
} else if (name == "pane") {
glm::vec3 vec = camera->dir;
if (abs(vec.x) > abs(vec.z)){
if (vec.x > 0.0f) states = BLOCK_DIR_EAST;
if (vec.x < 0.0f) states = BLOCK_DIR_WEST;
if (vec.x > 0.0f) voxel.setDir(BLOCK_DIR_EAST);
if (vec.x < 0.0f) voxel.setDir(BLOCK_DIR_WEST);
}
if (abs(vec.x) < abs(vec.z)){
if (vec.z > 0.0f) states = BLOCK_DIR_SOUTH;
if (vec.z < 0.0f) states = BLOCK_DIR_NORTH;
if (vec.z > 0.0f) voxel.setDir(BLOCK_DIR_SOUTH);
if (vec.z < 0.0f) voxel.setDir(BLOCK_DIR_NORTH);
}
}
}
@ -285,7 +285,8 @@ void PlayerController::updateInteraction(){
chosenBlock = 0;
}
if (chosenBlock != vox->id) {
chunks->set(x, y, z, chosenBlock, states);
voxel.id = chosenBlock;
chunks->set(x, y, z, voxel);
lighting->onBlockSet(x,y,z, chosenBlock);
if (def->rt.funcsset.onplaced) {
scripting::on_block_placed(player, def, x, y, z);

View file

@ -39,13 +39,14 @@ int l_block_index(lua_State* L) {
}
int l_set_block(lua_State* L) {
voxel voxel;
int x = lua_tointeger(L, 1);
int y = lua_tointeger(L, 2);
int z = lua_tointeger(L, 3);
int id = lua_tointeger(L, 4);
int states = lua_tointeger(L, 5);
scripting::level->chunks->set(x, y, z, id, states);
scripting::level->lighting->onBlockSet(x,y,z, id);
voxel.id = lua_tointeger(L, 4);
voxel.states = lua_tointeger(L, 5);
scripting::level->chunks->set(x, y, z, voxel);
scripting::level->lighting->onBlockSet(x,y,z, voxel.id);
return 0;
}