1
0
Files
cuberite-2a/src/Blocks/BlockAnvil.h

70 lines
1.5 KiB
C
Raw Normal View History

2014-03-16 17:42:23 +01:00
#pragma once
#include "BlockHandler.h"
#include "../World.h"
#include "../Entities/Player.h"
class cBlockAnvilHandler :
public cBlockHandler
{
public:
cBlockAnvilHandler(BLOCKTYPE a_BlockType)
: cBlockHandler(a_BlockType)
{
}
2014-04-01 14:23:11 +02:00
2014-03-16 17:42:23 +01:00
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
2014-03-16 19:25:00 +01:00
a_Pickups.push_back(cItem(E_BLOCK_ANVIL, 1, a_BlockMeta >> 2));
2014-03-16 17:42:23 +01:00
}
2014-05-01 00:47:57 +02:00
virtual void OnUse(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) override
{
cWindow * Window = new cAnvilWindow(a_BlockX, a_BlockY, a_BlockZ);
2014-05-01 00:47:57 +02:00
a_Player->OpenWindow(Window);
}
2014-03-16 17:42:23 +01:00
2014-04-01 14:23:11 +02:00
2014-03-16 17:42:23 +01:00
virtual bool GetPlacementBlockTypeMeta(
cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
2014-07-17 22:50:58 +02:00
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
2014-03-16 17:42:23 +01:00
int a_CursorX, int a_CursorY, int a_CursorZ,
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
) override
{
a_BlockType = m_BlockType;
2014-08-29 11:20:33 +03:00
NIBBLETYPE Meta = (NIBBLETYPE)a_Player->GetEquippedItem().m_ItemDamage;
2014-04-01 14:23:11 +02:00
int Direction = (int)floor(a_Player->GetYaw() * 4.0 / 360.0 + 1.5) & 0x3;
2014-08-28 18:57:56 +02:00
2014-03-16 17:42:23 +01:00
switch (Direction)
{
2014-08-28 18:57:56 +02:00
case 0: a_BlockMeta = 0x2 | Meta << 2; break;
case 1: a_BlockMeta = 0x3 | Meta << 2; break;
case 2: a_BlockMeta = 0x0 | Meta << 2; break;
case 3: a_BlockMeta = 0x1 | Meta << 2; break;
2014-03-16 17:42:23 +01:00
default:
{
return false;
}
}
return true;
}
2014-04-01 14:23:11 +02:00
2014-03-16 17:42:23 +01:00
virtual bool IsUseable() override
{
return true;
}
} ;