1
0

Merge pull request #602 from mc-server/improvementsandfixes

Redstone crash fix and current console line replace function
This commit is contained in:
Mattes D 2014-02-02 22:02:25 -08:00
commit b090547c17
7 changed files with 61 additions and 22 deletions

View File

@ -497,7 +497,7 @@ public:
/// Generic template that can store any kind of data together with a triplet of 3 coords:
/** Generic template that can store any kind of data together with a triplet of 3 coords*/
template <typename X> class cCoordWithData
{
public:
@ -517,12 +517,40 @@ public:
}
} ;
// Illegal in C++03: typedef std::list< cCoordWithData<X> > cCoordWithDataList<X>;
typedef cCoordWithData<int> cCoordWithInt;
typedef cCoordWithData<BLOCKTYPE> cCoordWithBlock;
typedef std::list<cCoordWithInt> cCoordWithIntList;
typedef std::vector<cCoordWithInt> cCoordWithIntVector;
typedef std::vector<cCoordWithBlock> cCoordWithBlockVector;
/** Generic template that can store two types of any kind of data together with a triplet of 3 coords */
template <typename X, typename Z> class cCoordWithDoubleData
{
public:
int x;
int y;
int z;
X Data;
Z DataTwo;
cCoordWithDoubleData(int a_X, int a_Y, int a_Z) :
x(a_X), y(a_Y), z(a_Z)
{
}
cCoordWithDoubleData(int a_X, int a_Y, int a_Z, const X & a_Data, const Z & a_DataTwo) :
x(a_X), y(a_Y), z(a_Z), Data(a_Data), DataTwo(a_DataTwo)
{
}
};
typedef cCoordWithDoubleData <BLOCKTYPE, bool> cCoordWithBlockAndBool;
typedef std::vector<cCoordWithBlockAndBool> cCoordWithBlockAndBoolVector;

View File

@ -263,6 +263,15 @@ inline bool IsBlockWater(BLOCKTYPE a_BlockType)
inline bool IsBlockWaterOrIce(BLOCKTYPE a_BlockType)
{
return (IsBlockWater(a_BlockType) || (a_BlockType == E_BLOCK_ICE));
}
inline bool IsBlockLava(BLOCKTYPE a_BlockType)
{
return ((a_BlockType == E_BLOCK_LAVA) || (a_BlockType == E_BLOCK_STATIONARY_LAVA));

View File

@ -397,6 +397,7 @@ int cEntity::GetArmorCoverAgainst(const cEntity * a_Attacker, eDamageType a_Dama
case dtPotionOfHarming:
case dtFalling:
case dtLightning:
case dtPlugin:
{
return 0;
}
@ -473,7 +474,7 @@ void cEntity::KilledBy(cEntity * a_Killer)
return;
}
// Drop loot:
// Drop loot:
cItems Drops;
GetDrops(Drops, a_Killer);
m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ());

View File

