![]() |
|
Explosions and TNT block and entity - Printable Version +- Cuberite Forum (https://forum.cuberite.org) +-- Forum: Cuberite (https://forum.cuberite.org/forum-4.html) +--- Forum: Development (https://forum.cuberite.org/forum-13.html) +--- Thread: Explosions and TNT block and entity (/thread-858.html) |
RE: Explosions and TNT block and entity - xoft - 04-21-2013 If it works, why not? Still, I'd prefer if the whole explosion method was moved into the cChunkMap + cChunk, so that it can manipulate blocks directly. RE: Explosions and TNT block and entity - NiLSPACE - 04-21-2013 ok so for some reason i can't edit the World.cpp so i'l just post the changes i made here. you may choose for yourself if you want to implent it or not ![]()
if (GetBlock(a_BlockX, a_BlockY, a_BlockZ) != 9)
{
for (int x = 0; x < ExplosionSizeInt; x++)
{
for (int y = 0; y < ExplosionSizeInt; y++)
{
for (int z = 0; z < ExplosionSizeInt; z++)
{
DigBlock(a_BlockX + x, a_BlockY + y, a_BlockZ + z);
DigBlock(a_BlockX + x, a_BlockY - y, a_BlockZ + z);
DigBlock(a_BlockX - x, a_BlockY - y, a_BlockZ - z);
DigBlock(a_BlockX - x, a_BlockY + y, a_BlockZ - z);
DigBlock(a_BlockX + x, a_BlockY + y, a_BlockZ - z);
DigBlock(a_BlockX + x, a_BlockY - y, a_BlockZ - z);
DigBlock(a_BlockX - x, a_BlockY + y, a_BlockZ + z);
DigBlock(a_BlockX - x, a_BlockY - y, a_BlockZ + z);
BlocksAffected.push_back(Vector3i(a_BlockX + x, a_BlockY + y, a_BlockZ + z));
BlocksAffected.push_back(Vector3i(a_BlockX + x, a_BlockY - y, a_BlockZ + z));
BlocksAffected.push_back(Vector3i(a_BlockX - x, a_BlockY - y, a_BlockZ - z));
BlocksAffected.push_back(Vector3i(a_BlockX - x, a_BlockY + y, a_BlockZ - z));
BlocksAffected.push_back(Vector3i(a_BlockX + x, a_BlockY + y, a_BlockZ - z));
BlocksAffected.push_back(Vector3i(a_BlockX + x, a_BlockY - y, a_BlockZ - z));
BlocksAffected.push_back(Vector3i(a_BlockX - x, a_BlockY + y, a_BlockZ + z));
BlocksAffected.push_back(Vector3i(a_BlockX - x, a_BlockY - y, a_BlockZ + z));
}
}
}
}
RE: Explosions and TNT block and entity - xoft - 04-21-2013 Bad idea: comparing to a number, instead of a named constant. If you come back to this code in a month, you won't know that 9 is "water" Even worse: You're checking only one value used for water, you need to check two: E_BLOCK_WATER and E_BLOCK_STATIONARY_WATER. Now, how about lava? Obsidian? Bedrock? Before you start writing a huge IF condition, let me suggest writing a switch block instead, with the block destroying in its default branch
RE: Explosions and TNT block and entity - NiLSPACE - 04-21-2013 i already tried to make it ignore both water blocks but it didn't realy work. i tried if (GetBlock(a_BlockX, a_BlockY, a_BlockZ) != 8,9) //should be E_BLOCK_ETC nowand if (GetBlock(a_BlockX, a_BlockY, a_BlockZ) != 8||9) //should be E_BLOCK_ETC nowthat was what i found on google for the obsydian and bedrock stuff. i don't think the explosion will be IN a obsydian/bedrock block
RE: Explosions and TNT block and entity - xoft - 04-21-2013 If you want to do it as an IF statement: BLOCKTYPE BlockType = GetBlock(a_BlockX, a_BlockY, a_BlockZ); if ((BlockType == E_BLOCK_WATER) || (BlockType == E_BLOCK_STATIONARY_WATER) || (BlockType == ...)) If you want to do it more intelligently, do a switch:
switch (GetBlock(a_BlockX, a_BlockY, a_BlockZ)
{
case E_BLOCK_STATIONARY_WATER:
case E_BLOCK_WATER:
{
// TNT in these blocks doesn't do environmental damage
break;
}
default:
{
// Destroy the neighboring blocks:
for (int y = 0; y < ExplosionSizeInt; y++) ...
}
}
RE: Explosions and TNT block and entity - keyboard - 04-21-2013 Yeah, I was going to rewrite to use chunk (maybe cBlockArea) and to actually create rays of explosions that attempts to destroy the blocks depending on their resistance. It was kind of a big task to make it on the first try (I am also working on the physics for entities which is another big task hehe ), so that's why i decided just to implement it as a simple cube as first step
RE: Explosions and TNT block and entity - NiLSPACE - 05-04-2013 TNT flows with water its pretty cool
RE: Explosions and TNT block and entity - keyboard - 05-05-2013 yeah, and the idea is that will also collide with other entities once we implement entity on entity collision
RE: Explosions and TNT block and entity - NiLSPACE - 05-05-2013 :O thats awsome
RE: Explosions and TNT block and entity - keyboard - 05-05-2013 mmmm, i was thinking: shouldn't explosion be its own class? cExplosion... |