summaryrefslogtreecommitdiffstats
path: root/src/Blocks
diff options
context:
space:
mode:
authorworktycho <work.tycho@gmail.com>2014-09-26 17:04:26 +0200
committerworktycho <work.tycho@gmail.com>2014-09-26 17:04:26 +0200
commit411c69b420acdc1e103a76a1a52e2c488aee5718 (patch)
tree06e33fb4b17d9c782ebb834a9821571f11ae103c /src/Blocks
parentImproved searching for spawn. (diff)
parentMerge branch 'master' into redstoneTests (diff)
downloadcuberite-411c69b420acdc1e103a76a1a52e2c488aee5718.tar
cuberite-411c69b420acdc1e103a76a1a52e2c488aee5718.tar.gz
cuberite-411c69b420acdc1e103a76a1a52e2c488aee5718.tar.bz2
cuberite-411c69b420acdc1e103a76a1a52e2c488aee5718.tar.lz
cuberite-411c69b420acdc1e103a76a1a52e2c488aee5718.tar.xz
cuberite-411c69b420acdc1e103a76a1a52e2c488aee5718.tar.zst
cuberite-411c69b420acdc1e103a76a1a52e2c488aee5718.zip
Diffstat (limited to '')
-rw-r--r--src/Blocks/BlockMobHead.h4
-rw-r--r--src/Blocks/BlockPiston.h2
-rw-r--r--src/Blocks/BlockPortal.h2
-rw-r--r--src/Blocks/BlockPumpkin.h6
-rw-r--r--src/Blocks/ChunkInterface.cpp132
-rw-r--r--src/Blocks/ChunkInterface.h63
-rw-r--r--src/Blocks/GetHandlerCompileTimeTemplate.h91
-rw-r--r--src/Blocks/WorldInterface.h7
8 files changed, 247 insertions, 60 deletions
diff --git a/src/Blocks/BlockMobHead.h b/src/Blocks/BlockMobHead.h
index b51155802..e21e42334 100644
--- a/src/Blocks/BlockMobHead.h
+++ b/src/Blocks/BlockMobHead.h
@@ -151,7 +151,7 @@ public:
a_ChunkInterface.SetBlock(a_BlockX - 1, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
// Spawn the wither:
- a_WorldInterface.SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtWither);
+ a_WorldInterface.SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, mtWither);
// Award Achievement
a_WorldInterface.ForEachPlayer(PlayerCallback);
@@ -181,7 +181,7 @@ public:
a_ChunkInterface.SetBlock(a_BlockX, a_BlockY, a_BlockZ - 1, E_BLOCK_AIR, 0);
// Spawn the wither:
- a_WorldInterface.SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtWither);
+ a_WorldInterface.SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, mtWither);
// Award Achievement
a_WorldInterface.ForEachPlayer(PlayerCallback);
diff --git a/src/Blocks/BlockPiston.h b/src/Blocks/BlockPiston.h
index 0bec603e3..78959595b 100644
--- a/src/Blocks/BlockPiston.h
+++ b/src/Blocks/BlockPiston.h
@@ -4,7 +4,7 @@
#include "BlockHandler.h"
-
+class cWorld;
class cBlockPistonHandler :
diff --git a/src/Blocks/BlockPortal.h b/src/Blocks/BlockPortal.h
index 8fac2a126..97ba26ee3 100644
--- a/src/Blocks/BlockPortal.h
+++ b/src/Blocks/BlockPortal.h
@@ -50,7 +50,7 @@ public:
int PosX = a_Chunk.GetPosX() * cChunkDef::Width + a_RelX;
int PosZ = a_Chunk.GetPosZ() * cChunkDef::Width + a_RelZ;
- a_WorldInterface.SpawnMob(PosX, a_RelY, PosZ, cMonster::mtZombiePigman);
+ a_WorldInterface.SpawnMob(PosX, a_RelY, PosZ, mtZombiePigman);
}
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
diff --git a/src/Blocks/BlockPumpkin.h b/src/Blocks/BlockPumpkin.h
index 15ac80fd7..275d1422a 100644
--- a/src/Blocks/BlockPumpkin.h
+++ b/src/Blocks/BlockPumpkin.h
@@ -36,7 +36,7 @@ public:
a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_AIR, 0);
a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 2, a_BlockZ, E_BLOCK_AIR, 0);
- a_WorldInterface.SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtSnowGolem);
+ a_WorldInterface.SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, mtSnowGolem);
return;
}
@@ -61,7 +61,7 @@ public:
a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 2, a_BlockZ, E_BLOCK_AIR, 0);
// Spawn the golem:
- a_WorldInterface.SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtIronGolem);
+ a_WorldInterface.SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, mtIronGolem);
}
else if (
(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ + 1) == E_BLOCK_IRON_BLOCK) &&
@@ -76,7 +76,7 @@ public:
a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 2, a_BlockZ, E_BLOCK_AIR, 0);
// Spawn the golem:
- a_WorldInterface.SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtIronGolem);
+ a_WorldInterface.SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, mtIronGolem);
}
}
diff --git a/src/Blocks/ChunkInterface.cpp b/src/Blocks/ChunkInterface.cpp
index 540581ae7..5ac4dcf80 100644
--- a/src/Blocks/ChunkInterface.cpp
+++ b/src/Blocks/ChunkInterface.cpp
@@ -2,11 +2,143 @@
#include "Globals.h"
#include "ChunkInterface.h"
+#include "ChunkMap.h"
#include "BlockHandler.h"
+
+
+
+
+
+BLOCKTYPE cChunkInterface::GetBlock(int a_BlockX, int a_BlockY, int a_BlockZ)
+{
+ return m_ChunkMap->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
+}
+
+
+
+
+
+BLOCKTYPE cChunkInterface::GetBlock(const Vector3i & a_Pos)
+{
+ return GetBlock(a_Pos.x, a_Pos.y, a_Pos.z);
+}
+
+
+
+
+
+NIBBLETYPE cChunkInterface::GetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ)
+{
+ return m_ChunkMap->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
+}
+
+
+
+
+
+
+bool cChunkInterface::GetBlockTypeMeta(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta)
+{
+ return m_ChunkMap->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta);
+}
+
+
+
+
+
+
+/** Sets the block at the specified coords to the specified value.
+Full processing, incl. updating neighbors, is performed.
+*/
+void cChunkInterface::SetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
+{
+ m_ChunkMap->SetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta);
+}
+
+
+
+
+
+
+void cChunkInterface::SetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_MetaData)
+{
+ m_ChunkMap->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_MetaData);
+}
+
+
+
+
+
+
+void cChunkInterface::QueueSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_TickDelay, BLOCKTYPE a_PreviousBlockType, cWorldInterface & a_WorldInterface)
+{
+ m_ChunkMap->QueueSetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_WorldInterface.GetWorldAge() + a_TickDelay, a_PreviousBlockType);
+}
+
+
+
+
+
+
+/** Sets the block at the specified coords to the specified value.
+The replacement doesn't trigger block updates.
+The replaced blocks aren't checked for block entities (block entity is leaked if it exists at this block)
+*/
+void cChunkInterface::FastSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
+{
+ m_ChunkMap->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta);
+}
+
+
+
+
+
+
+void cChunkInterface::FastSetBlock(const Vector3i & a_Pos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
+{
+ FastSetBlock( a_Pos.x, a_Pos.y, a_Pos.z, a_BlockType, a_BlockMeta);
+}
+
+
+
+
+
+
+void cChunkInterface::UseBlockEntity(cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ)
+{
+ m_ChunkMap->UseBlockEntity(a_Player, a_BlockX, a_BlockY, a_BlockZ);
+}
+
+
+
+
+
+
+bool cChunkInterface::ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ, cChunkDataCallback & a_Callback)
+{
+ return m_ChunkMap->ForEachChunkInRect(a_MinChunkX, a_MaxChunkX, a_MinChunkZ, a_MaxChunkZ, a_Callback);
+}
+
+
+
+
+
+
+bool cChunkInterface::WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes)
+{
+ return m_ChunkMap->WriteBlockArea(a_Area, a_MinBlockX, a_MinBlockY, a_MinBlockZ, a_DataTypes);
+}
+
+
+
+
+
+
bool cChunkInterface::DigBlock(cWorldInterface & a_WorldInterface, int a_X, int a_Y, int a_Z)
{
cBlockHandler * Handler = cBlockInfo::GetHandler(GetBlock(a_X, a_Y, a_Z));
Handler->OnDestroyed(*this, a_WorldInterface, a_X, a_Y, a_Z);
return m_ChunkMap->DigBlock(a_X, a_Y, a_Z);
}
+
diff --git a/src/Blocks/ChunkInterface.h b/src/Blocks/ChunkInterface.h
index d5f1f1273..51647dc04 100644
--- a/src/Blocks/ChunkInterface.h
+++ b/src/Blocks/ChunkInterface.h
@@ -1,13 +1,12 @@
#pragma once
-#include "../ChunkMap.h"
#include "../ForEachChunkProvider.h"
#include "WorldInterface.h"
-
+class cChunkMap;
class cChunkInterface:
public cForEachChunkProvider
@@ -16,70 +15,34 @@ public:
cChunkInterface(cChunkMap * a_ChunkMap) : m_ChunkMap(a_ChunkMap) {}
- BLOCKTYPE GetBlock(int a_BlockX, int a_BlockY, int a_BlockZ)
- {
- return m_ChunkMap->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
- }
- BLOCKTYPE GetBlock(const Vector3i & a_Pos)
- {
- return GetBlock(a_Pos.x, a_Pos.y, a_Pos.z);
- }
- NIBBLETYPE GetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ)
- {
- return m_ChunkMap->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
- }
+ BLOCKTYPE GetBlock(int a_BlockX, int a_BlockY, int a_BlockZ);
+ BLOCKTYPE GetBlock(const Vector3i & a_Pos);
+ NIBBLETYPE GetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ);
- bool GetBlockTypeMeta(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta)
- {
- return m_ChunkMap->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta);
- }
+ bool GetBlockTypeMeta(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta);
/** Sets the block at the specified coords to the specified value.
Full processing, incl. updating neighbors, is performed.
*/
- void SetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
- {
- m_ChunkMap->SetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta);
- }
+ void SetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
- void SetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_MetaData)
- {
- m_ChunkMap->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_MetaData);
- }
+ void SetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_MetaData);
- void QueueSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_TickDelay, BLOCKTYPE a_PreviousBlockType, cWorldInterface & a_WorldInterface)
- {
- m_ChunkMap->QueueSetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_WorldInterface.GetWorldAge() + a_TickDelay, a_PreviousBlockType);
- }
+ void QueueSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_TickDelay, BLOCKTYPE a_PreviousBlockType, cWorldInterface & a_WorldInterface);
/** Sets the block at the specified coords to the specified value.
The replacement doesn't trigger block updates.
The replaced blocks aren't checked for block entities (block entity is leaked if it exists at this block)
*/
- void FastSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
- {
- m_ChunkMap->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta);
- }
+ void FastSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
- void FastSetBlock(const Vector3i & a_Pos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
- {
- FastSetBlock( a_Pos.x, a_Pos.y, a_Pos.z, a_BlockType, a_BlockMeta);
- }
+ void FastSetBlock(const Vector3i & a_Pos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
- void UseBlockEntity(cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ)
- {
- m_ChunkMap->UseBlockEntity(a_Player, a_BlockX, a_BlockY, a_BlockZ);
- }
+ void UseBlockEntity(cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ);
- virtual bool ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ, cChunkDataCallback & a_Callback) override
- {
- return m_ChunkMap->ForEachChunkInRect(a_MinChunkX, a_MaxChunkX, a_MinChunkZ, a_MaxChunkZ, a_Callback);
- }
+ virtual bool ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ, cChunkDataCallback & a_Callback) override;
- virtual bool WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes) override
- {
- return m_ChunkMap->WriteBlockArea(a_Area, a_MinBlockX, a_MinBlockY, a_MinBlockZ, a_DataTypes);
- }
+ virtual bool WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes) override;
bool DigBlock(cWorldInterface & a_WorldInterface, int a_X, int a_Y, int a_Z);
diff --git a/src/Blocks/GetHandlerCompileTimeTemplate.h b/src/Blocks/GetHandlerCompileTimeTemplate.h
new file mode 100644
index 000000000..3466b5426
--- /dev/null
+++ b/src/Blocks/GetHandlerCompileTimeTemplate.h
@@ -0,0 +1,91 @@
+
+#pragma once
+
+class cBlockTorchHandler;
+class cBlockLeverHandler;
+class cBlockButtonHandler;
+class cBlockTripwireHookHandler;
+class cBlockDoorHandler;
+class cBlockPistonHandler;
+
+
+
+
+
+
+template<BLOCKTYPE T>
+class GetHandlerCompileTime;
+
+
+
+
+
+
+
+template<>
+class GetHandlerCompileTime<E_BLOCK_TORCH>
+{
+public:
+ typedef cBlockTorchHandler type;
+};
+
+
+
+
+
+
+template<>
+class GetHandlerCompileTime<E_BLOCK_LEVER>
+{
+public:
+ typedef cBlockLeverHandler type;
+};
+
+
+
+
+
+
+template<>
+class GetHandlerCompileTime<E_BLOCK_STONE_BUTTON>
+{
+public:
+ typedef cBlockButtonHandler type;
+};
+
+
+
+
+
+
+template<>
+class GetHandlerCompileTime<E_BLOCK_TRIPWIRE_HOOK>
+{
+public:
+ typedef cBlockTripwireHookHandler type;
+};
+
+
+
+
+
+
+template<>
+class GetHandlerCompileTime<E_BLOCK_WOODEN_DOOR>
+{
+public:
+ typedef cBlockDoorHandler type;
+};
+
+
+
+
+
+
+template<>
+class GetHandlerCompileTime<E_BLOCK_PISTON>
+{
+public:
+ typedef cBlockPistonHandler type;
+};
+
diff --git a/src/Blocks/WorldInterface.h b/src/Blocks/WorldInterface.h
index 889ef1d87..106c314e7 100644
--- a/src/Blocks/WorldInterface.h
+++ b/src/Blocks/WorldInterface.h
@@ -2,14 +2,15 @@
#pragma once
#include "BroadcastInterface.h"
-#include "../Mobs/Monster.h"
+#include "../Mobs/MonsterTypes.h"
class cItems;
typedef cItemCallback<cBlockEntity> cBlockEntityCallback;
-
+class cMonster;
+class cPlayer;
class cWorldInterface
@@ -33,7 +34,7 @@ public:
virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_SpeedX, double a_SpeedY, double a_SpeedZ, bool IsPlayerCreated = false) = 0;
/** Spawns a mob of the specified type. Returns the mob's EntityID if recognized and spawned, <0 otherwise */
- virtual int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, cMonster::eType a_MonsterType) = 0;
+ virtual int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, eMonsterType a_MonsterType) = 0;
/** Spawns an experience orb at the given location with the given reward. It returns the UniqueID of the spawned experience orb. */
virtual int SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward) = 0;