This commit is contained in:
@clasher113 2023-11-30 19:00:14 +02:00
commit bc4fe168d7
6 changed files with 47 additions and 15 deletions

View File

@ -13,6 +13,8 @@ using glm::vec3;
// All in-game definitions (blocks, items, etc..)
void setup_definitions(ContentBuilder* builder) {
Block* block = new Block("core:air", "air");
block->replaceable = true;
block->drawGroup = 1;
block->lightPassing = true;
block->skyLightPassing = true;
block->obstacle = false;
@ -60,6 +62,7 @@ void setup_definitions(ContentBuilder* builder) {
block->skyLightPassing = false;
block->obstacle = false;
block->selectable = false;
block->replaceable = true;
builder->add(block);
block = new Block("base:sand", "sand");
@ -73,6 +76,7 @@ void setup_definitions(ContentBuilder* builder) {
block->drawGroup = 1;
block->lightPassing = true;
block->obstacle = false;
block->replaceable = true;
block->model = BlockModel::xsprite;
block->hitbox.scale(vec3(0.7f), vec3(0.5f, 0.0f, 0.5f));
builder->add(block);
@ -81,6 +85,7 @@ void setup_definitions(ContentBuilder* builder) {
block->drawGroup = 1;
block->lightPassing = true;
block->obstacle = false;
block->replaceable = true;
block->model = BlockModel::xsprite;
block->hitbox.scale(vec3(0.7f));
builder->add(block);

View File

@ -238,9 +238,12 @@ void PlayerController::updateInteraction(){
y = (int)(iend.y)+(int)(norm.y);
z = (int)(iend.z)+(int)(norm.z);
}
if (!level->physics->isBlockInside(x,y,z, player->hitbox)){
chunks->set(x, y, z, player->choosenBlock, states);
lighting->onBlockSet(x,y,z, player->choosenBlock);
vox = chunks->get(x, y, z);
if (vox && (block = contentIds->getBlockDef(vox->id))->replaceable) {
if (!level->physics->isBlockInside(x,y,z, player->hitbox)){
chunks->set(x, y, z, player->choosenBlock, states);
lighting->onBlockSet(x,y,z, player->choosenBlock);
}
}
}
if (Events::jactive(BIND_PLAYER_PICK)){

View File

@ -34,6 +34,7 @@ public:
bool skyLightPassing = false;
bool obstacle = true;
bool selectable = true;
bool replaceable = false;
bool breakable = true;
bool rotatable = false;
AABB hitbox;

View File

@ -221,14 +221,21 @@ voxel* Chunks::rayCast(vec3 start,
// TODO: replace this dumb solution with something better
if (def && !def->rt.solid) {
const int gridSize = BLOCK_AABB_GRID * 2;
const AABB& box = def->hitbox;
const int subs = BLOCK_AABB_GRID;
const int subs = gridSize;
iend = vec3(ix, iy, iz);
end -= iend;
for (int i = 0; i < subs; i++) {
end.x += dx / float(subs);
end.y += dy / float(subs);
end.z += dz / float(subs);
int six = end.x * gridSize;
int siy = end.y * gridSize;
int siz = end.z * gridSize;
float stxMax = (txDelta < infinity) ? txDelta * xdist : infinity;
float styMax = (tyDelta < infinity) ? tyDelta * ydist : infinity;
float stzMax = (tzDelta < infinity) ? tzDelta * zdist : infinity;
for (int i = 0; i < subs*2; i++) {
end.x = six / float(gridSize);
end.y = siy / float(gridSize);
end.z = siz / float(gridSize);
if (box.inside(end)) {
end += iend;
norm.x = norm.y = norm.z = 0.0f;
@ -237,6 +244,27 @@ voxel* Chunks::rayCast(vec3 start,
if (steppedIndex == 2) norm.z = -stepz;
return voxel;
}
if (stxMax < styMax) {
if (stxMax < stzMax) {
six += stepx;
stxMax += txDelta;
steppedIndex = 0;
} else {
siz += stepz;
stzMax += tzDelta;
steppedIndex = 2;
}
} else {
if (styMax < stzMax) {
siy += stepy;
styMax += tyDelta;
steppedIndex = 1;
} else {
siz += stepz;
stzMax += tzDelta;
steppedIndex = 2;
}
}
}
} else {
iend.x = ix;

View File

@ -13,7 +13,6 @@
Level::Level(World* world, const Content* content, Player* player, EngineSettings& settings)
: world(world),
content(content),
contentIds(content->indices),
player(player),
chunksStorage(new ChunksStorage(this)),
events(new LevelEvents()) ,
@ -22,11 +21,8 @@ Level::Level(World* world, const Content* content, Player* player, EngineSetting
uint matrixSize = (settings.chunks.loadDistance+
settings.chunks.padding) * 2;
chunks = new Chunks(matrixSize, matrixSize,
0, 0,
world->wfile,
events,
content);
chunks = new Chunks(matrixSize, matrixSize, 0, 0,
world->wfile, events, content);
lighting = new Lighting(content, chunks);
events->listen(EVT_CHUNK_HIDDEN, [this](lvl_event_type type, Chunk* chunk) {

View File

@ -17,7 +17,6 @@ class ChunksStorage;
class PlayerController;
class Level {
const ContentIndices* const contentIds;
public:
World* world;
const Content* const content;