summaryrefslogtreecommitdiffstats
path: root/source/Blocks
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-06-04 21:22:14 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-06-04 21:22:14 +0200
commit3ee523628465a59070354781cda6585f6778192c (patch)
tree0ef22389cfc7738fd79a02b11e1bc33a63f28b09 /source/Blocks
parentExpat project: fixed intermediate files output folder (diff)
downloadcuberite-3ee523628465a59070354781cda6585f6778192c.tar
cuberite-3ee523628465a59070354781cda6585f6778192c.tar.gz
cuberite-3ee523628465a59070354781cda6585f6778192c.tar.bz2
cuberite-3ee523628465a59070354781cda6585f6778192c.tar.lz
cuberite-3ee523628465a59070354781cda6585f6778192c.tar.xz
cuberite-3ee523628465a59070354781cda6585f6778192c.tar.zst
cuberite-3ee523628465a59070354781cda6585f6778192c.zip
Diffstat (limited to '')
-rw-r--r--source/Blocks/BlockBed.h21
-rw-r--r--source/Blocks/BlockLadder.h33
-rw-r--r--source/Blocks/BlockRedstone.cpp1
-rw-r--r--source/Blocks/BlockRedstoneTorch.h1
-rw-r--r--source/Blocks/BlockSign.h32
-rw-r--r--source/Blocks/BlockStairs.h30
-rw-r--r--source/Blocks/BlockTorch.h67
-rw-r--r--source/Blocks/BlockVine.h31
8 files changed, 186 insertions, 30 deletions
diff --git a/source/Blocks/BlockBed.h b/source/Blocks/BlockBed.h
index ab55ffc92..bf8906750 100644
--- a/source/Blocks/BlockBed.h
+++ b/source/Blocks/BlockBed.h
@@ -3,7 +3,6 @@
#include "BlockHandler.h"
#include "../World.h"
-#include "../Sign.h"
#include "../Player.h"
@@ -44,13 +43,11 @@ public:
}
-
-
// Bed specific helper functions
static NIBBLETYPE RotationToMetaData(double a_Rotation)
{
- a_Rotation += 180 + (180/4); // So its not aligned with axis
- if( a_Rotation > 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)
{