1
0
Fork 0
cuberite-2a/src/Blocks/BlockPortal.h

147 lines
2.8 KiB
C
Raw Normal View History

2013-11-02 00:50:03 +00:00
#pragma once
#include "BlockHandler.h"
class cBlockPortalHandler:
2013-11-02 00:50:03 +00:00
public cBlockHandler
{
using Super = cBlockHandler;
public:
using Super::Super;
private:
2013-11-02 00:50:03 +00:00
virtual bool GetPlacementBlockTypeMeta(
cChunkInterface & a_ChunkInterface,
cPlayer & a_Player,
const Vector3i a_PlacedBlockPos,
eBlockFace a_ClickedBlockFace,
const Vector3i a_CursorPos,
2013-11-02 00:50:03 +00:00
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
) const override
2013-11-02 00:50:03 +00:00
{
// We set meta to zero so Cuberite doesn't stop a Creative-mode player from building custom portal shapes
2013-11-02 00:50:03 +00:00
// CanBeAt doesn't do anything if meta is zero
// We set to zero because the client sends meta = 1 or 2 to the server (it calculates rotation itself)
2013-11-02 00:50:03 +00:00
a_BlockType = m_BlockType;
a_BlockMeta = 0;
return true;
}
virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override
2013-11-02 00:50:03 +00:00
{
2014-08-19 20:14:37 +00:00
// No pickups
return {};
2013-11-02 00:50:03 +00:00
}
virtual void OnUpdate(
cChunkInterface & a_ChunkInterface,
cWorldInterface & a_WorldInterface,
cBlockPluginInterface & a_PluginInterface,
cChunk & a_Chunk,
const Vector3i a_RelPos
) const override
{
// Spawn zombie pigmen with a 0.05% chance:
2017-06-13 19:35:30 +00:00
if (GetRandomProvider().RandBool(0.9995))
{
return;
}
auto WorldPos = a_Chunk.RelativeToAbsolute(a_RelPos);
a_WorldInterface.SpawnMob(WorldPos.x, WorldPos.y, WorldPos.z, mtZombiePigman, false);
}
2013-11-02 00:50:03 +00:00
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, const Vector3i a_RelPos, const cChunk & a_Chunk) const override
2013-11-02 00:50:03 +00:00
{
if ((a_RelPos.y <= 0) || (a_RelPos.y >= cChunkDef::Height - 1))
2013-11-02 00:50:03 +00: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-02 00:50:03 +00:00
}
switch (a_Chunk.GetMeta(a_RelPos))
2013-11-02 00:50:03 +00:00
{
case 0x1:
{
2015-06-30 14:50:15 +00:00
static const std::array<Vector3i, 4> PortalCheck
2013-11-02 00:50:03 +00:00
{
2015-06-30 14:50:15 +00:00
{
{ 0, 1, 0 },
{ 0, -1, 0 },
{ 1, 0, 0 },
{ -1, 0, 0 },
}
};
2013-11-02 00:50:03 +00:00
2015-06-30 14:50:15 +00:00
for (const auto & Direction : PortalCheck)
2013-11-02 00:50:03 +00:00
{
BLOCKTYPE Block;
a_Chunk.UnboundedRelGetBlockType(a_RelPos + Direction, Block);
2013-11-02 00:50:03 +00:00
if ((Block != E_BLOCK_NETHER_PORTAL) && (Block != E_BLOCK_OBSIDIAN))
{
return false;
}
}
break;
}
case 0x2:
{
2015-06-30 14:50:15 +00:00
static const std::array<Vector3i, 4> PortalCheck
2013-11-02 00:50:03 +00:00
{
2015-06-30 14:50:15 +00:00
{
{ 0, 1, 0 },
{ 0, -1, 0 },
{ 0, 0, -1 },
{ 0, 0, 1 },
}
};
2013-11-02 00:50:03 +00:00
2015-06-30 14:50:15 +00:00
for (const auto & Direction : PortalCheck)
2013-11-02 00:50:03 +00:00
{
BLOCKTYPE Block;
a_Chunk.UnboundedRelGetBlockType(a_RelPos + Direction, Block);
2013-11-02 00:50:03 +00:00
if ((Block != E_BLOCK_NETHER_PORTAL) && (Block != E_BLOCK_OBSIDIAN))
{
return false;
}
}
break;
}
}
return true;
}
2016-02-05 21:45:45 +00:00
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
2015-06-30 14:50:15 +00:00
{
UNUSED(a_Meta);
return 24;
}
2013-11-02 00:50:03 +00:00
} ;