2014-02-18 15:40:02 -05:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BlockEntity.h"
|
2014-02-19 08:45:09 -05:00
|
|
|
#include "../BlockEntities/MobHeadEntity.h"
|
2014-02-18 15:40:02 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-19 08:45:09 -05:00
|
|
|
class cBlockMobHeadHandler :
|
2014-02-18 15:40:02 -05:00
|
|
|
public cBlockEntityHandler
|
|
|
|
{
|
|
|
|
public:
|
2014-02-19 08:45:09 -05:00
|
|
|
cBlockMobHeadHandler(BLOCKTYPE a_BlockType)
|
2014-02-18 15:40:02 -05:00
|
|
|
: cBlockEntityHandler(a_BlockType)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
|
|
|
|
{
|
2014-05-28 13:32:20 -04:00
|
|
|
// The drop spawn is in OnDestroyed method
|
2014-05-28 09:54:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override
|
|
|
|
{
|
|
|
|
if (a_Player->IsGameModeCreative())
|
|
|
|
{
|
|
|
|
// No drops in creative mode
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-16 19:15:38 -04:00
|
|
|
class cCallback : public cBlockEntityCallback
|
2014-05-28 09:54:43 -04:00
|
|
|
{
|
2014-06-16 19:15:38 -04:00
|
|
|
virtual bool Item(cBlockEntity * a_BlockEntity)
|
2014-05-28 09:54:43 -04:00
|
|
|
{
|
2014-06-17 08:45:29 -04:00
|
|
|
if (a_BlockEntity->GetBlockType() != E_BLOCK_HEAD)
|
2014-06-16 19:15:38 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-17 08:45:29 -04:00
|
|
|
cMobHeadEntity * MobHeadEntity = static_cast<cMobHeadEntity*>(a_BlockEntity);
|
2014-06-16 19:15:38 -04:00
|
|
|
|
2014-05-28 09:54:43 -04:00
|
|
|
cItems Pickups;
|
2014-06-16 19:15:38 -04:00
|
|
|
Pickups.Add(E_ITEM_HEAD, 1, (short) MobHeadEntity->GetType());
|
2014-05-28 09:54:43 -04:00
|
|
|
MTRand r1;
|
|
|
|
|
|
|
|
// Mid-block position first
|
|
|
|
double MicroX, MicroY, MicroZ;
|
2014-06-16 19:15:38 -04:00
|
|
|
MicroX = MobHeadEntity->GetPosX() + 0.5;
|
|
|
|
MicroY = MobHeadEntity->GetPosY() + 0.5;
|
|
|
|
MicroZ = MobHeadEntity->GetPosZ() + 0.5;
|
2014-05-28 09:54:43 -04:00
|
|
|
|
|
|
|
// Add random offset second
|
|
|
|
MicroX += r1.rand(1) - 0.5;
|
|
|
|
MicroZ += r1.rand(1) - 0.5;
|
|
|
|
|
2014-06-16 19:15:38 -04:00
|
|
|
MobHeadEntity->GetWorld()->SpawnItemPickups(Pickups, MicroX, MicroY, MicroZ);
|
2014-05-28 09:54:43 -04:00
|
|
|
return false;
|
|
|
|
}
|
2014-05-28 13:32:20 -04:00
|
|
|
} Callback;
|
2014-05-28 09:54:43 -04:00
|
|
|
|
2014-06-16 19:15:38 -04:00
|
|
|
a_WorldInterface.DoWithBlockEntityAt(a_BlockX, a_BlockY, a_BlockZ, Callback);
|
2014-02-18 15:40:02 -05:00
|
|
|
}
|
2014-03-24 06:29:19 -04:00
|
|
|
|
2014-06-16 19:15:38 -04:00
|
|
|
bool TrySpawnWither(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ)
|
2014-03-24 06:29:19 -04:00
|
|
|
{
|
|
|
|
if (a_BlockY < 2)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-25 04:32:58 -04:00
|
|
|
|
2014-06-16 19:15:38 -04:00
|
|
|
class cCallback : public cBlockEntityCallback
|
2014-03-25 04:32:58 -04:00
|
|
|
{
|
|
|
|
bool m_IsWither;
|
|
|
|
|
2014-06-17 08:45:29 -04:00
|
|
|
virtual bool Item(cBlockEntity * a_BlockEntity)
|
2014-03-25 04:32:58 -04:00
|
|
|
{
|
2014-06-17 08:45:29 -04:00
|
|
|
if (a_BlockEntity->GetBlockType() != E_BLOCK_HEAD)
|
2014-06-16 19:15:38 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-17 08:45:29 -04:00
|
|
|
cMobHeadEntity * MobHeadEntity = static_cast<cMobHeadEntity*>(a_BlockEntity);
|
2014-03-25 04:32:58 -04:00
|
|
|
|
2014-06-16 19:15:38 -04:00
|
|
|
m_IsWither = (MobHeadEntity->GetType() == SKULL_TYPE_WITHER);
|
2014-03-25 04:32:58 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
cCallback () : m_IsWither(false) {}
|
|
|
|
|
|
|
|
bool IsWither(void) const { return m_IsWither; }
|
|
|
|
|
|
|
|
void Reset(void) { m_IsWither = false; }
|
2014-05-20 08:52:59 -04:00
|
|
|
|
2014-03-25 04:32:58 -04:00
|
|
|
} CallbackA, CallbackB;
|
2014-03-25 05:13:27 -04:00
|
|
|
|
2014-05-20 08:52:59 -04:00
|
|
|
class cPlayerCallback : public cPlayerListCallback
|
|
|
|
{
|
|
|
|
Vector3f m_Pos;
|
|
|
|
|
|
|
|
virtual bool Item(cPlayer * a_Player)
|
|
|
|
{
|
2014-05-21 03:59:14 -04:00
|
|
|
// TODO 2014-05-21 xdot: Vanilla minecraft uses an AABB check instead of a radius one
|
2014-05-20 08:52:59 -04:00
|
|
|
double Dist = (a_Player->GetPosition() - m_Pos).Length();
|
|
|
|
if (Dist < 50.0)
|
|
|
|
{
|
|
|
|
// If player is close, award achievement
|
|
|
|
a_Player->AwardAchievement(achSpawnWither);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
cPlayerCallback(const Vector3f & a_Pos) : m_Pos(a_Pos) {}
|
|
|
|
|
2014-05-25 08:46:34 -04:00
|
|
|
} PlayerCallback(Vector3f((float)a_BlockX, (float)a_BlockY, (float)a_BlockZ));
|
2014-05-20 08:52:59 -04:00
|
|
|
|
2014-06-16 19:15:38 -04:00
|
|
|
a_WorldInterface.DoWithBlockEntityAt(a_BlockX, a_BlockY, a_BlockZ, CallbackA);
|
2014-03-25 05:13:27 -04:00
|
|
|
|
|
|
|
if (!CallbackA.IsWither())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CallbackA.Reset();
|
2014-03-25 04:32:58 -04:00
|
|
|
|
|
|
|
BLOCKTYPE BlockY1 = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ);
|
|
|
|
BLOCKTYPE BlockY2 = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 2, a_BlockZ);
|
|
|
|
|
|
|
|
if ((BlockY1 != E_BLOCK_SOULSAND) || (BlockY2 != E_BLOCK_SOULSAND))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-24 06:29:19 -04:00
|
|
|
|
2014-06-16 19:15:38 -04:00
|
|
|
a_WorldInterface.DoWithBlockEntityAt(a_BlockX - 1, a_BlockY, a_BlockZ, CallbackA);
|
|
|
|
a_WorldInterface.DoWithBlockEntityAt(a_BlockX + 1, a_BlockY, a_BlockZ, CallbackB);
|
2014-03-25 04:32:58 -04:00
|
|
|
|
|
|
|
BLOCKTYPE Block1 = a_ChunkInterface.GetBlock(a_BlockX - 1, a_BlockY - 1, a_BlockZ);
|
|
|
|
BLOCKTYPE Block2 = a_ChunkInterface.GetBlock(a_BlockX + 1, a_BlockY - 1, a_BlockZ);
|
|
|
|
|
|
|
|
if ((Block1 == E_BLOCK_SOULSAND) && (Block2 == E_BLOCK_SOULSAND) && CallbackA.IsWither() && CallbackB.IsWither())
|
|
|
|
{
|
|
|
|
a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0);
|
|
|
|
a_ChunkInterface.FastSetBlock(a_BlockX + 1, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0);
|
|
|
|
a_ChunkInterface.FastSetBlock(a_BlockX - 1, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0);
|
|
|
|
a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 2, a_BlockZ, E_BLOCK_AIR, 0);
|
|
|
|
|
|
|
|
// Block entities
|
2014-06-16 19:15:38 -04:00
|
|
|
a_ChunkInterface.SetBlock(a_WorldInterface, a_BlockX + 1, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
|
|
|
|
a_ChunkInterface.SetBlock(a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
|
|
|
|
a_ChunkInterface.SetBlock(a_WorldInterface, a_BlockX - 1, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
|
2014-03-25 04:32:58 -04:00
|
|
|
|
|
|
|
// Spawn the wither:
|
2014-06-16 19:15:38 -04:00
|
|
|
a_WorldInterface.SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtWither);
|
2014-03-25 04:32:58 -04:00
|
|
|
|
2014-05-20 08:52:59 -04:00
|
|
|
// Award Achievement
|
2014-06-16 19:15:38 -04:00
|
|
|
a_WorldInterface.ForEachPlayer(PlayerCallback);
|
2014-05-20 08:52:59 -04:00
|
|
|
|
2014-03-25 04:32:58 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CallbackA.Reset();
|
|
|
|
CallbackB.Reset();
|
2014-03-24 06:29:19 -04:00
|
|
|
|
2014-06-16 19:15:38 -04:00
|
|
|
a_WorldInterface.DoWithBlockEntityAt(a_BlockX, a_BlockY, a_BlockZ - 1, CallbackA);
|
|
|
|
a_WorldInterface.DoWithBlockEntityAt(a_BlockX, a_BlockY, a_BlockZ + 1, CallbackB);
|
2014-03-25 04:32:58 -04:00
|
|
|
|
|
|
|
Block1 = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ - 1);
|
|
|
|
Block2 = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ + 1);
|
|
|
|
|
|
|
|
if ((Block1 == E_BLOCK_SOULSAND) && (Block2 == E_BLOCK_SOULSAND) && CallbackA.IsWither() && CallbackB.IsWither())
|
|
|
|
{
|
|
|
|
a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0);
|
|
|
|
a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ + 1, E_BLOCK_AIR, 0);
|
|
|
|
a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ - 1, E_BLOCK_AIR, 0);
|
|
|
|
a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 2, a_BlockZ, E_BLOCK_AIR, 0);
|
|
|
|
|
|
|
|
// Block entities
|
2014-06-16 19:15:38 -04:00
|
|
|
a_ChunkInterface.SetBlock(a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ + 1, E_BLOCK_AIR, 0);
|
|
|
|
a_ChunkInterface.SetBlock(a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
|
|
|
|
a_ChunkInterface.SetBlock(a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ - 1, E_BLOCK_AIR, 0);
|
2014-03-25 04:32:58 -04:00
|
|
|
|
|
|
|
// Spawn the wither:
|
2014-06-16 19:15:38 -04:00
|
|
|
a_WorldInterface.SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtWither);
|
2014-03-25 04:32:58 -04:00
|
|
|
|
2014-05-20 08:52:59 -04:00
|
|
|
// Award Achievement
|
2014-06-16 19:15:38 -04:00
|
|
|
a_WorldInterface.ForEachPlayer(PlayerCallback);
|
2014-05-20 08:52:59 -04:00
|
|
|
|
2014-03-25 04:32:58 -04:00
|
|
|
return true;
|
|
|
|
}
|
2014-03-24 06:29:19 -04:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-18 15:40:02 -05:00
|
|
|
|
|
|
|
virtual void OnPlacedByPlayer(
|
|
|
|
cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player,
|
|
|
|
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
|
|
|
|
int a_CursorX, int a_CursorY, int a_CursorZ,
|
|
|
|
BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta
|
|
|
|
) override
|
|
|
|
{
|
2014-06-16 19:15:38 -04:00
|
|
|
class cCallback : public cBlockEntityCallback
|
2014-02-18 15:40:02 -05:00
|
|
|
{
|
|
|
|
cPlayer * m_Player;
|
|
|
|
NIBBLETYPE m_OldBlockMeta;
|
|
|
|
NIBBLETYPE m_NewBlockMeta;
|
|
|
|
|
2014-06-17 08:45:29 -04:00
|
|
|
virtual bool Item(cBlockEntity * a_BlockEntity)
|
2014-02-18 15:40:02 -05:00
|
|
|
{
|
2014-06-17 08:45:29 -04:00
|
|
|
if (a_BlockEntity->GetBlockType() != E_BLOCK_HEAD)
|
2014-06-16 19:15:38 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-17 08:45:29 -04:00
|
|
|
cMobHeadEntity * MobHeadEntity = static_cast<cMobHeadEntity*>(a_BlockEntity);
|
2014-06-16 19:15:38 -04:00
|
|
|
|
2014-02-18 15:40:02 -05:00
|
|
|
int Rotation = 0;
|
|
|
|
if (m_NewBlockMeta == 1)
|
|
|
|
{
|
|
|
|
Rotation = (int) floor(m_Player->GetYaw() * 16.0F / 360.0F + 0.5) & 0xF;
|
|
|
|
}
|
2014-06-16 19:15:38 -04:00
|
|
|
|
|
|
|
MobHeadEntity->SetType(static_cast<eMobHeadType>(m_OldBlockMeta));
|
|
|
|
MobHeadEntity->SetRotation(static_cast<eMobHeadRotation>(Rotation));
|
|
|
|
MobHeadEntity->GetWorld()->BroadcastBlockEntity(MobHeadEntity->GetPosX(), MobHeadEntity->GetPosY(), MobHeadEntity->GetPosZ());
|
2014-02-18 15:40:02 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2014-03-30 17:13:13 -04:00
|
|
|
cCallback (cPlayer * a_CBPlayer, NIBBLETYPE a_OldBlockMeta, NIBBLETYPE a_NewBlockMeta) :
|
|
|
|
m_Player(a_CBPlayer),
|
2014-02-18 15:40:02 -05:00
|
|
|
m_OldBlockMeta(a_OldBlockMeta),
|
|
|
|
m_NewBlockMeta(a_NewBlockMeta)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
cCallback Callback(a_Player, a_BlockMeta, static_cast<NIBBLETYPE>(a_BlockFace));
|
|
|
|
|
2014-04-01 08:55:46 -04:00
|
|
|
a_BlockMeta = (NIBBLETYPE)a_BlockFace;
|
2014-06-16 19:15:38 -04:00
|
|
|
a_WorldInterface.DoWithBlockEntityAt(a_BlockX, a_BlockY, a_BlockZ, Callback);
|
2014-02-18 15:40:02 -05:00
|
|
|
a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta);
|
2014-03-24 06:29:19 -04:00
|
|
|
|
2014-03-25 05:40:54 -04:00
|
|
|
if (a_BlockMeta == SKULL_TYPE_WITHER)
|
2014-03-25 05:13:27 -04:00
|
|
|
{
|
2014-03-25 05:40:54 -04:00
|
|
|
static const Vector3i Coords[] =
|
2014-03-25 05:13:27 -04:00
|
|
|
{
|
2014-03-25 05:40:54 -04:00
|
|
|
Vector3i( 0, 0, 0),
|
|
|
|
Vector3i( 1, 0, 0),
|
|
|
|
Vector3i(-1, 0, 0),
|
|
|
|
Vector3i( 0, 0, 1),
|
|
|
|
Vector3i( 0, 0, -1),
|
|
|
|
};
|
|
|
|
for (size_t i = 0; i < ARRAYCOUNT(Coords); ++i)
|
|
|
|
{
|
2014-06-16 19:15:38 -04:00
|
|
|
if (TrySpawnWither(a_ChunkInterface, a_WorldInterface, a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z))
|
2014-03-25 05:40:54 -04:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} // for i - Coords[]
|
|
|
|
}
|
2014-02-18 15:40:02 -05:00
|
|
|
}
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|