2013-07-29 11:13:03 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BlockHandler.h"
|
2019-10-16 08:06:34 +00:00
|
|
|
#include "Mixins.h"
|
|
|
|
#include "../Item.h"
|
|
|
|
|
2015-11-02 21:12:58 +00:00
|
|
|
|
2013-07-29 11:13:03 +00:00
|
|
|
|
2019-10-16 08:06:34 +00:00
|
|
|
|
|
|
|
// fwd:
|
2014-09-17 17:40:10 +00:00
|
|
|
class cWorld;
|
2013-07-29 11:13:03 +00:00
|
|
|
|
|
|
|
|
2019-10-16 08:06:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cBlockPistonHandler:
|
2020-04-10 23:20:51 +00:00
|
|
|
public cClearMetaOnDrop<cPitchYawRotator<cBlockHandler, 0x07, 0x03, 0x04, 0x02, 0x05, 0x01, 0x00>>
|
2013-07-29 11:13:03 +00:00
|
|
|
{
|
2020-04-13 16:38:06 +00:00
|
|
|
using Super = cClearMetaOnDrop<cPitchYawRotator<cBlockHandler, 0x07, 0x03, 0x04, 0x02, 0x05, 0x01, 0x00>>;
|
2019-10-16 08:06:34 +00:00
|
|
|
|
2013-07-29 11:13:03 +00:00
|
|
|
public:
|
2016-02-05 21:45:45 +00:00
|
|
|
|
2019-10-16 08:06:34 +00:00
|
|
|
cBlockPistonHandler(BLOCKTYPE a_BlockType);
|
2013-07-29 11:13:03 +00:00
|
|
|
|
2019-10-16 08:06:34 +00:00
|
|
|
virtual void OnBroken(
|
|
|
|
cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
|
|
|
|
Vector3i a_BlockPos,
|
|
|
|
BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta
|
|
|
|
) override;
|
2015-03-20 10:14:42 +00:00
|
|
|
|
2014-05-25 12:46:34 +00:00
|
|
|
static eBlockFace MetaDataToDirection(NIBBLETYPE a_MetaData)
|
|
|
|
{
|
2015-06-26 22:24:51 +00:00
|
|
|
switch (a_MetaData & 0x7) // We only want the bottom three bits (4th controls extended-ness))
|
2014-05-25 12:46:34 +00:00
|
|
|
{
|
|
|
|
case 0x0: return BLOCK_FACE_YM;
|
|
|
|
case 0x1: return BLOCK_FACE_YP;
|
|
|
|
case 0x2: return BLOCK_FACE_ZM;
|
|
|
|
case 0x3: return BLOCK_FACE_ZP;
|
|
|
|
case 0x4: return BLOCK_FACE_XM;
|
|
|
|
case 0x5: return BLOCK_FACE_XP;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
ASSERT(!"Invalid Metadata");
|
|
|
|
return BLOCK_FACE_NONE;
|
|
|
|
}
|
|
|
|
}
|
2014-07-17 20:50:58 +00:00
|
|
|
}
|
2014-05-25 12:46:34 +00:00
|
|
|
|
2015-11-06 16:11:54 +00:00
|
|
|
/** Converts piston block's metadata into a unit vector representing the direction in which the piston will extend. */
|
|
|
|
static Vector3i MetadataToOffset(NIBBLETYPE a_PistonMeta);
|
2015-11-05 13:50:43 +00:00
|
|
|
|
2017-07-15 02:09:55 +00:00
|
|
|
static void ExtendPiston(Vector3i a_BlockPos, cWorld & a_World);
|
|
|
|
static void RetractPiston(Vector3i a_BlockPos, cWorld & a_World);
|
2014-05-25 12:46:34 +00:00
|
|
|
|
2015-06-30 14:50:15 +00:00
|
|
|
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
|
|
|
|
{
|
|
|
|
UNUSED(a_Meta);
|
|
|
|
return 11;
|
|
|
|
}
|
|
|
|
|
2016-07-31 20:54:35 +00:00
|
|
|
/** Returns true if the piston (with the specified meta) is extended */
|
|
|
|
static inline bool IsExtended(NIBBLETYPE a_PistonMeta) { return ((a_PistonMeta & 0x8) != 0x0); }
|
|
|
|
|
2014-05-25 12:46:34 +00:00
|
|
|
private:
|
2016-02-05 21:45:45 +00:00
|
|
|
|
2015-11-06 16:11:54 +00:00
|
|
|
typedef std::unordered_set<Vector3i, VectorHasher<int>> Vector3iSet;
|
2014-05-25 12:46:34 +00:00
|
|
|
|
2018-07-23 23:35:20 +00:00
|
|
|
/** Piston extension block action */
|
|
|
|
static const Byte PistonExtendAction = 0U;
|
|
|
|
|
|
|
|
/** Piston retraction block action */
|
|
|
|
static const Byte PistonRetractAction = 1U;
|
|
|
|
|
2015-07-31 14:49:10 +00:00
|
|
|
/** Returns true if the piston (specified by blocktype) is a sticky piston */
|
2014-05-25 12:46:34 +00:00
|
|
|
static inline bool IsSticky(BLOCKTYPE a_BlockType) { return (a_BlockType == E_BLOCK_STICKY_PISTON); }
|
|
|
|
|
2015-07-31 14:49:10 +00:00
|
|
|
/** Returns true if the specified block can be pushed by a piston (and left intact) */
|
2014-05-25 12:46:34 +00:00
|
|
|
static inline bool CanPush(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
|
|
|
|
{
|
|
|
|
switch (a_BlockType)
|
|
|
|
{
|
|
|
|
case E_BLOCK_ANVIL:
|
2014-09-11 14:07:54 +00:00
|
|
|
case E_BLOCK_BARRIER:
|
2014-07-30 19:59:35 +00:00
|
|
|
case E_BLOCK_BEACON:
|
2014-05-25 12:46:34 +00:00
|
|
|
case E_BLOCK_BEDROCK:
|
|
|
|
case E_BLOCK_BREWING_STAND:
|
2017-02-14 10:13:55 +00:00
|
|
|
case E_BLOCK_CHAIN_COMMAND_BLOCK:
|
2014-05-25 12:46:34 +00:00
|
|
|
case E_BLOCK_CHEST:
|
|
|
|
case E_BLOCK_COMMAND_BLOCK:
|
2014-10-01 16:08:31 +00:00
|
|
|
case E_BLOCK_DAYLIGHT_SENSOR:
|
2014-05-25 12:46:34 +00:00
|
|
|
case E_BLOCK_DISPENSER:
|
|
|
|
case E_BLOCK_DROPPER:
|
|
|
|
case E_BLOCK_ENCHANTMENT_TABLE:
|
2017-02-14 10:13:55 +00:00
|
|
|
case E_BLOCK_END_GATEWAY:
|
2014-05-25 12:46:34 +00:00
|
|
|
case E_BLOCK_END_PORTAL:
|
|
|
|
case E_BLOCK_END_PORTAL_FRAME:
|
2020-03-22 00:18:49 +00:00
|
|
|
case E_BLOCK_ENDER_CHEST:
|
2014-05-25 12:46:34 +00:00
|
|
|
case E_BLOCK_FURNACE:
|
|
|
|
case E_BLOCK_LIT_FURNACE:
|
2014-10-01 16:08:31 +00:00
|
|
|
case E_BLOCK_INVERTED_DAYLIGHT_SENSOR:
|
2014-05-25 12:46:34 +00:00
|
|
|
case E_BLOCK_HOPPER:
|
|
|
|
case E_BLOCK_JUKEBOX:
|
|
|
|
case E_BLOCK_MOB_SPAWNER:
|
|
|
|
case E_BLOCK_NETHER_PORTAL:
|
|
|
|
case E_BLOCK_NOTE_BLOCK:
|
|
|
|
case E_BLOCK_OBSIDIAN:
|
|
|
|
case E_BLOCK_PISTON_EXTENSION:
|
2017-02-14 10:13:55 +00:00
|
|
|
case E_BLOCK_REPEATING_COMMAND_BLOCK:
|
2014-10-01 15:57:53 +00:00
|
|
|
case E_BLOCK_STANDING_BANNER:
|
2017-02-14 10:13:55 +00:00
|
|
|
case E_BLOCK_STRUCTURE_BLOCK:
|
2014-07-06 22:50:22 +00:00
|
|
|
case E_BLOCK_TRAPPED_CHEST:
|
2014-10-01 15:57:53 +00:00
|
|
|
case E_BLOCK_WALL_BANNER:
|
2014-05-25 12:46:34 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
case E_BLOCK_STICKY_PISTON:
|
|
|
|
case E_BLOCK_PISTON:
|
|
|
|
{
|
|
|
|
// A piston can only be pushed if retracted:
|
|
|
|
return !IsExtended(a_BlockMeta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-11-02 21:12:58 +00:00
|
|
|
/** Tries to push a block and increases the pushed blocks variable. Returns true if the block is pushable */
|
|
|
|
static bool CanPushBlock(
|
2017-07-15 02:09:55 +00:00
|
|
|
const Vector3i & a_BlockPos, cWorld & a_World, bool a_RequirePushable,
|
2015-11-06 16:11:54 +00:00
|
|
|
Vector3iSet & a_BlocksPushed, const Vector3i & a_PushDir
|
2015-11-02 21:12:58 +00:00
|
|
|
);
|
2016-02-05 21:45:45 +00:00
|
|
|
|
2015-11-05 19:13:58 +00:00
|
|
|
/** Moves a list of blocks in a specific direction */
|
2015-11-06 16:11:54 +00:00
|
|
|
static void PushBlocks(const Vector3iSet & a_BlocksToPush,
|
2017-07-15 02:09:55 +00:00
|
|
|
cWorld & a_World, const Vector3i & a_PushDir
|
2015-11-05 17:49:15 +00:00
|
|
|
);
|
2013-07-29 11:13:03 +00:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-09 14:20:12 +00:00
|
|
|
|
2019-10-16 08:06:34 +00:00
|
|
|
class cBlockPistonHeadHandler:
|
2013-08-09 14:20:12 +00:00
|
|
|
public cBlockHandler
|
|
|
|
{
|
2020-04-13 16:38:06 +00:00
|
|
|
using Super = cBlockHandler;
|
2016-02-05 21:45:45 +00:00
|
|
|
|
2013-08-09 14:20:12 +00:00
|
|
|
public:
|
|
|
|
cBlockPistonHeadHandler(void);
|
2016-02-05 21:45:45 +00:00
|
|
|
|
2019-10-16 08:06:34 +00:00
|
|
|
virtual void OnBroken(
|
|
|
|
cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
|
|
|
|
Vector3i a_BlockPos,
|
|
|
|
BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta
|
|
|
|
) override;
|
2013-12-07 18:03:56 +00:00
|
|
|
|
2020-08-01 10:25:06 +00:00
|
|
|
virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) override;
|
2013-08-09 14:20:12 +00:00
|
|
|
} ;
|