From 3ee523628465a59070354781cda6585f6778192c Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Tue, 4 Jun 2013 19:22:14 +0000 Subject: [PATCH] Removed cLadder, cSign, cStairs, cTorch and cVine classes, moved their functionality into the appropriate BlockHandlers / ItemHandlers git-svn-id: http://mc-server.googlecode.com/svn/trunk@1555 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- VC2008/MCServer.vcproj | 12 - source/AllToLua.pkg | 5 - source/Bindings.cpp | 291 +++---------------------- source/Bindings.h | 2 +- source/Blocks/BlockBed.h | 21 +- source/Blocks/BlockLadder.h | 33 ++- source/Blocks/BlockRedstone.cpp | 1 - source/Blocks/BlockRedstoneTorch.h | 1 - source/Blocks/BlockSign.h | 32 ++- source/Blocks/BlockStairs.h | 30 ++- source/Blocks/BlockTorch.h | 67 +++++- source/Blocks/BlockVine.h | 31 ++- source/Chunk.cpp | 2 - source/ClientHandle.cpp | 4 - source/Enchantments.h | 4 +- source/Items/ItemSign.h | 6 +- source/Ladder.h | 43 ---- source/Sign.h | 44 ---- source/Simulator/RedstoneSimulator.cpp | 4 +- source/Stairs.h | 44 ---- source/Torch.h | 77 ------- source/Vine.h | 42 ---- 22 files changed, 221 insertions(+), 575 deletions(-) delete mode 100644 source/Ladder.h delete mode 100644 source/Sign.h delete mode 100644 source/Stairs.h delete mode 100644 source/Torch.h delete mode 100644 source/Vine.h diff --git a/VC2008/MCServer.vcproj b/VC2008/MCServer.vcproj index c44356545..a8a3aede6 100644 --- a/VC2008/MCServer.vcproj +++ b/VC2008/MCServer.vcproj @@ -1000,10 +1000,6 @@ RelativePath="..\source\Sign.h" > - - @@ -1012,14 +1008,6 @@ RelativePath="..\source\TNTEntity.h" > - - - - 360 ) a_Rotation -= 360; + a_Rotation += 180 + (180 / 4); // So its not aligned with axis + if (a_Rotation > 360) a_Rotation -= 360; a_Rotation = (a_Rotation / 360) * 4; @@ -62,15 +59,11 @@ public: { switch (a_MetaData) { - case 0: // south +z - return Vector3i(0, 0, 1); - case 1: // west -x - return Vector3i(-1, 0, 0); - case 2: // north -z - return Vector3i(0, 0, -1); - case 3: // east +x - return Vector3i(1, 0, 0); - }; + case 0: return Vector3i(0, 0, 1); + case 1: return Vector3i(-1, 0, 0); + case 2: return Vector3i(0, 0, -1); + case 3: return Vector3i(1, 0, 0); + } return Vector3i(); } } ; diff --git a/source/Blocks/BlockLadder.h b/source/Blocks/BlockLadder.h index 280f0deb1..93473f757 100644 --- a/source/Blocks/BlockLadder.h +++ b/source/Blocks/BlockLadder.h @@ -3,7 +3,6 @@ #include "BlockHandler.h" #include "../World.h" -#include "../Ladder.h" @@ -37,11 +36,37 @@ public: } a_BlockType = m_BlockType; - a_BlockMeta = cLadder::DirectionToMetaData(a_BlockFace); + a_BlockMeta = DirectionToMetaData(a_BlockFace); return true; } + static NIBBLETYPE DirectionToMetaData(char a_Direction) // tolua_export + { // tolua_export + switch (a_Direction) + { + case 0x2: return 0x2; + case 0x3: return 0x3; + case 0x4: return 0x4; + case 0x5: return 0x5; + default: return 0x2; + } + } // tolua_export + + + static char MetaDataToDirection(NIBBLETYPE a_MetaData) // tolua_export + { // tolua_export + switch (a_MetaData) + { + case 0x2: return 0x2; + case 0x3: return 0x3; + case 0x4: return 0x4; + case 0x5: return 0x5; + default: return 0x2; + } + } // tolua_export + + /// Finds a suitable Direction for the Ladder. Returns BLOCK_FACE_BOTTOM on failure static char FindSuitableBlockFace(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) { @@ -71,8 +96,8 @@ public: virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { - // TODO: Use cTorch::AdjustCoordsByMeta(), then cChunk::UnboundedRelGetBlock() and finally some comparison - char BlockFace = cLadder::MetaDataToDirection(a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ)); + // TODO: Use AdjustCoordsByMeta(), then cChunk::UnboundedRelGetBlock() and finally some comparison + char BlockFace = MetaDataToDirection(a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ)); int BlockX = a_RelX + a_Chunk.GetPosX() * cChunkDef::Width; int BlockZ = a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width; return LadderCanBePlacedAt(a_Chunk.GetWorld(), BlockX, a_RelY, BlockZ, BlockFace); diff --git a/source/Blocks/BlockRedstone.cpp b/source/Blocks/BlockRedstone.cpp index ec54169c0..f433be4ef 100644 --- a/source/Blocks/BlockRedstone.cpp +++ b/source/Blocks/BlockRedstone.cpp @@ -3,7 +3,6 @@ #include "BlockRedstone.h" #include "../Item.h" #include "../World.h" -#include "../Torch.h" diff --git a/source/Blocks/BlockRedstoneTorch.h b/source/Blocks/BlockRedstoneTorch.h index 0127dc082..c8256ce64 100644 --- a/source/Blocks/BlockRedstoneTorch.h +++ b/source/Blocks/BlockRedstoneTorch.h @@ -3,7 +3,6 @@ #include "BlockRedstone.h" #include "BlockTorch.h" -#include "../Torch.h" diff --git a/source/Blocks/BlockSign.h b/source/Blocks/BlockSign.h index 23645d0d2..4bdccb47e 100644 --- a/source/Blocks/BlockSign.h +++ b/source/Blocks/BlockSign.h @@ -3,7 +3,6 @@ #include "BlockHandler.h" #include "../World.h" -#include "../Sign.h" #include "../Player.h" @@ -36,6 +35,37 @@ public: { return "step.wood"; } + + + static char RotationToMetaData(double a_Rotation) + { + a_Rotation += 180 + (180 / 16); // So it's not aligned with axis + if (a_Rotation > 360) + { + a_Rotation -= 360; + } + + a_Rotation = (a_Rotation / 360) * 16; + + return ((char)a_Rotation) % 16; + } + + + static char DirectionToMetaData(char a_Direction) + { + switch (a_Direction) + { + case 0x2: return 0x2; + case 0x3: return 0x3; + case 0x4: return 0x4; + case 0x5: return 0x5; + default: + { + break; + } + } + return 0x2; + } } ; diff --git a/source/Blocks/BlockStairs.h b/source/Blocks/BlockStairs.h index c85d07c00..6fc316e45 100644 --- a/source/Blocks/BlockStairs.h +++ b/source/Blocks/BlockStairs.h @@ -2,7 +2,6 @@ #pragma once #include "BlockHandler.h" -#include "../Stairs.h" @@ -27,7 +26,7 @@ public: ) override { a_BlockType = m_BlockType; - a_BlockMeta = cStairs::RotationToMetaData(a_Player->GetRotation()); + a_BlockMeta = RotationToMetaData(a_Player->GetRotation()); switch (a_BlockFace) { case BLOCK_FACE_TOP: break; @@ -51,6 +50,33 @@ public: // TODO: step sound + static NIBBLETYPE RotationToMetaData(double a_Rotation) + { + a_Rotation += 90 + 45; // So its not aligned with axis + NIBBLETYPE result = 0x0; + if (a_Rotation > 360) + { + a_Rotation -= 360; + } + if ((a_Rotation >= 0) && (a_Rotation < 90)) + { + return 0x0; + } + else if ((a_Rotation >= 180) && (a_Rotation < 270)) + { + return 0x1; + } + else if ((a_Rotation >= 90) && (a_Rotation < 180)) + { + return 0x2; + } + else + { + return 0x3; + } + } + + virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override { // Bits 3 and 4 stay, the rest is swapped around according to a table: diff --git a/source/Blocks/BlockTorch.h b/source/Blocks/BlockTorch.h index 97e31533b..9951b8ea4 100644 --- a/source/Blocks/BlockTorch.h +++ b/source/Blocks/BlockTorch.h @@ -2,7 +2,6 @@ #pragma once #include "BlockHandler.h" -#include "../Torch.h" #include "../World.h" @@ -37,11 +36,71 @@ public: } } a_BlockType = m_BlockType; - a_BlockMeta = cTorch::DirectionToMetaData(a_BlockFace); + a_BlockMeta = DirectionToMetaData(a_BlockFace); return true; } + static NIBBLETYPE DirectionToMetaData(char a_Direction) // tolua_export + { // tolua_export + switch (a_Direction) + { + case BLOCK_FACE_BOTTOM: ASSERT(!"Shouldn't be getting this face"); return 0; + case BLOCK_FACE_TOP: return E_META_TORCH_FLOOR; + case BLOCK_FACE_EAST: return E_META_TORCH_EAST; + case BLOCK_FACE_WEST: return E_META_TORCH_WEST; + case BLOCK_FACE_NORTH: return E_META_TORCH_NORTH; + case BLOCK_FACE_SOUTH: return E_META_TORCH_SOUTH; + default: + { + ASSERT(!"Unhandled torch direction!"); + break; + } + }; + return 0x0; + } // tolua_export + + + static char MetaDataToDirection(NIBBLETYPE a_MetaData) // tolua_export + { // tolua_export + switch (a_MetaData) + { + case 0: return BLOCK_FACE_TOP; // by default, the torches stand on the ground + case E_META_TORCH_FLOOR: return BLOCK_FACE_TOP; + case E_META_TORCH_EAST: return BLOCK_FACE_EAST; + case E_META_TORCH_WEST: return BLOCK_FACE_WEST; + case E_META_TORCH_NORTH: return BLOCK_FACE_NORTH; + case E_META_TORCH_SOUTH: return BLOCK_FACE_SOUTH; + default: + { + ASSERT(!"Unhandled torch metadata"); + break; + } + } + return 0; + } // tolua_export + + + static bool IsAttachedTo(const Vector3i & a_TorchPos, char a_TorchMeta, const Vector3i & a_BlockPos) + { + switch (a_TorchMeta) + { + case 0x0: + case E_META_TORCH_FLOOR: return ((a_TorchPos - a_BlockPos).Equals(Vector3i(0, 1, 0))); + case E_META_TORCH_EAST: return ((a_TorchPos - a_BlockPos).Equals(Vector3i(0, 0, -1))); + case E_META_TORCH_WEST: return ((a_TorchPos - a_BlockPos).Equals(Vector3i(0, 0, 1))); + case E_META_TORCH_NORTH: return ((a_TorchPos - a_BlockPos).Equals(Vector3i(-1, 0, 0))); + case E_META_TORCH_SOUTH: return ((a_TorchPos - a_BlockPos).Equals(Vector3i(1, 0, 0))); + default: + { + ASSERT(!"Unhandled torch meta!"); + break; + } + } + return false; + } + + virtual bool DoesAllowBlockOnTop(void) override { return false; @@ -113,8 +172,8 @@ public: virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { - // TODO: Use cTorch::AdjustCoordsByMeta(), then cChunk::UnboundedRelGetBlock() and finally some comparison - char Face = cTorch::MetaDataToDirection(a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ)); + // TODO: Use AdjustCoordsByMeta(), then cChunk::UnboundedRelGetBlock() and finally some comparison + char Face = MetaDataToDirection(a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ)); int BlockX = a_RelX + a_Chunk.GetPosX() * cChunkDef::Width; int BlockZ = a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width; return TorchCanBePlacedAt(a_Chunk.GetWorld(), BlockX, a_RelY, BlockZ, Face); diff --git a/source/Blocks/BlockVine.h b/source/Blocks/BlockVine.h index 67376a4d8..2a88c9b68 100644 --- a/source/Blocks/BlockVine.h +++ b/source/Blocks/BlockVine.h @@ -2,7 +2,6 @@ #pragma once #include "BlockHandler.h" -#include "../Vine.h" @@ -31,17 +30,43 @@ public: a_World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta); if (BlockType == m_BlockType) { - a_BlockMeta = BlockMeta | cVine::DirectionToMetaData(a_BlockFace); + a_BlockMeta = BlockMeta | DirectionToMetaData(a_BlockFace); } else { - a_BlockMeta = cVine::DirectionToMetaData(a_BlockFace); + a_BlockMeta = DirectionToMetaData(a_BlockFace); } a_BlockType = m_BlockType; return true; } + static NIBBLETYPE DirectionToMetaData(char a_BlockFace) + { + switch (a_BlockFace) + { + case BLOCK_FACE_NORTH: return 0x1; + case BLOCK_FACE_SOUTH: return 0x4; + case BLOCK_FACE_WEST: return 0x8; + case BLOCK_FACE_EAST: return 0x2; + default: return 0x0; + } + } + + + static char MetaDataToDirection(NIBBLETYPE a_MetaData) + { + switch(a_MetaData) + { + case 0x1: return BLOCK_FACE_NORTH; + case 0x4: return BLOCK_FACE_SOUTH; + case 0x8: return BLOCK_FACE_WEST; + case 0x2: return BLOCK_FACE_EAST; + default: return BLOCK_FACE_TOP; + } + } + + /// Returns true if the specified block type is good for vines to attach to static bool IsBlockAttachable(BLOCKTYPE a_BlockType) { diff --git a/source/Chunk.cpp b/source/Chunk.cpp index 60ec273be..3cebe7d5c 100644 --- a/source/Chunk.cpp +++ b/source/Chunk.cpp @@ -19,8 +19,6 @@ #include "BlockEntities/JukeboxEntity.h" #include "BlockEntities/NoteEntity.h" #include "BlockEntities/SignEntity.h" -#include "Torch.h" -#include "Ladder.h" #include "Pickup.h" #include "Item.h" #include "Noise.h" diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp index 0eb24e9e9..d0904bfb0 100644 --- a/source/ClientHandle.cpp +++ b/source/ClientHandle.cpp @@ -12,11 +12,7 @@ #include "BlockEntities/SignEntity.h" #include "UI/Window.h" #include "Item.h" -#include "Torch.h" #include "Doors.h" -#include "Ladder.h" -#include "Vine.h" -#include "Sign.h" #include "Piston.h" #include "Mobs/Monster.h" #include "ChatColor.h" diff --git a/source/Enchantments.h b/source/Enchantments.h index 30c2fe7b7..c20da654b 100644 --- a/source/Enchantments.h +++ b/source/Enchantments.h @@ -90,11 +90,11 @@ public: /// Returns true if a_Other contains exactly the same enchantments and levels bool operator ==(const cEnchantments & a_Other) const; + // tolua_end + /// Returns true if a_Other doesn't contain exactly the same enchantments and levels bool operator !=(const cEnchantments & a_Other) const; - // tolua_end - /// Writes the enchantments into the specified NBT writer; begins with the LIST tag of the specified name ("ench" or "StoredEnchantments") void WriteToNBTCompound(cFastNBTWriter & a_Writer, const AString & a_ListTagName) const; diff --git a/source/Items/ItemSign.h b/source/Items/ItemSign.h index 758e08c4d..7a0924147 100644 --- a/source/Items/ItemSign.h +++ b/source/Items/ItemSign.h @@ -3,7 +3,7 @@ #include "ItemHandler.h" #include "../World.h" -#include "../Sign.h" +#include "../Blocks/BlockSign.h" @@ -34,12 +34,12 @@ public: { if (a_BlockFace == BLOCK_FACE_TOP) { - a_BlockMeta = cSign::RotationToMetaData(a_Player->GetRotation()); + a_BlockMeta = cBlockSignHandler::RotationToMetaData(a_Player->GetRotation()); a_BlockType = E_BLOCK_SIGN_POST; } else { - a_BlockMeta = cSign::DirectionToMetaData(a_BlockFace); + a_BlockMeta = cBlockSignHandler::DirectionToMetaData(a_BlockFace); a_BlockType = E_BLOCK_WALLSIGN; } return true; diff --git a/source/Ladder.h b/source/Ladder.h deleted file mode 100644 index 50a697437..000000000 --- a/source/Ladder.h +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -class cLadder // tolua_export -{ // tolua_export -public: - - static char DirectionToMetaData( char a_Direction ) // tolua_export - { // tolua_export - switch( a_Direction ) - { - case 0x2: - return 0x2; - case 0x3: - return 0x3; - case 0x4: - return 0x4; - case 0x5: - return 0x5; - default: - break; - }; - return 0x2; - } // tolua_export - - static char MetaDataToDirection( char a_MetaData ) // tolua_export - { // tolua_export - switch( a_MetaData ) - { - case 0x2: - return 0x2; - case 0x3: - return 0x3; - case 0x4: - return 0x4; - case 0x5: - return 0x5; - default: - break; - }; - return 0x2; - } // tolua_export - -}; // tolua_export diff --git a/source/Sign.h b/source/Sign.h deleted file mode 100644 index cc71666b5..000000000 --- a/source/Sign.h +++ /dev/null @@ -1,44 +0,0 @@ - -#pragma once - - - - - -// tolua_begin -class cSign -{ -public: - static char RotationToMetaData(double a_Rotation) - { - a_Rotation += 180 + (180 / 16); // So it's not aligned with axis - if (a_Rotation > 360) - { - a_Rotation -= 360; - } - - a_Rotation = (a_Rotation / 360) * 16; - - return ((char)a_Rotation) % 16; - } - - - static char DirectionToMetaData(char a_Direction) - { - switch (a_Direction) - { - case 0x2: return 0x2; - case 0x3: return 0x3; - case 0x4: return 0x4; - case 0x5: return 0x5; - default: - break; - }; - return 0x2; - } -} ; -// tolua_end - - - - diff --git a/source/Simulator/RedstoneSimulator.cpp b/source/Simulator/RedstoneSimulator.cpp index 989443e41..97412cca1 100644 --- a/source/Simulator/RedstoneSimulator.cpp +++ b/source/Simulator/RedstoneSimulator.cpp @@ -3,10 +3,10 @@ #include "RedstoneSimulator.h" #include "../BlockEntities/DropSpenserEntity.h" +#include "../Blocks/BlockTorch.h" #include "../Piston.h" #include "../World.h" #include "../BlockID.h" -#include "../Torch.h" #include "../Chunk.h" @@ -179,7 +179,7 @@ void cRedstoneSimulator::RefreshTorchesAround(const Vector3i & a_BlockPos) { if (BlockType != TargetBlockType) { - if (cTorch::IsAttachedTo(TorchPos, BlockMeta, a_BlockPos)) + if (cBlockTorchHandler::IsAttachedTo(TorchPos, BlockMeta, a_BlockPos)) { m_World.FastSetBlock(TorchPos.x, TorchPos.y, TorchPos.z, TargetBlockType, BlockMeta); m_Blocks.push_back(TorchPos); diff --git a/source/Stairs.h b/source/Stairs.h deleted file mode 100644 index 6d3a5a45c..000000000 --- a/source/Stairs.h +++ /dev/null @@ -1,44 +0,0 @@ - -#pragma once - - - - - -// tolua_begin - -class cStairs -{ -public: - /// Converts player rotation to stair rotation metadata. To get upside-down stairs, OR with 0x4 - static NIBBLETYPE RotationToMetaData(double a_Rotation) - { - a_Rotation += 90 + 45; // So its not aligned with axis - NIBBLETYPE result = 0x0; - if (a_Rotation > 360) - { - a_Rotation -= 360; - } - if ((a_Rotation >= 0) && (a_Rotation < 90)) - { - return 0x0; - } - else if ((a_Rotation >= 180) && (a_Rotation < 270)) - { - return 0x1; - } - else if ((a_Rotation >= 90) && (a_Rotation < 180)) - { - return 0x2; - } - else - { - return 0x3; - } - } -} ; - -// tolua_end - - - diff --git a/source/Torch.h b/source/Torch.h deleted file mode 100644 index 2a84db072..000000000 --- a/source/Torch.h +++ /dev/null @@ -1,77 +0,0 @@ - -#pragma once -#include "Vector3i.h" -#include "Defines.h" - - - - - -class cTorch // tolua_export -{ // tolua_export -public: - - static char DirectionToMetaData( char a_Direction ) // tolua_export - { // tolua_export - switch (a_Direction) - { - case BLOCK_FACE_BOTTOM: ASSERT(!"Shouldn't be getting this face"); return 0; - case BLOCK_FACE_TOP: return E_META_TORCH_FLOOR; - case BLOCK_FACE_EAST: return E_META_TORCH_EAST; - case BLOCK_FACE_WEST: return E_META_TORCH_WEST; - case BLOCK_FACE_NORTH: return E_META_TORCH_NORTH; - case BLOCK_FACE_SOUTH: return E_META_TORCH_SOUTH; - default: - { - ASSERT(!"Unhandled torch direction!"); - break; - } - }; - return 0x0; - } // tolua_export - - - static char MetaDataToDirection(char a_MetaData) // tolua_export - { // tolua_export - switch (a_MetaData) - { - case 0: return BLOCK_FACE_TOP; // by default, the torches stand on the ground - case E_META_TORCH_FLOOR: return BLOCK_FACE_TOP; - case E_META_TORCH_EAST: return BLOCK_FACE_EAST; - case E_META_TORCH_WEST: return BLOCK_FACE_WEST; - case E_META_TORCH_NORTH: return BLOCK_FACE_NORTH; - case E_META_TORCH_SOUTH: return BLOCK_FACE_SOUTH; - default: - { - ASSERT(!"Unhandled torch metadata"); - break; - } - } - return 0; - } // tolua_export - - - static bool IsAttachedTo(const Vector3i & a_TorchPos, char a_TorchMeta, const Vector3i & a_BlockPos) - { - switch (a_TorchMeta) - { - case 0x0: - case E_META_TORCH_FLOOR: return ((a_TorchPos - a_BlockPos).Equals(Vector3i(0, 1, 0))); - case E_META_TORCH_EAST: return ((a_TorchPos - a_BlockPos).Equals(Vector3i(0, 0, -1))); - case E_META_TORCH_WEST: return ((a_TorchPos - a_BlockPos).Equals(Vector3i(0, 0, 1))); - case E_META_TORCH_NORTH: return ((a_TorchPos - a_BlockPos).Equals(Vector3i(-1, 0, 0))); - case E_META_TORCH_SOUTH: return ((a_TorchPos - a_BlockPos).Equals(Vector3i(1, 0, 0))); - default: - { - ASSERT(!"Unhandled torch meta!"); - break; - } - } - return false; - } - -} ; // tolua_export - - - - diff --git a/source/Vine.h b/source/Vine.h deleted file mode 100644 index 7abf3992b..000000000 --- a/source/Vine.h +++ /dev/null @@ -1,42 +0,0 @@ - -#pragma once - - - - - -// tolua_begin -class cVine -{ -public: - - static NIBBLETYPE DirectionToMetaData(char a_BlockFace) - { - switch (a_BlockFace) - { - case BLOCK_FACE_NORTH: return 0x1; - case BLOCK_FACE_SOUTH: return 0x4; - case BLOCK_FACE_WEST: return 0x8; - case BLOCK_FACE_EAST: return 0x2; - default: return 0x0; - } - } - - - static char MetaDataToDirection(NIBBLETYPE a_MetaData) - { - switch(a_MetaData) - { - case 0x1: return BLOCK_FACE_NORTH; - case 0x4: return BLOCK_FACE_SOUTH; - case 0x8: return BLOCK_FACE_WEST; - case 0x2: return BLOCK_FACE_EAST; - default: return BLOCK_FACE_TOP; - } - } -} ; -// tolua_end - - - -