1
0

Added MetaRotate/Mirror Support for a number of classes.

This commit is contained in:
narroo 2014-03-23 22:11:01 -04:00
parent d545be9614
commit 2343b0dfbe
12 changed files with 295 additions and 84 deletions

View File

@ -11,11 +11,11 @@
class cBlockChestHandler :
public cMetaRotater<cBlockEntityHandler, 0x07, 0x04, 0x01, 0x03, 0x02, true>
public cMetaRotater<cBlockEntityHandler, 0x07, 0x02, 0x05, 0x03, 0x04>
{
public:
cBlockChestHandler(BLOCKTYPE a_BlockType)
: cMetaRotater<cBlockEntityHandler, 0x07, 0x04, 0x01, 0x03, 0x02, true>(a_BlockType)
: cMetaRotater<cBlockEntityHandler, 0x07, 0x02, 0x05, 0x03, 0x04>(a_BlockType)
{
}

View File

@ -110,3 +110,78 @@ const char * cBlockDoorHandler::GetStepSound(void)
NIBBLETYPE cBlockDoorHandler::MetaRotateCCW(NIBBLETYPE a_Meta)
{
if (a_Meta & 0x08)
{
return a_Meta;
}
else
{
return super::MetaRotateCCW(a_Meta);
}
}
NIBBLETYPE cBlockDoorHandler::MetaRotateCW(NIBBLETYPE a_Meta)
{
if (a_Meta & 0x08)
{
return a_Meta;
}
else
{
return super::MetaRotateCW(a_Meta);
}
}
NIBBLETYPE cBlockDoorHandler::MetaMirrorXY(NIBBLETYPE a_Meta)
{
// Top bit (0x08) contains door panel type (Top/Bottom panel) Only Bottom panels contain position data
// Return a_Meta if panel is a top panel (0x08 bit is set to 1)
LOG("Test MirrorXY");
if (a_Meta & 0x08) return a_Meta;
// Holds open/closed meta data. 0x0C == 1100.
NIBBLETYPE OtherMeta = a_Meta & 0x0C;
// Mirrors according to a table. 0x03 == 0011.
switch (a_Meta & 0x03)
{
case 0x03: return 0x01 + OtherMeta; // South -> North
case 0x01: return 0x03 + OtherMeta; // North -> South
}
// Not Facing North or South; No change.
return a_Meta;
}
NIBBLETYPE cBlockDoorHandler::MetaMirrorYZ(NIBBLETYPE a_Meta)
{
// Top bit (0x08) contains door panel type (Top/Bottom panel) Only Bottom panels contain position data
// Return a_Meta if panel is a top panel (0x08 bit is set to 1)
LOG("Test MirrorYZ");
if (a_Meta & 0x08) return a_Meta;
// Holds open/closed meta data. 0x0C == 1100.
NIBBLETYPE OtherMeta = a_Meta & 0x0C;
// Mirrors according to a table. 0x03 == 0011.
switch (a_Meta & 0x03)
{
case 0x00: return 0x02 + OtherMeta; // West -> East
case 0x02: return 0x00 + OtherMeta; // East -> West
}
// Not Facing North or South; No change.
return a_Meta;
}

View File

@ -21,6 +21,10 @@ public:
virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override;
virtual const char * GetStepSound(void) override;
virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override;
virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override;
virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override;
virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override;
virtual bool GetPlacementBlockTypeMeta(
cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
@ -168,62 +172,6 @@ public:
}
}
}
virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override
{
if (a_Meta & 0x08)
{
return a_Meta;
}
else
{
return super::MetaRotateCCW(a_Meta);
}
}
virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override
{
if (a_Meta & 0x08)
{
return a_Meta;
}
else
{
return super::MetaRotateCW(a_Meta);
}
}
virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override
{
if (a_Meta & 0x08)
{
return a_Meta;
}
else
{
return super::MetaMirrorXY(a_Meta);
}
}
virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override
{
if (a_Meta & 0x08)
{
return a_Meta;
}
else
{
return super::MetaMirrorYZ(a_Meta);
}
}
} ;

