2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BlockHandler.h"
|
2019-10-16 04:06:34 -04:00
|
|
|
#include "Mixins.h"
|
|
|
|
#include "../Item.h"
|
|
|
|
|
2015-11-02 16:12:58 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
|
2019-10-16 04:06:34 -04:00
|
|
|
|
|
|
|
// fwd:
|
2014-09-17 13:40:10 -04:00
|
|
|
class cWorld;
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
2019-10-16 04:06:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-05 06:27:14 -04:00
|
|
|
class cBlockPistonHandler final :
|
2020-04-10 19:20:51 -04:00
|
|
|
public cClearMetaOnDrop<cPitchYawRotator<cBlockHandler, 0x07, 0x03, 0x04, 0x02, 0x05, 0x01, 0x00>>
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2020-04-13 12:38:06 -04:00
|
|
|
using Super = cClearMetaOnDrop<cPitchYawRotator<cBlockHandler, 0x07, 0x03, 0x04, 0x02, 0x05, 0x01, 0x00>>;
|
2019-10-16 04:06:34 -04:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
public:
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
using Super::Super;
|
2015-03-20 06:14:42 -04:00
|
|
|
|
2014-05-25 08:46:34 -04:00
|
|
|
static eBlockFace MetaDataToDirection(NIBBLETYPE a_MetaData)
|
|
|
|
{
|
2015-06-26 18:24:51 -04:00
|
|
|
switch (a_MetaData & 0x7) // We only want the bottom three bits (4th controls extended-ness))
|
2014-05-25 08:46:34 -04: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 16:50:58 -04:00
|
|
|
}
|
2014-05-25 08:46:34 -04:00
|
|
|
|
2015-11-06 11:11:54 -05: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 08:50:43 -05:00
|
|
|
|
2017-07-14 22:09:55 -04:00
|
|
|
static void ExtendPiston(Vector3i a_BlockPos, cWorld & a_World);
|
|
|
|
static void RetractPiston(Vector3i a_BlockPos, cWorld & a_World);
|
2014-05-25 08:46:34 -04:00
|
|
|
|
2016-07-31 16:54:35 -04: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 08:46:34 -04:00
|
|
|
private:
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-11-06 11:11:54 -05:00
|
|
|
typedef std::unordered_set<Vector3i, VectorHasher<int>> Vector3iSet;
|
2014-05-25 08:46:34 -04:00
|
|
|
|
2018-07-23 19:35:20 -04:00
|
|
|
/** Piston extension block action */
|
|
|
|
static const Byte PistonExtendAction = 0U;
|
|
|
|
|
|
|
|
/** Piston retraction block action */
|
|
|
|
static const Byte PistonRetractAction = 1U;
|
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Returns true if the piston (specified by blocktype) is a sticky piston */
|
2014-05-25 08:46:34 -04:00
|
|
|
static inline bool IsSticky(BLOCKTYPE a_BlockType) { return (a_BlockType == E_BLOCK_STICKY_PISTON); }
|
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Returns true if the specified block can be pushed by a piston (and left intact) */
|
2014-05-25 08:46:34 -04:00
|
|
|
static inline bool CanPush(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
|
|
|
|
{
|
|
|
|
switch (a_BlockType)
|
|
|
|
{
|
|
|
|
case E_BLOCK_ANVIL:
|
2014-09-11 10:07:54 -04:00
|
|
|
case E_BLOCK_BARRIER:
|
2014-07-30 15:59:35 -04:00
|
|
|
case E_BLOCK_BEACON:
|
2014-05-25 08:46:34 -04:00
|
|
|
case E_BLOCK_BEDROCK:
|
|
|
|
case E_BLOCK_BREWING_STAND:
|
2017-02-14 05:13:55 -05:00
|
|
|
case E_BLOCK_CHAIN_COMMAND_BLOCK:
|
2014-05-25 08:46:34 -04:00
|
|
|
case E_BLOCK_CHEST:
|
|
|
|
case E_BLOCK_COMMAND_BLOCK:
|
2014-10-01 12:08:31 -04:00
|
|
|
case E_BLOCK_DAYLIGHT_SENSOR:
|
2014-05-25 08:46:34 -04:00
|
|
|
case E_BLOCK_DISPENSER:
|
|
|
|
case E_BLOCK_DROPPER:
|
|
|
|
case E_BLOCK_ENCHANTMENT_TABLE:
|
2017-02-14 05:13:55 -05:00
|
|
|
case E_BLOCK_END_GATEWAY:
|
2014-05-25 08:46:34 -04:00
|
|
|
case E_BLOCK_END_PORTAL:
|
|
|
|
case E_BLOCK_END_PORTAL_FRAME:
|
2020-03-21 20:18:49 -04:00
|
|
|
case E_BLOCK_ENDER_CHEST:
|
2014-05-25 08:46:34 -04:00
|
|
|
case E_BLOCK_FURNACE:
|
|
|
|
case E_BLOCK_LIT_FURNACE:
|
2014-10-01 12:08:31 -04:00
|
|
|
case E_BLOCK_INVERTED_DAYLIGHT_SENSOR:
|
2014-05-25 08:46:34 -04: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 05:13:55 -05:00
|
|
|
case E_BLOCK_REPEATING_COMMAND_BLOCK:
|
2014-10-01 11:57:53 -04:00
|
|
|
case E_BLOCK_STANDING_BANNER:
|
2017-02-14 05:13:55 -05:00
|
|
|
case E_BLOCK_STRUCTURE_BLOCK:
|
2014-07-06 18:50:22 -04:00
|
|
|
case E_BLOCK_TRAPPED_CHEST:
|
2014-10-01 11:57:53 -04:00
|
|
|
case E_BLOCK_WALL_BANNER:
|
2014-05-25 08:46:34 -04: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 16:12:58 -05:00
|
|
|
/** Tries to push a block and increases the pushed blocks variable. Returns true if the block is pushable */
|
|
|
|
static bool CanPushBlock(
|
2017-07-14 22:09:55 -04:00
|
|
|
const Vector3i & a_BlockPos, cWorld & a_World, bool a_RequirePushable,
|
2015-11-06 11:11:54 -05:00
|
|
|
Vector3iSet & a_BlocksPushed, const Vector3i & a_PushDir
|
2015-11-02 16:12:58 -05:00
|
|
|
);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
|
|
|
|
{
|
|
|
|
UNUSED(a_Meta);
|
|
|
|
return 11;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnBroken(
|
|
|
|
cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
|
|
|
|
Vector3i a_BlockPos,
|
2020-10-08 15:13:44 -04:00
|
|
|
BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta,
|
|
|
|
const cEntity * a_Digger
|
2020-09-20 09:50:52 -04:00
|
|
|
) const override;
|
|
|
|
|
2015-11-05 14:13:58 -05:00
|
|
|
/** Moves a list of blocks in a specific direction */
|
2015-11-06 11:11:54 -05:00
|
|
|
static void PushBlocks(const Vector3iSet & a_BlocksToPush,
|
2017-07-14 22:09:55 -04:00
|
|
|
cWorld & a_World, const Vector3i & a_PushDir
|
2015-11-05 12:49:15 -05:00
|
|
|
);
|
2013-07-29 07:13:03 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-09 10:20:12 -04:00
|
|
|
|
2020-10-05 06:27:14 -04:00
|
|
|
class cBlockPistonHeadHandler final :
|
2013-08-09 10:20:12 -04:00
|
|
|
public cBlockHandler
|
|
|
|
{
|
2020-04-13 12:38:06 -04:00
|
|
|
using Super = cBlockHandler;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-08-09 10:20:12 -04:00
|
|
|
public:
|
2020-09-20 09:50:52 -04:00
|
|
|
|
|
|
|
constexpr cBlockPistonHeadHandler(void) :
|
|
|
|
Super(E_BLOCK_PISTON_EXTENSION)
|
|
|
|
{
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2019-10-16 04:06:34 -04:00
|
|
|
virtual void OnBroken(
|
|
|
|
cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
|
|
|
|
Vector3i a_BlockPos,
|
2020-10-08 15:13:44 -04:00
|
|
|
BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta,
|
|
|
|
const cEntity * a_Digger
|
2020-09-20 09:50:52 -04:00
|
|
|
) const override;
|
2013-12-07 13:03:56 -05:00
|
|
|
|
2021-03-28 09:41:34 -04:00
|
|
|
virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cItem * a_Tool) const override;
|
2013-08-09 10:20:12 -04:00
|
|
|
} ;
|