2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
#include "Globals.h"
|
|
|
|
#include "BlockPiston.h"
|
|
|
|
#include "../Item.h"
|
|
|
|
#include "../World.h"
|
2013-08-19 05:39:13 -04:00
|
|
|
#include "../Entities/Player.h"
|
2013-07-29 07:13:03 -04:00
|
|
|
#include "../Piston.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define AddPistonDir(x, y, z, dir, amount) \
|
|
|
|
switch (dir) \
|
|
|
|
{ \
|
|
|
|
case 0: (y) -= (amount); break; \
|
|
|
|
case 1: (y) += (amount); break; \
|
|
|
|
case 2: (z) -= (amount); break; \
|
|
|
|
case 3: (z) += (amount); break; \
|
|
|
|
case 4: (x) -= (amount); break; \
|
|
|
|
case 5: (x) += (amount); break; \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cBlockPistonHandler::cBlockPistonHandler(BLOCKTYPE a_BlockType)
|
|
|
|
: cBlockHandler(a_BlockType)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-01 08:06:32 -05:00
|
|
|
void cBlockPistonHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-02-01 08:06:32 -05:00
|
|
|
NIBBLETYPE OldMeta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
int newX = a_BlockX;
|
|
|
|
int newY = a_BlockY;
|
|
|
|
int newZ = a_BlockZ;
|
|
|
|
AddPistonDir(newX, newY, newZ, OldMeta & ~(8), 1);
|
|
|
|
|
2014-02-01 08:06:32 -05:00
|
|
|
if (a_ChunkInterface.GetBlock(newX, newY, newZ) == E_BLOCK_PISTON_EXTENSION)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-02-01 08:06:32 -05:00
|
|
|
a_ChunkInterface.SetBlock(a_WorldInterface, newX, newY, newZ, E_BLOCK_AIR, 0);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cBlockPistonHandler::GetPlacementBlockTypeMeta(
|
2014-02-01 08:06:32 -05:00
|
|
|
cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
|
2014-02-04 13:59:05 -05:00
|
|
|
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
|
2013-07-29 07:13:03 -04:00
|
|
|
int a_CursorX, int a_CursorY, int a_CursorZ,
|
|
|
|
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
|
|
|
|
)
|
|
|
|
{
|
|
|
|
a_BlockType = m_BlockType;
|
2014-01-17 05:11:17 -05:00
|
|
|
a_BlockMeta = cPiston::RotationPitchToMetaData(a_Player->GetYaw(), a_Player->GetPitch());
|
2013-07-29 07:13:03 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-09 10:20:12 -04:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// cBlockPistonHeadHandler:
|
|
|
|
|
|
|
|
cBlockPistonHeadHandler::cBlockPistonHeadHandler(void) :
|
|
|
|
super(E_BLOCK_PISTON_EXTENSION)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-01 09:01:13 -05:00
|
|
|
void cBlockPistonHeadHandler::OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ)
|
2013-08-09 10:20:12 -04:00
|
|
|
{
|
2014-02-01 09:01:13 -05:00
|
|
|
NIBBLETYPE OldMeta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
|
2013-08-09 10:20:12 -04:00
|
|
|
|
|
|
|
int newX = a_BlockX;
|
|
|
|
int newY = a_BlockY;
|
|
|
|
int newZ = a_BlockZ;
|
|
|
|
AddPistonDir(newX, newY, newZ, OldMeta & ~(8), -1);
|
|
|
|
|
2014-02-01 09:01:13 -05:00
|
|
|
BLOCKTYPE Block = a_ChunkInterface.GetBlock(newX, newY, newZ);
|
2013-08-09 10:20:12 -04:00
|
|
|
if ((Block == E_BLOCK_STICKY_PISTON) || (Block == E_BLOCK_PISTON))
|
|
|
|
{
|
2014-02-01 09:01:13 -05:00
|
|
|
a_ChunkInterface.DigBlock(a_WorldInterface, newX, newY, newZ);
|
2013-11-23 07:10:33 -05:00
|
|
|
if (a_Player->IsGameModeCreative())
|
|
|
|
{
|
|
|
|
return; // No pickups if creative
|
|
|
|
}
|
2013-11-22 16:57:06 -05:00
|
|
|
|
|
|
|
cItems Pickups;
|
|
|
|
Pickups.push_back(cItem(Block, 1));
|
2014-02-01 09:01:13 -05:00
|
|
|
a_WorldInterface.SpawnItemPickups(Pickups, a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5);
|
2013-08-09 10:20:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|