View File

@ -4,17 +4,17 @@
#include "BlockEntity.h"
#include "../World.h"
#include "../Piston.h"
#include "MetaRotater.h"
class cBlockFurnaceHandler :
public cBlockEntityHandler
public cMetaRotater<cBlockEntityHandler, 0x07, 0x02, 0x05, 0x03, 0x04>
{
public:
cBlockFurnaceHandler(BLOCKTYPE a_BlockType) :
cBlockEntityHandler(a_BlockType)
cBlockFurnaceHandler(BLOCKTYPE a_BlockType)
: cMetaRotater<cBlockEntityHandler, 0x07, 0x02, 0x05, 0x03, 0x04>(a_BlockType)
{
}

View File

@ -3,16 +3,16 @@
// Declares the cBlockHopperHandler class representing the handler for the Hopper block
#include "MetaRotator.h"
class cBlockHopperHandler :
public cBlockEntityHandler
public cMetaRotater<cBlockEntityHandler, 0x07, 0x02, 0x05, 0x03, 0x04>
{
public:
cBlockHopperHandler(BLOCKTYPE a_BlockType)
: cBlockEntityHandler(a_BlockType)
: cMetaRotater<cBlockEntityHandler, 0x07, 0x02, 0x05, 0x03, 0x04>(a_BlockType)
{
}
@ -39,6 +39,21 @@ public:
}
return true;
}
virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) override
{
// Bit 0x08 is a flag. Lowest three bits are position. 0x08 == 1000
NIBBLETYPE OtherMeta = a_Meta & 0x08;
// Mirrors defined by by a table. (Source, mincraft.gamepedia.com) 0x07 == 0111
switch (a_Meta & 0x07)
{
case 0x00: return 0x01 + OtherMeta; // Down -> Up
case 0x01: return 0x00 + OtherMeta; // Up -> Down
}
// Not Facing Up or Down; No change.
return a_Meta;
}
} ;

View File

@ -9,11 +9,11 @@
class cBlockLadderHandler :
public cBlockHandler
public cMetaRotater<cBlockHandler, 0x07, 0x02, 0x05, 0x03, 0x04>
{
public:
cBlockLadderHandler(BLOCKTYPE a_BlockType)
: cBlockHandler(a_BlockType)
: cMetaRotater<cBlockHandler, 0x07, 0x02, 0x05, 0x03, 0x04>(a_BlockType)
{
}

View File

@ -1,17 +1,18 @@
#pragma once
#include "BlockHandler.h"
#include "MetaRotator.h"
class cBlockLeverHandler :
public cBlockHandler
public cMetaRotator<cBlockHandler, 0x07, 0x04, 0x02, 0x03, 0x01, false>
{
typedef cMetaRotator<cBlockHandler, 0x07, 0x04, 0x02, 0x03, 0x01, false> super;
public:
cBlockLeverHandler(BLOCKTYPE a_BlockType)
: cBlockHandler(a_BlockType)
: cMetaRotator<cBlockHandler, 0x07, 0x04, 0x02, 0x03, 0x01, false>(a_BlockType)
{
}
@ -104,6 +105,36 @@ public:
return (a_RelY > 0) && cBlockInfo::IsSolid(BlockIsOn);
}
virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override
{
switch (a_Meta)
{
case 0x00: return 0x07; // Ceiling rotation
case 0x07: return 0x00;
case 0x05: return 0x06; // Ground rotation
case 0x06: return 0x05;
default: return super::MetaRotateCCW(a_Meta); // Wall Rotation
}
}
virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override
{
switch (a_Meta)
{
case 0x00: return 0x07; // Ceiling rotation
case 0x07: return 0x00;
case 0x05: return 0x06; // Ground rotation
case 0x06: return 0x05;
default: return super::MetaRotateCCW(a_Meta); // Wall Rotation
}
}
} ;

