Cuberite Forum

Full Version: Explosions and TNT block and entity
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
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.
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 Wink
	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));
				}
			}
			
		}
	}
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 Smile
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 now 
and
if (GetBlock(a_BlockX, a_BlockY, a_BlockZ) != 8||9)  //should be E_BLOCK_ETC now 
that was what i found on google Wink
for the obsydian and bedrock stuff. i don't think the explosion will be IN a obsydian/bedrock block Wink
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++) ...
	}
}
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 Smile), so that's why i decided just to implement it as a simple cube as first step Smile
TNT flows with waterBig Grin its pretty cool Smile
Smile yeah, and the idea is that will also collide with other entities once we implement entity on entity collision Smile
:O thats awsomeBig Grin
mmmm, i was thinking: shouldn't explosion be its own class? cExplosion...
Pages: 1 2 3