-
Notifications
You must be signed in to change notification settings - Fork 14
/
tntrenderer.cpp
40 lines (33 loc) · 1.48 KB
/
tntrenderer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <cstdlib>
#include "world.h"
#include "tntrenderer.h"
void TNTRenderer::tick(const BLOCK_WDATA /*block*/, int local_x, int local_y, int local_z, Chunk &c)
{
if(c.isBlockPowered(local_x, local_y, local_z))
explode(local_x, local_y, local_z, c);
}
void TNTRenderer::explode(const int local_x, const int local_y, const int local_z, Chunk &c)
{
c.spawnDestructionParticles(local_x, local_y, local_z);
c.setGlobalBlockRelative(local_x, local_y, local_z, BLOCK_AIR);
// Destroy everything in a sphere with a 3 block radius
const int dist = 3;
for(int x = -dist; x <= dist; ++x)
for(int y = -dist; y <= dist; ++y)
for(int z = -dist; z <= dist; ++z)
{
if(local_y + y + Chunk::SIZE * c.y < 1 || local_y + y + Chunk::SIZE * c.y >= World::HEIGHT*Chunk::SIZE)
continue;
if(x*x + y*y + z*z > dist*dist)
continue;
//Explode other TNT blocks
auto block = getBLOCK(c.getGlobalBlockRelative(local_x + x, local_y + y, local_z + z));
if(block == BLOCK_TNT)
explode(local_x + x, local_y + y, local_z + z, c);
else if(block != BLOCK_BEDROCK && block != BLOCK_AIR)
{
c.spawnDestructionParticles(local_x + x, local_y + y, local_z + z);
c.changeGlobalBlockRelative(local_x + x, local_y + y, local_z + z, BLOCK_AIR);
}
}
}