View File

@ -1,16 +1,16 @@
#pragma once
#include "BlockHandler.h"
#include "MetaRotator.h"
class cBlockPumpkinHandler :
public cBlockHandler
public cMetaRotator<cBlockHandler, 0x07, 0x02, 0x03, 0x00, 0x01, false>
{
public:
cBlockPumpkinHandler(BLOCKTYPE a_BlockType)
: cBlockHandler(a_BlockType)
: cMetaRotator<cBlockHandler, 0x07, 0x02, 0x03, 0x00, 0x01, false>(a_BlockType)
{
}

View File

@ -434,6 +434,141 @@ public:
}
return true;
}
virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override
{
// Bit 0x08 is a flag when a_Meta is in the range 0x00--0x05 and 0x0A--0x0F.
// Bit 0x08 specifies direction when a_Meta is in the range 0x06-0x09.
if ((a_Meta < 0x06) || (a_Meta > 0x09))
{
// Save powered rail flag.
NIBBLETYPE OtherMeta = a_Meta & 0x08;
// Rotates according to table; 0x07 == 0111.
// Rails can either be flat (North/South) or Ascending (Asc. East)
switch (a_Meta & 0x07)
{
case 0x00: return 0x01 + OtherMeta; // North/South -> East/West
case 0x01: return 0x00 + OtherMeta; // East/West -> North/South
case 0x02: return 0x04 + OtherMeta; // Asc. East -> Asc. North
case 0x04: return 0x03 + OtherMeta; // Asc. North -> Asc. West
case 0x03: return 0x05 + OtherMeta; // Asc. West -> Asc. South
case 0x05: return 0x02 + OtherMeta; // Asc. South -> Asc. East
}
}
else
{
switch (a_Meta)
{
// Corner Directions
case 0x06: return 0x09; // Northwest Cnr. -> Southwest Cnr.
case 0x07: return 0x06; // Northeast Cnr. -> Northwest Cnr.
case 0x08: return 0x07; // Southeast Cnr. -> Northeast Cnr.
case 0x09: return 0x08; // Southwest Cnr. -> Southeast Cnr.
}
}
// To avoid a compiler warning;
return a_Meta;
}
virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override
{
// Bit 0x08 is a flag for value in the range 0x00--0x05 and specifies direction for values withint 0x006--0x09.
if ((a_Meta < 0x06) || (a_Meta > 0x09))
{
// Save powered rail flag.
NIBBLETYPE OtherMeta = a_Meta & 0x08;
// Rotates according to table; 0x07 == 0111.
// Rails can either be flat (North/South) or Ascending (Asc. East)
switch (a_Meta & 0x07)
{
case 0x00: return 0x01 + OtherMeta; // North/South -> East/West
case 0x01: return 0x00 + OtherMeta; // East/West -> North/South
case 0x02: return 0x05 + OtherMeta; // Asc. East -> Asc. South
case 0x05: return 0x03 + OtherMeta; // Asc. South -> Asc. West
case 0x03: return 0x04 + OtherMeta; // Asc. West -> Asc. North
case 0x04: return 0x02 + OtherMeta; // Asc. North -> Asc. East
}
}
else
{
switch (a_Meta)
{
// Corner Directions
case 0x06: return 0x07; // Northwest Cnr. -> Northeast Cnr.
case 0x07: return 0x08; // Northeast Cnr. -> Southeast Cnr.
case 0x08: return 0x09; // Southeast Cnr. -> Southwest Cnr.
case 0x09: return 0x06; // Southwest Cnr. -> Northwest Cnr.
}
}
// To avoid a compiler warning;
return a_Meta;
}
virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override
{
// Bit 0x08 is a flag for value in the range 0x00--0x05 and specifies direction for values withint 0x006--0x09.
if ((a_Meta < 0x06) || (a_Meta > 0x09))
{
// Save powered rail flag.
NIBBLETYPE OtherMeta = a_Meta & 0x08;
// Mirrors according to table; 0x07 == 0111.
// Rails can either be flat (North/South) or Ascending (Asc. East)
switch (a_Meta & 0x07)
{
case 0x05: return 0x04 + OtherMeta; // Asc. South -> Asc. North
case 0x04: return 0x05 + OtherMeta; // Asc. North -> Asc. South
}
}
else
{
switch (a_Meta)
{
// Corner Directions
case 0x06: return 0x09; // Northwest Cnr. -> Southwest Cnr.
case 0x07: return 0x08; // Northeast Cnr. -> Southeast Cnr.
case 0x08: return 0x07; // Southeast Cnr. -> Northeast Cnr.
case 0x09: return 0x06; // Southwest Cnr. -> Northwest Cnr.
}
}
// To avoid a compiler warning;
return a_Meta;
}
virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override
{
// Bit 0x08 is a flag for value in the range 0x00--0x05 and specifies direction for values withint 0x006--0x09.
if ((a_Meta < 0x06) || (a_Meta > 0x09))
{
// Save powered rail flag.
NIBBLETYPE OtherMeta = a_Meta & 0x08;
// Mirrors according to table; 0x07 == 0111.
// Rails can either be flat (North/South) or Ascending (Asc. East)
switch (a_Meta & 0x07)
{
case 0x02: return 0x03 + OtherMeta; // Asc. East -> Asc. West
case 0x03: return 0x02 + OtherMeta; // Asc. West -> Asc. East
}
}
else
{
switch (a_Meta)
{
// Corner Directions
case 0x06: return 0x07; // Northwest Cnr. -> Northeast Cnr.
case 0x07: return 0x06; // Northeast Cnr. -> Northwest Cnr.
case 0x08: return 0x09; // Southeast Cnr. -> Southwest Cnr.
case 0x09: return 0x08; // Southwest Cnr. -> Southeast Cnr.
}
}
// To avoid a compiler warning;
return a_Meta;
}
} ;

