diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-01-12 05:46:01 +0100 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-01-12 05:46:01 +0100 |
commit | 43e684071933adef93040e8d4b830d5c6b71cf9a (patch) | |
tree | 014e5300feb1cdbbb8f24e4e42594eeb841f0be2 /source/Blocks/BlockRail.h | |
parent | Fixed rclk in doublechests (diff) | |
download | cuberite-43e684071933adef93040e8d4b830d5c6b71cf9a.tar cuberite-43e684071933adef93040e8d4b830d5c6b71cf9a.tar.gz cuberite-43e684071933adef93040e8d4b830d5c6b71cf9a.tar.bz2 cuberite-43e684071933adef93040e8d4b830d5c6b71cf9a.tar.lz cuberite-43e684071933adef93040e8d4b830d5c6b71cf9a.tar.xz cuberite-43e684071933adef93040e8d4b830d5c6b71cf9a.tar.zst cuberite-43e684071933adef93040e8d4b830d5c6b71cf9a.zip |
Diffstat (limited to '')
-rw-r--r-- | source/Blocks/BlockRail.h | 225 |
1 files changed, 126 insertions, 99 deletions
diff --git a/source/Blocks/BlockRail.h b/source/Blocks/BlockRail.h index 24947c0bc..733f92c8c 100644 --- a/source/Blocks/BlockRail.h +++ b/source/Blocks/BlockRail.h @@ -42,137 +42,144 @@ public: {
}
- virtual void PlaceBlock(cWorld * a_World, cPlayer * a_Player, NIBBLETYPE a_BlockMeta, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override
+ virtual bool GetPlacementBlockTypeMeta(
+ cWorld * a_World, cPlayer * a_Player,
+ int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace,
+ int a_CursorX, int a_CursorY, int a_CursorZ,
+ BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
+ ) override
{
- a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, FindMeta(a_World, a_BlockX, a_BlockY, a_BlockZ));
- OnPlacedByPlayer(a_World, a_Player, a_BlockX, a_BlockY, a_BlockZ, a_Dir);
- NeighborChanged(a_World, a_BlockX - 1, a_BlockY + 1, a_BlockZ);
- NeighborChanged(a_World, a_BlockX + 1, a_BlockY + 1, a_BlockZ);
- NeighborChanged(a_World, a_BlockX, a_BlockY + 1, a_BlockZ - 1);
- NeighborChanged(a_World, a_BlockX, a_BlockY + 1, a_BlockZ + 1);
- NeighborChanged(a_World, a_BlockX - 1, a_BlockY - 1, a_BlockZ);
- NeighborChanged(a_World, a_BlockX + 1, a_BlockY - 1, a_BlockZ);
- NeighborChanged(a_World, a_BlockX, a_BlockY - 1, a_BlockZ - 1);
- NeighborChanged(a_World, a_BlockX, a_BlockY - 1, a_BlockZ + 1);
+ a_BlockType = m_BlockType;
+ a_BlockMeta = FindMeta(a_World, a_BlockX, a_BlockY, a_BlockZ);
+ return true;
}
+
virtual void OnNeighborChanged(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override
{
- char Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
- if(IsUnstable(a_World, a_BlockX, a_BlockY, a_BlockZ) && Meta != FindMeta(a_World, a_BlockX, a_BlockY, a_BlockZ))
+ NIBBLETYPE Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
+ if (IsUnstable(a_World, a_BlockX, a_BlockY, a_BlockZ) && (Meta != FindMeta(a_World, a_BlockX, a_BlockY, a_BlockZ)))
+ {
a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, FindMeta(a_World, a_BlockX, a_BlockY, a_BlockZ));
+ }
}
+
virtual bool CanBeAt(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override
{
- if(!g_BlockIsSolid[a_World->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ)])
+ if (!g_BlockIsSolid[a_World->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ)])
+ {
return false;
- char Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
- switch(Meta)
+ }
+ NIBBLETYPE Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
+ switch (Meta)
{
case E_RAIL_ASCEND_EAST:
{
- if(!g_BlockIsSolid[a_World->GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ)])
+ if (!g_BlockIsSolid[a_World->GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ)])
+ {
return false;
+ }
break;
}
case E_RAIL_ASCEND_WEST:
{
- if(!g_BlockIsSolid[a_World->GetBlock(a_BlockX - 1, a_BlockY, a_BlockZ)])
+ if (!g_BlockIsSolid[a_World->GetBlock(a_BlockX - 1, a_BlockY, a_BlockZ)])
+ {
return false;
+ }
break;
}
case E_RAIL_ASCEND_NORTH:
{
- if(!g_BlockIsSolid[a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ - 1)])
+ if (!g_BlockIsSolid[a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ - 1)])
+ {
return false;
+ }
break;
}
case E_RAIL_ASCEND_SOUTH:
{
- if(!g_BlockIsSolid[a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ + 1)])
+ if (!g_BlockIsSolid[a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ + 1)])
+ {
return false;
+ }
break;
}
}
return true;
}
- char FindMeta(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ)
+ NIBBLETYPE FindMeta(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ)
{
- char Meta = 0;
+ NIBBLETYPE Meta = 0;
char RailsCnt = 0;
bool Neighbors[8]; // 0 - EAST, 1 - WEST, 2 - NORTH, 3 - SOUTH, 4 - EAST UP, 5 - WEST UP, 6 - NORTH UP, 7 - SOUTH UP
memset(Neighbors, false, sizeof(Neighbors));
- if(IsUnstable(a_World, a_BlockX + 1, a_BlockY, a_BlockZ) || !IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_EAST, E_PURE_DOWN))
+ Neighbors[0] = (IsUnstable(a_World, a_BlockX + 1, a_BlockY, a_BlockZ) || !IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_EAST, E_PURE_DOWN));
+ Neighbors[1] = (IsUnstable(a_World, a_BlockX - 1, a_BlockY, a_BlockZ) || !IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_WEST, E_PURE_DOWN));
+ Neighbors[2] = (IsUnstable(a_World, a_BlockX, a_BlockY, a_BlockZ - 1) || !IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH, E_PURE_DOWN));
+ Neighbors[3] = (IsUnstable(a_World, a_BlockX, a_BlockY, a_BlockZ + 1) || !IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_SOUTH, E_PURE_DOWN));
+ Neighbors[4] = (IsUnstable(a_World, a_BlockX + 1, a_BlockY + 1, a_BlockZ) || !IsNotConnected(a_World, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_EAST, E_PURE_NONE));
+ Neighbors[5] = (IsUnstable(a_World, a_BlockX - 1, a_BlockY + 1, a_BlockZ) || !IsNotConnected(a_World, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_WEST, E_PURE_NONE));
+ Neighbors[6] = (IsUnstable(a_World, a_BlockX, a_BlockY + 1, a_BlockZ - 1) || !IsNotConnected(a_World, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_NORTH, E_PURE_NONE));
+ Neighbors[7] = (IsUnstable(a_World, a_BlockX, a_BlockY + 1, a_BlockZ + 1) || !IsNotConnected(a_World, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_SOUTH, E_PURE_NONE));
+ if (IsUnstable(a_World, a_BlockX + 1, a_BlockY - 1, a_BlockZ) || !IsNotConnected(a_World, a_BlockX, a_BlockY - 1, a_BlockZ, BLOCK_FACE_EAST))
Neighbors[0] = true;
- if(IsUnstable(a_World, a_BlockX - 1, a_BlockY, a_BlockZ) || !IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_WEST, E_PURE_DOWN))
+ if (IsUnstable(a_World, a_BlockX - 1, a_BlockY - 1, a_BlockZ) || !IsNotConnected(a_World, a_BlockX, a_BlockY - 1, a_BlockZ, BLOCK_FACE_WEST))
Neighbors[1] = true;
- if(IsUnstable(a_World, a_BlockX, a_BlockY, a_BlockZ - 1) || !IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH, E_PURE_DOWN))
+ if (IsUnstable(a_World, a_BlockX, a_BlockY - 1, a_BlockZ - 1) || !IsNotConnected(a_World, a_BlockX, a_BlockY - 1, a_BlockZ, BLOCK_FACE_NORTH))
Neighbors[2] = true;
- if(IsUnstable(a_World, a_BlockX, a_BlockY, a_BlockZ + 1) || !IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_SOUTH, E_PURE_DOWN))
+ if (IsUnstable(a_World, a_BlockX, a_BlockY - 1, a_BlockZ + 1) || !IsNotConnected(a_World, a_BlockX, a_BlockY - 1, a_BlockZ, BLOCK_FACE_SOUTH))
Neighbors[3] = true;
- if(IsUnstable(a_World, a_BlockX + 1, a_BlockY + 1, a_BlockZ) || !IsNotConnected(a_World, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_EAST, E_PURE_NONE))
- Neighbors[4] = true;
- if(IsUnstable(a_World, a_BlockX - 1, a_BlockY + 1, a_BlockZ) || !IsNotConnected(a_World, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_WEST, E_PURE_NONE))
- Neighbors[5] = true;
- if(IsUnstable(a_World, a_BlockX, a_BlockY + 1, a_BlockZ - 1) || !IsNotConnected(a_World, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_NORTH, E_PURE_NONE))
- Neighbors[6] = true;
- if(IsUnstable(a_World, a_BlockX, a_BlockY + 1, a_BlockZ + 1) || !IsNotConnected(a_World, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_SOUTH, E_PURE_NONE))
- Neighbors[7] = true;
- if(IsUnstable(a_World, a_BlockX + 1, a_BlockY - 1, a_BlockZ) || !IsNotConnected(a_World, a_BlockX, a_BlockY - 1, a_BlockZ, BLOCK_FACE_EAST))
- Neighbors[0] = true;
- if(IsUnstable(a_World, a_BlockX - 1, a_BlockY - 1, a_BlockZ) || !IsNotConnected(a_World, a_BlockX, a_BlockY - 1, a_BlockZ, BLOCK_FACE_WEST))
- Neighbors[1] = true;
- if(IsUnstable(a_World, a_BlockX, a_BlockY - 1, a_BlockZ - 1) || !IsNotConnected(a_World, a_BlockX, a_BlockY - 1, a_BlockZ, BLOCK_FACE_NORTH))
- Neighbors[2] = true;
- if(IsUnstable(a_World, a_BlockX, a_BlockY - 1, a_BlockZ + 1) || !IsNotConnected(a_World, a_BlockX, a_BlockY - 1, a_BlockZ, BLOCK_FACE_SOUTH))
- Neighbors[3] = true;
- for(int i = 0; i < 8; i++)
+ for (int i = 0; i < 8; i++)
{
- if(Neighbors[i])
+ if (Neighbors[i])
{
RailsCnt++;
}
}
- if(RailsCnt == 1)
+ if (RailsCnt == 1)
{
- if(Neighbors[7]) Meta = E_RAIL_ASCEND_SOUTH;
- else if(Neighbors[6]) Meta = E_RAIL_ASCEND_NORTH;
- else if(Neighbors[5]) Meta = E_RAIL_ASCEND_WEST;
- else if(Neighbors[4]) Meta = E_RAIL_ASCEND_EAST;
- else if(Neighbors[0] || Neighbors[1]) Meta = E_RAIL_EAST_WEST;
- else if(Neighbors[2] || Neighbors[3]) Meta = E_RAIL_NORTH_SOUTH;
+ if (Neighbors[7]) return E_RAIL_ASCEND_SOUTH;
+ else if (Neighbors[6]) return E_RAIL_ASCEND_NORTH;
+ else if (Neighbors[5]) return E_RAIL_ASCEND_WEST;
+ else if (Neighbors[4]) return E_RAIL_ASCEND_EAST;
+ else if (Neighbors[0] || Neighbors[1]) return E_RAIL_EAST_WEST;
+ else if (Neighbors[2] || Neighbors[3]) return E_RAIL_NORTH_SOUTH;
+ ASSERT(!"Weird neighbor count");
return Meta;
}
- for(int i = 0; i < 4; i++)
+ for (int i = 0; i < 4; i++)
{
- if(Neighbors[i+4])
+ if (Neighbors[i + 4])
{
Neighbors[i] = true;
}
}
- if(RailsCnt > 1)
+ if (RailsCnt > 1)
{
- if(Neighbors[3] && Neighbors[0]) Meta = E_RAIL_CURVED_SOUTH_EAST;
- else if(Neighbors[3] && Neighbors[1]) Meta = E_RAIL_CURVED_SOUTH_WEST;
- else if(Neighbors[2] && Neighbors[0]) Meta = E_RAIL_CURVED_NORTH_EAST;
- else if(Neighbors[2] && Neighbors[1]) Meta = E_RAIL_CURVED_NORTH_WEST;
- else if(Neighbors[7] && Neighbors[2]) Meta = E_RAIL_ASCEND_SOUTH;
- else if(Neighbors[3] && Neighbors[6]) Meta = E_RAIL_ASCEND_NORTH;
- else if(Neighbors[5] && Neighbors[0]) Meta = E_RAIL_ASCEND_WEST;
- else if(Neighbors[4] && Neighbors[1]) Meta = E_RAIL_ASCEND_EAST;
- else if(Neighbors[0] && Neighbors[1]) Meta = E_RAIL_EAST_WEST;
- else if(Neighbors[2] && Neighbors[3]) Meta = E_RAIL_NORTH_SOUTH;
+ if (Neighbors[3] && Neighbors[0]) return E_RAIL_CURVED_SOUTH_EAST;
+ else if(Neighbors[3] && Neighbors[1]) return E_RAIL_CURVED_SOUTH_WEST;
+ else if(Neighbors[2] && Neighbors[0]) return E_RAIL_CURVED_NORTH_EAST;
+ else if(Neighbors[2] && Neighbors[1]) return E_RAIL_CURVED_NORTH_WEST;
+ else if(Neighbors[7] && Neighbors[2]) return E_RAIL_ASCEND_SOUTH;
+ else if(Neighbors[3] && Neighbors[6]) return E_RAIL_ASCEND_NORTH;
+ else if(Neighbors[5] && Neighbors[0]) return E_RAIL_ASCEND_WEST;
+ else if(Neighbors[4] && Neighbors[1]) return E_RAIL_ASCEND_EAST;
+ else if(Neighbors[0] && Neighbors[1]) return E_RAIL_EAST_WEST;
+ else if(Neighbors[2] && Neighbors[3]) return E_RAIL_NORTH_SOUTH;
+ ASSERT(!"Weird neighbor count");
}
return Meta;
}
- bool IsUnstable(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ)
+
+ bool IsUnstable(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ)
{
- if(a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) != E_BLOCK_RAIL) return false;
- char Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
- switch(Meta)
+ if (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) != E_BLOCK_RAIL) return false;
+ NIBBLETYPE Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
+ switch (Meta)
{
case E_RAIL_NORTH_SOUTH:
{
@@ -238,15 +245,16 @@ public: return false;
}
- bool IsNotConnected(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Direction, char a_Pure = 0)
+
+ bool IsNotConnected(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Pure = 0)
{
- AddDirection(a_BlockX, a_BlockY, a_BlockZ, a_Direction, false);
- char Meta;
- if(a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) != E_BLOCK_RAIL)
+ AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, false);
+ NIBBLETYPE Meta;
+ if (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) != E_BLOCK_RAIL)
{
- if((a_World->GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ) != E_BLOCK_RAIL) || (a_Pure != E_PURE_UPDOWN))
+ if ((a_World->GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ) != E_BLOCK_RAIL) || (a_Pure != E_PURE_UPDOWN))
{
- if((a_World->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ) != E_BLOCK_RAIL) || (a_Pure == E_PURE_NONE))
+ if ((a_World->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ) != E_BLOCK_RAIL) || (a_Pure == E_PURE_NONE))
{
return true;
}
@@ -264,46 +272,65 @@ public: {
Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
}
- switch(a_Direction)
+
+ switch (a_BlockFace)
{
case BLOCK_FACE_NORTH:
{
- if(Meta == E_RAIL_NORTH_SOUTH ||
- Meta == E_RAIL_ASCEND_NORTH ||
- Meta == E_RAIL_ASCEND_SOUTH ||
- Meta == E_RAIL_CURVED_SOUTH_EAST ||
- Meta == E_RAIL_CURVED_SOUTH_WEST)
- return false;
+ if (
+ (Meta == E_RAIL_NORTH_SOUTH) ||
+ (Meta == E_RAIL_ASCEND_NORTH) ||
+ (Meta == E_RAIL_ASCEND_SOUTH) ||
+ (Meta == E_RAIL_CURVED_SOUTH_EAST) ||
+ (Meta == E_RAIL_CURVED_SOUTH_WEST)
+ )
+ {
+ return false;
+ }
break;
}
+
case BLOCK_FACE_SOUTH:
{
- if(Meta == E_RAIL_NORTH_SOUTH ||
- Meta == E_RAIL_ASCEND_NORTH ||
- Meta == E_RAIL_ASCEND_SOUTH ||
- Meta == E_RAIL_CURVED_NORTH_EAST ||
- Meta == E_RAIL_CURVED_NORTH_WEST)
- return false;
+ if (
+ (Meta == E_RAIL_NORTH_SOUTH) ||
+ (Meta == E_RAIL_ASCEND_NORTH) ||
+ (Meta == E_RAIL_ASCEND_SOUTH) ||
+ (Meta == E_RAIL_CURVED_NORTH_EAST) ||
+ (Meta == E_RAIL_CURVED_NORTH_WEST)
+ )
+ {
+ return false;
+ }
break;
}
+
case BLOCK_FACE_EAST:
{
- if(Meta == E_RAIL_EAST_WEST ||
- Meta == E_RAIL_ASCEND_EAST ||
- Meta == E_RAIL_ASCEND_WEST ||
- Meta == E_RAIL_CURVED_SOUTH_WEST ||
- Meta == E_RAIL_CURVED_NORTH_WEST)
- return false;
+ if (
+ (Meta == E_RAIL_EAST_WEST) ||
+ (Meta == E_RAIL_ASCEND_EAST) ||
+ (Meta == E_RAIL_ASCEND_WEST) ||
+ (Meta == E_RAIL_CURVED_SOUTH_WEST) ||
+ (Meta == E_RAIL_CURVED_NORTH_WEST)
+ )
+ {
+ return false;
+ }
break;
}
case BLOCK_FACE_WEST:
{
- if(Meta == E_RAIL_EAST_WEST ||
- Meta == E_RAIL_ASCEND_EAST ||
- Meta == E_RAIL_ASCEND_WEST ||
- Meta == E_RAIL_CURVED_SOUTH_EAST ||
- Meta == E_RAIL_CURVED_NORTH_EAST)
- return false;
+ if (
+ (Meta == E_RAIL_EAST_WEST) ||
+ (Meta == E_RAIL_ASCEND_EAST) ||
+ (Meta == E_RAIL_ASCEND_WEST) ||
+ (Meta == E_RAIL_CURVED_SOUTH_EAST) ||
+ (Meta == E_RAIL_CURVED_NORTH_EAST)
+ )
+ {
+ return false;
+ }
break;
}
}
|