2013-11-01 20:50:03 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BlockHandler.h"
|
2014-05-10 10:43:06 -04:00
|
|
|
#include "../Mobs/Monster.h"
|
2013-11-01 20:50:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cBlockPortalHandler :
|
|
|
|
public cBlockHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cBlockPortalHandler(BLOCKTYPE a_BlockType)
|
|
|
|
: cBlockHandler(a_BlockType)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool GetPlacementBlockTypeMeta(
|
2014-02-01 08:06:32 -05:00
|
|
|
cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
|
2014-07-17 16:50:58 -04:00
|
|
|
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
|
2013-11-01 20:50:03 -04:00
|
|
|
int a_CursorX, int a_CursorY, int a_CursorZ,
|
|
|
|
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
|
|
|
|
) override
|
|
|
|
{
|
|
|
|
// We set to zero so MCS doesn't stop you from building weird portals like vanilla does
|
|
|
|
// CanBeAt doesn't do anything if meta is zero
|
|
|
|
// We set to zero because the client sends meta = 2 to the server (it calculates rotation itself)
|
|
|
|
|
|
|
|
a_BlockType = m_BlockType;
|
|
|
|
a_BlockMeta = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
|
|
|
|
{
|
2014-08-19 16:14:37 -04:00
|
|
|
// No pickups
|
2013-11-01 20:50:03 -04:00
|
|
|
}
|
|
|
|
|
2014-05-10 10:43:06 -04:00
|
|
|
virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
|
|
|
|
{
|
2017-06-13 15:35:30 -04:00
|
|
|
if (GetRandomProvider().RandBool(0.9995))
|
2014-05-10 10:43:06 -04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-19 16:14:37 -04:00
|
|
|
int PosX = a_Chunk.GetPosX() * cChunkDef::Width + a_RelX;
|
|
|
|
int PosZ = a_Chunk.GetPosZ() * cChunkDef::Width + a_RelZ;
|
2014-05-10 10:43:06 -04:00
|
|
|
|
2015-07-16 09:06:54 -04:00
|
|
|
a_WorldInterface.SpawnMob(PosX, a_RelY, PosZ, mtZombiePigman, false);
|
2014-05-10 10:43:06 -04:00
|
|
|
}
|
2013-11-01 20:50:03 -04:00
|
|
|
|
2014-02-01 08:06:32 -05:00
|
|
|
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
|
2013-11-01 20:50:03 -04:00
|
|
|
{
|
2015-02-14 17:11:38 -05:00
|
|
|
if ((a_RelY <= 0) || (a_RelY >= cChunkDef::Height - 1))
|
2013-11-01 20:50:03 -04:00
|
|
|
{
|
2014-07-17 16:15:34 -04:00
|
|
|
return false; // In case someone places a portal with meta 1 or 2 at boundaries, and server tries to get invalid coords at Y - 1 or Y + 1
|
2013-11-01 20:50:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ))
|
|
|
|
{
|
|
|
|
case 0x1:
|
|
|
|
{
|
2015-06-30 10:50:15 -04:00
|
|
|
static const std::array<Vector3i, 4> PortalCheck
|
2013-11-01 20:50:03 -04:00
|
|
|
{
|
2015-06-30 10:50:15 -04:00
|
|
|
{
|
|
|
|
{ 0, 1, 0 },
|
|
|
|
{ 0, -1, 0 },
|
|
|
|
{ 1, 0, 0 },
|
|
|
|
{ -1, 0, 0 },
|
|
|
|
}
|
|
|
|
};
|
2013-11-01 20:50:03 -04:00
|
|
|
|
2015-06-30 10:50:15 -04:00
|
|
|
for (const auto & Direction : PortalCheck)
|
2013-11-01 20:50:03 -04:00
|
|
|
{
|
|
|
|
BLOCKTYPE Block;
|
2015-06-30 10:50:15 -04:00
|
|
|
a_Chunk.UnboundedRelGetBlockType(a_RelX + Direction.x, a_RelY + Direction.y, a_RelZ + Direction.z, Block);
|
2013-11-01 20:50:03 -04:00
|
|
|
|
|
|
|
if ((Block != E_BLOCK_NETHER_PORTAL) && (Block != E_BLOCK_OBSIDIAN))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 0x2:
|
|
|
|
{
|
2015-06-30 10:50:15 -04:00
|
|
|
static const std::array<Vector3i, 4> PortalCheck
|
2013-11-01 20:50:03 -04:00
|
|
|
{
|
2015-06-30 10:50:15 -04:00
|
|
|
{
|
|
|
|
{ 0, 1, 0 },
|
|
|
|
{ 0, -1, 0 },
|
|
|
|
{ 0, 0, -1 },
|
|
|
|
{ 0, 0, 1 },
|
|
|
|
}
|
|
|
|
};
|
2013-11-01 20:50:03 -04:00
|
|
|
|
2015-06-30 10:50:15 -04:00
|
|
|
for (const auto & Direction : PortalCheck)
|
2013-11-01 20:50:03 -04:00
|
|
|
{
|
|
|
|
BLOCKTYPE Block;
|
2015-06-30 10:50:15 -04:00
|
|
|
a_Chunk.UnboundedRelGetBlockType(a_RelX + Direction.x, a_RelY + Direction.y, a_RelZ + Direction.z, Block);
|
2013-11-01 20:50:03 -04:00
|
|
|
|
|
|
|
if ((Block != E_BLOCK_NETHER_PORTAL) && (Block != E_BLOCK_OBSIDIAN))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-06-30 10:50:15 -04:00
|
|
|
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
|
|
|
|
{
|
|
|
|
UNUSED(a_Meta);
|
|
|
|
return 24;
|
|
|
|
}
|
2013-11-01 20:50:03 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|