@ -786,11 +786,11 @@ void cPlayer::SetFlying(bool a_IsFlying)
void cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI)
{
if (a_TDI.DamageType != dtInVoid)
if ((a_TDI.DamageType != dtInVoid) && (a_TDI.DamageType != dtPlugin))
{
if (IsGameModeCreative())
{
// No damage / health in creative mode if not void damage
// No damage / health in creative mode if not void or plugin damage
return;
}
}

View File

@ -9,7 +9,6 @@
#include "../Blocks/BlockTorch.h"
#include "../Blocks/BlockDoor.h"
#include "../Piston.h"
#include "../Tracer.h"
@ -170,7 +169,7 @@ void cRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChu
{
if (!IsAllowedBlock(Block))
{
ChunkData.erase(itr); // The new blocktype is not redstone; it must be removed from this list
itr->DataTwo = true; // The new blocktype is not redstone; it must be queued to be removed from this list
}
else
{
@ -185,7 +184,7 @@ void cRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChu
return;
}
ChunkData.push_back(cCoordWithBlock(RelX, a_BlockY, RelZ, Block));
ChunkData.push_back(cCoordWithBlockAndBool(RelX, a_BlockY, RelZ, Block, false));
}
@ -208,8 +207,14 @@ void cRedstoneSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, c
int BaseX = a_Chunk->GetPosX() * cChunkDef::Width;
int BaseZ = a_Chunk->GetPosZ() * cChunkDef::Width;
for (cRedstoneSimulatorChunkData::const_iterator dataitr = ChunkData.begin(); dataitr != ChunkData.end(); ++dataitr)
for (cRedstoneSimulatorChunkData::iterator dataitr = ChunkData.begin(); dataitr != ChunkData.end();)
{
if (dataitr->DataTwo)
{
dataitr = ChunkData.erase(dataitr);
continue;
}
int a_X = BaseX + dataitr->x;
int a_Z = BaseZ + dataitr->z;
switch (dataitr->Data)
@ -279,6 +284,7 @@ void cRedstoneSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, c
break;
}
}
++dataitr;
}
}
@ -919,7 +925,7 @@ void cRedstoneSimulator::HandlePressurePlate(int a_BlockX, int a_BlockY, int a_B
case E_BLOCK_STONE_PRESSURE_PLATE:
{
// MCS feature - stone pressure plates can only be triggered by players :D
cPlayer * a_Player = m_World.FindClosestPlayer(Vector3f(a_BlockX + 0.5f, (float)a_BlockY, a_BlockZ + 0.5f), 0.5f);
cPlayer * a_Player = m_World.FindClosestPlayer(Vector3f(a_BlockX + 0.5f, (float)a_BlockY, a_BlockZ + 0.5f), 0.5f, false);
if (a_Player != NULL)
{
@ -950,19 +956,14 @@ void cRedstoneSimulator::HandlePressurePlate(int a_BlockX, int a_BlockY, int a_B
virtual bool Item(cEntity * a_Entity) override
{
cTracer LineOfSight(m_World);
Vector3f EntityPos = a_Entity->GetPosition();
Vector3f BlockPos(m_X + 0.5f, (float)m_Y, m_Z + 0.5f);
float Distance = (EntityPos - BlockPos).Length();
if (Distance < 0.5)
{
if (!LineOfSight.Trace(BlockPos, (EntityPos - BlockPos), (int)(EntityPos - BlockPos).Length()))
{
m_Entity = a_Entity;
return true; // Break out, we only need to know for wooden plates that at least one entity is on top
}
m_Entity = a_Entity;
return true; // Break out, we only need to know for wooden plates that at least one entity is on top
}
return false;
}

View File

@ -4,7 +4,7 @@
#include "Simulator.h"
/// Per-chunk data for the simulator, specified individual chunks to simulate; 'Data' is not used
typedef cCoordWithBlockVector cRedstoneSimulatorChunkData;
typedef cCoordWithBlockAndBoolVector cRedstoneSimulatorChunkData;

View File

@ -632,7 +632,7 @@ void cWorld::GenerateRandomSpawn(void)
{
LOGD("Generating random spawnpoint...");
while (IsBlockWater(GetBlock((int)m_SpawnX, GetHeight((int)m_SpawnX, (int)m_SpawnZ), (int)m_SpawnZ)))
while (IsBlockWaterOrIce(GetBlock((int)m_SpawnX, GetHeight((int)m_SpawnX, (int)m_SpawnZ), (int)m_SpawnZ)))
{
if ((GetTickRandomNumber(4) % 2) == 0) // Randomise whether to increment X or Z coords
{
@ -1551,7 +1551,7 @@ void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double
a_FlyAwaySpeed /= 100; // Pre-divide, so that we don't have to divide each time inside the loop
for (cItems::const_iterator itr = a_Pickups.begin(); itr != a_Pickups.end(); ++itr)
{
if (!IsValidItem(itr->m_ItemType))
if (!IsValidItem(itr->m_ItemType) || itr->m_ItemType == E_BLOCK_AIR)
{
// Don't spawn pickup if item isn't even valid; should prevent client crashing too
continue;
@ -1577,7 +1577,7 @@ void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double
{
for (cItems::const_iterator itr = a_Pickups.begin(); itr != a_Pickups.end(); ++itr)
{
if (!IsValidItem(itr->m_ItemType))
if (!IsValidItem(itr->m_ItemType) || itr->m_ItemType == E_BLOCK_AIR)
{
continue;
}