BlockArea: Finished rotation and mirroring with meta. Implemented example meta handling for vines, stairs and torches.
git-svn-id: http://mc-server.googlecode.com/svn/trunk@1319 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
@@ -112,6 +112,21 @@ public:
|
||||
*/
|
||||
virtual void Check(int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk);
|
||||
|
||||
/// Returns the meta for a block after rotating it counter-clockwise from the specified meta. Default: no change
|
||||
virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) { return a_Meta; }
|
||||
|
||||
/// Returns the meta for a block after rotating it clockwise from the specified meta. Default: no change
|
||||
virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) { return a_Meta; }
|
||||
|
||||
/// Returns the meta for a block after mirroring it around the XY plane. Default: no change
|
||||
virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) { return a_Meta; }
|
||||
|
||||
/// Returns the meta for a block after mirroring it around the XZ plane. Default: no change
|
||||
virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) { return a_Meta; }
|
||||
|
||||
/// Returns the meta for a block after mirroring it around the YZ plane. Default: no change
|
||||
virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) { return a_Meta; }
|
||||
|
||||
|
||||
/// Get the blockhandler for a specific block id
|
||||
static cBlockHandler * GetBlockHandler(BLOCKTYPE a_BlockType);
|
||||
|
||||
@@ -49,6 +49,77 @@ public:
|
||||
}
|
||||
|
||||
// TODO: step sound
|
||||
|
||||
|
||||
virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override
|
||||
{
|
||||
// Bits 3 and 4 stay, the rest is swapped around according to a table:
|
||||
NIBBLETYPE TopBits = (a_Meta & 0x0c);
|
||||
switch (a_Meta & 0x03)
|
||||
{
|
||||
case 0x00: return TopBits | 0x03; // East -> North
|
||||
case 0x01: return TopBits | 0x02; // West -> South
|
||||
case 0x02: return TopBits | 0x00; // South -> East
|
||||
case 0x03: return TopBits | 0x01; // North -> West
|
||||
}
|
||||
// Not reachable, but to avoid a compiler warning:
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override
|
||||
{
|
||||
// Bits 3 and 4 stay, the rest is swapped around according to a table:
|
||||
NIBBLETYPE TopBits = (a_Meta & 0x0c);
|
||||
switch (a_Meta & 0x03)
|
||||
{
|
||||
case 0x00: return TopBits | 0x02; // East -> South
|
||||
case 0x01: return TopBits | 0x03; // West -> North
|
||||
case 0x02: return TopBits | 0x01; // South -> West
|
||||
case 0x03: return TopBits | 0x00; // North -> East
|
||||
}
|
||||
// Not reachable, but to avoid a compiler warning:
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override
|
||||
{
|
||||
// Bits 3 and 4 stay, the rest is swapped around according to a table:
|
||||
NIBBLETYPE TopBits = (a_Meta & 0x0c);
|
||||
switch (a_Meta & 0x03)
|
||||
{
|
||||
case 0x00: return TopBits | 0x00; // East -> East
|
||||
case 0x01: return TopBits | 0x01; // West -> West
|
||||
case 0x02: return TopBits | 0x03; // South -> North
|
||||
case 0x03: return TopBits | 0x02; // North -> South
|
||||
}
|
||||
// Not reachable, but to avoid a compiler warning:
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) override
|
||||
{
|
||||
// Toggle bit 3:
|
||||
return (a_Meta & 0x0b) | ((~a_Meta) & 0x04);
|
||||
}
|
||||
|
||||
|
||||
virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override
|
||||
{
|
||||
// Bits 3 and 4 stay, the rest is swapped around according to a table:
|
||||
NIBBLETYPE TopBits = (a_Meta & 0x0c);
|
||||
switch (a_Meta & 0x03)
|
||||
{
|
||||
case 0x00: return TopBits | 0x01; // East -> West
|
||||
case 0x01: return TopBits | 0x00; // West -> East
|
||||
case 0x02: return TopBits | 0x02; // South -> South
|
||||
case 0x03: return TopBits | 0x03; // North -> North
|
||||
}
|
||||
// Not reachable, but to avoid a compiler warning:
|
||||
return 0;
|
||||
}
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
@@ -132,6 +132,67 @@ public:
|
||||
{
|
||||
return "step.wood";
|
||||
}
|
||||
|
||||
|
||||
virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override
|
||||
{
|
||||
// Bit 4 stays, the rest is swapped around according to a table:
|
||||
NIBBLETYPE TopBits = (a_Meta & 0x08);
|
||||
switch (a_Meta & 0x07)
|
||||
{
|
||||
case 0x01: return TopBits | 0x04; // East -> North
|
||||
case 0x02: return TopBits | 0x03; // West -> South
|
||||
case 0x03: return TopBits | 0x01; // South -> East
|
||||
case 0x04: return TopBits | 0x02; // North -> West
|
||||
default: return a_Meta; // Floor -> Floor
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override
|
||||
{
|
||||
// Bit 4 stays, the rest is swapped around according to a table:
|
||||
NIBBLETYPE TopBits = (a_Meta & 0x08);
|
||||
switch (a_Meta & 0x07)
|
||||
{
|
||||
case 0x01: return TopBits | 0x03; // East -> South
|
||||
case 0x02: return TopBits | 0x04; // West -> North
|
||||
case 0x03: return TopBits | 0x02; // South -> West
|
||||
case 0x04: return TopBits | 0x01; // North -> East
|
||||
default: return a_Meta; // Floor -> Floor
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override
|
||||
{
|
||||
// Bit 4 stays, the rest is swapped around according to a table:
|
||||
NIBBLETYPE TopBits = (a_Meta & 0x08);
|
||||
switch (a_Meta & 0x07)
|
||||
{
|
||||
case 0x03: return TopBits | 0x04; // South -> North
|
||||
case 0x04: return TopBits | 0x03; // North -> South
|
||||
default: return a_Meta; // Keep the rest
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Mirroring around the XZ plane doesn't make sense for floor torches,
|
||||
// the others stay the same, so let's keep all the metas the same.
|
||||
// The base class does tht for us, no need to override MetaMirrorXZ()
|
||||
|
||||
|
||||
virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override
|
||||
{
|
||||
// Bit 4 stays, the rest is swapped around according to a table:
|
||||
NIBBLETYPE TopBits = (a_Meta & 0x08);
|
||||
switch (a_Meta & 0x07)
|
||||
{
|
||||
case 0x01: return TopBits | 0x02; // East -> West
|
||||
case 0x02: return TopBits | 0x01; // West -> East
|
||||
default: return a_Meta; // Keep the rest
|
||||
}
|
||||
}
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
@@ -138,10 +138,36 @@ public:
|
||||
}
|
||||
|
||||
|
||||
bool DoesDropOnUnsuitable(void)
|
||||
virtual bool DoesDropOnUnsuitable(void) override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override
|
||||
{
|
||||
return ((a_Meta >> 1) | (a_Meta << 3)) & 0x0f; // Rotate bits to the right
|
||||
}
|
||||
|
||||
|
||||
virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override
|
||||
{
|
||||
return ((a_Meta << 1) | (a_Meta >> 3)) & 0x0f; // Rotate bits to the left
|
||||
}
|
||||
|
||||
|
||||
virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override
|
||||
{
|
||||
// Bits 2 and 4 stay, bits 1 and 3 swap
|
||||
return ((a_Meta & 0x0a) | ((a_Meta & 0x01) << 2) | ((a_Meta & 0x04) >> 2));
|
||||
}
|
||||
|
||||
|
||||
virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override
|
||||
{
|
||||
// Bits 1 and 3 stay, bits 2 and 4 swap
|
||||
return ((a_Meta & 0x05) | ((a_Meta & 0x02) << 2) | ((a_Meta & 0x08) >> 2));
|
||||
}
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user