mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-08 20:41:49 +00:00
commit
dc27bd1430
12 changed files with 149 additions and 16 deletions
|
|
@ -111,10 +111,17 @@ void BlocksController::updateBlock(int x, int y, int z) {
|
|||
if (vox == nullptr) return;
|
||||
const auto& def = level.content.getIndices()->blocks.require(vox->id);
|
||||
if (def.grounded) {
|
||||
const auto& vec = get_ground_direction(def, vox->state.rotation);
|
||||
if (!blocks_agent::is_solid_at(chunks, x + vec.x, y + vec.y, z + vec.z)) {
|
||||
breakBlock(nullptr, def, x, y, z);
|
||||
return;
|
||||
if (def.rt.extended) {
|
||||
auto origin = blocks_agent::seek_origin(chunks, {x, y, z}, def, vox->state);
|
||||
if (!blocks_agent::check_grounding(chunks, def, vox->state.rotation, origin)) {
|
||||
breakBlock(nullptr, def, origin.x, origin.y, origin.z);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!blocks_agent::check_grounding(chunks, def, vox->state.rotation, {x, y, z})) {
|
||||
breakBlock(nullptr, def, x, y, z);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (def.rt.funcsset.update) {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
#include "scripting/scripting.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "voxels/Block.hpp"
|
||||
#include "voxels/blocks_agent.hpp"
|
||||
#include "voxels/Chunks.hpp"
|
||||
#include "voxels/voxel.hpp"
|
||||
#include "window/Camera.hpp"
|
||||
|
|
@ -448,10 +449,7 @@ void PlayerController::processRightClick(
|
|||
return;
|
||||
}
|
||||
if (def.grounded) {
|
||||
const auto& vec = get_ground_direction(def, state.rotation);
|
||||
if (!chunks.isSolidBlock(
|
||||
coord.x + vec.x, coord.y + vec.y, coord.z + vec.z
|
||||
)) {
|
||||
if (!blocks_agent::check_grounding(chunks, def, state.rotation, coord)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -246,11 +246,12 @@ static int l_get_user_bits(lua::State* L) {
|
|||
}
|
||||
|
||||
static int l_get_variant(lua::State* L) {
|
||||
auto& chunks = *level->chunks;
|
||||
auto x = lua::tointeger(L, 1);
|
||||
auto y = lua::tointeger(L, 2);
|
||||
auto z = lua::tointeger(L, 3);
|
||||
|
||||
auto vox = blocks_agent::get(*level->chunks, x, y, z);
|
||||
auto vox = blocks_agent::get(chunks, x, y, z);
|
||||
if (vox == nullptr) {
|
||||
return lua::pushinteger(L, 0);
|
||||
}
|
||||
|
|
@ -258,6 +259,13 @@ static int l_get_variant(lua::State* L) {
|
|||
if (def.variants == nullptr) {
|
||||
return lua::pushinteger(L, 0);
|
||||
}
|
||||
if (def.rt.extended) {
|
||||
auto origin = blocks_agent::seek_origin(chunks, {x, y, z}, def, vox->state);
|
||||
vox = blocks_agent::get(chunks, origin.x, origin.y, origin.z);
|
||||
if (vox == nullptr) {
|
||||
return lua::pushinteger(L, 0);
|
||||
}
|
||||
}
|
||||
return lua::pushinteger(
|
||||
L, (vox->state.userbits >> def.variants->offset) & def.variants->mask
|
||||
);
|
||||
|
|
@ -290,6 +298,14 @@ static int l_set_user_bits(lua::State* L) {
|
|||
if (vox == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
int ocx = floordiv<CHUNK_W>(origin.x);
|
||||
int ocz = floordiv<CHUNK_D>(origin.z);
|
||||
if (cx != ocx || cz != ocz) {
|
||||
chunk = blocks_agent::get_chunk(chunks, ocx, ocz);
|
||||
if (chunk == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
vox->state.userbits = (vox->state.userbits & (~mask)) | value;
|
||||
chunk->setModifiedAndUnsaved();
|
||||
|
|
@ -318,8 +334,8 @@ static int l_set_variant(lua::State* L) {
|
|||
}
|
||||
|
||||
auto offset = def.variants->offset;
|
||||
auto mask = def.variants->mask;
|
||||
auto value = (lua::tointeger(L, 4) << offset) & mask;
|
||||
auto mask = def.variants->mask << offset;
|
||||
auto value = (lua::tointeger(L, 4) << offset);
|
||||
|
||||
if (def.rt.extended) {
|
||||
auto origin = blocks_agent::seek_origin(chunks, {x, y, z}, def, vox->state);
|
||||
|
|
@ -327,6 +343,14 @@ static int l_set_variant(lua::State* L) {
|
|||
if (vox == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
int ocx = floordiv<CHUNK_W>(origin.x);
|
||||
int ocz = floordiv<CHUNK_D>(origin.z);
|
||||
if (cx != ocx || cz != ocz) {
|
||||
chunk = blocks_agent::get_chunk(chunks, ocx, ocz);
|
||||
if (chunk == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
vox->state.userbits = (vox->state.userbits & (~mask)) | value;
|
||||
chunk->setModifiedAndUnsaved();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue