diff options
author | Tycho <work.tycho+git@gmail.com> | 2014-02-27 20:33:35 +0100 |
---|---|---|
committer | Tycho <work.tycho+git@gmail.com> | 2014-02-27 20:33:35 +0100 |
commit | 84913299f45a28d3bd6146b3decbf14764449030 (patch) | |
tree | 02707f55323bb35f4d0de65a376ba10e3a1fb5e4 /src | |
parent | Fixed crash and some warnings in map handling. (diff) | |
download | cuberite-84913299f45a28d3bd6146b3decbf14764449030.tar cuberite-84913299f45a28d3bd6146b3decbf14764449030.tar.gz cuberite-84913299f45a28d3bd6146b3decbf14764449030.tar.bz2 cuberite-84913299f45a28d3bd6146b3decbf14764449030.tar.lz cuberite-84913299f45a28d3bd6146b3decbf14764449030.tar.xz cuberite-84913299f45a28d3bd6146b3decbf14764449030.tar.zst cuberite-84913299f45a28d3bd6146b3decbf14764449030.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/Blocks/BlockBed.h | 5 | ||||
-rw-r--r-- | src/Blocks/BlockButton.h | 4 | ||||
-rw-r--r-- | src/Blocks/BlockChest.h | 4 | ||||
-rw-r--r-- | src/Blocks/BlockComparator.h | 4 | ||||
-rw-r--r-- | src/Blocks/BlockDoor.cpp | 2 | ||||
-rw-r--r-- | src/Blocks/BlockDoor.h | 57 | ||||
-rw-r--r-- | src/Blocks/BlockDropSpenser.h | 18 | ||||
-rw-r--r-- | src/Blocks/BlockEnderchest.h | 4 | ||||
-rw-r--r-- | src/Blocks/BlockFenceGate.h | 4 | ||||
-rw-r--r-- | src/Blocks/MetaRotater.h | 82 |
10 files changed, 168 insertions, 16 deletions
diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h index caec2b56f..6e8884114 100644 --- a/src/Blocks/BlockBed.h +++ b/src/Blocks/BlockBed.h @@ -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) { } diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h index ca6850ced..5a4bf7c96 100644 --- a/src/Blocks/BlockButton.h +++ b/src/Blocks/BlockButton.h @@ -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) { } diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h index 02ecc4346..4ab23bced 100644 --- a/src/Blocks/BlockChest.h +++ b/src/Blocks/BlockChest.h @@ -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) { } diff --git a/src/Blocks/BlockComparator.h b/src/Blocks/BlockComparator.h index aba390d9d..7e672eece 100644 --- a/src/Blocks/BlockComparator.h +++ b/src/Blocks/BlockComparator.h @@ -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) { } diff --git a/src/Blocks/BlockDoor.cpp b/src/Blocks/BlockDoor.cpp index 2ff5c1c37..f0d0b4b7f 100644 --- a/src/Blocks/BlockDoor.cpp +++ b/src/Blocks/BlockDoor.cpp @@ -9,7 +9,7 @@ cBlockDoorHandler::cBlockDoorHandler(BLOCKTYPE a_BlockType) - : cBlockHandler(a_BlockType) + : super(a_BlockType) { } diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h index ef0dbb787..c3647b203 100644 --- a/src/Blocks/BlockDoor.h +++ b/src/Blocks/BlockDoor.h @@ -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); + } + } + } ; diff --git a/src/Blocks/BlockDropSpenser.h b/src/Blocks/BlockDropSpenser.h index 30d347ec9..2253fcd1b 100644 --- a/src/Blocks/BlockDropSpenser.h +++ b/src/Blocks/BlockDropSpenser.h @@ -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; + } } ; diff --git a/src/Blocks/BlockEnderchest.h b/src/Blocks/BlockEnderchest.h index b4b0b995d..ed3f37013 100644 --- a/src/Blocks/BlockEnderchest.h +++ b/src/Blocks/BlockEnderchest.h @@ -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) { } diff --git a/src/Blocks/BlockFenceGate.h b/src/Blocks/BlockFenceGate.h index fb984f345..035579e8e 100644 --- a/src/Blocks/BlockFenceGate.h +++ b/src/Blocks/BlockFenceGate.h @@ -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) { } diff --git a/src/Blocks/MetaRotater.h b/src/Blocks/MetaRotater.h new file mode 100644 index 000000000..f1656f1bd --- /dev/null +++ b/src/Blocks/MetaRotater.h @@ -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; +} |