fixes + Block.replaceable
This commit is contained in:
@@ -13,6 +13,7 @@ using glm::vec3;
|
|||||||
// All in-game definitions (blocks, items, etc..)
|
// All in-game definitions (blocks, items, etc..)
|
||||||
void setup_definitions(ContentBuilder* builder) {
|
void setup_definitions(ContentBuilder* builder) {
|
||||||
Block* block = new Block("core:air", "air");
|
Block* block = new Block("core:air", "air");
|
||||||
|
block->replaceable = true;
|
||||||
block->drawGroup = 1;
|
block->drawGroup = 1;
|
||||||
block->lightPassing = true;
|
block->lightPassing = true;
|
||||||
block->skyLightPassing = true;
|
block->skyLightPassing = true;
|
||||||
@@ -61,6 +62,7 @@ void setup_definitions(ContentBuilder* builder) {
|
|||||||
block->skyLightPassing = false;
|
block->skyLightPassing = false;
|
||||||
block->obstacle = false;
|
block->obstacle = false;
|
||||||
block->selectable = false;
|
block->selectable = false;
|
||||||
|
block->replaceable = true;
|
||||||
builder->add(block);
|
builder->add(block);
|
||||||
|
|
||||||
block = new Block("base:sand", "sand");
|
block = new Block("base:sand", "sand");
|
||||||
@@ -74,6 +76,7 @@ void setup_definitions(ContentBuilder* builder) {
|
|||||||
block->drawGroup = 5;
|
block->drawGroup = 5;
|
||||||
block->lightPassing = true;
|
block->lightPassing = true;
|
||||||
block->obstacle = false;
|
block->obstacle = false;
|
||||||
|
block->replaceable = true;
|
||||||
block->model = BlockModel::xsprite;
|
block->model = BlockModel::xsprite;
|
||||||
block->hitbox.scale(vec3(0.7f), vec3(0.5f, 0.0f, 0.5f));
|
block->hitbox.scale(vec3(0.7f), vec3(0.5f, 0.0f, 0.5f));
|
||||||
builder->add(block);
|
builder->add(block);
|
||||||
@@ -82,6 +85,7 @@ void setup_definitions(ContentBuilder* builder) {
|
|||||||
block->drawGroup = 5;
|
block->drawGroup = 5;
|
||||||
block->lightPassing = true;
|
block->lightPassing = true;
|
||||||
block->obstacle = false;
|
block->obstacle = false;
|
||||||
|
block->replaceable = true;
|
||||||
block->model = BlockModel::xsprite;
|
block->model = BlockModel::xsprite;
|
||||||
block->hitbox.scale(vec3(0.7f));
|
block->hitbox.scale(vec3(0.7f));
|
||||||
builder->add(block);
|
builder->add(block);
|
||||||
|
|||||||
@@ -238,11 +238,14 @@ void PlayerController::updateInteraction(){
|
|||||||
y = (int)(iend.y)+(int)(norm.y);
|
y = (int)(iend.y)+(int)(norm.y);
|
||||||
z = (int)(iend.z)+(int)(norm.z);
|
z = (int)(iend.z)+(int)(norm.z);
|
||||||
}
|
}
|
||||||
|
vox = chunks->get(x, y, z);
|
||||||
|
if (vox && (block = contentIds->getBlockDef(vox->id))->replaceable) {
|
||||||
if (!level->physics->isBlockInside(x,y,z, player->hitbox)){
|
if (!level->physics->isBlockInside(x,y,z, player->hitbox)){
|
||||||
chunks->set(x, y, z, player->choosenBlock, states);
|
chunks->set(x, y, z, player->choosenBlock, states);
|
||||||
lighting->onBlockSet(x,y,z, player->choosenBlock);
|
lighting->onBlockSet(x,y,z, player->choosenBlock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (Events::jactive(BIND_PLAYER_PICK)){
|
if (Events::jactive(BIND_PLAYER_PICK)){
|
||||||
player->choosenBlock = chunks->get(x,y,z)->id;
|
player->choosenBlock = chunks->get(x,y,z)->id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ public:
|
|||||||
bool skyLightPassing = false;
|
bool skyLightPassing = false;
|
||||||
bool obstacle = true;
|
bool obstacle = true;
|
||||||
bool selectable = true;
|
bool selectable = true;
|
||||||
|
bool replaceable = false;
|
||||||
bool breakable = true;
|
bool breakable = true;
|
||||||
bool rotatable = false;
|
bool rotatable = false;
|
||||||
AABB hitbox;
|
AABB hitbox;
|
||||||
|
|||||||
+33
-5
@@ -221,14 +221,21 @@ voxel* Chunks::rayCast(vec3 start,
|
|||||||
|
|
||||||
// TODO: replace this dumb solution with something better
|
// TODO: replace this dumb solution with something better
|
||||||
if (def && !def->rt.solid) {
|
if (def && !def->rt.solid) {
|
||||||
|
const int gridSize = BLOCK_AABB_GRID * 2;
|
||||||
const AABB& box = def->hitbox;
|
const AABB& box = def->hitbox;
|
||||||
const int subs = BLOCK_AABB_GRID;
|
const int subs = gridSize;
|
||||||
iend = vec3(ix, iy, iz);
|
iend = vec3(ix, iy, iz);
|
||||||
end -= iend;
|
end -= iend;
|
||||||
for (int i = 0; i < subs; i++) {
|
int six = end.x * gridSize;
|
||||||
end.x += dx / float(subs);
|
int siy = end.y * gridSize;
|
||||||
end.y += dy / float(subs);
|
int siz = end.z * gridSize;
|
||||||
end.z += dz / float(subs);
|
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)) {
|
if (box.inside(end)) {
|
||||||
end += iend;
|
end += iend;
|
||||||
norm.x = norm.y = norm.z = 0.0f;
|
norm.x = norm.y = norm.z = 0.0f;
|
||||||
@@ -237,6 +244,27 @@ voxel* Chunks::rayCast(vec3 start,
|
|||||||
if (steppedIndex == 2) norm.z = -stepz;
|
if (steppedIndex == 2) norm.z = -stepz;
|
||||||
return voxel;
|
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 {
|
} else {
|
||||||
iend.x = ix;
|
iend.x = ix;
|
||||||
|
|||||||
+2
-6
@@ -13,7 +13,6 @@
|
|||||||
Level::Level(World* world, const Content* content, Player* player, EngineSettings& settings)
|
Level::Level(World* world, const Content* content, Player* player, EngineSettings& settings)
|
||||||
: world(world),
|
: world(world),
|
||||||
content(content),
|
content(content),
|
||||||
contentIds(content->indices),
|
|
||||||
player(player),
|
player(player),
|
||||||
chunksStorage(new ChunksStorage(this)),
|
chunksStorage(new ChunksStorage(this)),
|
||||||
events(new LevelEvents()) ,
|
events(new LevelEvents()) ,
|
||||||
@@ -22,11 +21,8 @@ Level::Level(World* world, const Content* content, Player* player, EngineSetting
|
|||||||
|
|
||||||
uint matrixSize = (settings.chunks.loadDistance+
|
uint matrixSize = (settings.chunks.loadDistance+
|
||||||
settings.chunks.padding) * 2;
|
settings.chunks.padding) * 2;
|
||||||
chunks = new Chunks(matrixSize, matrixSize,
|
chunks = new Chunks(matrixSize, matrixSize, 0, 0,
|
||||||
0, 0,
|
world->wfile, events, content);
|
||||||
world->wfile,
|
|
||||||
events,
|
|
||||||
content);
|
|
||||||
lighting = new Lighting(content, chunks);
|
lighting = new Lighting(content, chunks);
|
||||||
|
|
||||||
events->listen(EVT_CHUNK_HIDDEN, [this](lvl_event_type type, Chunk* chunk) {
|
events->listen(EVT_CHUNK_HIDDEN, [this](lvl_event_type type, Chunk* chunk) {
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ class ChunksStorage;
|
|||||||
class PlayerController;
|
class PlayerController;
|
||||||
|
|
||||||
class Level {
|
class Level {
|
||||||
const ContentIndices* const contentIds;
|
|
||||||
public:
|
public:
|
||||||
World* world;
|
World* world;
|
||||||
const Content* const content;
|
const Content* const content;
|
||||||
|
|||||||
Reference in New Issue
Block a user