1
0

Added some Metadate rotaters using templated Mixin

This commit is contained in:
Tycho 2014-02-27 11:33:35 -08:00
parent 9c6d72a023
commit 84913299f4
10 changed files with 168 additions and 16 deletions

View File

@ -4,6 +4,7 @@
#include "BlockHandler.h"
#include "ChunkInterface.h"
#include "WorldInterface.h"
#include "MetaRotater.h"
#include "../Entities/Player.h"
@ -11,11 +12,11 @@
class cBlockBedHandler :
public cBlockHandler
public cMetaRotater<cBlockHandler,0x3,0x02,0x03,0x00,0x01>
{
public:
cBlockBedHandler(BLOCKTYPE a_BlockType)
: cBlockHandler(a_BlockType)
: cMetaRotater<cBlockHandler,0x3,0x02,0x03,0x00,0x01>(a_BlockType)
{
}

View File

@ -7,11 +7,11 @@
class cBlockButtonHandler :
public cBlockHandler
public cMetaRotater<cBlockHandler,0x07,0x04,0x01,0x03,0x02>
{
public:
cBlockButtonHandler(BLOCKTYPE a_BlockType)
: cBlockHandler(a_BlockType)
: cMetaRotater<cBlockHandler,0x07,0x04,0x01,0x03,0x02>(a_BlockType)
{
}

View File

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

View File

@ -9,11 +9,11 @@
class cBlockComparatorHandler :
public cBlockHandler
public cMetaRotater<cBlockHandler,0x03,0x00,0x01,0x02,0x03>
{
public:
cBlockComparatorHandler(BLOCKTYPE a_BlockType)
: cBlockHandler(a_BlockType)
: cMetaRotater<cBlockHandler,0x03,0x00,0x01,0x02,0x03>(a_BlockType)
{
}

View File

@ -9,7 +9,7 @@
cBlockDoorHandler::cBlockDoorHandler(BLOCKTYPE a_BlockType)
: cBlockHandler(a_BlockType)
: super(a_BlockType)
{
}

View File

@ -9,8 +9,9 @@
class cBlockDoorHandler :
public cBlockHandler
public cMetaRotater<cBlockHandler,0x03,0x01,0x02,0x03,0x00>
{
typedef super cMetaRotater<cBlockHandler,0x03,0x01,0x02,0x03,0x00>;
public:
cBlockDoorHandler(BLOCKTYPE a_BlockType);
@ -167,6 +168,60 @@ 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

@ -12,11 +12,11 @@
class cBlockDropSpenserHandler :
public cBlockEntityHandler
public cMetaRotater<cBlockEntityHandler,0x07,0x02,0x05,0x03,0x04>
{
public:
cBlockDropSpenserHandler(BLOCKTYPE a_BlockType) :
cBlockEntityHandler(a_BlockType)
cMetaRotater<cBlockEntitHandler,0x07,0x02,0x05,0x03,0x04>(a_BlockType)
{
}
@ -34,6 +34,20 @@ public:
a_BlockMeta = cPiston::RotationPitchToMetaData(a_Player->GetYaw(), a_Player->GetPitch());
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

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

View File

@ -8,11 +8,11 @@
class cBlockFenceGateHandler :
public cBlockHandler
public cMetaRotater<cBlockHandler,0x03,0x02,0x03,0x00,0x01>
{
public:
cBlockFenceGateHandler(BLOCKTYPE a_BlockType) :
cBlockHandler(a_BlockType)
cMetaRotater<cBlockHandler,0x03,0x02,0x03,0x00,0x01>(a_BlockType)
{
}

82
src/Blocks/MetaRotater.h Normal file
View File

@ -0,0 +1,82 @@
#pragma once
template<class Base, NIBBLETYPE BitFilter, NIBBLETYPE North, NIBBLETYPE East, NIBBLETYPE South, NIBBLETYPE West>
class cMetaRotater : public Base
{
public:
cMetaRotater(BLOCKTYPE a_BlockType) :
Base(a_BlockType)
{}
virtual ~cMetaRotater() {}
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;
};
template<class Base, NIBBLETYPE BitFilter, NIBBLETYPE North, NIBBLETYPE East, NIBBLETYPE South, NIBBLETYPE West>
NIBBLETYPE cMetaRotater<Base, BitFilter, North, East, South, West>::MetaRotateCW(NIBBLETYPE a_Meta)
{
NIBBLETYPE OtherMeta = a_Meta & (~BitFilter);
switch (a_Meta & BitFilter)
{
case South: return West | OtherMeta;
case West: return North | OtherMeta;
case North: return East | OtherMeta;
case East: return South | OtherMeta;
}
ASSERT(!"Invalid Meta value");
return a_Meta;
}
template<class Base, NIBBLETYPE BitFilter, NIBBLETYPE North, NIBBLETYPE East, NIBBLETYPE South, NIBBLETYPE West>
NIBBLETYPE cMetaRotater<Base, BitFilter, North, East, South, West>::MetaRotateCCW(NIBBLETYPE a_Meta)
{
NIBBLETYPE OtherMeta = a_Meta & (~BitFilter);
switch (a_Meta & BitFilter)
{
case South: return East | OtherMeta;
case East: return North | OtherMeta;
case North: return West | OtherMeta;
case West: return South | OtherMeta;
}
ASSERT(!"Invalid Meta value");
return a_Meta;
}
template<class Base, NIBBLETYPE BitFilter, NIBBLETYPE North, NIBBLETYPE East, NIBBLETYPE South, NIBBLETYPE West>
NIBBLETYPE cMetaRotater<Base, BitFilter, North, East, South, West>::MetaMirrorXY(NIBBLETYPE a_Meta)
{
NIBBLETYPE OtherMeta = a_Meta & (~BitFilter);
switch (a_Meta & BitFilter)
{
case South: return North | OtherMeta;
case North: return South | OtherMeta;
}
// Not Facing North or South; No change.
return a_Meta;
}
template<class Base, NIBBLETYPE BitFilter, NIBBLETYPE North, NIBBLETYPE East, NIBBLETYPE South, NIBBLETYPE West>
NIBBLETYPE cMetaRotater<Base, BitFilter, North, East, South, West>::MetaMirrorYZ(NIBBLETYPE a_Meta)
{
NIBBLETYPE OtherMeta = a_Meta & (~BitFilter);
switch (a_Meta & BitFilter)
{
case West: return East | OtherMeta;
case East: return West | OtherMeta;
}
// Not Facing East or West; No change.
return a_Meta;
}