From 84913299f45a28d3bd6146b3decbf14764449030 Mon Sep 17 00:00:00 2001 From: Tycho Date: Thu, 27 Feb 2014 11:33:35 -0800 Subject: Added some Metadate rotaters using templated Mixin --- src/Blocks/BlockBed.h | 5 +-- src/Blocks/BlockButton.h | 4 +-- src/Blocks/BlockChest.h | 4 +-- src/Blocks/BlockComparator.h | 4 +-- src/Blocks/BlockDoor.cpp | 2 +- src/Blocks/BlockDoor.h | 57 +++++++++++++++++++++++++++++- src/Blocks/BlockDropSpenser.h | 18 ++++++++-- src/Blocks/BlockEnderchest.h | 4 +-- src/Blocks/BlockFenceGate.h | 4 +-- src/Blocks/MetaRotater.h | 82 +++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 168 insertions(+), 16 deletions(-) create mode 100644 src/Blocks/MetaRotater.h 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 { public: cBlockBedHandler(BLOCKTYPE a_BlockType) - : cBlockHandler(a_BlockType) + : cMetaRotater(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 { public: cBlockButtonHandler(BLOCKTYPE a_BlockType) - : cBlockHandler(a_BlockType) + : cMetaRotater(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 { public: cBlockChestHandler(BLOCKTYPE a_BlockType) - : cBlockEntityHandler(a_BlockType) + : cMetaRotater(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 { public: cBlockComparatorHandler(BLOCKTYPE a_BlockType) - : cBlockHandler(a_BlockType) + : cMetaRotater(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 { + typedef super cMetaRotater; 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 { public: cBlockDropSpenserHandler(BLOCKTYPE a_BlockType) : - cBlockEntityHandler(a_BlockType) + cMetaRotater(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 { public: cBlockEnderchestHandler(BLOCKTYPE a_BlockType) - : cBlockEntityHandler(a_BlockType) + : cMetaRotater(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 { public: cBlockFenceGateHandler(BLOCKTYPE a_BlockType) : - cBlockHandler(a_BlockType) + cMetaRotater(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 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 +NIBBLETYPE cMetaRotater::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 +NIBBLETYPE cMetaRotater::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 +NIBBLETYPE cMetaRotater::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 +NIBBLETYPE cMetaRotater::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; +} -- cgit v1.2.3 From 0acfbdd91283c96fd0f371f51029a72d6c9cd3de Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 1 Mar 2014 09:47:27 -0800 Subject: Final implementation of MetaRotater --- src/Blocks/MetaRotater.h | 96 +++++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 45 deletions(-) diff --git a/src/Blocks/MetaRotater.h b/src/Blocks/MetaRotater.h index f1656f1bd..b83ed177a 100644 --- a/src/Blocks/MetaRotater.h +++ b/src/Blocks/MetaRotater.h @@ -1,7 +1,7 @@ #pragma once -template +template class cMetaRotater : public Base { public: @@ -19,64 +19,70 @@ public: }; -template -NIBBLETYPE cMetaRotater::MetaRotateCW(NIBBLETYPE a_Meta) +template +NIBBLETYPE cMetaRotater::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; + 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; + } + if(AssertIfNotMatched) + { + ASSERT(!"Invalid Meta value"); + return a_Meta; + } } -template -NIBBLETYPE cMetaRotater::MetaRotateCCW(NIBBLETYPE a_Meta) +template +NIBBLETYPE cMetaRotater::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; + 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; + } + if(AssertIfNotMatched) + { + ASSERT(!"Invalid Meta value"); + return a_Meta; + } } -template -NIBBLETYPE cMetaRotater::MetaMirrorXY(NIBBLETYPE a_Meta) +template +NIBBLETYPE cMetaRotater::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; + 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 -NIBBLETYPE cMetaRotater::MetaMirrorYZ(NIBBLETYPE a_Meta) +template +NIBBLETYPE cMetaRotater::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; + 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; } -- cgit v1.2.3 From 65edffd5b04623dcd4cebbd1afb2575e98eee5db Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 1 Mar 2014 10:04:50 -0800 Subject: Implemented Rotations --- src/Blocks/BlockBed.h | 4 +-- src/Blocks/BlockButton.h | 5 ++-- src/Blocks/BlockChest.h | 5 ++-- src/Blocks/BlockComparator.h | 5 ++-- src/Blocks/BlockDoor.h | 5 ++-- src/Blocks/BlockDropSpenser.h | 1 + src/Blocks/BlockEnderchest.h | 2 +- src/Blocks/BlockFenceGate.h | 6 ++-- src/Blocks/BlockStairs.h | 68 ++----------------------------------------- src/Blocks/BlockTorch.h | 67 ++---------------------------------------- src/Blocks/BlockVine.h | 30 ++----------------- 11 files changed, 28 insertions(+), 170 deletions(-) diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h index 6e8884114..d8a796735 100644 --- a/src/Blocks/BlockBed.h +++ b/src/Blocks/BlockBed.h @@ -12,11 +12,11 @@ class cBlockBedHandler : - public cMetaRotater + public cMetaRotater { public: cBlockBedHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h index 5a4bf7c96..4daa03005 100644 --- a/src/Blocks/BlockButton.h +++ b/src/Blocks/BlockButton.h @@ -2,16 +2,17 @@ #include "BlockHandler.h" #include "Chunk.h" +#include "MetaRotater.h" class cBlockButtonHandler : - public cMetaRotater + public cMetaRotater { public: cBlockButtonHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h index 4ab23bced..6a13e826e 100644 --- a/src/Blocks/BlockChest.h +++ b/src/Blocks/BlockChest.h @@ -4,17 +4,18 @@ #include "BlockEntity.h" #include "../BlockArea.h" #include "../Entities/Player.h" +#include "MetaRotater.h" class cBlockChestHandler : - public cMetaRotater + public cMetaRotater { public: cBlockChestHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockComparator.h b/src/Blocks/BlockComparator.h index 7e672eece..238e687ab 100644 --- a/src/Blocks/BlockComparator.h +++ b/src/Blocks/BlockComparator.h @@ -3,17 +3,18 @@ #include "BlockHandler.h" #include "BlockRedstoneRepeater.h" +#include "MetaRotater.h" class cBlockComparatorHandler : - public cMetaRotater + public cMetaRotater { public: cBlockComparatorHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h index c3647b203..8e3f2d83f 100644 --- a/src/Blocks/BlockDoor.h +++ b/src/Blocks/BlockDoor.h @@ -4,14 +4,15 @@ #include "BlockHandler.h" #include "../Entities/Player.h" #include "Chunk.h" +#include "MetaRotater.h" class cBlockDoorHandler : - public cMetaRotater + public cMetaRotater { - typedef super cMetaRotater; + typedef super cMetaRotater; public: cBlockDoorHandler(BLOCKTYPE a_BlockType); diff --git a/src/Blocks/BlockDropSpenser.h b/src/Blocks/BlockDropSpenser.h index 2253fcd1b..73937577a 100644 --- a/src/Blocks/BlockDropSpenser.h +++ b/src/Blocks/BlockDropSpenser.h @@ -6,6 +6,7 @@ #pragma once #include "../Piston.h" +#include "MetaRotater.h" diff --git a/src/Blocks/BlockEnderchest.h b/src/Blocks/BlockEnderchest.h index ed3f37013..6ca83399a 100644 --- a/src/Blocks/BlockEnderchest.h +++ b/src/Blocks/BlockEnderchest.h @@ -2,7 +2,7 @@ #pragma once #include "BlockEntity.h" - +#include "MetaRotater.h" diff --git a/src/Blocks/BlockFenceGate.h b/src/Blocks/BlockFenceGate.h index 035579e8e..c33393590 100644 --- a/src/Blocks/BlockFenceGate.h +++ b/src/Blocks/BlockFenceGate.h @@ -2,17 +2,17 @@ #pragma once #include "BlockHandler.h" - +#include "MetaRotater.h" class cBlockFenceGateHandler : - public cMetaRotater + public cMetaRotater { public: cBlockFenceGateHandler(BLOCKTYPE a_BlockType) : - cMetaRotater(a_BlockType) + cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockStairs.h b/src/Blocks/BlockStairs.h index c1887bc46..f07afc9f0 100644 --- a/src/Blocks/BlockStairs.h +++ b/src/Blocks/BlockStairs.h @@ -2,17 +2,17 @@ #pragma once #include "BlockHandler.h" - +#include "MetaRotater.h" class cBlockStairsHandler : - public cBlockHandler + public cMetaRotater { public: cBlockStairsHandler(BLOCKTYPE a_BlockType) : - cBlockHandler(a_BlockType) + cMetaRotater(a_BlockType) { } @@ -96,54 +96,6 @@ public: } - 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: @@ -151,20 +103,6 @@ public: } - 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; - } } ; diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h index f2a4c8665..59c896857 100644 --- a/src/Blocks/BlockTorch.h +++ b/src/Blocks/BlockTorch.h @@ -2,17 +2,17 @@ #include "BlockHandler.h" #include "../Chunk.h" - +#include "MetaRotater.h" class cBlockTorchHandler : - public cBlockHandler + public cMetaRotater { public: cBlockTorchHandler(BLOCKTYPE a_BlockType) - : cBlockHandler(a_BlockType) + : cMetaRotater(a_BlockType) { } @@ -185,67 +185,6 @@ 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 - } - } } ; diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h index ee7dcee8a..9e2105f67 100644 --- a/src/Blocks/BlockVine.h +++ b/src/Blocks/BlockVine.h @@ -2,17 +2,17 @@ #pragma once #include "BlockHandler.h" - +#include "MetaRotater.h" class cBlockVineHandler : - public cBlockHandler + public cMetaRotater { public: cBlockVineHandler(BLOCKTYPE a_BlockType) - : cBlockHandler(a_BlockType) + : cMetaRotater(a_BlockType) { } @@ -169,31 +169,7 @@ public: a_World->SetBlock(X, Y - 1, Z, E_BLOCK_VINES, a_World->GetBlockMeta(X, Y, Z)); } } - - 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)); - } } ; -- cgit v1.2.3 From 5093b75ef1488b3687e1c54c893ab68b4475e451 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 1 Mar 2014 10:14:24 -0800 Subject: Revesed typedef --- src/Blocks/BlockDoor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h index 8e3f2d83f..0caeb7dba 100644 --- a/src/Blocks/BlockDoor.h +++ b/src/Blocks/BlockDoor.h @@ -12,7 +12,7 @@ class cBlockDoorHandler : public cMetaRotater { - typedef super cMetaRotater; + typedef cMetaRotater super; public: cBlockDoorHandler(BLOCKTYPE a_BlockType); -- cgit v1.2.3 From 1e1d89fd2005ee634094fd3d55638965d41acecf Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 1 Mar 2014 10:17:55 -0800 Subject: Fixed errors --- src/Blocks/BlockChest.h | 2 +- src/Blocks/BlockDropSpenser.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h index 6a13e826e..1646454a7 100644 --- a/src/Blocks/BlockChest.h +++ b/src/Blocks/BlockChest.h @@ -15,7 +15,7 @@ class cBlockChestHandler : { public: cBlockChestHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockDropSpenser.h b/src/Blocks/BlockDropSpenser.h index 73937577a..adc819a4c 100644 --- a/src/Blocks/BlockDropSpenser.h +++ b/src/Blocks/BlockDropSpenser.h @@ -17,7 +17,7 @@ class cBlockDropSpenserHandler : { public: cBlockDropSpenserHandler(BLOCKTYPE a_BlockType) : - cMetaRotater(a_BlockType) + cMetaRotater(a_BlockType) { } -- cgit v1.2.3 From 8990410f18a03ca553cca0103cd167bac06443cc Mon Sep 17 00:00:00 2001 From: worktycho Date: Sun, 2 Mar 2014 12:02:29 +0000 Subject: Reverted BlockVine --- src/Blocks/BlockVine.h | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h index 9e2105f67..b8213f29b 100644 --- a/src/Blocks/BlockVine.h +++ b/src/Blocks/BlockVine.h @@ -1,4 +1,3 @@ - #pragma once #include "BlockHandler.h" @@ -8,11 +7,11 @@ class cBlockVineHandler : - public cMetaRotater + public cBlockHandler { public: cBlockVineHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cBlockHandler(a_BlockType) { } @@ -169,6 +168,31 @@ public: a_World->SetBlock(X, Y - 1, Z, E_BLOCK_VINES, a_World->GetBlockMeta(X, Y, Z)); } } + + 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)); + } } ; -- cgit v1.2.3 From 6536233f4d0bb9411895ce78d1c57e37a7aac044 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 2 Mar 2014 12:29:20 -0800 Subject: Reformated MetaRotater --- src/Blocks/MetaRotater.h | 49 +++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/src/Blocks/MetaRotater.h b/src/Blocks/MetaRotater.h index b83ed177a..5493c87e2 100644 --- a/src/Blocks/MetaRotater.h +++ b/src/Blocks/MetaRotater.h @@ -1,7 +1,18 @@ +// MetaRotater.h + +// Provides a mixin for rotations and reflections + #pragma once -template +/* +Provides a mixin for rotations and reflections following the standard pattern of apply mask then use case. + +Usage: +Inherit from this class providing your base class as Base, the BitMask for the direction bits in bitmask and the masked value for the directions in North, East, South, West. There is also an aptional parameter AssertIfNotMatched. Set this if it is invalid for a block to exist in any other state. +*/ + +template class cMetaRotater : public Base { public: @@ -19,18 +30,18 @@ public: }; -template -NIBBLETYPE cMetaRotater::MetaRotateCW(NIBBLETYPE a_Meta) +template +NIBBLETYPE cMetaRotater::MetaRotateCW(NIBBLETYPE a_Meta) { - NIBBLETYPE OtherMeta = a_Meta & (~BitFilter); - switch (a_Meta & BitFilter) + NIBBLETYPE OtherMeta = a_Meta & (~BitMask); + switch (a_Meta & BitMask) { case South: return West | OtherMeta; case West: return North | OtherMeta; case North: return East | OtherMeta; case East: return South | OtherMeta; } - if(AssertIfNotMatched) + if (AssertIfNotMatched) { ASSERT(!"Invalid Meta value"); return a_Meta; @@ -38,18 +49,18 @@ NIBBLETYPE cMetaRotater -NIBBLETYPE cMetaRotater::MetaRotateCCW(NIBBLETYPE a_Meta) +template +NIBBLETYPE cMetaRotater::MetaRotateCCW(NIBBLETYPE a_Meta) { - NIBBLETYPE OtherMeta = a_Meta & (~BitFilter); - switch (a_Meta & BitFilter) + NIBBLETYPE OtherMeta = a_Meta & (~BitMask); + switch (a_Meta & BitMask) { case South: return East | OtherMeta; case East: return North | OtherMeta; case North: return West | OtherMeta; case West: return South | OtherMeta; } - if(AssertIfNotMatched) + if (AssertIfNotMatched) { ASSERT(!"Invalid Meta value"); return a_Meta; @@ -58,11 +69,11 @@ NIBBLETYPE cMetaRotater -NIBBLETYPE cMetaRotater::MetaMirrorXY(NIBBLETYPE a_Meta) +template +NIBBLETYPE cMetaRotater::MetaMirrorXY(NIBBLETYPE a_Meta) { - NIBBLETYPE OtherMeta = a_Meta & (~BitFilter); - switch (a_Meta & BitFilter) + NIBBLETYPE OtherMeta = a_Meta & (~BitMask); + switch (a_Meta & BitMask) { case South: return North | OtherMeta; case North: return South | OtherMeta; @@ -74,11 +85,11 @@ NIBBLETYPE cMetaRotater -NIBBLETYPE cMetaRotater::MetaMirrorYZ(NIBBLETYPE a_Meta) +template +NIBBLETYPE cMetaRotater::MetaMirrorYZ(NIBBLETYPE a_Meta) { - NIBBLETYPE OtherMeta = a_Meta & (~BitFilter); - switch (a_Meta & BitFilter) + NIBBLETYPE OtherMeta = a_Meta & (~BitMask); + switch (a_Meta & BitMask) { case West: return East | OtherMeta; case East: return West | OtherMeta; -- cgit v1.2.3 From a38be148ba980e7d54bf72c9056502850d81c77a Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 2 Mar 2014 12:33:08 -0800 Subject: Reformatted --- src/Blocks/BlockBed.h | 4 ++-- src/Blocks/BlockButton.h | 4 ++-- src/Blocks/BlockChest.h | 4 ++-- src/Blocks/BlockComparator.h | 4 ++-- src/Blocks/BlockDoor.h | 4 ++-- src/Blocks/BlockDropSpenser.h | 4 ++-- src/Blocks/BlockEnderchest.h | 4 ++-- src/Blocks/BlockFenceGate.h | 4 ++-- src/Blocks/BlockStairs.h | 4 ++-- src/Blocks/BlockTorch.h | 4 ++-- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h index d8a796735..6daa94730 100644 --- a/src/Blocks/BlockBed.h +++ b/src/Blocks/BlockBed.h @@ -12,11 +12,11 @@ class cBlockBedHandler : - public cMetaRotater + public cMetaRotater { public: cBlockBedHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h index 4daa03005..e4923c441 100644 --- a/src/Blocks/BlockButton.h +++ b/src/Blocks/BlockButton.h @@ -8,11 +8,11 @@ class cBlockButtonHandler : - public cMetaRotater + public cMetaRotater { public: cBlockButtonHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h index 1646454a7..30588d8fc 100644 --- a/src/Blocks/BlockChest.h +++ b/src/Blocks/BlockChest.h @@ -11,11 +11,11 @@ class cBlockChestHandler : - public cMetaRotater + public cMetaRotater { public: cBlockChestHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockComparator.h b/src/Blocks/BlockComparator.h index 238e687ab..a8536b149 100644 --- a/src/Blocks/BlockComparator.h +++ b/src/Blocks/BlockComparator.h @@ -10,11 +10,11 @@ class cBlockComparatorHandler : - public cMetaRotater + public cMetaRotater { public: cBlockComparatorHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h index 0caeb7dba..ef73a5d42 100644 --- a/src/Blocks/BlockDoor.h +++ b/src/Blocks/BlockDoor.h @@ -10,9 +10,9 @@ class cBlockDoorHandler : - public cMetaRotater + public cMetaRotater { - typedef cMetaRotater super; + typedef cMetaRotater super; public: cBlockDoorHandler(BLOCKTYPE a_BlockType); diff --git a/src/Blocks/BlockDropSpenser.h b/src/Blocks/BlockDropSpenser.h index adc819a4c..7e0ad0e55 100644 --- a/src/Blocks/BlockDropSpenser.h +++ b/src/Blocks/BlockDropSpenser.h @@ -13,11 +13,11 @@ class cBlockDropSpenserHandler : - public cMetaRotater + public cMetaRotater { public: cBlockDropSpenserHandler(BLOCKTYPE a_BlockType) : - cMetaRotater(a_BlockType) + cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockEnderchest.h b/src/Blocks/BlockEnderchest.h index 6ca83399a..97cf484fb 100644 --- a/src/Blocks/BlockEnderchest.h +++ b/src/Blocks/BlockEnderchest.h @@ -8,11 +8,11 @@ class cBlockEnderchestHandler : - public cMetaRotater + public cMetaRotater { public: cBlockEnderchestHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockFenceGate.h b/src/Blocks/BlockFenceGate.h index c33393590..8c94e4875 100644 --- a/src/Blocks/BlockFenceGate.h +++ b/src/Blocks/BlockFenceGate.h @@ -8,11 +8,11 @@ class cBlockFenceGateHandler : - public cMetaRotater + public cMetaRotater { public: cBlockFenceGateHandler(BLOCKTYPE a_BlockType) : - cMetaRotater(a_BlockType) + cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockStairs.h b/src/Blocks/BlockStairs.h index f07afc9f0..bbbe0ee84 100644 --- a/src/Blocks/BlockStairs.h +++ b/src/Blocks/BlockStairs.h @@ -8,11 +8,11 @@ class cBlockStairsHandler : - public cMetaRotater + public cMetaRotater { public: cBlockStairsHandler(BLOCKTYPE a_BlockType) : - cMetaRotater(a_BlockType) + cMetaRotater(a_BlockType) { } diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h index 59c896857..03a63ac72 100644 --- a/src/Blocks/BlockTorch.h +++ b/src/Blocks/BlockTorch.h @@ -8,11 +8,11 @@ class cBlockTorchHandler : - public cMetaRotater + public cMetaRotater { public: cBlockTorchHandler(BLOCKTYPE a_BlockType) - : cMetaRotater(a_BlockType) + : cMetaRotater(a_BlockType) { } -- cgit v1.2.3 From 16ebbca35b8fc91061f0141625c292a8096e3b6d Mon Sep 17 00:00:00 2001 From: worktycho Date: Sat, 8 Mar 2014 14:23:00 +0000 Subject: Moved returns --- src/Blocks/MetaRotater.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Blocks/MetaRotater.h b/src/Blocks/MetaRotater.h index 5493c87e2..d3664b6f1 100644 --- a/src/Blocks/MetaRotater.h +++ b/src/Blocks/MetaRotater.h @@ -1,4 +1,3 @@ - // MetaRotater.h // Provides a mixin for rotations and reflections @@ -44,11 +43,12 @@ NIBBLETYPE cMetaRotater NIBBLETYPE cMetaRotater::MetaRotateCCW(NIBBLETYPE a_Meta) { @@ -63,8 +63,8 @@ NIBBLETYPE cMetaRotater Date: Sat, 8 Mar 2014 17:55:53 +0100 Subject: Split cClientHandle::HandleEntityAction() into three seperate functions HandleEntityCrouch, HandleEntityLeaveBed and HandleEntitySprinting. --- src/ClientHandle.cpp | 58 +++++++++++++++++++++++--------------------- src/ClientHandle.h | 4 ++- src/Protocol/Protocol125.cpp | 23 +++++++++++++++++- src/Protocol/Protocol16x.cpp | 23 +++++++++++++++++- src/Protocol/Protocol17x.cpp | 22 ++++++++++++++++- 5 files changed, 98 insertions(+), 32 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 870568cdf..79fdc5e04 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1453,7 +1453,7 @@ bool cClientHandle::HandleHandshake(const AString & a_Username) -void cClientHandle::HandleEntityAction(int a_EntityID, char a_ActionID) +void cClientHandle::HandleEntityCrouch(int a_EntityID, bool a_IsCrouching) { if (a_EntityID != m_Player->GetUniqueID()) { @@ -1461,35 +1461,37 @@ void cClientHandle::HandleEntityAction(int a_EntityID, char a_ActionID) return; } - switch (a_ActionID) + m_Player->SetCrouch(a_IsCrouching); +} + + + + + +void cClientHandle::HandleEntityLeaveBed(int a_EntityID) +{ + if (a_EntityID != m_Player->GetUniqueID()) { - case 1: // Crouch - { - m_Player->SetCrouch(true); - break; - } - case 2: // Uncrouch - { - m_Player->SetCrouch(false); - break; - } - case 3: // Leave bed - { - m_Player->GetWorld()->BroadcastEntityAnimation(*m_Player, 2); - break; - } - case 4: // Start sprinting - { - m_Player->SetSprint(true); - break; - } - case 5: // Stop sprinting - { - m_Player->SetSprint(false); - SendPlayerMaxSpeed(); - break; - } + // We should only receive entity actions from the entity that is performing the action + return; } + + m_Player->GetWorld()->BroadcastEntityAnimation(*m_Player, 2); +} + + + + + +void cClientHandle::HandleEntitySprinting(int a_EntityID, bool a_IsSprinting) +{ + if (a_EntityID != m_Player->GetUniqueID()) + { + // We should only receive entity actions from the entity that is performing the action + return; + } + + m_Player->SetSprint(a_IsSprinting); } diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 194533402..035fadfe4 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -188,7 +188,9 @@ public: void HandleChat (const AString & a_Message); void HandleCreativeInventory(short a_SlotNum, const cItem & a_HeldItem); void HandleDisconnect (const AString & a_Reason); - void HandleEntityAction (int a_EntityID, char a_ActionID); + void HandleEntityCrouch (int a_EntityID, bool a_IsCrouching); + void HandleEntityLeaveBed (int a_EntityID); + void HandleEntitySprinting (int a_EntityID, bool a_IsSprinting); /** Called when the protocol handshake has been received (for protocol versions that support it; otherwise the first instant when a username is received). diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 3980350f5..556ed1d08 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -1375,7 +1375,28 @@ int cProtocol125::ParseEntityAction(void) { HANDLE_PACKET_READ(ReadBEInt, int, EntityID); HANDLE_PACKET_READ(ReadChar, char, ActionID); - m_Client->HandleEntityAction(EntityID, ActionID); + + if (ActionID == 1) // Crouch + { + m_Client->HandleEntityCrouch(EntityID, true); + } + else if (ActionID == 2) // Uncrouch + { + m_Client->HandleEntityCrouch(EntityID, false); + } + else if (ActionID == 3) // Leave Bed + { + m_Client->HandleEntityLeaveBed(EntityID); + } + else if (ActionID == 4) // Start sprinting + { + m_Client->HandleEntitySprinting(EntityID, true); + } + else if (ActionID == 5) // Stop sprinting + { + m_Client->HandleEntitySprinting(EntityID, false); + } + return PARSE_OK; } diff --git a/src/Protocol/Protocol16x.cpp b/src/Protocol/Protocol16x.cpp index cfa27b3c4..6a41a577f 100644 --- a/src/Protocol/Protocol16x.cpp +++ b/src/Protocol/Protocol16x.cpp @@ -184,7 +184,28 @@ int cProtocol161::ParseEntityAction(void) HANDLE_PACKET_READ(ReadBEInt, int, EntityID); HANDLE_PACKET_READ(ReadChar, char, ActionID); HANDLE_PACKET_READ(ReadBEInt, int, UnknownHorseVal); - m_Client->HandleEntityAction(EntityID, ActionID); + + if (ActionID == 1) // Crouch + { + m_Client->HandleEntityCrouch(EntityID, true); + } + else if (ActionID == 2) // Uncrouch + { + m_Client->HandleEntityCrouch(EntityID, false); + } + else if (ActionID == 3) // Leave Bed + { + m_Client->HandleEntityLeaveBed(EntityID); + } + else if (ActionID == 4) // Start sprinting + { + m_Client->HandleEntitySprinting(EntityID, true); + } + else if (ActionID == 5) // Stop sprinting + { + m_Client->HandleEntitySprinting(EntityID, false); + } + return PARSE_OK; } diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 18646254f..19998a483 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1732,7 +1732,27 @@ void cProtocol172::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadBEInt, int, PlayerID); HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Action); HANDLE_READ(a_ByteBuffer, ReadBEInt, int, JumpBoost); - m_Client->HandleEntityAction(PlayerID, Action); + + if (Action == 1) // Crouch + { + m_Client->HandleEntityCrouch(PlayerID, true); + } + else if (Action == 2) // Uncrouch + { + m_Client->HandleEntityCrouch(PlayerID, false); + } + else if (Action == 3) // Leave Bed + { + m_Client->HandleEntityLeaveBed(PlayerID); + } + else if (Action == 4) // Start sprinting + { + m_Client->HandleEntitySprinting(PlayerID, true); + } + else if (Action == 5) // Stop sprinting + { + m_Client->HandleEntitySprinting(PlayerID, false); + } } -- cgit v1.2.3 From 72f9c8b06970cb351121ad1e02cccc268db8c56d Mon Sep 17 00:00:00 2001 From: Jan-Fabian Humann Date: Sat, 8 Mar 2014 19:26:32 +0100 Subject: Changed if-else to switch-case --- src/Protocol/Protocol125.cpp | 24 +++++++++++------------- src/Protocol/Protocol16x.cpp | 24 +++++++++++------------- src/Protocol/Protocol17x.cpp | 24 +++++++++++------------- 3 files changed, 33 insertions(+), 39 deletions(-) diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 556ed1d08..169ab0c85 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -1376,25 +1376,23 @@ int cProtocol125::ParseEntityAction(void) HANDLE_PACKET_READ(ReadBEInt, int, EntityID); HANDLE_PACKET_READ(ReadChar, char, ActionID); - if (ActionID == 1) // Crouch + switch (ActionID) { + case 1: // Crouch m_Client->HandleEntityCrouch(EntityID, true); - } - else if (ActionID == 2) // Uncrouch - { + break; + case 2: // Uncrouch m_Client->HandleEntityCrouch(EntityID, false); - } - else if (ActionID == 3) // Leave Bed - { + break; + case 3: // Leave Bed m_Client->HandleEntityLeaveBed(EntityID); - } - else if (ActionID == 4) // Start sprinting - { + break; + case 4: // Start sprinting m_Client->HandleEntitySprinting(EntityID, true); - } - else if (ActionID == 5) // Stop sprinting - { + break; + case 5: // Stop sprinting m_Client->HandleEntitySprinting(EntityID, false); + break; } return PARSE_OK; diff --git a/src/Protocol/Protocol16x.cpp b/src/Protocol/Protocol16x.cpp index 6a41a577f..4b1b4f408 100644 --- a/src/Protocol/Protocol16x.cpp +++ b/src/Protocol/Protocol16x.cpp @@ -185,25 +185,23 @@ int cProtocol161::ParseEntityAction(void) HANDLE_PACKET_READ(ReadChar, char, ActionID); HANDLE_PACKET_READ(ReadBEInt, int, UnknownHorseVal); - if (ActionID == 1) // Crouch + switch (ActionID) { + case 1: // Crouch m_Client->HandleEntityCrouch(EntityID, true); - } - else if (ActionID == 2) // Uncrouch - { + break; + case 2: // Uncrouch m_Client->HandleEntityCrouch(EntityID, false); - } - else if (ActionID == 3) // Leave Bed - { + break; + case 3: // Leave Bed m_Client->HandleEntityLeaveBed(EntityID); - } - else if (ActionID == 4) // Start sprinting - { + break; + case 4: // Start sprinting m_Client->HandleEntitySprinting(EntityID, true); - } - else if (ActionID == 5) // Stop sprinting - { + break; + case 5: // Stop sprinting m_Client->HandleEntitySprinting(EntityID, false); + break; } return PARSE_OK; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 19998a483..b0ec72a7d 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1733,25 +1733,23 @@ void cProtocol172::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer) HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Action); HANDLE_READ(a_ByteBuffer, ReadBEInt, int, JumpBoost); - if (Action == 1) // Crouch + switch (Action) { + case 1: // Crouch m_Client->HandleEntityCrouch(PlayerID, true); - } - else if (Action == 2) // Uncrouch - { + break; + case 2: // Unchrouch m_Client->HandleEntityCrouch(PlayerID, false); - } - else if (Action == 3) // Leave Bed - { + break; + case 3: // Leave Bed m_Client->HandleEntityLeaveBed(PlayerID); - } - else if (Action == 4) // Start sprinting - { + break; + case 4: // Start sprinting m_Client->HandleEntitySprinting(PlayerID, true); - } - else if (Action == 5) // Stop sprinting - { + break; + case 5: // Stop sprinting m_Client->HandleEntitySprinting(PlayerID, false); + break; } } -- cgit v1.2.3 From 17f27d1750083dc0a3eb958d554184839d7f92f2 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sat, 8 Mar 2014 21:14:59 +0100 Subject: Added switch case indent notice --- CONTRIBUTING.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a0a332f30..7ec7058ae 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -22,8 +22,10 @@ Code Stuff - This helps prevent mistakes such as `if (a & 1 == 0)` * White space is free, so use it freely - "freely" as in "plentifully", not "arbitrarily" + * All `case` statements inside a `switch` need an extra indent. * Each and every control statement deserves its braces. This helps maintainability later on when the file is edited, lines added or removed - the control logic doesn't break so easily. - The only exception: a `switch` statement with all `case` statements being a single short statement is allowed to use the short brace-less form. + - These two rules really mean that indent is governed by braces * Add an empty last line in all source files (GCC and GIT can complain otherwise) * Use doxy-comments for functions in the header file, format as `/** Description */` * Use spaces after the comment markers: `// Comment` instead of `//Comment` -- cgit v1.2.3 From 8d2ebf8e19e1556d256f75678d2272bb6739030f Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 6 Mar 2014 20:06:53 +0000 Subject: Slight plugin messaging changes - Clients are not allowed to register duplicate channels - Clients are not allowed to use channels that were not registered --- src/ClientHandle.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 870568cdf..c677862eb 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -555,12 +555,25 @@ void cClientHandle::HandlePluginMessage(const AString & a_Channel, const AString } else if (a_Channel == "REGISTER") { + if (HasPluginChannel(a_Channel)) + { + SendPluginMessage("UNREGISTER", a_Channel); + return; // Can't register again if already taken - kinda defeats the point of plugin messaging! + } + RegisterPluginChannels(BreakApartPluginChannels(a_Message)); } else if (a_Channel == "UNREGISTER") { UnregisterPluginChannels(BreakApartPluginChannels(a_Message)); } + else if (!HasPluginChannel(a_Channel)) + { + // Ignore if client sent something but didn't register the channel first + LOGD("Player %s sent a plugin message on channel \"%s\", but didn't REGISTER it first", GetUsername().c_str(), a_Channel.c_str()); + SendPluginMessage("UNREGISTER", a_Channel); + return; + } cPluginManager::Get()->CallHookPluginMessage(*this, a_Channel, a_Message); } -- cgit v1.2.3 From d872f2e41dfe141e1b04cdfb73c915b9bcdb55ea Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 9 Mar 2014 01:49:32 +0000 Subject: Updated Core --- MCServer/Plugins/Core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/Core b/MCServer/Plugins/Core index 3b416b07a..013a32a7f 160000 --- a/MCServer/Plugins/Core +++ b/MCServer/Plugins/Core @@ -1 +1 @@ -Subproject commit 3b416b07a339b3abcbc127070d56eea05b05373d +Subproject commit 013a32a7fb3c8a6cfe0aef892d4c7394d4e1be59 -- cgit v1.2.3 From f74ee8fb51c015f678438cc1dccf23d1d3c2cf6a Mon Sep 17 00:00:00 2001 From: Jan-Fabian Humann Date: Sun, 9 Mar 2014 10:55:06 +0100 Subject: Adjusted style of switch/case --- src/Protocol/Protocol125.cpp | 20 +++++--------------- src/Protocol/Protocol16x.cpp | 20 +++++--------------- src/Protocol/Protocol17x.cpp | 20 +++++--------------- 3 files changed, 15 insertions(+), 45 deletions(-) diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 169ab0c85..ca286bafb 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -1378,21 +1378,11 @@ int cProtocol125::ParseEntityAction(void) switch (ActionID) { - case 1: // Crouch - m_Client->HandleEntityCrouch(EntityID, true); - break; - case 2: // Uncrouch - m_Client->HandleEntityCrouch(EntityID, false); - break; - case 3: // Leave Bed - m_Client->HandleEntityLeaveBed(EntityID); - break; - case 4: // Start sprinting - m_Client->HandleEntitySprinting(EntityID, true); - break; - case 5: // Stop sprinting - m_Client->HandleEntitySprinting(EntityID, false); - break; + case 1: m_Client->HandleEntityCrouch(EntityID, true); break; // Crouch + case 2: m_Client->HandleEntityCrouch(EntityID, false); break; // Uncrouch + case 3: m_Client->HandleEntityLeaveBed(EntityID); break; // Leave Bed + case 4: m_Client->HandleEntitySprinting(EntityID, true); break; // Start sprinting + case 5: m_Client->HandleEntitySprinting(EntityID, false); break; // Stop sprinting } return PARSE_OK; diff --git a/src/Protocol/Protocol16x.cpp b/src/Protocol/Protocol16x.cpp index 4b1b4f408..f6ec0a199 100644 --- a/src/Protocol/Protocol16x.cpp +++ b/src/Protocol/Protocol16x.cpp @@ -187,21 +187,11 @@ int cProtocol161::ParseEntityAction(void) switch (ActionID) { - case 1: // Crouch - m_Client->HandleEntityCrouch(EntityID, true); - break; - case 2: // Uncrouch - m_Client->HandleEntityCrouch(EntityID, false); - break; - case 3: // Leave Bed - m_Client->HandleEntityLeaveBed(EntityID); - break; - case 4: // Start sprinting - m_Client->HandleEntitySprinting(EntityID, true); - break; - case 5: // Stop sprinting - m_Client->HandleEntitySprinting(EntityID, false); - break; + case 1: m_Client->HandleEntityCrouch(EntityID, true); break; // Crouch + case 2: m_Client->HandleEntityCrouch(EntityID, false); break; // Uncrouch + case 3: m_Client->HandleEntityLeaveBed(EntityID); break; // Leave Bed + case 4: m_Client->HandleEntitySprinting(EntityID, true); break; // Start sprinting + case 5: m_Client->HandleEntitySprinting(EntityID, false); break; // Stop sprinting } return PARSE_OK; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index b0ec72a7d..0bb9a1204 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1735,21 +1735,11 @@ void cProtocol172::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer) switch (Action) { - case 1: // Crouch - m_Client->HandleEntityCrouch(PlayerID, true); - break; - case 2: // Unchrouch - m_Client->HandleEntityCrouch(PlayerID, false); - break; - case 3: // Leave Bed - m_Client->HandleEntityLeaveBed(PlayerID); - break; - case 4: // Start sprinting - m_Client->HandleEntitySprinting(PlayerID, true); - break; - case 5: // Stop sprinting - m_Client->HandleEntitySprinting(PlayerID, false); - break; + case 1: m_Client->HandleEntityCrouch(PlayerID, true); break; // Crouch + case 2: m_Client->HandleEntityCrouch(PlayerID, false); break; // Uncrouch + case 3: m_Client->HandleEntityLeaveBed(PlayerID); break; // Leave Bed + case 4: m_Client->HandleEntitySprinting(PlayerID, true); break; // Start sprinting + case 5: m_Client->HandleEntitySprinting(PlayerID, false); break; // Stop sprinting } } -- cgit v1.2.3 From b8cd0b0897f42f0d294203cec68729f43ecb711d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 9 Mar 2014 17:48:17 +0100 Subject: Hotfix for MSVC compilation. --- src/Protocol/Protocol125.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Protocol/Protocol125.h b/src/Protocol/Protocol125.h index 66f3227b0..aca24c03a 100644 --- a/src/Protocol/Protocol125.h +++ b/src/Protocol/Protocol125.h @@ -11,6 +11,7 @@ #include "Protocol.h" #include "../ByteBuffer.h" +#include "../Entities/Painting.h" -- cgit v1.2.3 From 5c4c147e487e9dc08cfacd156b1f60a485460b75 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 9 Mar 2014 17:58:01 +0100 Subject: Silenced useless MSVC warnings in cMetaRotater. --- src/Blocks/MetaRotater.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Blocks/MetaRotater.h b/src/Blocks/MetaRotater.h index d3664b6f1..dde88e6db 100644 --- a/src/Blocks/MetaRotater.h +++ b/src/Blocks/MetaRotater.h @@ -4,6 +4,15 @@ #pragma once +// MSVC generates warnings for the templated AssertIfNotMatched parameter conditions, so disable it: +#ifdef _MSC_VER + #pragma warning(disable: 4127) // Conditional expression is constant +#endif + + + + + /* Provides a mixin for rotations and reflections following the standard pattern of apply mask then use case. @@ -29,6 +38,9 @@ public: }; + + + template NIBBLETYPE cMetaRotater::MetaRotateCW(NIBBLETYPE a_Meta) { @@ -49,6 +61,8 @@ NIBBLETYPE cMetaRotater NIBBLETYPE cMetaRotater::MetaRotateCCW(NIBBLETYPE a_Meta) { @@ -69,6 +83,8 @@ NIBBLETYPE cMetaRotater NIBBLETYPE cMetaRotater::MetaMirrorXY(NIBBLETYPE a_Meta) { @@ -85,6 +101,7 @@ NIBBLETYPE cMetaRotater NIBBLETYPE cMetaRotater::MetaMirrorYZ(NIBBLETYPE a_Meta) { @@ -97,3 +114,7 @@ NIBBLETYPE cMetaRotater Date: Sun, 9 Mar 2014 17:51:02 +0000 Subject: Fixed #778 - stack overflow.com --- src/Entities/Floater.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Entities/Floater.h b/src/Entities/Floater.h index 865d6dc50..f3b51d77b 100644 --- a/src/Entities/Floater.h +++ b/src/Entities/Floater.h @@ -11,7 +11,7 @@ class cFloater : public cEntity { - typedef cFloater super; + typedef cEntity super; public: //tolua_end -- cgit v1.2.3