format: reformat project
Signed-off-by: Vyacheslav Ivanov <islavaivanov76@gmail.com>
This commit is contained in:
@@ -1,23 +1,22 @@
|
||||
#include "BlocksController.hpp"
|
||||
|
||||
#include "../voxels/voxel.hpp"
|
||||
#include "../content/Content.hpp"
|
||||
#include "../items/Inventories.hpp"
|
||||
#include "../items/Inventory.hpp"
|
||||
#include "../lighting/Lighting.hpp"
|
||||
#include "../maths/fastmaths.hpp"
|
||||
#include "../util/timeutil.hpp"
|
||||
#include "../voxels/Block.hpp"
|
||||
#include "../voxels/Chunk.hpp"
|
||||
#include "../voxels/Chunks.hpp"
|
||||
#include "../voxels/voxel.hpp"
|
||||
#include "../world/Level.hpp"
|
||||
#include "../world/World.hpp"
|
||||
#include "../content/Content.hpp"
|
||||
#include "../lighting/Lighting.hpp"
|
||||
#include "../util/timeutil.hpp"
|
||||
#include "../maths/fastmaths.hpp"
|
||||
#include "../items/Inventory.hpp"
|
||||
#include "../items/Inventories.hpp"
|
||||
|
||||
#include "scripting/scripting.hpp"
|
||||
|
||||
BlocksController::BlocksController(Level* level, uint padding)
|
||||
: level(level),
|
||||
chunks(level->chunks.get()),
|
||||
BlocksController::BlocksController(Level* level, uint padding)
|
||||
: level(level),
|
||||
chunks(level->chunks.get()),
|
||||
lighting(level->lighting.get()),
|
||||
randTickClock(20, 3),
|
||||
blocksTickClock(20, 1),
|
||||
@@ -26,26 +25,32 @@ BlocksController::BlocksController(Level* level, uint padding)
|
||||
}
|
||||
|
||||
void BlocksController::updateSides(int x, int y, int z) {
|
||||
updateBlock(x-1, y, z);
|
||||
updateBlock(x+1, y, z);
|
||||
updateBlock(x, y-1, z);
|
||||
updateBlock(x, y+1, z);
|
||||
updateBlock(x, y, z-1);
|
||||
updateBlock(x, y, z+1);
|
||||
updateBlock(x - 1, y, z);
|
||||
updateBlock(x + 1, y, z);
|
||||
updateBlock(x, y - 1, z);
|
||||
updateBlock(x, y + 1, z);
|
||||
updateBlock(x, y, z - 1);
|
||||
updateBlock(x, y, z + 1);
|
||||
}
|
||||
|
||||
void BlocksController::breakBlock(Player* player, const Block* def, int x, int y, int z) {
|
||||
void BlocksController::breakBlock(
|
||||
Player* player, const Block* def, int x, int y, int z
|
||||
) {
|
||||
onBlockInteraction(
|
||||
player, glm::ivec3(x, y, z), def, BlockInteraction::destruction);
|
||||
player, glm::ivec3(x, y, z), def, BlockInteraction::destruction
|
||||
);
|
||||
chunks->set(x, y, z, 0, {});
|
||||
lighting->onBlockSet(x, y, z, 0);
|
||||
scripting::on_block_broken(player, def, x, y, z);
|
||||
updateSides(x, y, z);
|
||||
}
|
||||
|
||||
void BlocksController::placeBlock(Player* player, const Block* def, blockstate state, int x, int y, int z) {
|
||||
void BlocksController::placeBlock(
|
||||
Player* player, const Block* def, blockstate state, int x, int y, int z
|
||||
) {
|
||||
onBlockInteraction(
|
||||
player, glm::ivec3(x, y, z), def, BlockInteraction::placing);
|
||||
player, glm::ivec3(x, y, z), def, BlockInteraction::placing
|
||||
);
|
||||
chunks->set(x, y, z, def->rt.id, state);
|
||||
lighting->onBlockSet(x, y, z, def->rt.id);
|
||||
if (def->rt.funcsset.onplaced) {
|
||||
@@ -56,12 +61,11 @@ void BlocksController::placeBlock(Player* player, const Block* def, blockstate s
|
||||
|
||||
void BlocksController::updateBlock(int x, int y, int z) {
|
||||
voxel* vox = chunks->get(x, y, z);
|
||||
if (vox == nullptr)
|
||||
return;
|
||||
if (vox == nullptr) return;
|
||||
auto def = level->content->getIndices()->blocks.get(vox->id);
|
||||
if (def->grounded) {
|
||||
const auto& vec = get_ground_direction(def, vox->state.rotation);
|
||||
if (!chunks->isSolidBlock(x+vec.x, y+vec.y, z+vec.z)) {
|
||||
if (!chunks->isSolidBlock(x + vec.x, y + vec.y, z + vec.z)) {
|
||||
breakBlock(nullptr, def, x, y, z);
|
||||
return;
|
||||
}
|
||||
@@ -88,8 +92,7 @@ void BlocksController::onBlocksTick(int tickid, int parts) {
|
||||
auto indices = content->getIndices();
|
||||
int tickRate = blocksTickClock.getTickRate();
|
||||
for (size_t id = 0; id < indices->blocks.count(); id++) {
|
||||
if ((id + tickid) % parts != 0)
|
||||
continue;
|
||||
if ((id + tickid) % parts != 0) continue;
|
||||
auto def = indices->blocks.get(id);
|
||||
auto interval = def->tickInterval;
|
||||
if (def->rt.funcsset.onblockstick && tickid / parts % interval == 0) {
|
||||
@@ -112,9 +115,7 @@ void BlocksController::randomTick(
|
||||
Block* block = indices->blocks.get(vox.id);
|
||||
if (block->rt.funcsset.randupdate) {
|
||||
scripting::random_update_block(
|
||||
block,
|
||||
chunk.x * CHUNK_W + bx, by,
|
||||
chunk.z * CHUNK_D + bz
|
||||
block, chunk.x * CHUNK_W + bx, by, chunk.z * CHUNK_D + bz
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -126,9 +127,9 @@ void BlocksController::randomTick(int tickid, int parts) {
|
||||
const int w = chunks->w;
|
||||
const int d = chunks->d;
|
||||
int segments = 4;
|
||||
|
||||
for (uint z = padding; z < d-padding; z++){
|
||||
for (uint x = padding; x < w-padding; x++){
|
||||
|
||||
for (uint z = padding; z < d - padding; z++) {
|
||||
for (uint x = padding; x < w - padding; x++) {
|
||||
int index = z * w + x;
|
||||
if ((index + tickid) % parts != 0) {
|
||||
continue;
|
||||
@@ -187,16 +188,15 @@ void BlocksController::unbindInventory(int x, int y, int z) {
|
||||
}
|
||||
|
||||
void BlocksController::onBlockInteraction(
|
||||
Player* player,
|
||||
glm::ivec3 pos,
|
||||
const Block* def,
|
||||
BlockInteraction type
|
||||
Player* player, glm::ivec3 pos, const Block* def, BlockInteraction type
|
||||
) {
|
||||
for (const auto& callback : blockInteractionCallbacks) {
|
||||
callback(player, pos, def, type);
|
||||
}
|
||||
}
|
||||
|
||||
void BlocksController::listenBlockInteraction(const on_block_interaction& callback) {
|
||||
void BlocksController::listenBlockInteraction(
|
||||
const on_block_interaction& callback
|
||||
) {
|
||||
blockInteractionCallbacks.push_back(callback);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user