View File

@ -3,17 +3,17 @@
#include "BlockHandler.h"
#include "Chunk.h"
#include "MetaRotator.h"
class cBlockRedstoneRepeaterHandler :
public cBlockHandler
public cMetaRotator<cBlockHandler, 0x03, 0x00, 0x01, 0x02, 0x03, true>
{
public:
cBlockRedstoneRepeaterHandler(BLOCKTYPE a_BlockType)
: cBlockHandler(a_BlockType)
: cMetaRotator<cBlockHandler, 0x03, 0x00, 0x01, 0x02, 0x03, true>(a_BlockType)
{
}

View File

@ -14,8 +14,6 @@
class cBlockSlabHandler :
public cBlockHandler
{
@ -184,6 +182,15 @@ public:
ASSERT(!"Unhandled double slab type!");
return "";
}
virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) override
{
NIBBLETYPE OtherMeta = a_Meta & 0x07; // Contains unrelate meta data.
// 8th bit is up/down. 1 right-side-up, 0 is up-side-down.
return (a_Meta & 0x08) ? 0x00 + OtherMeta : 0x01 + OtherMeta;
}
} ;

View File

@ -2,17 +2,17 @@
#pragma once
#include "BlockHandler.h"
#include "MetaRotator.h"
class cBlockTrapdoorHandler :
public cBlockHandler
public cMetaRotator<cBlockHandler, 0x03, 0x01, 0x02, 0x00, 0x03, false>
{
public:
cBlockTrapdoorHandler(BLOCKTYPE a_BlockType)
: cBlockHandler(a_BlockType)
: cMetaRotator<cBlockHandler, 0x03, 0x01, 0x02, 0x00, 0x03, false>(a_BlockType)
{
}