1
0

TNT fixes.

Other blocks can be placed next to TNT.
Explosions activate nearby TNT blocks.
TNT doesn't destroy bedrock, obsidian and liquid blocks.
Server doesn't crash when a TNT (or other entity) leaves the valid Y range.

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1603 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2013-06-18 08:24:34 +00:00
parent c48b5c52ae
commit 547c341325
8 changed files with 85 additions and 69 deletions

View File

@ -2008,10 +2008,6 @@
RelativePath="..\source\blocks\BlockTallGrass.h"
>
</File>
<File
RelativePath="..\source\Blocks\BlockTNT.h"
>
</File>
<File
RelativePath="..\source\blocks\BlockTorch.h"
>

View File

@ -56,7 +56,6 @@
#include "BlockCauldron.h"
#include "BlockBrewingStand.h"
#include "BlockCobWeb.h"
#include "BlockTNT.h"
#include "BlockDeadBush.h"
#include "BlockHopper.h"
@ -177,7 +176,6 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
case E_BLOCK_STONE_SLAB: return new cBlockSlabHandler (a_BlockType);
case E_BLOCK_SUGARCANE: return new cBlockSugarcaneHandler (a_BlockType);
case E_BLOCK_TALL_GRASS: return new cBlockTallGrassHandler (a_BlockType);
case E_BLOCK_TNT: return new cBlockTNTHandler (a_BlockType);
case E_BLOCK_TORCH: return new cBlockTorchHandler (a_BlockType);
case E_BLOCK_VINES: return new cBlockVineHandler (a_BlockType);
case E_BLOCK_WALLSIGN: return new cBlockSignHandler (a_BlockType);

View File

@ -1,38 +0,0 @@
#pragma once
#include "BlockHandler.h"
#include "../Player.h"
#include "../TNTEntity.h"
class cBlockTNTHandler : public cBlockHandler
{
public:
cBlockTNTHandler(BLOCKTYPE a_BlockType)
: cBlockHandler(a_BlockType)
{
}
virtual void OnUse(cWorld * a_World, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
{
if (a_Player->GetEquippedWeapon().m_ItemType == E_ITEM_FLINT_AND_STEEL)
{
a_World->BroadcastSoundEffect("random.fuse", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.6f);
cTNTEntity *TNT = new cTNTEntity(a_BlockX,a_BlockY,a_BlockZ,4); //4 seconds to boom
TNT->Initialize(a_World);
a_World->SetBlock(a_BlockX,a_BlockY,a_BlockZ, E_BLOCK_AIR, 0);
}
}
virtual bool IsUseable() override
{
return true;
}
};

View File

@ -12,6 +12,7 @@
#include "Generating/Trees.h" // used in cChunkMap::ReplaceTreeBlocks() for tree block discrimination
#include "BlockArea.h"
#include "PluginManager.h"
#include "TNTEntity.h"
#ifndef _WIN32
#include <cstdlib> // abs
@ -1501,21 +1502,53 @@ cVector3iArray *cChunkMap::DoExplosiontAt(float a_ExplosionSize, int a_BlockX, i
cBlockArea area;
cVector3iArray * BlocksAffected = new cVector3iArray();
int ExplosionSizeInt = (int) ceil(a_ExplosionSize);
int ExplosionSizeSq = ExplosionSizeInt * ExplosionSizeInt;
BlocksAffected->reserve(8 * ExplosionSizeInt * ExplosionSizeInt * ExplosionSizeInt);
area.Read(m_World, a_BlockX - ExplosionSizeInt, a_BlockX + ExplosionSizeInt, a_BlockY - ExplosionSizeInt, a_BlockY + ExplosionSizeInt, a_BlockZ - ExplosionSizeInt,a_BlockZ + ExplosionSizeInt);
for (int x = -ExplosionSizeInt; x < ExplosionSizeInt; x++)
{
for (int y = -ExplosionSizeInt; y < ExplosionSizeInt; y++)
{
if ((a_BlockY + y >= cChunkDef::Height) || (a_BlockY + y < 0))
{
// Outside of the world
continue;
}
for (int z = -ExplosionSizeInt; z < ExplosionSizeInt; z++)
{
if ((x*x + y*y + z*z) < (ExplosionSizeInt * ExplosionSizeInt))
if ((x * x + y * y + z * z) < ExplosionSizeSq)
{
switch (area.GetBlockType(a_BlockX + x, a_BlockY + y, a_BlockZ + z))
{
case E_BLOCK_TNT:
{
// Activate the TNT, with a random fuse between 10 to 30 game ticks
float FuseTime = (float)(10 + m_World->GetTickRandomNumber(20)) / 20;
cTNTEntity * TNT = new cTNTEntity(a_BlockX, a_BlockY, a_BlockZ, FuseTime);
TNT->Initialize(m_World);
area.SetBlockType(a_BlockX + x, a_BlockY + y, a_BlockZ + z, E_BLOCK_AIR);
BlocksAffected->push_back(Vector3i(a_BlockX + x, a_BlockY + y, a_BlockZ + z));
break;
}
case E_BLOCK_OBSIDIAN:
case E_BLOCK_BEDROCK:
case E_BLOCK_WATER:
case E_BLOCK_STATIONARY_WATER:
case E_BLOCK_STATIONARY_LAVA:
case E_BLOCK_LAVA:
{
// These blocks are not affected by explosions
break;
}
default:
{
area.SetBlockType(a_BlockX + x, a_BlockY + y, a_BlockZ + z, E_BLOCK_AIR);
BlocksAffected->push_back(Vector3i(a_BlockX + x, a_BlockY + y, a_BlockZ + z));
}
}
}
}
}
}
area.Write(m_World,a_BlockX - ExplosionSizeInt,a_BlockY - ExplosionSizeInt,a_BlockZ - ExplosionSizeInt);

View File

@ -218,6 +218,15 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
int BlockX = (int) floor(NextPos.x);
int BlockY = (int) floor(NextPos.y);
int BlockZ = (int) floor(NextPos.z);
if ((BlockY >= cChunkDef::Height) || (BlockY < 0))
{
// Outside of the world
// TODO: Current speed should still be added to the entity position
// Otherwise TNT explosions in the void will still effect the bottommost layers of the world
return;
}
// Make sure we got the correct chunk and a valid one. No one ever knows...
cChunk * NextChunk = a_Chunk.GetNeighborChunk(BlockX,BlockZ);
if (NextChunk != NULL)
@ -353,7 +362,8 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
NextPos += (NextSpeed * a_Dt);
}
else
{ // We didn't hit anything, so move =]
{
// We didn't hit anything, so move =]
NextPos += (NextSpeed * a_Dt);
}
}

View File

@ -4,6 +4,7 @@
#include "ItemHandler.h"
#include "../World.h"
#include "../Player.h"
#include "../TNTEntity.h"
@ -27,9 +28,25 @@ public:
a_Player->UseEquippedItem();
switch (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ))
{
case E_BLOCK_TNT:
{
// Activate the TNT:
a_World->BroadcastSoundEffect("random.fuse", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.6f);
cTNTEntity * TNT = new cTNTEntity(a_BlockX, a_BlockY, a_BlockZ, 4); // 4 seconds to boom
TNT->Initialize(a_World);
a_World->SetBlock(a_BlockX,a_BlockY,a_BlockZ, E_BLOCK_AIR, 0);
break;
}
default:
{
// Light a fire next to the block:
AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_FIRE, 0); //0 -> new fire
a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_FIRE, 0);
break;
}
}
return false;
}