1
0

TNT position fixes (#4519)

* TNT position fixes

* Don't add offset to explosion spawn coords

* Don't make other entities push TNT

* Correct initial TNT speed

* Fix typo

* Improvements

* Revert unwanted change

* Style fixes

* Update format
This commit is contained in:
Mat 2020-03-22 17:33:36 +02:00 committed by GitHub
parent 00ae9604e1
commit c968f1f7da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 20 additions and 13 deletions

View File

@ -3548,6 +3548,10 @@ function OnAllChunksAvailable()</pre> All return values from the callbacks are i
Name = "InitialVelocityCoeff",
Type = "number",
},
{
Name = "ShouldPlayFuseSound",
Type = "boolean",
},
},
Returns =
{

View File

@ -1199,7 +1199,7 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_
{
// Activate the TNT, with a random fuse between 10 to 30 game ticks
int FuseTime = GetRandomProvider().RandInt(10, 30);
m_World->SpawnPrimedTNT({a_BlockX + x + 0.5, a_BlockY + y + 0.5, a_BlockZ + z + 0.5}, FuseTime);
m_World->SpawnPrimedTNT({a_BlockX + x + 0.5, a_BlockY + y + 0.5, a_BlockZ + z + 0.5}, FuseTime, 1, false); // Initial velocity, no fuse sound
area.SetBlockTypeMeta(bx + x, by + y, bz + z, E_BLOCK_AIR, 0);
a_BlocksAffected.push_back(Vector3i(bx + x, by + y, bz + z));
break;

View File

@ -972,7 +972,7 @@ void cEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
}
}
}
else
else if (!(IsMinecart() || IsTNT()))
{
// Push out entity.
BLOCKTYPE GotBlock;

View File

@ -36,7 +36,7 @@ void cTNTEntity::Explode(void)
m_FuseTicks = 0;
Destroy();
FLOGD("BOOM at {0}", GetPosition());
m_World->DoExplosionAt(4.0, GetPosX() + 0.49, GetPosY() + 0.49, GetPosZ() + 0.49, true, esPrimedTNT, this);
m_World->DoExplosionAt(4.0, GetPosX(), GetPosY(), GetPosZ(), true, esPrimedTNT, this);
}

View File

@ -56,7 +56,6 @@ public:
case E_BLOCK_TNT:
{
// Activate the TNT:
a_World->BroadcastSoundEffect("entity.tnt.primed", Vector3d(a_BlockX, a_BlockY, a_BlockZ), 1.0f, 1.0f);
a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
a_World->SpawnPrimedTNT({a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5}); // 80 ticks to boom
break;

View File

@ -385,7 +385,7 @@ void cFireSimulator::RemoveFuelNeighbors(cChunk * a_Chunk, Vector3i a_RelPos)
if (BlockType == E_BLOCK_TNT)
{
neighbor->SetBlock(relPos, E_BLOCK_AIR, 0);
m_World.SpawnPrimedTNT(absPos, 0);
m_World.SpawnPrimedTNT(Vector3d(absPos) + Vector3d(0.5, 0.5, 0.5)); // 80 ticks to boom
return;
}

View File

@ -37,9 +37,8 @@ public:
// LOGD("Evaluating explodinator the trinitrotoluene (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
if (a_PoweringData.PowerLevel != 0)
{
a_World.BroadcastSoundEffect("entity.tnt.primed", a_Position, 0.5f, 0.6f);
a_World.SetBlock(a_Position.x, a_Position.y, a_Position.z, E_BLOCK_AIR, 0);
a_World.SpawnPrimedTNT(a_Position + Vector3d(0.5, 0.5, 0.5)); // 80 ticks to boom
a_World.SpawnPrimedTNT(Vector3d(a_Position) + Vector3d(0.5, 0.5, 0.5)); // 80 ticks to boom
}
return {};
}

View File

@ -2145,7 +2145,7 @@ UInt32 cWorld::SpawnBoat(Vector3d a_Pos, cBoat::eMaterial a_Material)
UInt32 cWorld::SpawnPrimedTNT(Vector3d a_Pos, int a_FuseTicks, double a_InitialVelocityCoeff)
UInt32 cWorld::SpawnPrimedTNT(Vector3d a_Pos, int a_FuseTicks, double a_InitialVelocityCoeff, bool a_ShouldPlayFuseSound)
{
auto TNT = cpp14::make_unique<cTNTEntity>(a_Pos, a_FuseTicks);
auto TNTPtr = TNT.get();
@ -2154,11 +2154,16 @@ UInt32 cWorld::SpawnPrimedTNT(Vector3d a_Pos, int a_FuseTicks, double a_InitialV
return cEntity::INVALID_ID;
}
if (a_ShouldPlayFuseSound)
{
BroadcastSoundEffect("entity.tnt.primed", a_Pos, 1.0f, 1.0f);
}
auto & Random = GetRandomProvider();
TNTPtr->SetSpeed(
a_InitialVelocityCoeff * Random.RandInt(-1, 1),
a_InitialVelocityCoeff * Random.RandReal(-0.5f, 0.5f),
a_InitialVelocityCoeff * 2,
a_InitialVelocityCoeff * Random.RandInt(-1, 1)
a_InitialVelocityCoeff * Random.RandReal(-0.5f, 0.5f)
);
return TNTPtr->GetUniqueID();
}

View File

@ -625,16 +625,16 @@ public:
// tolua_begin
// DEPRECATED, use the vector-parametered version instead.
UInt32 SpawnPrimedTNT(double a_X, double a_Y, double a_Z, int a_FuseTimeInSec = 80, double a_InitialVelocityCoeff = 1)
UInt32 SpawnPrimedTNT(double a_X, double a_Y, double a_Z, int a_FuseTimeInSec = 80, double a_InitialVelocityCoeff = 1, bool a_ShouldPlayFuseSound = true)
{
LOGWARNING("cWorld::SpawnPrimedTNT(double, double, double) is deprecated, use cWorld::SpawnPrimedTNT(Vector3d) instead.");
return SpawnPrimedTNT({a_X, a_Y, a_Z}, a_FuseTimeInSec, a_InitialVelocityCoeff);
return SpawnPrimedTNT({a_X, a_Y, a_Z}, a_FuseTimeInSec, a_InitialVelocityCoeff, a_ShouldPlayFuseSound);
}
/** Spawns a new primed TNT entity at the specified block coords and specified fuse duration.
Initial velocity is given based on the relative coefficient provided.
Returns the UniqueID of the created entity, or cEntity::INVALID_ID on failure. */
UInt32 SpawnPrimedTNT(Vector3d a_Pos, int a_FuseTimeInSec = 80, double a_InitialVelocityCoeff = 1);
UInt32 SpawnPrimedTNT(Vector3d a_Pos, int a_FuseTimeInSec = 80, double a_InitialVelocityCoeff = 1, bool a_ShouldPlayFuseSound = true);
// tolua_end