summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Bindings/LuaChunkStay.cpp3
-rw-r--r--src/Bindings/LuaState.cpp31
-rw-r--r--src/Bindings/LuaState.h6
-rw-r--r--src/Bindings/ManualBindings.cpp11
-rw-r--r--src/Bindings/Plugin.h3
-rw-r--r--src/Bindings/PluginLua.cpp61
-rw-r--r--src/Bindings/PluginLua.h3
-rw-r--r--src/Bindings/PluginManager.cpp65
-rw-r--r--src/Bindings/PluginManager.h11
-rw-r--r--src/Bindings/lua51.dll (renamed from src/Bindings/lua5.1.dll)bin167424 -> 167424 bytes
-rw-r--r--src/Bindings/tolua++.exebin484864 -> 200192 bytes
-rw-r--r--src/BlockArea.cpp333
-rw-r--r--src/BlockArea.h46
-rw-r--r--src/BlockEntities/DispenserEntity.cpp6
-rw-r--r--src/BlockEntities/HopperEntity.cpp2
-rw-r--r--src/BlockID.h27
-rw-r--r--src/BlockInfo.cpp4
-rw-r--r--src/Blocks/BlockAnvil.h63
-rw-r--r--src/Blocks/BlockBed.cpp73
-rw-r--r--src/Blocks/BlockCake.h55
-rw-r--r--src/Blocks/BlockDirt.h5
-rw-r--r--src/Blocks/BlockHandler.cpp6
-rw-r--r--src/Blocks/BlockLeaves.h1
-rw-r--r--src/Blocks/BlockLilypad.h28
-rw-r--r--src/Blocks/BlockMobHead.h14
-rw-r--r--src/Blocks/BlockMushroom.h4
-rw-r--r--src/Blocks/BlockMycelium.h2
-rw-r--r--src/Blocks/BlockSideways.h8
-rw-r--r--src/Blocks/BlockVine.h7
-rw-r--r--src/Blocks/BroadcastInterface.h8
-rw-r--r--src/Blocks/WorldInterface.h11
-rw-r--r--src/BoundingBox.cpp2
-rw-r--r--src/ByteBuffer.cpp32
-rw-r--r--src/ByteBuffer.h2
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/Chunk.cpp13
-rw-r--r--src/ChunkDef.h21
-rw-r--r--src/ChunkMap.cpp131
-rw-r--r--src/ClientHandle.cpp35
-rw-r--r--src/CommandOutput.cpp4
-rw-r--r--src/CommandOutput.h2
-rw-r--r--src/CompositeChat.cpp64
-rw-r--r--src/CraftingRecipes.cpp4
-rw-r--r--src/Cuboid.cpp14
-rw-r--r--src/Cuboid.h1
-rw-r--r--src/DeadlockDetect.cpp6
-rw-r--r--src/DeadlockDetect.h2
-rw-r--r--src/Defines.h32
-rw-r--r--src/Entities/EnderCrystal.cpp56
-rw-r--r--src/Entities/EnderCrystal.h33
-rw-r--r--src/Entities/Entity.cpp381
-rw-r--r--src/Entities/Entity.h25
-rw-r--r--src/Entities/ExpOrb.cpp26
-rw-r--r--src/Entities/ExpOrb.h23
-rw-r--r--src/Entities/FallingBlock.cpp19
-rw-r--r--src/Entities/HangingEntity.cpp53
-rw-r--r--src/Entities/HangingEntity.h49
-rw-r--r--src/Entities/ItemFrame.cpp39
-rw-r--r--src/Entities/ItemFrame.h22
-rw-r--r--src/Entities/Pickup.cpp2
-rw-r--r--src/Entities/Pickup.h23
-rw-r--r--src/Entities/Player.cpp38
-rw-r--r--src/Entities/Player.h181
-rw-r--r--src/Entities/ProjectileEntity.cpp12
-rw-r--r--src/ForEachChunkProvider.h2
-rw-r--r--src/FurnaceRecipe.cpp2
-rw-r--r--src/Generating/BioGen.cpp16
-rw-r--r--src/Generating/ChunkDesc.cpp6
-rw-r--r--src/Generating/ChunkGenerator.cpp4
-rw-r--r--src/Generating/CompoGen.cpp4
-rw-r--r--src/Generating/HeiGen.cpp2
-rw-r--r--src/Generating/Noise3DGenerator.cpp2
-rw-r--r--src/Generating/PieceGenerator.cpp11
-rw-r--r--src/Generating/PieceGenerator.h4
-rw-r--r--src/Generating/Prefab.cpp312
-rw-r--r--src/Generating/Prefab.h105
-rw-r--r--src/Generating/StructGen.cpp4
-rw-r--r--src/Globals.h54
-rw-r--r--src/HTTPServer/HTTPServer.h4
-rw-r--r--src/Inventory.h2
-rw-r--r--src/Item.cpp8
-rw-r--r--src/ItemGrid.h46
-rw-r--r--src/Items/ItemBucket.h8
-rw-r--r--src/Items/ItemCake.h41
-rw-r--r--src/Items/ItemHandler.cpp7
-rw-r--r--src/Items/ItemItemFrame.h6
-rw-r--r--src/Items/ItemLighter.h24
-rw-r--r--src/Items/ItemLilypad.h109
-rw-r--r--src/Items/ItemMinecart.h6
-rw-r--r--src/Items/ItemShears.h5
-rw-r--r--src/LightingThread.cpp6
-rw-r--r--src/LinearUpscale.h46
-rw-r--r--src/Log.cpp2
-rw-r--r--src/Log.h4
-rw-r--r--src/MCLogger.h16
-rw-r--r--src/Map.cpp4
-rw-r--r--src/Map.h2
-rw-r--r--src/MersenneTwister.h10
-rw-r--r--src/MobSpawner.cpp2
-rw-r--r--src/Mobs/Monster.cpp11
-rw-r--r--src/Mobs/Villager.h2
-rw-r--r--src/Mobs/Wither.cpp52
-rw-r--r--src/Mobs/Wither.h13
-rw-r--r--src/Noise.cpp8
-rw-r--r--src/OSSupport/BlockingTCPLink.cpp2
-rw-r--r--src/OSSupport/File.h2
-rw-r--r--src/OSSupport/GZipFile.cpp5
-rw-r--r--src/OSSupport/IsThread.h2
-rw-r--r--src/OSSupport/ListenThread.h20
-rw-r--r--src/OSSupport/Socket.cpp3
-rw-r--r--src/OSSupport/SocketThreads.cpp2
-rw-r--r--src/Protocol/Protocol125.cpp13
-rw-r--r--src/Protocol/Protocol132.cpp2
-rw-r--r--src/Protocol/Protocol16x.cpp4
-rw-r--r--src/Protocol/Protocol17x.cpp22
-rw-r--r--src/RCONServer.h2
-rw-r--r--src/Root.cpp11
-rw-r--r--src/Scoreboard.cpp6
-rw-r--r--src/Server.cpp2
-rw-r--r--src/Simulator/FireSimulator.cpp14
-rw-r--r--src/Simulator/FluidSimulator.cpp1
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator.cpp4
-rw-r--r--src/StringUtils.cpp8
-rw-r--r--src/StringUtils.h10
-rw-r--r--src/UI/Window.cpp2
-rw-r--r--src/UI/WindowOwner.h4
-rw-r--r--src/Vector3.h25
-rw-r--r--src/World.cpp72
-rw-r--r--src/World.h103
-rw-r--r--src/WorldStorage/FastNBT.cpp16
-rw-r--r--src/WorldStorage/FireworksSerializer.cpp28
-rw-r--r--src/WorldStorage/MapSerializer.cpp6
-rw-r--r--src/WorldStorage/NBTChunkSerializer.cpp80
-rw-r--r--src/WorldStorage/NBTChunkSerializer.h8
-rw-r--r--src/WorldStorage/SchematicFileSerializer.cpp10
-rw-r--r--src/WorldStorage/WSSAnvil.cpp232
-rw-r--r--src/WorldStorage/WSSAnvil.h7
-rw-r--r--src/WorldStorage/WSSCompact.cpp13
-rw-r--r--src/main.cpp1
139 files changed, 2858 insertions, 1104 deletions
diff --git a/src/Bindings/LuaChunkStay.cpp b/src/Bindings/LuaChunkStay.cpp
index 0e982637f..db865cfa4 100644
--- a/src/Bindings/LuaChunkStay.cpp
+++ b/src/Bindings/LuaChunkStay.cpp
@@ -131,9 +131,6 @@ void cLuaChunkStay::Enable(cChunkMap & a_ChunkMap, int a_OnChunkAvailableStackPo
void cLuaChunkStay::OnChunkAvailable(int a_ChunkX, int a_ChunkZ)
{
- // DEBUG:
- LOGD("LuaChunkStay: Chunk [%d, %d] is now available, calling the callback...", a_ChunkX, a_ChunkZ);
-
cPluginLua::cOperation Op(m_Plugin);
Op().Call((int)m_OnChunkAvailable, a_ChunkX, a_ChunkZ);
}
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp
index dfc428bbc..13eb17f7d 100644
--- a/src/Bindings/LuaState.cpp
+++ b/src/Bindings/LuaState.cpp
@@ -479,6 +479,18 @@ void cLuaState::Push(cEntity * a_Entity)
+void cLuaState::Push(cProjectileEntity * a_ProjectileEntity)
+{
+ ASSERT(IsValid());
+
+ tolua_pushusertype(m_LuaState, a_ProjectileEntity, "cProjectileEntity");
+ m_NumCurrentFunctionArgs += 1;
+}
+
+
+
+
+
void cLuaState::Push(cMonster * a_Monster)
{
ASSERT(IsValid());
@@ -689,9 +701,10 @@ void cLuaState::Push(void * a_Ptr)
ASSERT(IsValid());
// Investigate the cause of this - what is the callstack?
- LOGWARNING("Lua engine encountered an error - attempting to push a plain pointer");
+ // One code path leading here is the OnHookExploding / OnHookExploded with exotic parameters. Need to decide what to do with them
+ LOGWARNING("Lua engine: attempting to push a plain pointer, pushing nil instead.");
+ LOGWARNING("This indicates an unimplemented part of MCS bindings");
LogStackTrace();
- ASSERT(!"A plain pointer should never be pushed on Lua stack");
lua_pushnil(m_LuaState);
m_NumCurrentFunctionArgs += 1;
@@ -1080,20 +1093,20 @@ bool cLuaState::ReportErrors(lua_State * a_LuaState, int a_Status)
-void cLuaState::LogStackTrace(void)
+void cLuaState::LogStackTrace(int a_StartingDepth)
{
- LogStackTrace(m_LuaState);
+ LogStackTrace(m_LuaState, a_StartingDepth);
}
-void cLuaState::LogStackTrace(lua_State * a_LuaState)
+void cLuaState::LogStackTrace(lua_State * a_LuaState, int a_StartingDepth)
{
LOGWARNING("Stack trace:");
lua_Debug entry;
- int depth = 0;
+ int depth = a_StartingDepth;
while (lua_getstack(a_LuaState, depth, &entry))
{
lua_getinfo(a_LuaState, "Sln", &entry);
@@ -1285,7 +1298,9 @@ void cLuaState::LogStack(lua_State * a_LuaState, const char * a_Header)
{
UNUSED(a_Header); // The param seems unused when compiling for release, so the compiler warns
- LOGD((a_Header != NULL) ? a_Header : "Lua C API Stack contents:");
+
+ // Format string consisting only of %s is used to appease the compiler
+ LOGD("%s",(a_Header != NULL) ? a_Header : "Lua C API Stack contents:");
for (int i = lua_gettop(a_LuaState); i > 0; i--)
{
AString Value;
@@ -1310,7 +1325,7 @@ void cLuaState::LogStack(lua_State * a_LuaState, const char * a_Header)
int cLuaState::ReportFnCallErrors(lua_State * a_LuaState)
{
LOGWARNING("LUA: %s", lua_tostring(a_LuaState, -1));
- LogStackTrace(a_LuaState);
+ LogStackTrace(a_LuaState, 1);
return 1; // We left the error message on the stack as the return value
}
diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h
index 73f9629cb..b9ca2f29b 100644
--- a/src/Bindings/LuaState.h
+++ b/src/Bindings/LuaState.h
@@ -38,6 +38,7 @@ extern "C"
class cWorld;
class cPlayer;
class cEntity;
+class cProjectileEntity;
class cMonster;
class cItem;
class cItems;
@@ -183,6 +184,7 @@ public:
void Push(cPlayer * a_Player);
void Push(const cPlayer * a_Player);
void Push(cEntity * a_Entity);
+ void Push(cProjectileEntity * a_ProjectileEntity);
void Push(cMonster * a_Monster);
void Push(cItem * a_Item);
void Push(cItems * a_Items);
@@ -868,10 +870,10 @@ public:
static bool ReportErrors(lua_State * a_LuaState, int status);
/** Logs all items in the current stack trace to the server console */
- void LogStackTrace(void);
+ void LogStackTrace(int a_StartingDepth = 0);
/** Logs all items in the current stack trace to the server console */
- static void LogStackTrace(lua_State * a_LuaState);
+ static void LogStackTrace(lua_State * a_LuaState, int a_StartingDepth = 0);
/** Returns the type of the item on the specified position in the stack */
AString GetTypeText(int a_StackPos);
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index a5247bbe6..20bbc48f2 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -1497,7 +1497,8 @@ static int tolua_cPluginManager_BindCommand(lua_State * L)
}
Plugin->BindCommand(Command, FnRef);
- return 0;
+ lua_pushboolean(L, true);
+ return 1;
}
@@ -1521,7 +1522,10 @@ static int tolua_cPluginManager_BindConsoleCommand(lua_State * L)
// Read the arguments to this API call:
tolua_Error tolua_err;
int idx = 1;
- if (tolua_isusertype(L, 1, "cPluginManager", 0, &tolua_err))
+ if (
+ tolua_isusertype(L, 1, "cPluginManager", 0, &tolua_err) ||
+ tolua_isusertable(L, 1, "cPluginManager", 0, &tolua_err)
+ )
{
idx++;
}
@@ -1561,7 +1565,8 @@ static int tolua_cPluginManager_BindConsoleCommand(lua_State * L)
}
Plugin->BindConsoleCommand(Command, FnRef);
- return 0;
+ lua_pushboolean(L, true);
+ return 1;
}
diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h
index 949e4693a..df0bd4dcc 100644
--- a/src/Bindings/Plugin.h
+++ b/src/Bindings/Plugin.h
@@ -46,6 +46,7 @@ public:
* On all these functions, return true if you want to override default behavior and not call other plugins on that callback.
* You can also return false, so default behavior is used.
**/
+ virtual bool OnBlockSpread (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, eSpreadSource a_Source) = 0;
virtual bool OnBlockToPickups (cWorld * a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups) = 0;
virtual bool OnChat (cPlayer * a_Player, AString & a_Message) = 0;
virtual bool OnChunkAvailable (cWorld * a_World, int a_ChunkX, int a_ChunkZ) = 0;
@@ -89,6 +90,8 @@ public:
virtual bool OnPluginsLoaded (void) = 0;
virtual bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) = 0;
virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) = 0;
+ virtual bool OnProjectileHitBlock (cProjectileEntity & a_Projectile) = 0;
+ virtual bool OnProjectileHitEntity (cProjectileEntity & a_Projectile, cEntity & a_HitEntity) = 0;
virtual bool OnSpawnedEntity (cWorld & a_World, cEntity & a_Entity) = 0;
virtual bool OnSpawnedMonster (cWorld & a_World, cMonster & a_Monster) = 0;
virtual bool OnSpawningEntity (cWorld & a_World, cEntity & a_Entity) = 0;
diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp
index cccbc3c93..7e69e0f4b 100644
--- a/src/Bindings/PluginLua.cpp
+++ b/src/Bindings/PluginLua.cpp
@@ -195,6 +195,26 @@ void cPluginLua::Tick(float a_Dt)
+bool cPluginLua::OnBlockSpread(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, eSpreadSource a_Source)
+{
+ cCSLock Lock(m_CriticalSection);
+ bool res = false;
+ cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_BLOCK_SPREAD];
+ for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
+ {
+ m_LuaState.Call((int)(**itr), a_World, a_BlockX, a_BlockY, a_BlockZ, a_Source, cLuaState::Return, res);
+ if (res)
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+
+
+
bool cPluginLua::OnBlockToPickups(cWorld * a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups)
{
cCSLock Lock(m_CriticalSection);
@@ -1088,6 +1108,46 @@ bool cPluginLua::OnPreCrafting(const cPlayer * a_Player, const cCraftingGrid * a
+bool cPluginLua::OnProjectileHitBlock(cProjectileEntity & a_Projectile)
+{
+ cCSLock Lock(m_CriticalSection);
+ bool res = false;
+ cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PROJECTILE_HIT_BLOCK];
+ for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
+ {
+ m_LuaState.Call((int)(**itr), &a_Projectile, cLuaState::Return, res);
+ if (res)
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+
+
+
+bool cPluginLua::OnProjectileHitEntity(cProjectileEntity & a_Projectile, cEntity & a_HitEntity)
+{
+ cCSLock Lock(m_CriticalSection);
+ bool res = false;
+ cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PROJECTILE_HIT_ENTITY];
+ for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
+ {
+ m_LuaState.Call((int)(**itr), &a_Projectile, &a_HitEntity, cLuaState::Return, res);
+ if (res)
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+
+
+
bool cPluginLua::OnSpawnedEntity(cWorld & a_World, cEntity & a_Entity)
{
cCSLock Lock(m_CriticalSection);
@@ -1430,6 +1490,7 @@ const char * cPluginLua::GetHookFnName(int a_HookType)
{
switch (a_HookType)
{
+ case cPluginManager::HOOK_BLOCK_SPREAD: return "OnBlockSpread";
case cPluginManager::HOOK_BLOCK_TO_PICKUPS: return "OnBlockToPickups";
case cPluginManager::HOOK_CHAT: return "OnChat";
case cPluginManager::HOOK_CHUNK_AVAILABLE: return "OnChunkAvailable";
diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h
index a177f5288..59542d23a 100644
--- a/src/Bindings/PluginLua.h
+++ b/src/Bindings/PluginLua.h
@@ -69,6 +69,7 @@ public:
virtual void Tick(float a_Dt) override;
+ virtual bool OnBlockSpread (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, eSpreadSource a_Source) override;
virtual bool OnBlockToPickups (cWorld * a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups) override;
virtual bool OnChat (cPlayer * a_Player, AString & a_Message) override;
virtual bool OnChunkAvailable (cWorld * a_World, int a_ChunkX, int a_ChunkZ) override;
@@ -112,6 +113,8 @@ public:
virtual bool OnPluginsLoaded (void) override;
virtual bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
+ virtual bool OnProjectileHitBlock (cProjectileEntity & a_Projectile) override;
+ virtual bool OnProjectileHitEntity (cProjectileEntity & a_Projectile, cEntity & a_HitEntity) override;
virtual bool OnSpawnedEntity (cWorld & a_World, cEntity & a_Entity) override;
virtual bool OnSpawnedMonster (cWorld & a_World, cMonster & a_Monster) override;
virtual bool OnSpawningEntity (cWorld & a_World, cEntity & a_Entity) override;
diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp
index c7df6357e..6a5356c0b 100644
--- a/src/Bindings/PluginManager.cpp
+++ b/src/Bindings/PluginManager.cpp
@@ -205,6 +205,27 @@ void cPluginManager::Tick(float a_Dt)
+bool cPluginManager::CallHookBlockSpread(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, eSpreadSource a_Source)
+{
+ HookMap::iterator Plugins = m_Hooks.find(HOOK_BLOCK_SPREAD);
+ if (Plugins == m_Hooks.end())
+ {
+ return false;
+ }
+ for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
+ {
+ if ((*itr)->OnBlockSpread(a_World, a_BlockX, a_BlockY, a_BlockZ, a_Source))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+
+
+
bool cPluginManager::CallHookBlockToPickups(
cWorld * a_World, cEntity * a_Digger,
int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta,
@@ -248,7 +269,7 @@ bool cPluginManager::CallHookChat(cPlayer * a_Player, AString & a_Message)
{
AStringVector Split(StringSplit(a_Message, " "));
ASSERT(!Split.empty()); // This should not happen - we know there's at least one char in the message so the split needs to be at least one item long
- a_Player->SendMessageInfo(Printf("Unknown command: \"%s\"", Split[0].c_str()));
+ a_Player->SendMessageInfo(Printf("Unknown command: \"%s\"", a_Message.c_str()));
LOGINFO("Player %s issued an unknown command: \"%s\"", a_Player->GetName().c_str(), a_Message.c_str());
return true; // Cancel sending
}
@@ -1133,6 +1154,48 @@ bool cPluginManager::CallHookPreCrafting(const cPlayer * a_Player, const cCrafti
+bool cPluginManager::CallHookProjectileHitBlock(cProjectileEntity & a_Projectile)
+{
+ HookMap::iterator Plugins = m_Hooks.find(HOOK_PROJECTILE_HIT_BLOCK);
+ if (Plugins == m_Hooks.end())
+ {
+ return false;
+ }
+ for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
+ {
+ if ((*itr)->OnProjectileHitBlock(a_Projectile))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+
+
+
+bool cPluginManager::CallHookProjectileHitEntity(cProjectileEntity & a_Projectile, cEntity & a_HitEntity)
+{
+ HookMap::iterator Plugins = m_Hooks.find(HOOK_PROJECTILE_HIT_ENTITY);
+ if (Plugins == m_Hooks.end())
+ {
+ return false;
+ }
+ for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
+ {
+ if ((*itr)->OnProjectileHitEntity(a_Projectile, a_HitEntity))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+
+
+
bool cPluginManager::CallHookSpawnedEntity(cWorld & a_World, cEntity & a_Entity)
{
HookMap::iterator Plugins = m_Hooks.find(HOOK_SPAWNED_ENTITY);
diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h
index 44bc5a8d7..512bc1351 100644
--- a/src/Bindings/PluginManager.h
+++ b/src/Bindings/PluginManager.h
@@ -18,6 +18,9 @@ class cChunkDesc;
// fwd: Entities/Entity.h
class cEntity;
+// fwd: Entities/ProjectileEntity.h
+class cProjectileEntity;
+
// fwd: Mobs/Monster.h
class cMonster;
@@ -58,6 +61,7 @@ public: // tolua_export
// tolua_begin
enum PluginHook
{
+ HOOK_BLOCK_SPREAD,
HOOK_BLOCK_TO_PICKUPS,
HOOK_CHAT,
HOOK_CHUNK_AVAILABLE,
@@ -101,6 +105,8 @@ public: // tolua_export
HOOK_PLUGINS_LOADED,
HOOK_POST_CRAFTING,
HOOK_PRE_CRAFTING,
+ HOOK_PROJECTILE_HIT_BLOCK,
+ HOOK_PROJECTILE_HIT_ENTITY,
HOOK_SPAWNED_ENTITY,
HOOK_SPAWNED_MONSTER,
HOOK_SPAWNING_ENTITY,
@@ -127,6 +133,8 @@ public: // tolua_export
class cCommandEnumCallback
{
public:
+ virtual ~cCommandEnumCallback() {}
+
/** Called for each command; return true to abort enumeration
For console commands, a_Permission is not used (set to empty string)
*/
@@ -154,6 +162,7 @@ public: // tolua_export
unsigned int GetNumPlugins() const; // tolua_export
// Calls for individual hooks. Each returns false if the action is to continue or true if the plugin wants to abort
+ bool CallHookBlockSpread (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, eSpreadSource a_Source);
bool CallHookBlockToPickups (cWorld * a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups);
bool CallHookChat (cPlayer * a_Player, AString & a_Message);
bool CallHookChunkAvailable (cWorld * a_World, int a_ChunkX, int a_ChunkZ);
@@ -197,6 +206,8 @@ public: // tolua_export
bool CallHookPluginsLoaded (void);
bool CallHookPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
bool CallHookPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
+ bool CallHookProjectileHitBlock (cProjectileEntity & a_Projectile);
+ bool CallHookProjectileHitEntity (cProjectileEntity & a_Projectile, cEntity & a_HitEntity);
bool CallHookSpawnedEntity (cWorld & a_World, cEntity & a_Entity);
bool CallHookSpawnedMonster (cWorld & a_World, cMonster & a_Monster);
bool CallHookSpawningEntity (cWorld & a_World, cEntity & a_Entity);
diff --git a/src/Bindings/lua5.1.dll b/src/Bindings/lua51.dll
index 515cf8b30..515cf8b30 100644
--- a/src/Bindings/lua5.1.dll
+++ b/src/Bindings/lua51.dll
Binary files differ
diff --git a/src/Bindings/tolua++.exe b/src/Bindings/tolua++.exe
index e5cec6d78..1e3cc7789 100644
--- a/src/Bindings/tolua++.exe
+++ b/src/Bindings/tolua++.exe
Binary files differ
diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp
index 406e18a3b..f6d54e41c 100644
--- a/src/BlockArea.cpp
+++ b/src/BlockArea.cpp
@@ -162,13 +162,6 @@ static void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBB
// cBlockArea:
cBlockArea::cBlockArea(void) :
- m_OriginX(0),
- m_OriginY(0),
- m_OriginZ(0),
- m_SizeX(0),
- m_SizeY(0),
- m_SizeZ(0),
- m_WEOffset(0, 0, 0),
m_BlockTypes(NULL),
m_BlockMetas(NULL),
m_BlockLight(NULL),
@@ -195,12 +188,8 @@ void cBlockArea::Clear(void)
delete[] m_BlockMetas; m_BlockMetas = NULL;
delete[] m_BlockLight; m_BlockLight = NULL;
delete[] m_BlockSkyLight; m_BlockSkyLight = NULL;
- m_OriginX = 0;
- m_OriginY = 0;
- m_OriginZ = 0;
- m_SizeX = 0;
- m_SizeY = 0;
- m_SizeZ = 0;
+ m_Origin.Set(0, 0, 0);
+ m_Size.Set(0, 0, 0);
}
@@ -243,12 +232,17 @@ void cBlockArea::Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
m_BlockSkyLight[i] = 0x0f;
}
}
- m_SizeX = a_SizeX;
- m_SizeY = a_SizeY;
- m_SizeZ = a_SizeZ;
- m_OriginX = 0;
- m_OriginY = 0;
- m_OriginZ = 0;
+ m_Size.Set(a_SizeX, a_SizeY, a_SizeZ);
+ m_Origin.Set(0, 0, 0);
+}
+
+
+
+
+
+void cBlockArea::Create(const Vector3i & a_Size, int a_DataTypes)
+{
+ Create(a_Size.x, a_Size.y, a_Size.z, a_DataTypes);
}
@@ -275,9 +269,7 @@ void cBlockArea::SetWEOffset(const Vector3i & a_Offset)
void cBlockArea::SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ)
{
- m_OriginX = a_OriginX;
- m_OriginY = a_OriginY;
- m_OriginZ = a_OriginZ;
+ m_Origin.Set(a_OriginX, a_OriginY, a_OriginZ);
}
@@ -286,7 +278,7 @@ void cBlockArea::SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ)
void cBlockArea::SetOrigin(const Vector3i & a_Origin)
{
- SetOrigin(a_Origin.x, a_Origin.y, a_Origin.z);
+ m_Origin.Set(a_Origin.x, a_Origin.y, a_Origin.z);
}
@@ -342,9 +334,7 @@ bool cBlockArea::Read(cForEachChunkProvider * a_ForEachChunkProvider, int a_MinB
{
return false;
}
- m_OriginX = a_MinBlockX;
- m_OriginY = a_MinBlockY;
- m_OriginZ = a_MinBlockZ;
+ m_Origin.Set(a_MinBlockX, a_MinBlockY, a_MinBlockZ);
cChunkReader Reader(*this);
// Convert block coords to chunks coords:
@@ -408,10 +398,10 @@ bool cBlockArea::Write(cForEachChunkProvider * a_ForEachChunkProvider, int a_Min
LOGWARNING("%s: MinBlockY less than zero, adjusting to zero", __FUNCTION__);
a_MinBlockY = 0;
}
- else if (a_MinBlockY > cChunkDef::Height - m_SizeY)
+ else if (a_MinBlockY > cChunkDef::Height - m_Size.y)
{
LOGWARNING("%s: MinBlockY + m_SizeY more than chunk height, adjusting to chunk height", __FUNCTION__);
- a_MinBlockY = cChunkDef::Height - m_SizeY;
+ a_MinBlockY = cChunkDef::Height - m_Size.y;
}
return a_ForEachChunkProvider->WriteBlockArea(*this, a_MinBlockX, a_MinBlockY, a_MinBlockZ, a_DataTypes);
@@ -443,10 +433,8 @@ void cBlockArea::CopyTo(cBlockArea & a_Into) const
}
a_Into.Clear();
- a_Into.SetSize(m_SizeX, m_SizeY, m_SizeZ, GetDataTypes());
- a_Into.m_OriginX = m_OriginX;
- a_Into.m_OriginY = m_OriginY;
- a_Into.m_OriginZ = m_OriginZ;
+ a_Into.SetSize(m_Size.x, m_Size.y, m_Size.z, GetDataTypes());
+ a_Into.m_Origin = m_Origin;
int BlockCount = GetBlockCount();
if (HasBlockTypes())
{
@@ -487,9 +475,9 @@ void cBlockArea::DumpToRawFile(const AString & a_FileName)
LOGWARNING("cBlockArea: Cannot open file \"%s\" for raw dump", a_FileName.c_str());
return;
}
- UInt32 SizeX = ntohl(m_SizeX);
- UInt32 SizeY = ntohl(m_SizeY);
- UInt32 SizeZ = ntohl(m_SizeZ);
+ UInt32 SizeX = ntohl(m_Size.x);
+ UInt32 SizeY = ntohl(m_Size.y);
+ UInt32 SizeZ = ntohl(m_Size.z);
f.Write(&SizeX, 4);
f.Write(&SizeY, 4);
f.Write(&SizeZ, 4);
@@ -532,13 +520,13 @@ void cBlockArea::DumpToRawFile(const AString & a_FileName)
void cBlockArea::Crop(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ)
{
if (
- (a_AddMinX + a_SubMaxX >= m_SizeX) ||
- (a_AddMinY + a_SubMaxY >= m_SizeY) ||
- (a_AddMinZ + a_SubMaxZ >= m_SizeZ)
+ (a_AddMinX + a_SubMaxX >= m_Size.x) ||
+ (a_AddMinY + a_SubMaxY >= m_Size.y) ||
+ (a_AddMinZ + a_SubMaxZ >= m_Size.z)
)
{
LOGWARNING("cBlockArea:Crop called with more croping than the dimensions: %d x %d x %d with cropping %d, %d and %d",
- m_SizeX, m_SizeY, m_SizeZ,
+ m_Size.x, m_Size.y, m_Size.z,
a_AddMinX + a_SubMaxX, a_AddMinY + a_SubMaxY, a_AddMinZ + a_SubMaxZ
);
return;
@@ -560,12 +548,10 @@ void cBlockArea::Crop(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY
{
CropNibbles(m_BlockSkyLight, a_AddMinX, a_SubMaxX, a_AddMinY, a_SubMaxY, a_AddMinZ, a_SubMaxZ);
}
- m_OriginX += a_AddMinX;
- m_OriginY += a_AddMinY;
- m_OriginZ += a_AddMinZ;
- m_SizeX -= a_AddMinX + a_SubMaxX;
- m_SizeY -= a_AddMinY + a_SubMaxY;
- m_SizeZ -= a_AddMinZ + a_SubMaxZ;
+ m_Origin.Move(a_AddMinX, a_AddMinY, a_AddMinZ);
+ m_Size.x -= a_AddMinX + a_SubMaxX;
+ m_Size.y -= a_AddMinY + a_SubMaxY;
+ m_Size.z -= a_AddMinZ + a_SubMaxZ;
}
@@ -590,12 +576,10 @@ void cBlockArea::Expand(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMa
{
ExpandNibbles(m_BlockSkyLight, a_SubMinX, a_AddMaxX, a_SubMinY, a_AddMaxY, a_SubMinZ, a_AddMaxZ);
}
- m_OriginX -= a_SubMinX;
- m_OriginY -= a_SubMinY;
- m_OriginZ -= a_SubMinZ;
- m_SizeX += a_SubMinX + a_AddMaxX;
- m_SizeY += a_SubMinY + a_AddMaxY;
- m_SizeZ += a_SubMinZ + a_AddMaxZ;
+ m_Origin.Move(-a_SubMinX, -a_SubMinY, -a_SubMinZ);
+ m_Size.x += a_SubMinX + a_AddMaxX;
+ m_Size.y += a_SubMinY + a_AddMaxY;
+ m_Size.z += a_SubMinZ + a_AddMaxZ;
}
@@ -645,7 +629,7 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R
SrcOffX, SrcOffY, SrcOffZ,
DstOffX, DstOffY, DstOffZ,
a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(),
- m_SizeX, m_SizeY, m_SizeZ,
+ m_Size.x, m_Size.y, m_Size.z,
MergeCombinatorOverwrite
);
break;
@@ -660,7 +644,7 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R
SrcOffX, SrcOffY, SrcOffZ,
DstOffX, DstOffY, DstOffZ,
a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(),
- m_SizeX, m_SizeY, m_SizeZ,
+ m_Size.x, m_Size.y, m_Size.z,
MergeCombinatorFillAir
);
break;
@@ -675,7 +659,7 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R
SrcOffX, SrcOffY, SrcOffZ,
DstOffX, DstOffY, DstOffZ,
a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(),
- m_SizeX, m_SizeY, m_SizeZ,
+ m_Size.x, m_Size.y, m_Size.z,
MergeCombinatorImprint
);
break;
@@ -690,7 +674,7 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R
SrcOffX, SrcOffY, SrcOffZ,
DstOffX, DstOffY, DstOffZ,
a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(),
- m_SizeX, m_SizeY, m_SizeZ,
+ m_Size.x, m_Size.y, m_Size.z,
MergeCombinatorLake
);
break;
@@ -982,17 +966,17 @@ void cBlockArea::RotateCCW(void)
}
// We are guaranteed that both blocktypes and blockmetas exist; rotate both at the same time:
- BLOCKTYPE * NewTypes = new BLOCKTYPE[m_SizeX * m_SizeY * m_SizeZ];
- NIBBLETYPE * NewMetas = new NIBBLETYPE[m_SizeX * m_SizeY * m_SizeZ];
- for (int x = 0; x < m_SizeX; x++)
+ BLOCKTYPE * NewTypes = new BLOCKTYPE[GetBlockCount()];
+ NIBBLETYPE * NewMetas = new NIBBLETYPE[GetBlockCount()];
+ for (int x = 0; x < m_Size.x; x++)
{
- int NewZ = m_SizeX - x - 1;
- for (int z = 0; z < m_SizeZ; z++)
+ int NewZ = m_Size.x - x - 1;
+ for (int z = 0; z < m_Size.z; z++)
{
int NewX = z;
- for (int y = 0; y < m_SizeY; y++)
+ for (int y = 0; y < m_Size.y; y++)
{
- int NewIdx = NewX + NewZ * m_SizeZ + y * m_SizeX * m_SizeZ;
+ int NewIdx = NewX + NewZ * m_Size.z + y * m_Size.x * m_Size.z;
int OldIdx = MakeIndex(x, y, z);
NewTypes[NewIdx] = m_BlockTypes[OldIdx];
NewMetas[NewIdx] = BlockHandler(m_BlockTypes[OldIdx])->MetaRotateCCW(m_BlockMetas[OldIdx]);
@@ -1004,7 +988,7 @@ void cBlockArea::RotateCCW(void)
delete[] NewTypes;
delete[] NewMetas;
- std::swap(m_SizeX, m_SizeZ);
+ std::swap(m_Size.x, m_Size.z);
}
@@ -1027,17 +1011,17 @@ void cBlockArea::RotateCW(void)
}
// We are guaranteed that both blocktypes and blockmetas exist; rotate both at the same time:
- BLOCKTYPE * NewTypes = new BLOCKTYPE[m_SizeX * m_SizeY * m_SizeZ];
- NIBBLETYPE * NewMetas = new NIBBLETYPE[m_SizeX * m_SizeY * m_SizeZ];
- for (int x = 0; x < m_SizeX; x++)
+ BLOCKTYPE * NewTypes = new BLOCKTYPE[GetBlockCount()];
+ NIBBLETYPE * NewMetas = new NIBBLETYPE[GetBlockCount()];
+ for (int x = 0; x < m_Size.x; x++)
{
int NewZ = x;
- for (int z = 0; z < m_SizeZ; z++)
+ for (int z = 0; z < m_Size.z; z++)
{
- int NewX = m_SizeZ - z - 1;
- for (int y = 0; y < m_SizeY; y++)
+ int NewX = m_Size.z - z - 1;
+ for (int y = 0; y < m_Size.y; y++)
{
- int NewIdx = NewX + NewZ * m_SizeZ + y * m_SizeX * m_SizeZ;
+ int NewIdx = NewX + NewZ * m_Size.z + y * m_Size.x * m_Size.z;
int OldIdx = MakeIndex(x, y, z);
NewTypes[NewIdx] = m_BlockTypes[OldIdx];
NewMetas[NewIdx] = BlockHandler(m_BlockTypes[OldIdx])->MetaRotateCW(m_BlockMetas[OldIdx]);
@@ -1049,7 +1033,7 @@ void cBlockArea::RotateCW(void)
delete[] NewTypes;
delete[] NewMetas;
- std::swap(m_SizeX, m_SizeZ);
+ std::swap(m_Size.x, m_Size.z);
}
@@ -1072,13 +1056,13 @@ void cBlockArea::MirrorXY(void)
}
// We are guaranteed that both blocktypes and blockmetas exist; mirror both at the same time:
- int HalfZ = m_SizeZ / 2;
- int MaxZ = m_SizeZ - 1;
- for (int y = 0; y < m_SizeY; y++)
+ int HalfZ = m_Size.z / 2;
+ int MaxZ = m_Size.z - 1;
+ for (int y = 0; y < m_Size.y; y++)
{
for (int z = 0; z < HalfZ; z++)
{
- for (int x = 0; x < m_SizeX; x++)
+ for (int x = 0; x < m_Size.x; x++)
{
int Idx1 = MakeIndex(x, y, z);
int Idx2 = MakeIndex(x, y, MaxZ - z);
@@ -1112,13 +1096,13 @@ void cBlockArea::MirrorXZ(void)
}
// We are guaranteed that both blocktypes and blockmetas exist; mirror both at the same time:
- int HalfY = m_SizeY / 2;
- int MaxY = m_SizeY - 1;
+ int HalfY = m_Size.y / 2;
+ int MaxY = m_Size.y - 1;
for (int y = 0; y < HalfY; y++)
{
- for (int z = 0; z < m_SizeZ; z++)
+ for (int z = 0; z < m_Size.z; z++)
{
- for (int x = 0; x < m_SizeX; x++)
+ for (int x = 0; x < m_Size.x; x++)
{
int Idx1 = MakeIndex(x, y, z);
int Idx2 = MakeIndex(x, MaxY - y, z);
@@ -1152,11 +1136,11 @@ void cBlockArea::MirrorYZ(void)
}
// We are guaranteed that both blocktypes and blockmetas exist; mirror both at the same time:
- int HalfX = m_SizeX / 2;
- int MaxX = m_SizeX - 1;
- for (int y = 0; y < m_SizeY; y++)
+ int HalfX = m_Size.x / 2;
+ int MaxX = m_Size.x - 1;
+ for (int y = 0; y < m_Size.y; y++)
{
- for (int z = 0; z < m_SizeZ; z++)
+ for (int z = 0; z < m_Size.z; z++)
{
for (int x = 0; x < HalfX; x++)
{
@@ -1180,16 +1164,16 @@ void cBlockArea::RotateCCWNoMeta(void)
{
if (HasBlockTypes())
{
- BLOCKTYPE * NewTypes = new BLOCKTYPE[m_SizeX * m_SizeY * m_SizeZ];
- for (int x = 0; x < m_SizeX; x++)
+ BLOCKTYPE * NewTypes = new BLOCKTYPE[GetBlockCount()];
+ for (int x = 0; x < m_Size.x; x++)
{
- int NewZ = m_SizeX - x - 1;
- for (int z = 0; z < m_SizeZ; z++)
+ int NewZ = m_Size.x - x - 1;
+ for (int z = 0; z < m_Size.z; z++)
{
int NewX = z;
- for (int y = 0; y < m_SizeY; y++)
+ for (int y = 0; y < m_Size.y; y++)
{
- NewTypes[NewX + NewZ * m_SizeZ + y * m_SizeX * m_SizeZ] = m_BlockTypes[MakeIndex(x, y, z)];
+ NewTypes[NewX + NewZ * m_Size.z + y * m_Size.x * m_Size.z] = m_BlockTypes[MakeIndex(x, y, z)];
} // for y
} // for z
} // for x
@@ -1198,23 +1182,23 @@ void cBlockArea::RotateCCWNoMeta(void)
}
if (HasBlockMetas())
{
- NIBBLETYPE * NewMetas = new NIBBLETYPE[m_SizeX * m_SizeY * m_SizeZ];
- for (int x = 0; x < m_SizeX; x++)
+ NIBBLETYPE * NewMetas = new NIBBLETYPE[GetBlockCount()];
+ for (int x = 0; x < m_Size.x; x++)
{
- int NewZ = m_SizeX - x - 1;
- for (int z = 0; z < m_SizeZ; z++)
+ int NewZ = m_Size.x - x - 1;
+ for (int z = 0; z < m_Size.z; z++)
{
int NewX = z;
- for (int y = 0; y < m_SizeY; y++)
+ for (int y = 0; y < m_Size.y; y++)
{
- NewMetas[NewX + NewZ * m_SizeZ + y * m_SizeX * m_SizeZ] = m_BlockMetas[MakeIndex(x, y, z)];
+ NewMetas[NewX + NewZ * m_Size.z + y * m_Size.x * m_Size.z] = m_BlockMetas[MakeIndex(x, y, z)];
} // for y
} // for z
} // for x
std::swap(m_BlockMetas, NewMetas);
delete[] NewMetas;
}
- std::swap(m_SizeX, m_SizeZ);
+ std::swap(m_Size.x, m_Size.z);
}
@@ -1225,16 +1209,16 @@ void cBlockArea::RotateCWNoMeta(void)
{
if (HasBlockTypes())
{
- BLOCKTYPE * NewTypes = new BLOCKTYPE[m_SizeX * m_SizeY * m_SizeZ];
- for (int z = 0; z < m_SizeZ; z++)
+ BLOCKTYPE * NewTypes = new BLOCKTYPE[GetBlockCount()];
+ for (int z = 0; z < m_Size.z; z++)
{
- int NewX = m_SizeZ - z - 1;
- for (int x = 0; x < m_SizeX; x++)
+ int NewX = m_Size.z - z - 1;
+ for (int x = 0; x < m_Size.x; x++)
{
int NewZ = x;
- for (int y = 0; y < m_SizeY; y++)
+ for (int y = 0; y < m_Size.y; y++)
{
- NewTypes[NewX + NewZ * m_SizeZ + y * m_SizeX * m_SizeZ] = m_BlockTypes[MakeIndex(x, y, z)];
+ NewTypes[NewX + NewZ * m_Size.z + y * m_Size.x * m_Size.z] = m_BlockTypes[MakeIndex(x, y, z)];
} // for y
} // for x
} // for z
@@ -1243,23 +1227,23 @@ void cBlockArea::RotateCWNoMeta(void)
}
if (HasBlockMetas())
{
- NIBBLETYPE * NewMetas = new NIBBLETYPE[m_SizeX * m_SizeY * m_SizeZ];
- for (int z = 0; z < m_SizeZ; z++)
+ NIBBLETYPE * NewMetas = new NIBBLETYPE[GetBlockCount()];
+ for (int z = 0; z < m_Size.z; z++)
{
- int NewX = m_SizeZ - z - 1;
- for (int x = 0; x < m_SizeX; x++)
+ int NewX = m_Size.z - z - 1;
+ for (int x = 0; x < m_Size.x; x++)
{
int NewZ = x;
- for (int y = 0; y < m_SizeY; y++)
+ for (int y = 0; y < m_Size.y; y++)
{
- NewMetas[NewX + NewZ * m_SizeZ + y * m_SizeX * m_SizeZ] = m_BlockMetas[MakeIndex(x, y, z)];
+ NewMetas[NewX + NewZ * m_Size.z + y * m_Size.x * m_Size.z] = m_BlockMetas[MakeIndex(x, y, z)];
} // for y
} // for x
} // for z
std::swap(m_BlockMetas, NewMetas);
delete[] NewMetas;
}
- std::swap(m_SizeX, m_SizeZ);
+ std::swap(m_Size.x, m_Size.z);
}
@@ -1268,15 +1252,15 @@ void cBlockArea::RotateCWNoMeta(void)
void cBlockArea::MirrorXYNoMeta(void)
{
- int HalfZ = m_SizeZ / 2;
- int MaxZ = m_SizeZ - 1;
+ int HalfZ = m_Size.z / 2;
+ int MaxZ = m_Size.z - 1;
if (HasBlockTypes())
{
- for (int y = 0; y < m_SizeY; y++)
+ for (int y = 0; y < m_Size.y; y++)
{
for (int z = 0; z < HalfZ; z++)
{
- for (int x = 0; x < m_SizeX; x++)
+ for (int x = 0; x < m_Size.x; x++)
{
std::swap(m_BlockTypes[MakeIndex(x, y, z)], m_BlockTypes[MakeIndex(x, y, MaxZ - z)]);
} // for x
@@ -1286,11 +1270,11 @@ void cBlockArea::MirrorXYNoMeta(void)
if (HasBlockMetas())
{
- for (int y = 0; y < m_SizeY; y++)
+ for (int y = 0; y < m_Size.y; y++)
{
for (int z = 0; z < HalfZ; z++)
{
- for (int x = 0; x < m_SizeX; x++)
+ for (int x = 0; x < m_Size.x; x++)
{
std::swap(m_BlockMetas[MakeIndex(x, y, z)], m_BlockMetas[MakeIndex(x, y, MaxZ - z)]);
} // for x
@@ -1305,15 +1289,15 @@ void cBlockArea::MirrorXYNoMeta(void)
void cBlockArea::MirrorXZNoMeta(void)
{
- int HalfY = m_SizeY / 2;
- int MaxY = m_SizeY - 1;
+ int HalfY = m_Size.y / 2;
+ int MaxY = m_Size.y - 1;
if (HasBlockTypes())
{
for (int y = 0; y < HalfY; y++)
{
- for (int z = 0; z < m_SizeZ; z++)
+ for (int z = 0; z < m_Size.z; z++)
{
- for (int x = 0; x < m_SizeX; x++)
+ for (int x = 0; x < m_Size.x; x++)
{
std::swap(m_BlockTypes[MakeIndex(x, y, z)], m_BlockTypes[MakeIndex(x, MaxY - y, z)]);
} // for x
@@ -1325,9 +1309,9 @@ void cBlockArea::MirrorXZNoMeta(void)
{
for (int y = 0; y < HalfY; y++)
{
- for (int z = 0; z < m_SizeZ; z++)
+ for (int z = 0; z < m_Size.z; z++)
{
- for (int x = 0; x < m_SizeX; x++)
+ for (int x = 0; x < m_Size.x; x++)
{
std::swap(m_BlockMetas[MakeIndex(x, y, z)], m_BlockMetas[MakeIndex(x, MaxY - y, z)]);
} // for x
@@ -1342,13 +1326,13 @@ void cBlockArea::MirrorXZNoMeta(void)
void cBlockArea::MirrorYZNoMeta(void)
{
- int HalfX = m_SizeX / 2;
- int MaxX = m_SizeX - 1;
+ int HalfX = m_Size.x / 2;
+ int MaxX = m_Size.x - 1;
if (HasBlockTypes())
{
- for (int y = 0; y < m_SizeY; y++)
+ for (int y = 0; y < m_Size.y; y++)
{
- for (int z = 0; z < m_SizeZ; z++)
+ for (int z = 0; z < m_Size.z; z++)
{
for (int x = 0; x < HalfX; x++)
{
@@ -1360,9 +1344,9 @@ void cBlockArea::MirrorYZNoMeta(void)
if (HasBlockMetas())
{
- for (int y = 0; y < m_SizeY; y++)
+ for (int y = 0; y < m_Size.y; y++)
{
- for (int z = 0; z < m_SizeZ; z++)
+ for (int z = 0; z < m_Size.z; z++)
{
for (int x = 0; x < HalfX; x++)
{
@@ -1393,7 +1377,7 @@ void cBlockArea::SetRelBlockType(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a
void cBlockArea::SetBlockType(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType)
{
- SetRelBlockType(a_BlockX - m_OriginX, a_BlockY - m_OriginY, a_BlockZ - m_OriginZ, a_BlockType);
+ SetRelBlockType(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z, a_BlockType);
}
@@ -1470,7 +1454,7 @@ BLOCKTYPE cBlockArea::GetRelBlockType(int a_RelX, int a_RelY, int a_RelZ) const
BLOCKTYPE cBlockArea::GetBlockType(int a_BlockX, int a_BlockY, int a_BlockZ) const
{
- return GetRelBlockType(a_BlockX - m_OriginX, a_BlockY - m_OriginY, a_BlockZ - m_OriginZ);
+ return GetRelBlockType(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z);
}
@@ -1533,7 +1517,7 @@ NIBBLETYPE cBlockArea::GetBlockSkyLight(int a_BlockX, int a_BlockY, int a_BlockZ
void cBlockArea::SetBlockTypeMeta(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{
- SetRelBlockTypeMeta(a_BlockX - m_OriginX, a_BlockY - m_OriginY, a_BlockZ - m_OriginZ, a_BlockType, a_BlockMeta);
+ SetRelBlockTypeMeta(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z, a_BlockType, a_BlockMeta);
}
@@ -1567,7 +1551,7 @@ void cBlockArea::SetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, B
void cBlockArea::GetBlockTypeMeta(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const
{
- return GetRelBlockTypeMeta(a_BlockX - m_OriginX, a_BlockY - m_OriginY, a_BlockZ - m_OriginZ, a_BlockType, a_BlockMeta);
+ return GetRelBlockTypeMeta(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z, a_BlockType, a_BlockMeta);
}
@@ -1670,9 +1654,7 @@ bool cBlockArea::SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
return false;
}
}
- m_SizeX = a_SizeX;
- m_SizeY = a_SizeY;
- m_SizeZ = a_SizeZ;
+ m_Size.Set(a_SizeX, a_SizeY, a_SizeZ);
return true;
}
@@ -1683,13 +1665,13 @@ bool cBlockArea::SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
int cBlockArea::MakeIndex(int a_RelX, int a_RelY, int a_RelZ) const
{
ASSERT(a_RelX >= 0);
- ASSERT(a_RelX < m_SizeX);
+ ASSERT(a_RelX < m_Size.x);
ASSERT(a_RelY >= 0);
- ASSERT(a_RelY < m_SizeY);
+ ASSERT(a_RelY < m_Size.y);
ASSERT(a_RelZ >= 0);
- ASSERT(a_RelZ < m_SizeZ);
+ ASSERT(a_RelZ < m_Size.z);
- return a_RelX + a_RelZ * m_SizeX + a_RelY * m_SizeX * m_SizeZ;
+ return a_RelX + a_RelZ * m_Size.x + a_RelY * m_Size.x * m_Size.z;
}
@@ -1712,7 +1694,7 @@ void cBlockArea::SetRelNibble(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_V
void cBlockArea::SetNibble(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Value, NIBBLETYPE * a_Array)
{
- SetRelNibble(a_BlockX - m_OriginX, a_BlockY - m_OriginY, a_BlockZ - m_OriginZ, a_Value, a_Array);
+ SetRelNibble(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z, a_Value, a_Array);
}
@@ -1735,7 +1717,7 @@ NIBBLETYPE cBlockArea::GetRelNibble(int a_RelX, int a_RelY, int a_RelZ, NIBBLETY
NIBBLETYPE cBlockArea::GetNibble(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE * a_Array) const
{
- return GetRelNibble(a_BlockX - m_OriginX, a_BlockY - m_OriginY, a_BlockZ - m_OriginZ, a_Array);
+ return GetRelNibble(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z, a_Array);
}
@@ -1748,9 +1730,7 @@ NIBBLETYPE cBlockArea::GetNibble(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBL
cBlockArea::cChunkReader::cChunkReader(cBlockArea & a_Area) :
m_Area(a_Area),
- m_OriginX(a_Area.m_OriginX),
- m_OriginY(a_Area.m_OriginY),
- m_OriginZ(a_Area.m_OriginZ)
+ m_Origin(a_Area.m_Origin.x, a_Area.m_Origin.y, a_Area.m_Origin.z)
{
}
@@ -1760,8 +1740,8 @@ cBlockArea::cChunkReader::cChunkReader(cBlockArea & a_Area) :
void cBlockArea::cChunkReader::CopyNibbles(NIBBLETYPE * a_AreaDst, const NIBBLETYPE * a_ChunkSrc)
{
- int SizeY = m_Area.m_SizeY;
- int MinY = m_OriginY;
+ int SizeY = m_Area.m_Size.y;
+ int MinY = m_Origin.y;
// SizeX, SizeZ are the dmensions of the block data to copy from the current chunk (size of the geometric union)
// OffX, OffZ are the offsets of the current chunk data from the area origin
@@ -1770,7 +1750,7 @@ void cBlockArea::cChunkReader::CopyNibbles(NIBBLETYPE * a_AreaDst, const NIBBLET
int SizeZ = cChunkDef::Width;
int OffX, OffZ;
int BaseX, BaseZ;
- OffX = m_CurrentChunkX * cChunkDef::Width - m_OriginX;
+ OffX = m_CurrentChunkX * cChunkDef::Width - m_Origin.x;
if (OffX < 0)
{
BaseX = -OffX;
@@ -1781,7 +1761,7 @@ void cBlockArea::cChunkReader::CopyNibbles(NIBBLETYPE * a_AreaDst, const NIBBLET
{
BaseX = 0;
}
- OffZ = m_CurrentChunkZ * cChunkDef::Width - m_OriginZ;
+ OffZ = m_CurrentChunkZ * cChunkDef::Width - m_Origin.z;
if (OffZ < 0)
{
BaseZ = -OffZ;
@@ -1793,13 +1773,13 @@ void cBlockArea::cChunkReader::CopyNibbles(NIBBLETYPE * a_AreaDst, const NIBBLET
BaseZ = 0;
}
// If the chunk extends beyond the area in the X or Z axis, cut off the Size:
- if ((m_CurrentChunkX + 1) * cChunkDef::Width > m_OriginX + m_Area.m_SizeX)
+ if ((m_CurrentChunkX + 1) * cChunkDef::Width > m_Origin.x + m_Area.m_Size.x)
{
- SizeX -= (m_CurrentChunkX + 1) * cChunkDef::Width - (m_OriginX + m_Area.m_SizeX);
+ SizeX -= (m_CurrentChunkX + 1) * cChunkDef::Width - (m_Origin.x + m_Area.m_Size.x);
}
- if ((m_CurrentChunkZ + 1) * cChunkDef::Width > m_OriginZ + m_Area.m_SizeZ)
+ if ((m_CurrentChunkZ + 1) * cChunkDef::Width > m_Origin.z + m_Area.m_Size.z)
{
- SizeZ -= (m_CurrentChunkZ + 1) * cChunkDef::Width - (m_OriginZ + m_Area.m_SizeZ);
+ SizeZ -= (m_CurrentChunkZ + 1) * cChunkDef::Width - (m_Origin.z + m_Area.m_Size.z);
}
for (int y = 0; y < SizeY; y++)
@@ -1843,8 +1823,8 @@ void cBlockArea::cChunkReader::BlockTypes(const BLOCKTYPE * a_BlockTypes)
return;
}
- int SizeY = m_Area.m_SizeY;
- int MinY = m_OriginY;
+ int SizeY = m_Area.m_Size.y;
+ int MinY = m_Origin.y;
// SizeX, SizeZ are the dmensions of the block data to copy from the current chunk (size of the geometric union)
// OffX, OffZ are the offsets of the current chunk data from the area origin
@@ -1853,7 +1833,7 @@ void cBlockArea::cChunkReader::BlockTypes(const BLOCKTYPE * a_BlockTypes)
int SizeZ = cChunkDef::Width;
int OffX, OffZ;
int BaseX, BaseZ;
- OffX = m_CurrentChunkX * cChunkDef::Width - m_OriginX;
+ OffX = m_CurrentChunkX * cChunkDef::Width - m_Origin.x;
if (OffX < 0)
{
BaseX = -OffX;
@@ -1864,7 +1844,7 @@ void cBlockArea::cChunkReader::BlockTypes(const BLOCKTYPE * a_BlockTypes)
{
BaseX = 0;
}
- OffZ = m_CurrentChunkZ * cChunkDef::Width - m_OriginZ;
+ OffZ = m_CurrentChunkZ * cChunkDef::Width - m_Origin.z;
if (OffZ < 0)
{
BaseZ = -OffZ;
@@ -1876,13 +1856,13 @@ void cBlockArea::cChunkReader::BlockTypes(const BLOCKTYPE * a_BlockTypes)
BaseZ = 0;
}
// If the chunk extends beyond the area in the X or Z axis, cut off the Size:
- if ((m_CurrentChunkX + 1) * cChunkDef::Width > m_OriginX + m_Area.m_SizeX)
+ if ((m_CurrentChunkX + 1) * cChunkDef::Width > m_Origin.x + m_Area.m_Size.x)
{
- SizeX -= (m_CurrentChunkX + 1) * cChunkDef::Width - (m_OriginX + m_Area.m_SizeX);
+ SizeX -= (m_CurrentChunkX + 1) * cChunkDef::Width - (m_Origin.x + m_Area.m_Size.x);
}
- if ((m_CurrentChunkZ + 1) * cChunkDef::Width > m_OriginZ + m_Area.m_SizeZ)
+ if ((m_CurrentChunkZ + 1) * cChunkDef::Width > m_Origin.z + m_Area.m_Size.z)
{
- SizeZ -= (m_CurrentChunkZ + 1) * cChunkDef::Width - (m_OriginZ + m_Area.m_SizeZ);
+ SizeZ -= (m_CurrentChunkZ + 1) * cChunkDef::Width - (m_Origin.z + m_Area.m_Size.z);
}
for (int y = 0; y < SizeY; y++)
@@ -2002,21 +1982,21 @@ void cBlockArea::CropNibbles(NIBBLEARRAY & a_Array, int a_AddMinX, int a_SubMaxX
void cBlockArea::ExpandBlockTypes(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ)
{
- int NewSizeX = m_SizeX + a_SubMinX + a_AddMaxX;
- int NewSizeY = m_SizeY + a_SubMinY + a_AddMaxY;
- int NewSizeZ = m_SizeZ + a_SubMinZ + a_AddMaxZ;
+ int NewSizeX = m_Size.x + a_SubMinX + a_AddMaxX;
+ int NewSizeY = m_Size.y + a_SubMinY + a_AddMaxY;
+ int NewSizeZ = m_Size.z + a_SubMinZ + a_AddMaxZ;
int BlockCount = NewSizeX * NewSizeY * NewSizeZ;
BLOCKTYPE * NewBlockTypes = new BLOCKTYPE[BlockCount];
memset(NewBlockTypes, 0, BlockCount * sizeof(BLOCKTYPE));
int OldIndex = 0;
- for (int y = 0; y < m_SizeY; y++)
+ for (int y = 0; y < m_Size.y; y++)
{
- int IndexBaseY = (y + a_SubMinY) * m_SizeX * m_SizeZ;
- for (int z = 0; z < m_SizeZ; z++)
+ int IndexBaseY = (y + a_SubMinY) * m_Size.x * m_Size.z;
+ for (int z = 0; z < m_Size.z; z++)
{
- int IndexBaseZ = IndexBaseY + (z + a_SubMinZ) * m_SizeX;
+ int IndexBaseZ = IndexBaseY + (z + a_SubMinZ) * m_Size.x;
int idx = IndexBaseZ + a_SubMinX;
- for (int x = 0; x < m_SizeX; x++)
+ for (int x = 0; x < m_Size.x; x++)
{
NewBlockTypes[idx++] = m_BlockTypes[OldIndex++];
} // for x
@@ -2032,21 +2012,21 @@ void cBlockArea::ExpandBlockTypes(int a_SubMinX, int a_AddMaxX, int a_SubMinY, i
void cBlockArea::ExpandNibbles(NIBBLEARRAY & a_Array, int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ)
{
- int NewSizeX = m_SizeX + a_SubMinX + a_AddMaxX;
- int NewSizeY = m_SizeY + a_SubMinY + a_AddMaxY;
- int NewSizeZ = m_SizeZ + a_SubMinZ + a_AddMaxZ;
+ int NewSizeX = m_Size.x + a_SubMinX + a_AddMaxX;
+ int NewSizeY = m_Size.y + a_SubMinY + a_AddMaxY;
+ int NewSizeZ = m_Size.z + a_SubMinZ + a_AddMaxZ;
int BlockCount = NewSizeX * NewSizeY * NewSizeZ;
NIBBLETYPE * NewNibbles = new NIBBLETYPE[BlockCount];
memset(NewNibbles, 0, BlockCount * sizeof(NIBBLETYPE));
int OldIndex = 0;
- for (int y = 0; y < m_SizeY; y++)
+ for (int y = 0; y < m_Size.y; y++)
{
- int IndexBaseY = (y + a_SubMinY) * m_SizeX * m_SizeZ;
- for (int z = 0; z < m_SizeZ; z++)
+ int IndexBaseY = (y + a_SubMinY) * m_Size.x * m_Size.z;
+ for (int z = 0; z < m_Size.z; z++)
{
- int IndexBaseZ = IndexBaseY + (z + a_SubMinZ) * m_SizeX;
+ int IndexBaseZ = IndexBaseY + (z + a_SubMinZ) * m_Size.x;
int idx = IndexBaseZ + a_SubMinX;
- for (int x = 0; x < m_SizeX; x++)
+ for (int x = 0; x < m_Size.x; x++)
{
NewNibbles[idx++] = a_Array[OldIndex++];
} // for x
@@ -2057,6 +2037,9 @@ void cBlockArea::ExpandNibbles(NIBBLEARRAY & a_Array, int a_SubMinX, int a_AddMa
}
+
+
+
void cBlockArea::RelSetData(
int a_RelX, int a_RelY, int a_RelZ,
int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta,
diff --git a/src/BlockArea.h b/src/BlockArea.h
index e0e8fe972..d28325d7d 100644
--- a/src/BlockArea.h
+++ b/src/BlockArea.h
@@ -43,6 +43,8 @@ public:
baSkyLight = 8,
} ;
+ /** The per-block strategy to use when merging another block area into this object.
+ See the Merge function for the description of these */
enum eMergeStrategy
{
msOverwrite,
@@ -57,12 +59,18 @@ public:
/** Clears the data stored to reclaim memory */
void Clear(void);
- /** Creates a new area of the specified size and contents.
- Origin is set to all zeroes.
+ /** Creates a new area of the specified size and contents.
+ Origin is set to all zeroes.
BlockTypes are set to air, block metas to zero, blocklights to zero and skylights to full light.
*/
void Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes = baTypes | baMetas);
+ /** Creates a new area of the specified size and contents.
+ Origin is set to all zeroes.
+ BlockTypes are set to air, block metas to zero, blocklights to zero and skylights to full light.
+ */
+ void Create(const Vector3i & a_Size, int a_DataTypes = baTypes | baMetas);
+
/** Resets the origin. No other changes are made, contents are untouched. */
void SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ);
@@ -232,18 +240,24 @@ public:
void GetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const;
void GetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const;
+ // GetSize() is already exported manually to return 3 numbers, can't auto-export
+ const Vector3i & GetSize(void) const { return m_Size; }
+
+ // GetOrigin() is already exported manually to return 3 numbers, can't auto-export
+ const Vector3i & GetOrigin(void) const { return m_Origin; }
+
// tolua_begin
- int GetSizeX(void) const { return m_SizeX; }
- int GetSizeY(void) const { return m_SizeY; }
- int GetSizeZ(void) const { return m_SizeZ; }
+ int GetSizeX(void) const { return m_Size.x; }
+ int GetSizeY(void) const { return m_Size.y; }
+ int GetSizeZ(void) const { return m_Size.z; }
/** Returns the volume of the area, as number of blocks */
- int GetVolume(void) const { return m_SizeX * m_SizeY * m_SizeZ; }
+ int GetVolume(void) const { return m_Size.x * m_Size.y * m_Size.z; }
- int GetOriginX(void) const { return m_OriginX; }
- int GetOriginY(void) const { return m_OriginY; }
- int GetOriginZ(void) const { return m_OriginZ; }
+ int GetOriginX(void) const { return m_Origin.x; }
+ int GetOriginY(void) const { return m_Origin.y; }
+ int GetOriginZ(void) const { return m_Origin.z; }
/** Returns the datatypes that are stored in the object (bitmask of baXXX values) */
int GetDataTypes(void) const;
@@ -261,7 +275,7 @@ public:
NIBBLETYPE * GetBlockMetas (void) const { return m_BlockMetas; } // NOTE: one byte per block!
NIBBLETYPE * GetBlockLight (void) const { return m_BlockLight; } // NOTE: one byte per block!
NIBBLETYPE * GetBlockSkyLight(void) const { return m_BlockSkyLight; } // NOTE: one byte per block!
- int GetBlockCount(void) const { return m_SizeX * m_SizeY * m_SizeZ; }
+ int GetBlockCount(void) const { return m_Size.x * m_Size.y * m_Size.z; }
int MakeIndex(int a_RelX, int a_RelY, int a_RelZ) const;
protected:
@@ -276,9 +290,7 @@ protected:
protected:
cBlockArea & m_Area;
- int m_OriginX;
- int m_OriginY;
- int m_OriginZ;
+ Vector3i m_Origin;
int m_CurrentChunkX;
int m_CurrentChunkZ;
@@ -295,12 +307,8 @@ protected:
typedef NIBBLETYPE * NIBBLEARRAY;
- int m_OriginX;
- int m_OriginY;
- int m_OriginZ;
- int m_SizeX;
- int m_SizeY;
- int m_SizeZ;
+ Vector3i m_Origin;
+ Vector3i m_Size;
/** An extra data value sometimes stored in the .schematic file. Used mainly by the WorldEdit plugin.
cBlockArea doesn't use this value in any way. */
diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp
index cbfbb1b6a..e03bf776d 100644
--- a/src/BlockEntities/DispenserEntity.cpp
+++ b/src/BlockEntities/DispenserEntity.cpp
@@ -138,6 +138,12 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum)
break;
}
+ case E_ITEM_FIRE_CHARGE:
+ {
+ // TODO: Spawn fireball entity
+ break;
+ }
+
default:
{
DropFromSlot(a_Chunk, a_SlotNum);
diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp
index af7043767..41fb9f811 100644
--- a/src/BlockEntities/HopperEntity.cpp
+++ b/src/BlockEntities/HopperEntity.cpp
@@ -219,7 +219,7 @@ bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick)
Vector3f EntityPos = a_Entity->GetPosition();
Vector3f BlockPos(m_Pos.x + 0.5f, (float)m_Pos.y + 1, m_Pos.z + 0.5f); // One block above hopper, and search from center outwards
- float Distance = (EntityPos - BlockPos).Length();
+ double Distance = (EntityPos - BlockPos).Length();
if (Distance < 0.5)
{
diff --git a/src/BlockID.h b/src/BlockID.h
index 1c454cd23..2fec512e2 100644
--- a/src/BlockID.h
+++ b/src/BlockID.h
@@ -853,9 +853,30 @@ enum eExplosionSource
esWitherSkullBlue,
esWitherBirth,
esPlugin,
-
- // Obsolete constants, kept for compatibility, will be removed after some time:
- esCreeper = esMonster,
+} ;
+
+
+
+
+
+enum eShrapnelLevel
+{
+ slNone,
+ slGravityAffectedOnly,
+ slAll
+} ;
+
+
+
+
+
+enum eSpreadSource
+{
+ ssFireSpread,
+ ssGrassSpread,
+ ssMushroomSpread,
+ ssMycelSpread,
+ ssVineSpread,
} ;
// tolua_end
diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp
index d1ecfdf7e..6fb5aa5b3 100644
--- a/src/BlockInfo.cpp
+++ b/src/BlockInfo.cpp
@@ -93,6 +93,7 @@ void cBlockInfo::Initialize(void)
ms_Info[E_BLOCK_IRON_BARS ].m_SpreadLightFalloff = 1;
ms_Info[E_BLOCK_IRON_DOOR ].m_SpreadLightFalloff = 1;
ms_Info[E_BLOCK_LEAVES ].m_SpreadLightFalloff = 1;
+ ms_Info[E_BLOCK_NEW_LEAVES ].m_SpreadLightFalloff = 1;
ms_Info[E_BLOCK_SIGN_POST ].m_SpreadLightFalloff = 1;
ms_Info[E_BLOCK_TORCH ].m_SpreadLightFalloff = 1;
ms_Info[E_BLOCK_VINES ].m_SpreadLightFalloff = 1;
@@ -364,7 +365,7 @@ void cBlockInfo::Initialize(void)
ms_Info[E_BLOCK_WOODEN_SLAB ].m_IsSolid = false;
- // Torch placeable blocks:
+ // Blocks that fully occupy their voxel - used as a guide for torch placeable blocks, amongst other things:
ms_Info[E_BLOCK_NEW_LOG ].m_FullyOccupiesVoxel = true;
ms_Info[E_BLOCK_BEDROCK ].m_FullyOccupiesVoxel = true;
ms_Info[E_BLOCK_BLOCK_OF_COAL ].m_FullyOccupiesVoxel = true;
@@ -396,6 +397,7 @@ void cBlockInfo::Initialize(void)
ms_Info[E_BLOCK_HAY_BALE ].m_FullyOccupiesVoxel = true;
ms_Info[E_BLOCK_HUGE_BROWN_MUSHROOM ].m_FullyOccupiesVoxel = true;
ms_Info[E_BLOCK_HUGE_RED_MUSHROOM ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_ICE ].m_FullyOccupiesVoxel = true;
ms_Info[E_BLOCK_IRON_BLOCK ].m_FullyOccupiesVoxel = true;
ms_Info[E_BLOCK_IRON_ORE ].m_FullyOccupiesVoxel = true;
ms_Info[E_BLOCK_JACK_O_LANTERN ].m_FullyOccupiesVoxel = true;
diff --git a/src/Blocks/BlockAnvil.h b/src/Blocks/BlockAnvil.h
new file mode 100644
index 000000000..9f5f84be0
--- /dev/null
+++ b/src/Blocks/BlockAnvil.h
@@ -0,0 +1,63 @@
+
+#pragma once
+
+#include "BlockHandler.h"
+#include "../World.h"
+#include "../Entities/Player.h"
+
+
+
+
+
+class cBlockAnvilHandler :
+ public cBlockHandler
+{
+public:
+ cBlockAnvilHandler(BLOCKTYPE a_BlockType)
+ : cBlockHandler(a_BlockType)
+ {
+ }
+
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
+ {
+ a_Pickups.push_back(cItem(E_BLOCK_ANVIL, 1, a_BlockMeta >> 2));
+ }
+
+ virtual bool GetPlacementBlockTypeMeta(
+ cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
+ int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
+ int a_CursorX, int a_CursorY, int a_CursorZ,
+ BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
+ ) override
+ {
+ a_BlockType = m_BlockType;
+
+ int Direction = (int)floor(a_Player->GetYaw() * 4.0 / 360.0 + 0.5) & 0x3;
+ int RawMeta = a_BlockMeta >> 2;
+
+ Direction++;
+ Direction %= 4;
+ switch (Direction)
+ {
+ case 0: a_BlockMeta = 0x2 | RawMeta << 2; break;
+ case 1: a_BlockMeta = 0x3 | RawMeta << 2; break;
+ case 2: a_BlockMeta = 0x0 | RawMeta << 2; break;
+ case 3: a_BlockMeta = 0x1 | RawMeta << 2; break;
+ default:
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ virtual bool IsUseable() override
+ {
+ return true;
+ }
+} ;
+
+
+
+
diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp
index 3dad4feba..6a3c6a55b 100644
--- a/src/Blocks/BlockBed.cpp
+++ b/src/Blocks/BlockBed.cpp
@@ -51,6 +51,49 @@ void cBlockBedHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInt
+class cTimeFastForwardTester :
+ public cPlayerListCallback
+{
+ virtual bool Item(cPlayer * a_Player) override
+ {
+ if (!a_Player->IsInBed())
+ {
+ return true;
+ }
+
+ return false;
+ }
+};
+
+
+
+
+
+class cPlayerBedStateUnsetter :
+ public cPlayerListCallback
+{
+public:
+ cPlayerBedStateUnsetter(Vector3i a_Position, cWorldInterface & a_WorldInterface) :
+ m_Position(a_Position), m_WorldInterface(a_WorldInterface)
+ {
+ }
+
+ virtual bool Item(cPlayer * a_Player) override
+ {
+ a_Player->SetIsInBed(false);
+ m_WorldInterface.GetBroadcastManager().BroadcastEntityAnimation(*a_Player, 2);
+ return false;
+ }
+
+private:
+ Vector3i m_Position;
+ cWorldInterface & m_WorldInterface;
+};
+
+
+
+
+
void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ)
{
if (a_WorldInterface.GetDimension() != dimOverworld)
@@ -69,6 +112,8 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface
}
else
{
+ Vector3i PillowDirection(0, 0, 0);
+
if (Meta & 0x8)
{
// Is pillow
@@ -77,16 +122,30 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface
else
{
// Is foot end
- Vector3i Direction = MetaDataToDirection( Meta & 0x7 );
- if (a_ChunkInterface.GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) == E_BLOCK_BED) // Must always use pillow location for sleeping
+ VERIFY((Meta & 0x4) != 0x4); // Occupied flag should never be set, else our compilator (intended) is broken
+
+ PillowDirection = MetaDataToDirection(Meta & 0x7);
+ if (a_ChunkInterface.GetBlock(a_BlockX + PillowDirection.x, a_BlockY, a_BlockZ + PillowDirection.z) == E_BLOCK_BED) // Must always use pillow location for sleeping
{
- a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z);
+ a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX + PillowDirection.x, a_BlockY, a_BlockZ + PillowDirection.z);
}
}
- a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, (Meta | (1 << 2)));
- }
-
- } else {
+
+ a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta | 0x4); // Where 0x4 = occupied bit
+ a_Player->SetIsInBed(true);
+
+ cTimeFastForwardTester Tester;
+ if (a_WorldInterface.ForEachPlayer(Tester))
+ {
+ cPlayerBedStateUnsetter Unsetter(Vector3i(a_BlockX + PillowDirection.x, a_BlockY, a_BlockZ + PillowDirection.z), a_WorldInterface);
+ a_WorldInterface.ForEachPlayer(Unsetter);
+ a_WorldInterface.SetTimeOfDay(0);
+ a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta & 0xB); // Where 0xB = 1011, and zero is to make sure 'occupied' bit is always unset
+ }
+ }
+ }
+ else
+ {
a_Player->SendMessageFailure("You can only sleep at night");
}
}
diff --git a/src/Blocks/BlockCake.h b/src/Blocks/BlockCake.h
new file mode 100644
index 000000000..36e133388
--- /dev/null
+++ b/src/Blocks/BlockCake.h
@@ -0,0 +1,55 @@
+#pragma once
+
+#include "BlockHandler.h"
+
+
+
+
+
+class cBlockCakeHandler :
+ public cBlockHandler
+{
+public:
+ cBlockCakeHandler(BLOCKTYPE a_BlockType)
+ : cBlockHandler(a_BlockType)
+ {
+ }
+
+ virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
+ {
+ NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
+
+ if (!a_Player->Feed(2, 0.1))
+ {
+ return;
+ }
+
+ if (Meta >= 5)
+ {
+ a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
+ }
+ else
+ {
+ a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta + 1);
+ }
+ }
+
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
+ {
+ // Give nothing
+ }
+
+ virtual bool IsUseable(void) override
+ {
+ return true;
+ }
+
+ virtual const char * GetStepSound(void) override
+ {
+ return "step.cloth";
+ }
+} ;
+
+
+
+
diff --git a/src/Blocks/BlockDirt.h b/src/Blocks/BlockDirt.h
index 544424a04..a1ab74257 100644
--- a/src/Blocks/BlockDirt.h
+++ b/src/Blocks/BlockDirt.h
@@ -79,7 +79,10 @@ public:
Chunk->GetBlockTypeMeta(BlockX, BlockY + 1, BlockZ, AboveDest, AboveMeta);
if ((cBlockInfo::IsOneHitDig(AboveDest) || cBlockInfo::IsTransparent(AboveDest)) && !IsBlockWater(AboveDest))
{
- Chunk->FastSetBlock(BlockX, BlockY, BlockZ, E_BLOCK_GRASS, 0);
+ if (!cRoot::Get()->GetPluginManager()->CallHookBlockSpread((cWorld*) &a_WorldInterface, BlockX * cChunkDef::Width, BlockY, BlockZ * cChunkDef::Width, ssGrassSpread))
+ {
+ Chunk->FastSetBlock(BlockX, BlockY, BlockZ, E_BLOCK_GRASS, 0);
+ }
}
} // for i - repeat twice
}
diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp
index aa97b2ca9..7fd8c183c 100644
--- a/src/Blocks/BlockHandler.cpp
+++ b/src/Blocks/BlockHandler.cpp
@@ -6,10 +6,12 @@
#include "../Root.h"
#include "../Bindings/PluginManager.h"
#include "../Chunk.h"
+#include "BlockAnvil.h"
#include "BlockBed.h"
#include "BlockBrewingStand.h"
#include "BlockButton.h"
#include "BlockCactus.h"
+#include "BlockCake.h"
#include "BlockCarpet.h"
#include "BlockCauldron.h"
#include "BlockChest.h"
@@ -39,6 +41,7 @@
#include "BlockIce.h"
#include "BlockLadder.h"
#include "BlockLeaves.h"
+#include "BlockLilypad.h"
#include "BlockNewLeaves.h"
#include "BlockLever.h"
#include "BlockMelon.h"
@@ -85,12 +88,14 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
// Block handlers, alphabetically sorted:
case E_BLOCK_ACACIA_WOOD_STAIRS: return new cBlockStairsHandler (a_BlockType);
case E_BLOCK_ACTIVATOR_RAIL: return new cBlockRailHandler (a_BlockType);
+ case E_BLOCK_ANVIL: return new cBlockAnvilHandler (a_BlockType);
case E_BLOCK_BED: return new cBlockBedHandler (a_BlockType);
case E_BLOCK_BIRCH_WOOD_STAIRS: return new cBlockStairsHandler (a_BlockType);
case E_BLOCK_BREWING_STAND: return new cBlockBrewingStandHandler (a_BlockType);
case E_BLOCK_BRICK_STAIRS: return new cBlockStairsHandler (a_BlockType);
case E_BLOCK_BROWN_MUSHROOM: return new cBlockMushroomHandler (a_BlockType);
case E_BLOCK_CACTUS: return new cBlockCactusHandler (a_BlockType);
+ case E_BLOCK_CAKE: return new cBlockCakeHandler (a_BlockType);
case E_BLOCK_CARROTS: return new cBlockCropsHandler (a_BlockType);
case E_BLOCK_CARPET: return new cBlockCarpetHandler (a_BlockType);
case E_BLOCK_CAULDRON: return new cBlockCauldronHandler (a_BlockType);
@@ -138,6 +143,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
case E_BLOCK_LAPIS_ORE: return new cBlockOreHandler (a_BlockType);
case E_BLOCK_LAVA: return new cBlockLavaHandler (a_BlockType);
case E_BLOCK_LEAVES: return new cBlockLeavesHandler (a_BlockType);
+ case E_BLOCK_LILY_PAD: return new cBlockLilypadHandler (a_BlockType);
case E_BLOCK_LIT_FURNACE: return new cBlockFurnaceHandler (a_BlockType);
case E_BLOCK_LOG: return new cBlockSidewaysHandler (a_BlockType);
case E_BLOCK_MELON: return new cBlockMelonHandler (a_BlockType);
diff --git a/src/Blocks/BlockLeaves.h b/src/Blocks/BlockLeaves.h
index 7b8f0b378..a6d3373c1 100644
--- a/src/Blocks/BlockLeaves.h
+++ b/src/Blocks/BlockLeaves.h
@@ -16,6 +16,7 @@
{ \
case E_BLOCK_LEAVES: a_Area.SetBlockType(x, y, z, (BLOCKTYPE)(E_BLOCK_SPONGE + i + 1)); break; \
case E_BLOCK_LOG: return true; \
+ case E_BLOCK_NEW_LOG: return true; \
}
bool HasNearLog(cBlockArea &a_Area, int a_BlockX, int a_BlockY, int a_BlockZ);
diff --git a/src/Blocks/BlockLilypad.h b/src/Blocks/BlockLilypad.h
new file mode 100644
index 000000000..2dd4ec768
--- /dev/null
+++ b/src/Blocks/BlockLilypad.h
@@ -0,0 +1,28 @@
+
+#pragma once
+
+#include "BlockHandler.h"
+#include "Entities/Pickup.h"
+
+
+
+
+class cBlockLilypadHandler :
+ public cBlockHandler
+{
+public:
+ cBlockLilypadHandler(BLOCKTYPE a_BlockType)
+ : cBlockHandler(a_BlockType)
+ {
+ }
+
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
+ {
+ // Reset meta to zero
+ a_Pickups.push_back(cItem(E_BLOCK_LILY_PAD, 1, 0));
+ }
+};
+
+
+
+
diff --git a/src/Blocks/BlockMobHead.h b/src/Blocks/BlockMobHead.h
index 2b128f13b..6aa01f986 100644
--- a/src/Blocks/BlockMobHead.h
+++ b/src/Blocks/BlockMobHead.h
@@ -21,6 +21,18 @@ public:
{
a_Pickups.push_back(cItem(E_ITEM_HEAD, 1, 0));
}
+
+ bool TrySpawnWither(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ)
+ {
+ if (a_BlockY < 2)
+ {
+ return false;
+ }
+
+ // TODO 2014-03-24 xdot
+
+ return false;
+ }
virtual void OnPlacedByPlayer(
cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player,
@@ -62,6 +74,8 @@ public:
cWorld * World = (cWorld *) &a_WorldInterface;
World->DoWithMobHeadAt(a_BlockX, a_BlockY, a_BlockZ, Callback);
a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta);
+
+ TrySpawnWither(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ);
}
} ;
diff --git a/src/Blocks/BlockMushroom.h b/src/Blocks/BlockMushroom.h
index 623cfda64..135d418d7 100644
--- a/src/Blocks/BlockMushroom.h
+++ b/src/Blocks/BlockMushroom.h
@@ -17,6 +17,9 @@ public:
}
+ // TODO: Add Mushroom Spread
+
+
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
// Reset meta to 0
@@ -39,6 +42,7 @@ public:
case E_BLOCK_CACTUS:
case E_BLOCK_ICE:
case E_BLOCK_LEAVES:
+ case E_BLOCK_NEW_LEAVES:
case E_BLOCK_AIR:
{
return false;
diff --git a/src/Blocks/BlockMycelium.h b/src/Blocks/BlockMycelium.h
index 7f897c72a..2a8ef5fca 100644
--- a/src/Blocks/BlockMycelium.h
+++ b/src/Blocks/BlockMycelium.h
@@ -16,6 +16,8 @@ public:
{
}
+ // TODO: Add Mycel Spread
+
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
a_Pickups.push_back(cItem(E_BLOCK_DIRT, 1, 0));
diff --git a/src/Blocks/BlockSideways.h b/src/Blocks/BlockSideways.h
index 69c0a7230..d67c3aa24 100644
--- a/src/Blocks/BlockSideways.h
+++ b/src/Blocks/BlockSideways.h
@@ -29,7 +29,13 @@ public:
return true;
}
-
+
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
+ {
+ a_Pickups.Add(m_BlockType, 1, a_BlockMeta & 0x3);
+ }
+
+
inline static NIBBLETYPE BlockFaceToMetaData(eBlockFace a_BlockFace, NIBBLETYPE a_WoodMeta)
{
switch (a_BlockFace)
diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h
index 0b57acc7b..e14218633 100644
--- a/src/Blocks/BlockVine.h
+++ b/src/Blocks/BlockVine.h
@@ -73,7 +73,7 @@ public:
/// Returns true if the specified block type is good for vines to attach to
static bool IsBlockAttachable(BLOCKTYPE a_BlockType)
{
- return (a_BlockType == E_BLOCK_LEAVES) || cBlockInfo::IsSolid(a_BlockType);
+ return (a_BlockType == E_BLOCK_LEAVES) || (a_BlockType == E_BLOCK_NEW_LEAVES) || cBlockInfo::IsSolid(a_BlockType);
}
@@ -175,7 +175,10 @@ public:
a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY - 1, a_RelZ, Block);
if (Block == E_BLOCK_AIR)
{
- a_Chunk.UnboundedRelSetBlock(a_RelX, a_RelY - 1, a_RelZ, E_BLOCK_VINES, a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ));
+ if (!cRoot::Get()->GetPluginManager()->CallHookBlockSpread((cWorld*) &a_WorldInterface, a_RelX * cChunkDef::Width, a_RelY - 1, a_RelZ * cChunkDef::Width, ssVineSpread))
+ {
+ a_Chunk.UnboundedRelSetBlock(a_RelX, a_RelY - 1, a_RelZ, E_BLOCK_VINES, a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ));
+ }
}
}
diff --git a/src/Blocks/BroadcastInterface.h b/src/Blocks/BroadcastInterface.h
index f6ccd580b..b1b450690 100644
--- a/src/Blocks/BroadcastInterface.h
+++ b/src/Blocks/BroadcastInterface.h
@@ -4,7 +4,9 @@
class cBroadcastInterface
{
public:
-
- virtual void BroadcastUseBed(const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ) = 0;
- virtual void BroadcastSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL) = 0;
+ virtual ~cBroadcastInterface() {}
+
+ virtual void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ) = 0;
+ virtual void BroadcastSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL) = 0;
+ virtual void BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL) = 0;
};
diff --git a/src/Blocks/WorldInterface.h b/src/Blocks/WorldInterface.h
index e59b00eff..bfbb053d9 100644
--- a/src/Blocks/WorldInterface.h
+++ b/src/Blocks/WorldInterface.h
@@ -9,7 +9,8 @@ class cItems;
class cWorldInterface
{
public:
-
+ virtual ~cWorldInterface() {}
+
virtual Int64 GetTimeOfDay(void) const = 0;
virtual Int64 GetWorldAge(void) const = 0;
@@ -27,7 +28,13 @@ public:
/** 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;
-
+
/** Sends the block on those coords to the player */
virtual void SendBlockTo(int a_BlockX, int a_BlockY, int a_BlockZ, cPlayer * a_Player) = 0;
+
+ /** Calls the callback for each player in the list; returns true if all players processed, false if the callback aborted by returning true */
+ virtual bool ForEachPlayer(cItemCallback<cPlayer> & a_Callback) = 0;
+
+ virtual void SetTimeOfDay(Int64 a_TimeOfDay) = 0;
+
};
diff --git a/src/BoundingBox.cpp b/src/BoundingBox.cpp
index aab51c539..482f9923f 100644
--- a/src/BoundingBox.cpp
+++ b/src/BoundingBox.cpp
@@ -10,7 +10,7 @@
-#if SELF_TEST
+#ifdef SELF_TEST
/** A simple self-test that is executed on program start, used to verify bbox functionality */
static class SelfTest_BoundingBox
diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp
index 96a135562..1893d89a8 100644
--- a/src/ByteBuffer.cpp
+++ b/src/ByteBuffer.cpp
@@ -62,11 +62,11 @@ public:
cByteBuffer buf(50);
buf.Write("\x05\xac\x02\x00", 4);
UInt32 v1;
- assert(buf.ReadVarInt(v1) && (v1 == 5));
+ assert_test(buf.ReadVarInt(v1) && (v1 == 5));
UInt32 v2;
- assert(buf.ReadVarInt(v2) && (v2 == 300));
+ assert_test(buf.ReadVarInt(v2) && (v2 == 300));
UInt32 v3;
- assert(buf.ReadVarInt(v3) && (v3 == 0));
+ assert_test(buf.ReadVarInt(v3) && (v3 == 0));
}
void TestWrite(void)
@@ -77,8 +77,8 @@ public:
buf.WriteVarInt(0);
AString All;
buf.ReadAll(All);
- assert(All.size() == 4);
- assert(memcmp(All.data(), "\x05\xac\x02\x00", All.size()) == 0);
+ assert_test(All.size() == 4);
+ assert_test(memcmp(All.data(), "\x05\xac\x02\x00", All.size()) == 0);
}
void TestWrap(void)
@@ -87,17 +87,17 @@ public:
for (int i = 0; i < 1000; i++)
{
size_t FreeSpace = buf.GetFreeSpace();
- assert(buf.GetReadableSpace() == 0);
- assert(FreeSpace > 0);
- assert(buf.Write("a", 1));
- assert(buf.CanReadBytes(1));
- assert(buf.GetReadableSpace() == 1);
+ assert_test(buf.GetReadableSpace() == 0);
+ assert_test(FreeSpace > 0);
+ assert_test(buf.Write("a", 1));
+ assert_test(buf.CanReadBytes(1));
+ assert_test(buf.GetReadableSpace() == 1);
unsigned char v = 0;
- assert(buf.ReadByte(v));
- assert(v == 'a');
- assert(buf.GetReadableSpace() == 0);
+ assert_test(buf.ReadByte(v));
+ assert_test(v == 'a');
+ assert_test(buf.GetReadableSpace() == 0);
buf.CommitRead();
- assert(buf.GetFreeSpace() == FreeSpace); // We're back to normal
+ assert_test(buf.GetFreeSpace() == FreeSpace); // We're back to normal
}
}
@@ -459,7 +459,7 @@ bool cByteBuffer::ReadVarUTF8String(AString & a_Value)
}
if (Size > MAX_STRING_SIZE)
{
- LOGWARNING("%s: String too large: %llu (%llu KiB)", __FUNCTION__, Size, Size / 1024);
+ LOGWARNING("%s: String too large: %u (%u KiB)", __FUNCTION__, Size, Size / 1024);
}
return ReadString(a_Value, (int)Size);
}
@@ -767,7 +767,7 @@ bool cByteBuffer::ReadUTF16String(AString & a_String, int a_NumChars)
{
return false;
}
- RawBEToUTF8((short *)(RawData.data()), a_NumChars, a_String);
+ RawBEToUTF8(RawData.data(), a_NumChars, a_String);
return true;
}
diff --git a/src/ByteBuffer.h b/src/ByteBuffer.h
index ed2e10a55..1915467f3 100644
--- a/src/ByteBuffer.h
+++ b/src/ByteBuffer.h
@@ -43,7 +43,7 @@ public:
size_t GetReadableSpace(void) const;
/// Returns the current data start index. For debugging purposes.
- int GetDataStart(void) const { return m_DataStart; }
+ size_t GetDataStart(void) const { return m_DataStart; }
/// Returns true if the specified amount of bytes are available for reading
bool CanReadBytes(size_t a_Count) const;
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0f8700692..448dc4b70 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -16,6 +16,7 @@ if (NOT MSVC)
#lib dependecies are not included
set(BINDING_DEPENDECIES
+ tolua
${CMAKE_CURRENT_SOURCE_DIR}/Bindings/virtual_method_hooks.lua
${CMAKE_CURRENT_SOURCE_DIR}/Bindings/AllToLua.pkg
Bindings/LuaFunctions.h
@@ -57,6 +58,9 @@ if (NOT MSVC)
Entities/Player.h
Entities/ProjectileEntity.h
Entities/TNTEntity.h
+ Entities/ExpOrb.h
+ Entities/HangingEntity.h
+ Entities/ItemFrame.h
Generating/ChunkDesc.h
Group.h
Inventory.h
diff --git a/src/Chunk.cpp b/src/Chunk.cpp
index 957d7d575..22b33c595 100644
--- a/src/Chunk.cpp
+++ b/src/Chunk.cpp
@@ -884,7 +884,7 @@ void cChunk::ApplyWeatherToTop()
FastSetBlock(X, Height, Z, E_BLOCK_SNOW, TopMeta - 1);
}
}
- else if (cBlockInfo::IsSnowable(TopBlock))
+ else if (cBlockInfo::IsSnowable(TopBlock) && (Height + 1 < cChunkDef::Height))
{
SetBlock(X, Height + 1, Z, E_BLOCK_SNOW, 0);
}
@@ -2510,6 +2510,17 @@ cChunk * cChunk::GetNeighborChunk(int a_BlockX, int a_BlockZ)
cChunk * cChunk::GetRelNeighborChunk(int a_RelX, int a_RelZ)
{
+ // If the relative coords are too far away, use the parent's chunk lookup instead:
+ if ((a_RelX < 128) || (a_RelX > 128) || (a_RelZ < -128) || (a_RelZ > 128))
+ {
+ int BlockX = m_PosX * cChunkDef::Width + a_RelX;
+ int BlockZ = m_PosZ * cChunkDef::Width + a_RelZ;
+ int BlockY, ChunkX, ChunkZ;
+ AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
+ return m_ChunkMap->GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ }
+
+ // Walk the neighbors:
bool ReturnThis = true;
if (a_RelX < 0)
{
diff --git a/src/ChunkDef.h b/src/ChunkDef.h
index 04a7f5af2..9c7753820 100644
--- a/src/ChunkDef.h
+++ b/src/ChunkDef.h
@@ -112,7 +112,7 @@ public:
}
- inline static unsigned int MakeIndex(int x, int y, int z )
+ inline static int MakeIndex(int x, int y, int z )
{
if (
(x < Width) && (x > -1) &&
@@ -128,7 +128,7 @@ public:
}
- inline static unsigned int MakeIndexNoCheck(int x, int y, int z)
+ inline static int MakeIndexNoCheck(int x, int y, int z)
{
#if AXIS_ORDER == AXIS_ORDER_XZY
// For some reason, NOT using the Horner schema is faster. Weird.
@@ -251,7 +251,7 @@ public:
ASSERT(!"cChunkDef::SetNibble(): index out of range!");
return;
}
- a_Buffer[a_BlockIdx / 2] = (
+ a_Buffer[a_BlockIdx / 2] = static_cast<NIBBLETYPE>(
(a_Buffer[a_BlockIdx / 2] & (0xf0 >> ((a_BlockIdx & 1) * 4))) | // The untouched nibble
((a_Nibble & 0x0f) << ((a_BlockIdx & 1) * 4)) // The nibble being set
);
@@ -271,20 +271,20 @@ public:
}
int Index = MakeIndexNoCheck(x, y, z);
- a_Buffer[Index / 2] = (
+ a_Buffer[Index / 2] = static_cast<NIBBLETYPE>(
(a_Buffer[Index / 2] & (0xf0 >> ((Index & 1) * 4))) | // The untouched nibble
((a_Nibble & 0x0f) << ((Index & 1) * 4)) // The nibble being set
);
}
- inline static char GetNibble(const NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos )
+ inline static NIBBLETYPE GetNibble(const NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos )
{
return GetNibble(a_Buffer, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z );
}
- inline static void SetNibble(NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos, char a_Value )
+ inline static void SetNibble(NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos, NIBBLETYPE a_Value )
{
SetNibble( a_Buffer, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, a_Value );
}
@@ -302,6 +302,9 @@ The virtual methods are called in the same order as they're declared here.
class cChunkDataCallback abstract
{
public:
+
+ virtual ~cChunkDataCallback() {}
+
/** Called before any other callbacks to inform of the current coords
(only in processes where multiple chunks can be processed, such as cWorld::ForEachChunkInRect()).
If false is returned, the chunk is skipped.
@@ -428,6 +431,9 @@ Used primarily for entity moving while both chunks are locked.
class cClientDiffCallback
{
public:
+
+ virtual ~cClientDiffCallback() {}
+
/// Called for clients that are in Chunk1 and not in Chunk2,
virtual void Removed(cClientHandle * a_Client) = 0;
@@ -488,6 +494,9 @@ typedef std::vector<cChunkCoords> cChunkCoordsVector;
class cChunkCoordCallback
{
public:
+
+ virtual ~cChunkCoordCallback() {}
+
virtual void Call(int a_ChunkX, int a_ChunkZ) = 0;
} ;
diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp
index 40964c654..e695f0ab2 100644
--- a/src/ChunkMap.cpp
+++ b/src/ChunkMap.cpp
@@ -1376,8 +1376,9 @@ void cChunkMap::ReplaceTreeBlocks(const sSetBlockVector & a_Blocks)
break;
}
case E_BLOCK_LEAVES:
+ case E_BLOCK_NEW_LEAVES:
{
- if (itr->BlockType == E_BLOCK_LOG)
+ if ((itr->BlockType == E_BLOCK_LOG) || (itr->BlockType == E_BLOCK_NEW_LOG))
{
Chunk->SetBlock(itr->x, itr->y, itr->z, itr->BlockType, itr->BlockMeta);
}
@@ -1784,57 +1785,73 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_
BLOCKTYPE Block = area.GetBlockType(bx + x, by + y, bz + z);
switch (Block)
{
- case E_BLOCK_TNT:
- {
- // Activate the TNT, with a random fuse between 10 to 30 game ticks
- double FuseTime = (double)(10 + m_World->GetTickRandomNumber(20)) / 20;
- m_World->SpawnPrimedTNT(a_BlockX + x + 0.5, a_BlockY + y + 0.5, a_BlockZ + z + 0.5, FuseTime);
- area.SetBlockType(bx + x, by + y, bz + z, E_BLOCK_AIR);
- a_BlocksAffected.push_back(Vector3i(bx + x, by + y, bz + z));
- break;
- }
- case E_BLOCK_OBSIDIAN:
- case E_BLOCK_BEDROCK:
- case E_BLOCK_WATER:
- case E_BLOCK_LAVA:
- {
- // These blocks are not affected by explosions
- break;
- }
-
- case E_BLOCK_STATIONARY_WATER:
- {
- // Turn into simulated water:
- area.SetBlockType(bx + x, by + y, bz + z, E_BLOCK_WATER);
- break;
- }
+ case E_BLOCK_TNT:
+ {
+ // Activate the TNT, with a random fuse between 10 to 30 game ticks
+ int FuseTime = 10 + m_World->GetTickRandomNumber(20);
+ m_World->SpawnPrimedTNT(a_BlockX + x + 0.5, a_BlockY + y + 0.5, a_BlockZ + z + 0.5, FuseTime);
+ area.SetBlockType(bx + x, by + y, bz + z, E_BLOCK_AIR);
+ a_BlocksAffected.push_back(Vector3i(bx + x, by + y, bz + z));
+ break;
+ }
+
+ case E_BLOCK_OBSIDIAN:
+ case E_BLOCK_BEDROCK:
+ case E_BLOCK_WATER:
+ case E_BLOCK_LAVA:
+ {
+ // These blocks are not affected by explosions
+ break;
+ }
- case E_BLOCK_STATIONARY_LAVA:
- {
- // Turn into simulated lava:
- area.SetBlockType(bx + x, by + y, bz + z, E_BLOCK_LAVA);
- break;
- }
+ case E_BLOCK_STATIONARY_WATER:
+ {
+ // Turn into simulated water:
+ area.SetBlockType(bx + x, by + y, bz + z, E_BLOCK_WATER);
+ break;
+ }
- case E_BLOCK_AIR:
- {
- // No pickups for air
- break;
- }
+ case E_BLOCK_STATIONARY_LAVA:
+ {
+ // Turn into simulated lava:
+ area.SetBlockType(bx + x, by + y, bz + z, E_BLOCK_LAVA);
+ break;
+ }
- default:
- {
- if (m_World->GetTickRandomNumber(100) <= 25) // 25% chance of pickups
+ case E_BLOCK_AIR:
{
- cItems Drops;
- cBlockHandler * Handler = BlockHandler(Block);
+ // No pickups for air
+ break;
+ }
- Handler->ConvertToPickups(Drops, area.GetBlockMeta(bx + x, by + y, bz + z)); // Stone becomes cobblestone, coal ore becomes coal, etc.
- m_World->SpawnItemPickups(Drops, bx + x, by + y, bz + z);
+ default:
+ {
+ if (m_World->GetTickRandomNumber(100) <= 25) // 25% chance of pickups
+ {
+ cItems Drops;
+ cBlockHandler * Handler = BlockHandler(Block);
+
+ Handler->ConvertToPickups(Drops, area.GetBlockMeta(bx + x, by + y, bz + z)); // Stone becomes cobblestone, coal ore becomes coal, etc.
+ m_World->SpawnItemPickups(Drops, bx + x, by + y, bz + z);
+ }
+ else if ((m_World->GetTNTShrapnelLevel() > slNone) && (m_World->GetTickRandomNumber(100) < 20)) // 20% chance of flinging stuff around
+ {
+ if (!cBlockInfo::FullyOccupiesVoxel(Block))
+ {
+ break;
+ }
+ else if ((m_World->GetTNTShrapnelLevel() == slGravityAffectedOnly) && ((Block != E_BLOCK_SAND) && (Block != E_BLOCK_GRAVEL)))
+ {
+ break;
+ }
+ m_World->SpawnFallingBlock(bx + x, by + y + 5, bz + z, Block, area.GetBlockMeta(bx + x, by + y, bz + z));
+ }
+
+ area.SetBlockType(bx + x, by + y, bz + z, E_BLOCK_AIR);
+ a_BlocksAffected.push_back(Vector3i(bx + x, by + y, bz + z));
+ break;
+
}
- area.SetBlockType(bx + x, by + y, bz + z, E_BLOCK_AIR);
- a_BlocksAffected.push_back(Vector3i(bx + x, by + y, bz + z));
- }
} // switch (BlockType)
} // for z
} // for y
@@ -1846,11 +1863,10 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_
public cEntityCallback
{
public:
- cTNTDamageCallback(cBoundingBox & a_bbTNT, Vector3d a_ExplosionPos, int a_ExplosionSize, int a_ExplosionSizeSq) :
+ cTNTDamageCallback(cBoundingBox & a_bbTNT, Vector3d a_ExplosionPos, int a_ExplosionSize) :
m_bbTNT(a_bbTNT),
m_ExplosionPos(a_ExplosionPos),
- m_ExplosionSize(a_ExplosionSize),
- m_ExplosionSizeSq(a_ExplosionSizeSq)
+ m_ExplosionSize(a_ExplosionSize)
{
}
@@ -1873,14 +1889,16 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_
}
Vector3d AbsoluteEntityPos(abs(EntityPos.x), abs(EntityPos.y), abs(EntityPos.z));
- Vector3d MaxExplosionBoundary(m_ExplosionSizeSq, m_ExplosionSizeSq, m_ExplosionSizeSq);
// Work out how far we are from the edge of the TNT's explosive effect
AbsoluteEntityPos -= m_ExplosionPos;
- AbsoluteEntityPos = MaxExplosionBoundary - AbsoluteEntityPos;
- double FinalDamage = ((AbsoluteEntityPos.x + AbsoluteEntityPos.y + AbsoluteEntityPos.z) / 3) * m_ExplosionSize;
- FinalDamage = a_Entity->GetMaxHealth() - abs(FinalDamage);
+ // All to positive
+ AbsoluteEntityPos.x = abs(AbsoluteEntityPos.x);
+ AbsoluteEntityPos.y = abs(AbsoluteEntityPos.y);
+ AbsoluteEntityPos.z = abs(AbsoluteEntityPos.z);
+
+ double FinalDamage = (((1 / AbsoluteEntityPos.x) + (1 / AbsoluteEntityPos.y) + (1 / AbsoluteEntityPos.z)) * 2) * m_ExplosionSize;
// Clip damage values
if (FinalDamage > a_Entity->GetMaxHealth())
@@ -1888,7 +1906,7 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_
else if (FinalDamage < 0)
FinalDamage = 0;
- if (!a_Entity->IsTNT()) // Don't apply damage to other TNT entities, they should be invincible
+ if (!a_Entity->IsTNT() && !a_Entity->IsFallingBlock()) // Don't apply damage to other TNT entities and falling blocks, they should be invincible
{
a_Entity->TakeDamage(dtExplosion, NULL, (int)FinalDamage, 0);
}
@@ -1898,7 +1916,7 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_
if (distance_explosion.SqrLength() < 4096.0)
{
distance_explosion.Normalize();
- distance_explosion *= m_ExplosionSizeSq;
+ distance_explosion *= m_ExplosionSize * m_ExplosionSize;
a_Entity->AddSpeed(distance_explosion);
}
@@ -1910,14 +1928,13 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_
cBoundingBox & m_bbTNT;
Vector3d m_ExplosionPos;
int m_ExplosionSize;
- int m_ExplosionSizeSq;
};
cBoundingBox bbTNT(Vector3d(a_BlockX, a_BlockY, a_BlockZ), 0.5, 1);
bbTNT.Expand(ExplosionSizeInt * 2, ExplosionSizeInt * 2, ExplosionSizeInt * 2);
- cTNTDamageCallback TNTDamageCallback(bbTNT, Vector3d(a_BlockX, a_BlockY, a_BlockZ), ExplosionSizeInt, ExplosionSizeSq);
+ cTNTDamageCallback TNTDamageCallback(bbTNT, Vector3d(a_BlockX, a_BlockY, a_BlockZ), ExplosionSizeInt);
ForEachEntity(TNTDamageCallback);
// Wake up all simulators for the area, so that water and lava flows and sand falls into the blasted holes (FS #391):
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 9083d7ae0..5ed5f1085 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -33,19 +33,6 @@
-
-
-#define AddPistonDir(x, y, z, dir, amount) switch (dir) { case 0: (y)-=(amount); break; case 1: (y)+=(amount); break;\
- case 2: (z)-=(amount); break; case 3: (z)+=(amount); break;\
- case 4: (x)-=(amount); break; case 5: (x)+=(amount); break; }
-
-
-
-
-
-/** If the number of queued outgoing packets reaches this, the client will be kicked */
-#define MAX_OUTGOING_PACKETS 2000
-
/** Maximum number of explosions to send this tick, server will start dropping if exceeded */
#define MAX_EXPLOSIONS_PER_TICK 20
@@ -892,7 +879,7 @@ void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_Blo
LOGD("Prevented a dig/aim bug in the client (finish {%d, %d, %d} vs start {%d, %d, %d}, HSD: %s)",
a_BlockX, a_BlockY, a_BlockZ,
m_LastDigBlockX, m_LastDigBlockY, m_LastDigBlockZ,
- m_HasStartedDigging
+ (m_HasStartedDigging ? "True" : "False")
);
return;
}
@@ -954,6 +941,8 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
}
return;
}
+
+ m_NumBlockChangeInteractionsThisTick++;
if (!CheckBlockInteractionsRate())
{
@@ -973,7 +962,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
);
// Let's send the current world block to the client, so that it can immediately "let the user know" that they haven't placed the block
- if (a_BlockFace > -1)
+ if (a_BlockFace != BLOCK_FACE_NONE)
{
AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
@@ -1001,7 +990,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
cItemHandler * ItemHandler = cItemHandler::GetItemHandler(Equipped.m_ItemType);
- if (ItemHandler->IsPlaceable() && (a_BlockFace > -1))
+ if (ItemHandler->IsPlaceable() && (a_BlockFace != BLOCK_FACE_NONE))
{
HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler);
}
@@ -1039,6 +1028,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, cItemHandler & a_ItemHandler)
{
+ BLOCKTYPE EquippedBlock = (BLOCKTYPE)(m_Player->GetEquippedItem().m_ItemType);
if (a_BlockFace < 0)
{
// Clicked in air
@@ -1049,7 +1039,6 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, e
BLOCKTYPE ClickedBlock;
NIBBLETYPE ClickedBlockMeta;
- BLOCKTYPE EquippedBlock = (BLOCKTYPE)(m_Player->GetEquippedItem().m_ItemType);
NIBBLETYPE EquippedBlockDamage = (NIBBLETYPE)(m_Player->GetEquippedItem().m_ItemDamage);
if ((a_BlockY < 0) || (a_BlockY >= cChunkDef::Height))
@@ -1066,8 +1055,8 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, e
cBlockSlabHandler::IsAnySlabType(EquippedBlock) && // Is the player placing another slab?
((ClickedBlockMeta & 0x07) == EquippedBlockDamage) && // Is it the same slab type?
(
- (a_BlockFace == BLOCK_FACE_TOP) || // Clicking the top of a bottom slab
- (a_BlockFace == BLOCK_FACE_BOTTOM) // Clicking the bottom of a top slab
+ (a_BlockFace == BLOCK_FACE_TOP) || // Clicking the top of a bottom slab
+ (a_BlockFace == BLOCK_FACE_BOTTOM) // Clicking the bottom of a top slab
)
)
{
@@ -1151,7 +1140,7 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, e
// The actual block placement:
World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta);
- if (m_Player->GetGameMode() != gmCreative)
+ if (!m_Player->IsGameModeCreative())
{
m_Player->GetInventory().RemoveOneEquippedItem();
}
@@ -1619,10 +1608,8 @@ void cClientHandle::MoveToWorld(cWorld & a_World, bool a_SendRespawnPacket)
m_Protocol->SendUnloadChunk(itr->m_ChunkX, itr->m_ChunkZ);
} // for itr - Chunks[]
- // Do NOT stream new chunks, the new world runs its own tick thread and may deadlock
- // Instead, the chunks will be streamed when the client is moved to the new world's Tick list,
- // by setting state to csAuthenticated
- m_State = csAuthenticated;
+ // StreamChunks() called in cPlayer::MoveToWorld() after new world has been set
+ // Meanwhile here, we set last streamed values to bogus ones so everything is resent
m_LastStreamedChunkX = 0x7fffffff;
m_LastStreamedChunkZ = 0x7fffffff;
m_HasSentPlayerChunk = false;
diff --git a/src/CommandOutput.cpp b/src/CommandOutput.cpp
index c221682a1..2c116b3d6 100644
--- a/src/CommandOutput.cpp
+++ b/src/CommandOutput.cpp
@@ -51,7 +51,7 @@ void cLogCommandOutputCallback::Finished(void)
{
case '\n':
{
- LOG(m_Buffer.substr(last, i - last).c_str());
+ LOG("%s", m_Buffer.substr(last, i - last).c_str());
last = i + 1;
break;
}
@@ -59,7 +59,7 @@ void cLogCommandOutputCallback::Finished(void)
} // for i - m_Buffer[]
if (last < len)
{
- LOG(m_Buffer.substr(last).c_str());
+ LOG("%s", m_Buffer.substr(last).c_str());
}
// Clear the buffer for the next command output:
diff --git a/src/CommandOutput.h b/src/CommandOutput.h
index 3763d625f..5682b4fd8 100644
--- a/src/CommandOutput.h
+++ b/src/CommandOutput.h
@@ -17,7 +17,7 @@ public:
virtual ~cCommandOutputCallback() {}; // Force a virtual destructor in subclasses
/// Syntax sugar function, calls Out() with Printf()-ed parameters; appends a "\n"
- void Out(const char * a_Fmt, ...);
+ void Out(const char * a_Fmt, ...) FORMATSTRING(2, 3);
/// Called when the command wants to output anything; may be called multiple times
virtual void Out(const AString & a_Text) = 0;
diff --git a/src/CompositeChat.cpp b/src/CompositeChat.cpp
index 3eec35657..a917ee70f 100644
--- a/src/CompositeChat.cpp
+++ b/src/CompositeChat.cpp
@@ -10,7 +10,7 @@
-#if SELF_TEST
+#ifdef SELF_TEST
/** A simple self-test that verifies that the composite chat parser is working properly. */
class SelfTest_CompositeChat
@@ -32,15 +32,15 @@ public:
cCompositeChat Msg;
Msg.ParseText("Testing @2color codes and http://links parser");
const cCompositeChat::cParts & Parts = Msg.GetParts();
- assert(Parts.size() == 4);
- assert(Parts[0]->m_PartType == cCompositeChat::ptText);
- assert(Parts[1]->m_PartType == cCompositeChat::ptText);
- assert(Parts[2]->m_PartType == cCompositeChat::ptUrl);
- assert(Parts[3]->m_PartType == cCompositeChat::ptText);
- assert(Parts[0]->m_Style == "");
- assert(Parts[1]->m_Style == "@2");
- assert(Parts[2]->m_Style == "@2");
- assert(Parts[3]->m_Style == "@2");
+ assert_test(Parts.size() == 4);
+ assert_test(Parts[0]->m_PartType == cCompositeChat::ptText);
+ assert_test(Parts[1]->m_PartType == cCompositeChat::ptText);
+ assert_test(Parts[2]->m_PartType == cCompositeChat::ptUrl);
+ assert_test(Parts[3]->m_PartType == cCompositeChat::ptText);
+ assert_test(Parts[0]->m_Style == "");
+ assert_test(Parts[1]->m_Style == "@2");
+ assert_test(Parts[2]->m_Style == "@2");
+ assert_test(Parts[3]->m_Style == "@2");
}
void TestParser2(void)
@@ -48,15 +48,15 @@ public:
cCompositeChat Msg;
Msg.ParseText("@3Advanced stuff: @5overriding color codes and http://links.with/@4color-in-them handling");
const cCompositeChat::cParts & Parts = Msg.GetParts();
- assert(Parts.size() == 4);
- assert(Parts[0]->m_PartType == cCompositeChat::ptText);
- assert(Parts[1]->m_PartType == cCompositeChat::ptText);
- assert(Parts[2]->m_PartType == cCompositeChat::ptUrl);
- assert(Parts[3]->m_PartType == cCompositeChat::ptText);
- assert(Parts[0]->m_Style == "@3");
- assert(Parts[1]->m_Style == "@5");
- assert(Parts[2]->m_Style == "@5");
- assert(Parts[3]->m_Style == "@5");
+ assert_test(Parts.size() == 4);
+ assert_test(Parts[0]->m_PartType == cCompositeChat::ptText);
+ assert_test(Parts[1]->m_PartType == cCompositeChat::ptText);
+ assert_test(Parts[2]->m_PartType == cCompositeChat::ptUrl);
+ assert_test(Parts[3]->m_PartType == cCompositeChat::ptText);
+ assert_test(Parts[0]->m_Style == "@3");
+ assert_test(Parts[1]->m_Style == "@5");
+ assert_test(Parts[2]->m_Style == "@5");
+ assert_test(Parts[3]->m_Style == "@5");
}
void TestParser3(void)
@@ -64,11 +64,11 @@ public:
cCompositeChat Msg;
Msg.ParseText("http://links.starting the text");
const cCompositeChat::cParts & Parts = Msg.GetParts();
- assert(Parts.size() == 2);
- assert(Parts[0]->m_PartType == cCompositeChat::ptUrl);
- assert(Parts[1]->m_PartType == cCompositeChat::ptText);
- assert(Parts[0]->m_Style == "");
- assert(Parts[1]->m_Style == "");
+ assert_test(Parts.size() == 2);
+ assert_test(Parts[0]->m_PartType == cCompositeChat::ptUrl);
+ assert_test(Parts[1]->m_PartType == cCompositeChat::ptText);
+ assert_test(Parts[0]->m_Style == "");
+ assert_test(Parts[1]->m_Style == "");
}
void TestParser4(void)
@@ -76,11 +76,11 @@ public:
cCompositeChat Msg;
Msg.ParseText("links finishing the text: http://some.server");
const cCompositeChat::cParts & Parts = Msg.GetParts();
- assert(Parts.size() == 2);
- assert(Parts[0]->m_PartType == cCompositeChat::ptText);
- assert(Parts[1]->m_PartType == cCompositeChat::ptUrl);
- assert(Parts[0]->m_Style == "");
- assert(Parts[1]->m_Style == "");
+ assert_test(Parts.size() == 2);
+ assert_test(Parts[0]->m_PartType == cCompositeChat::ptText);
+ assert_test(Parts[1]->m_PartType == cCompositeChat::ptUrl);
+ assert_test(Parts[0]->m_Style == "");
+ assert_test(Parts[1]->m_Style == "");
}
void TestParser5(void)
@@ -88,9 +88,9 @@ public:
cCompositeChat Msg;
Msg.ParseText("http://only.links");
const cCompositeChat::cParts & Parts = Msg.GetParts();
- assert(Parts.size() == 1);
- assert(Parts[0]->m_PartType == cCompositeChat::ptUrl);
- assert(Parts[0]->m_Style == "");
+ assert_test(Parts.size() == 1);
+ assert_test(Parts[0]->m_PartType == cCompositeChat::ptUrl);
+ assert_test(Parts[0]->m_Style == "");
}
} gTest;
diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp
index 868182394..30e7a8733 100644
--- a/src/CraftingRecipes.cpp
+++ b/src/CraftingRecipes.cpp
@@ -192,7 +192,9 @@ void cCraftingGrid::Dump(void)
{
for (int y = 0; y < m_Height; y++) for (int x = 0; x < m_Width; x++)
{
+ #ifdef _DEBUG
int idx = x + m_Width * y;
+ #endif
LOGD("Slot (%d, %d): Type %d, health %d, count %d",
x, y, m_Items[idx].m_ItemType, m_Items[idx].m_ItemDamage, m_Items[idx].m_ItemCount
);
@@ -338,7 +340,7 @@ void cCraftingRecipes::LoadRecipes(void)
}
AddRecipeLine(LineNum, Recipe);
} // for itr - Split[]
- LOG("Loaded %d crafting recipes", m_Recipes.size());
+ LOG("Loaded " SIZE_T_FMT " crafting recipes", m_Recipes.size());
}
diff --git a/src/Cuboid.cpp b/src/Cuboid.cpp
index 2400c64f3..3e5240248 100644
--- a/src/Cuboid.cpp
+++ b/src/Cuboid.cpp
@@ -38,6 +38,20 @@ void cCuboid::Assign(int a_X1, int a_Y1, int a_Z1, int a_X2, int a_Y2, int a_Z2)
+void cCuboid::Assign(const cCuboid & a_SrcCuboid)
+{
+ p1.x = a_SrcCuboid.p1.x;
+ p1.y = a_SrcCuboid.p1.y;
+ p1.z = a_SrcCuboid.p1.z;
+ p2.x = a_SrcCuboid.p2.x;
+ p2.y = a_SrcCuboid.p2.y;
+ p2.z = a_SrcCuboid.p2.z;
+}
+
+
+
+
+
void cCuboid::Sort(void)
{
if (p1.x > p2.x)
diff --git a/src/Cuboid.h b/src/Cuboid.h
index b90a09e05..3239c54fc 100644
--- a/src/Cuboid.h
+++ b/src/Cuboid.h
@@ -21,6 +21,7 @@ public:
cCuboid(int a_X1, int a_Y1, int a_Z1, int a_X2, int a_Y2, int a_Z2) : p1(a_X1, a_Y1, a_Z1), p2(a_X2, a_Y2, a_Z2) {}
void Assign(int a_X1, int a_Y1, int a_Z1, int a_X2, int a_Y2, int a_Z2);
+ void Assign(const cCuboid & a_SrcCuboid);
void Sort(void);
diff --git a/src/DeadlockDetect.cpp b/src/DeadlockDetect.cpp
index c42d09b89..322084dc4 100644
--- a/src/DeadlockDetect.cpp
+++ b/src/DeadlockDetect.cpp
@@ -7,7 +7,7 @@
#include "DeadlockDetect.h"
#include "Root.h"
#include "World.h"
-# include <cstdlib>
+#include <cstdlib>
@@ -16,9 +16,6 @@
/// Number of milliseconds per cycle
const int CYCLE_MILLISECONDS = 100;
-/// When the number of cycles for the same world age hits this value, it is considered a deadlock
-const int NUM_CYCLES_LIMIT = 200; // 200 = twenty seconds
-
@@ -121,7 +118,6 @@ void cDeadlockDetect::CheckWorldAge(const AString & a_WorldName, Int64 a_Age)
if (itr->second.m_NumCyclesSame > (1000 * m_IntervalSec) / CYCLE_MILLISECONDS)
{
DeadlockDetected();
- return;
}
}
else
diff --git a/src/DeadlockDetect.h b/src/DeadlockDetect.h
index cb2309169..6aa98acbb 100644
--- a/src/DeadlockDetect.h
+++ b/src/DeadlockDetect.h
@@ -60,7 +60,7 @@ protected:
void CheckWorldAge(const AString & a_WorldName, Int64 a_Age);
/// Called when a deadlock is detected. Aborts the server.
- void DeadlockDetected(void);
+ NORETURN void DeadlockDetected(void);
} ;
diff --git a/src/Defines.h b/src/Defines.h
index d2fcce576..1a8b3fa4a 100644
--- a/src/Defines.h
+++ b/src/Defines.h
@@ -2,6 +2,7 @@
#pragma once
#include "ChatColor.h"
+#include <limits>
@@ -289,7 +290,10 @@ inline AString BlockFaceToString(eBlockFace a_BlockFace)
case BLOCK_FACE_ZP: return "BLOCK_FACE_ZP";
case BLOCK_FACE_NONE: return "BLOCK_FACE_NONE";
}
+ // clang optimisises this line away then warns that it has done so.
+ #if !defined(__clang__)
return Printf("Unknown BLOCK_FACE: %d", a_BlockFace);
+ #endif
}
@@ -489,7 +493,7 @@ inline void EulerToVector(double a_Pan, double a_Pitch, double & a_X, double & a
inline void VectorToEuler(double a_X, double a_Y, double a_Z, double & a_Pan, double & a_Pitch)
{
- if (a_X != 0)
+ if (fabs(a_X) < std::numeric_limits<double>::epsilon())
{
a_Pan = atan2(a_Z, a_X) * 180 / PI - 90;
}
@@ -529,16 +533,22 @@ enum eMessageType
// http://forum.mc-server.org/showthread.php?tid=1212
// MessageType...
- mtCustom, // Send raw data without any processing
- mtFailure, // Something could not be done (i.e. command not executed due to insufficient privilege)
- mtInformation, // Informational message (i.e. command usage)
- mtSuccess, // Something executed successfully
- mtWarning, // Something concerning (i.e. reload) is about to happen
- mtFatal, // Something catastrophic occured (i.e. plugin crash)
- mtDeath, // Denotes death of player
- mtPrivateMessage, // Player to player messaging identifier
- mtJoin, // A player has joined the server
- mtLeave, // A player has left the server
+ mtCustom, // Send raw data without any processing
+ mtFailure, // Something could not be done (i.e. command not executed due to insufficient privilege)
+ mtInformation, // Informational message (i.e. command usage)
+ mtSuccess, // Something executed successfully
+ mtWarning, // Something concerning (i.e. reload) is about to happen
+ mtFatal, // Something catastrophic occured (i.e. plugin crash)
+ mtDeath, // Denotes death of player
+ mtPrivateMessage, // Player to player messaging identifier
+ mtJoin, // A player has joined the server
+ mtLeave, // A player has left the server
+
+ // Common aliases:
+ mtFail = mtFailure,
+ mtError = mtFailure,
+ mtInfo = mtInformation,
+ mtPM = mtPrivateMessage,
};
diff --git a/src/Entities/EnderCrystal.cpp b/src/Entities/EnderCrystal.cpp
new file mode 100644
index 000000000..a640b236c
--- /dev/null
+++ b/src/Entities/EnderCrystal.cpp
@@ -0,0 +1,56 @@
+
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "EnderCrystal.h"
+#include "ClientHandle.h"
+#include "Player.h"
+#include "../Chunk.h"
+
+
+
+
+
+cEnderCrystal::cEnderCrystal(double a_X, double a_Y, double a_Z)
+ : cEntity(etEnderCrystal, a_X, a_Y, a_Z, 1.0, 1.0)
+{
+ SetMaxHealth(5);
+}
+
+
+
+
+
+void cEnderCrystal::SpawnOn(cClientHandle & a_ClientHandle)
+{
+ a_ClientHandle.SendSpawnObject(*this, 51, 0, (Byte)GetYaw(), (Byte)GetPitch());
+}
+
+
+
+
+
+void cEnderCrystal::Tick(float a_Dt, cChunk & a_Chunk)
+{
+ UNUSED(a_Dt);
+
+ a_Chunk.SetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT, E_BLOCK_FIRE, 0);
+
+ // No further processing (physics e.t.c.) is needed
+}
+
+
+
+
+
+void cEnderCrystal::KilledBy(cEntity * a_Killer)
+{
+ super::KilledBy(a_Killer);
+
+ m_World->DoExplosionAt(6.0, GetPosX(), GetPosY(), GetPosZ(), true, esEnderCrystal, this);
+
+ Destroy();
+}
+
+
+
+
diff --git a/src/Entities/EnderCrystal.h b/src/Entities/EnderCrystal.h
new file mode 100644
index 000000000..5b86df987
--- /dev/null
+++ b/src/Entities/EnderCrystal.h
@@ -0,0 +1,33 @@
+
+#pragma once
+
+#include "Entity.h"
+
+
+
+
+
+// tolua_begin
+class cEnderCrystal :
+ public cEntity
+{
+ // tolua_end
+ typedef cEntity super;
+
+public:
+ CLASS_PROTODEF(cEnderCrystal);
+
+ cEnderCrystal(double a_X, double a_Y, double a_Z);
+
+private:
+
+ // cEntity overrides:
+ virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
+ virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
+ virtual void KilledBy(cEntity * a_Killer) override;
+
+}; // tolua_export
+
+
+
+
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 0750ae05e..221cbbea7 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -521,27 +521,35 @@ void cEntity::Tick(float a_Dt, cChunk & a_Chunk)
{
if (a_Chunk.IsValid())
{
- HandlePhysics(a_Dt, a_Chunk);
- }
- }
- if (a_Chunk.IsValid())
- {
- TickBurning(a_Chunk);
- }
- if ((a_Chunk.IsValid()) && (GetPosY() < -46))
- {
- TickInVoid(a_Chunk);
- }
- else
- m_TicksSinceLastVoidDamage = 0;
+ cChunk * NextChunk = a_Chunk.GetNeighborChunk(POSX_TOINT, POSZ_TOINT);
- if (IsMob() || IsPlayer())
- {
- // Set swimming state
- SetSwimState(a_Chunk);
+ if ((NextChunk == NULL) || !NextChunk->IsValid())
+ {
+ return;
+ }
+
+ TickBurning(*NextChunk);
+
+ if (GetPosY() < VOID_BOUNDARY)
+ {
+ TickInVoid(*NextChunk);
+ }
+ else
+ {
+ m_TicksSinceLastVoidDamage = 0;
+ }
+
+ if (IsMob() || IsPlayer())
+ {
+ // Set swimming state
+ SetSwimState(*NextChunk);
- // Handle drowning
- HandleAir();
+ // Handle drowning
+ HandleAir();
+ }
+
+ HandlePhysics(a_Dt, *NextChunk);
+ }
}
}
@@ -562,7 +570,7 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
if ((BlockY >= cChunkDef::Height) || (BlockY < 0))
{
// Outside of the world
-
+
cChunk * NextChunk = a_Chunk.GetNeighborChunk(BlockX, BlockZ);
// See if we can commit our changes. If not, we will discard them.
if (NextChunk != NULL)
@@ -571,210 +579,205 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
NextPos += (NextSpeed * a_Dt);
SetPosition(NextPos);
}
+
return;
}
- // Make sure we got the correct chunk and a valid one. No one ever knows...
- cChunk * NextChunk = a_Chunk.GetNeighborChunk(BlockX, BlockZ);
- if (NextChunk != NULL)
+ int RelBlockX = BlockX - (a_Chunk.GetPosX() * cChunkDef::Width);
+ int RelBlockZ = BlockZ - (a_Chunk.GetPosZ() * cChunkDef::Width);
+ BLOCKTYPE BlockIn = a_Chunk.GetBlock( RelBlockX, BlockY, RelBlockZ );
+ BLOCKTYPE BlockBelow = (BlockY > 0) ? a_Chunk.GetBlock(RelBlockX, BlockY - 1, RelBlockZ) : E_BLOCK_AIR;
+ if (!cBlockInfo::IsSolid(BlockIn)) // Making sure we are not inside a solid block
{
- int RelBlockX = BlockX - (NextChunk->GetPosX() * cChunkDef::Width);
- int RelBlockZ = BlockZ - (NextChunk->GetPosZ() * cChunkDef::Width);
- BLOCKTYPE BlockIn = NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ );
- BLOCKTYPE BlockBelow = (BlockY > 0) ? NextChunk->GetBlock(RelBlockX, BlockY - 1, RelBlockZ) : E_BLOCK_AIR;
- if (!cBlockInfo::IsSolid(BlockIn)) // Making sure we are not inside a solid block
+ if (m_bOnGround) // check if it's still on the ground
{
- if (m_bOnGround) // check if it's still on the ground
+ if (!cBlockInfo::IsSolid(BlockBelow)) // Check if block below is air or water.
{
- if (!cBlockInfo::IsSolid(BlockBelow)) // Check if block below is air or water.
- {
- m_bOnGround = false;
- }
+ m_bOnGround = false;
}
}
- else
- {
- // Push out entity.
- BLOCKTYPE GotBlock;
+ }
+ else
+ {
+ // Push out entity.
+ BLOCKTYPE GotBlock;
- static const struct
- {
- int x, y, z;
- } gCrossCoords[] =
- {
- { 1, 0, 0},
- {-1, 0, 0},
- { 0, 0, 1},
- { 0, 0, -1},
- } ;
-
- bool IsNoAirSurrounding = true;
- for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++)
+ static const struct
+ {
+ int x, y, z;
+ } gCrossCoords[] =
+ {
+ { 1, 0, 0},
+ {-1, 0, 0},
+ { 0, 0, 1},
+ { 0, 0, -1},
+ } ;
+
+ bool IsNoAirSurrounding = true;
+ for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++)
+ {
+ if (!a_Chunk.UnboundedRelGetBlockType(RelBlockX + gCrossCoords[i].x, BlockY, RelBlockZ + gCrossCoords[i].z, GotBlock))
{
- if (!NextChunk->UnboundedRelGetBlockType(RelBlockX + gCrossCoords[i].x, BlockY, RelBlockZ + gCrossCoords[i].z, GotBlock))
- {
- // The pickup is too close to an unloaded chunk, bail out of any physics handling
- return;
- }
- if (!cBlockInfo::IsSolid(GotBlock))
- {
- NextPos.x += gCrossCoords[i].x;
- NextPos.z += gCrossCoords[i].z;
- IsNoAirSurrounding = false;
- break;
- }
- } // for i - gCrossCoords[]
-
- if (IsNoAirSurrounding)
+ // The pickup is too close to an unloaded chunk, bail out of any physics handling
+ return;
+ }
+ if (!cBlockInfo::IsSolid(GotBlock))
{
- NextPos.y += 0.5;
+ NextPos.x += gCrossCoords[i].x;
+ NextPos.z += gCrossCoords[i].z;
+ IsNoAirSurrounding = false;
+ break;
}
+ } // for i - gCrossCoords[]
+
+ if (IsNoAirSurrounding)
+ {
+ NextPos.y += 0.5;
+ }
- m_bOnGround = true;
+ m_bOnGround = true;
- /*
- // DEBUG:
- LOGD("Entity #%d (%s) is inside a block at {%d, %d, %d}",
- m_UniqueID, GetClass(), BlockX, BlockY, BlockZ
- );
- */
- }
+ /*
+ // DEBUG:
+ LOGD("Entity #%d (%s) is inside a block at {%d, %d, %d}",
+ m_UniqueID, GetClass(), BlockX, BlockY, BlockZ
+ );
+ */
+ }
- if (!m_bOnGround)
+ if (!m_bOnGround)
+ {
+ float fallspeed;
+ if (IsBlockWater(BlockIn))
{
- float fallspeed;
- if (IsBlockWater(BlockIn))
- {
- fallspeed = m_Gravity * a_Dt / 3; // Fall 3x slower in water.
- }
- else if (BlockIn == E_BLOCK_COBWEB)
- {
- NextSpeed.y *= 0.05; // Reduce overall falling speed
- fallspeed = 0; // No falling.
- }
- else
- {
- // Normal gravity
- fallspeed = m_Gravity * a_Dt;
- }
- NextSpeed.y += fallspeed;
+ fallspeed = m_Gravity * a_Dt / 3; // Fall 3x slower in water.
+ }
+ else if (BlockIn == E_BLOCK_COBWEB)
+ {
+ NextSpeed.y *= 0.05; // Reduce overall falling speed
+ fallspeed = 0; // No falling.
}
else
{
- // Friction
- if (NextSpeed.SqrLength() > 0.0004f)
+ // Normal gravity
+ fallspeed = m_Gravity * a_Dt;
+ }
+ NextSpeed.y += fallspeed;
+ }
+ else
+ {
+ // Friction
+ if (NextSpeed.SqrLength() > 0.0004f)
+ {
+ NextSpeed.x *= 0.7f / (1 + a_Dt);
+ if (fabs(NextSpeed.x) < 0.05)
{
- NextSpeed.x *= 0.7f / (1 + a_Dt);
- if (fabs(NextSpeed.x) < 0.05)
- {
- NextSpeed.x = 0;
- }
- NextSpeed.z *= 0.7f / (1 + a_Dt);
- if (fabs(NextSpeed.z) < 0.05)
- {
- NextSpeed.z = 0;
- }
+ NextSpeed.x = 0;
+ }
+ NextSpeed.z *= 0.7f / (1 + a_Dt);
+ if (fabs(NextSpeed.z) < 0.05)
+ {
+ NextSpeed.z = 0;
}
}
+ }
- // Adjust X and Z speed for COBWEB temporary. This speed modification should be handled inside block handlers since we
- // might have different speed modifiers according to terrain.
- if (BlockIn == E_BLOCK_COBWEB)
- {
- NextSpeed.x *= 0.25;
- NextSpeed.z *= 0.25;
- }
+ // Adjust X and Z speed for COBWEB temporary. This speed modification should be handled inside block handlers since we
+ // might have different speed modifiers according to terrain.
+ if (BlockIn == E_BLOCK_COBWEB)
+ {
+ NextSpeed.x *= 0.25;
+ NextSpeed.z *= 0.25;
+ }
- //Get water direction
- Direction WaterDir = m_World->GetWaterSimulator()->GetFlowingDirection(BlockX, BlockY, BlockZ);
+ //Get water direction
+ Direction WaterDir = m_World->GetWaterSimulator()->GetFlowingDirection(BlockX, BlockY, BlockZ);
- m_WaterSpeed *= 0.9f; //Reduce speed each tick
+ m_WaterSpeed *= 0.9f; //Reduce speed each tick
- switch(WaterDir)
- {
- case X_PLUS:
- m_WaterSpeed.x = 0.2f;
- m_bOnGround = false;
- break;
- case X_MINUS:
- m_WaterSpeed.x = -0.2f;
- m_bOnGround = false;
- break;
- case Z_PLUS:
- m_WaterSpeed.z = 0.2f;
- m_bOnGround = false;
- break;
- case Z_MINUS:
- m_WaterSpeed.z = -0.2f;
- m_bOnGround = false;
- break;
-
- default:
+ switch(WaterDir)
+ {
+ case X_PLUS:
+ m_WaterSpeed.x = 0.2f;
+ m_bOnGround = false;
break;
- }
+ case X_MINUS:
+ m_WaterSpeed.x = -0.2f;
+ m_bOnGround = false;
+ break;
+ case Z_PLUS:
+ m_WaterSpeed.z = 0.2f;
+ m_bOnGround = false;
+ break;
+ case Z_MINUS:
+ m_WaterSpeed.z = -0.2f;
+ m_bOnGround = false;
+ break;
+
+ default:
+ break;
+ }
- if (fabs(m_WaterSpeed.x) < 0.05)
- {
- m_WaterSpeed.x = 0;
- }
+ if (fabs(m_WaterSpeed.x) < 0.05)
+ {
+ m_WaterSpeed.x = 0;
+ }
- if (fabs(m_WaterSpeed.z) < 0.05)
- {
- m_WaterSpeed.z = 0;
- }
+ if (fabs(m_WaterSpeed.z) < 0.05)
+ {
+ m_WaterSpeed.z = 0;
+ }
- NextSpeed += m_WaterSpeed;
+ NextSpeed += m_WaterSpeed;
- if( NextSpeed.SqrLength() > 0.f )
+ if( NextSpeed.SqrLength() > 0.f )
+ {
+ cTracer Tracer( GetWorld() );
+ bool HasHit = Tracer.Trace( NextPos, NextSpeed, 2 );
+ if (HasHit) // Oh noez! we hit something
{
- cTracer Tracer( GetWorld() );
- int Ret = Tracer.Trace( NextPos, NextSpeed, 2 );
- if( Ret ) // Oh noez! we hit something
+ // Set to hit position
+ if ((Tracer.RealHit - NextPos).SqrLength() <= (NextSpeed * a_Dt).SqrLength())
{
- // Set to hit position
- if( (Tracer.RealHit - NextPos).SqrLength() <= ( NextSpeed * a_Dt ).SqrLength() )
- {
- if( Ret == 1 )
- {
- if( Tracer.HitNormal.x != 0.f ) NextSpeed.x = 0.f;
- if( Tracer.HitNormal.y != 0.f ) NextSpeed.y = 0.f;
- if( Tracer.HitNormal.z != 0.f ) NextSpeed.z = 0.f;
-
- if( Tracer.HitNormal.y > 0 ) // means on ground
- {
- m_bOnGround = true;
- }
- }
- NextPos.Set(Tracer.RealHit.x,Tracer.RealHit.y,Tracer.RealHit.z);
- NextPos.x += Tracer.HitNormal.x * 0.3f;
- NextPos.y += Tracer.HitNormal.y * 0.05f; // Any larger produces entity vibration-upon-the-spot
- NextPos.z += Tracer.HitNormal.z * 0.3f;
- }
- else
+ if (Tracer.HitNormal.x != 0.f) NextSpeed.x = 0.f;
+ if (Tracer.HitNormal.y != 0.f) NextSpeed.y = 0.f;
+ if (Tracer.HitNormal.z != 0.f) NextSpeed.z = 0.f;
+
+ if (Tracer.HitNormal.y > 0) // means on ground
{
- NextPos += (NextSpeed * a_Dt);
+ m_bOnGround = true;
}
+ NextPos.Set(Tracer.RealHit.x,Tracer.RealHit.y,Tracer.RealHit.z);
+ NextPos.x += Tracer.HitNormal.x * 0.3f;
+ NextPos.y += Tracer.HitNormal.y * 0.05f; // Any larger produces entity vibration-upon-the-spot
+ NextPos.z += Tracer.HitNormal.z * 0.3f;
}
else
{
- // We didn't hit anything, so move =]
NextPos += (NextSpeed * a_Dt);
}
}
- BlockX = (int) floor(NextPos.x);
- BlockZ = (int) floor(NextPos.z);
- NextChunk = NextChunk->GetNeighborChunk(BlockX,BlockZ);
- // See if we can commit our changes. If not, we will discard them.
- if (NextChunk != NULL)
+ else
{
- if (NextPos.x != GetPosX()) SetPosX(NextPos.x);
- if (NextPos.y != GetPosY()) SetPosY(NextPos.y);
- if (NextPos.z != GetPosZ()) SetPosZ(NextPos.z);
- if (NextSpeed.x != GetSpeedX()) SetSpeedX(NextSpeed.x);
- if (NextSpeed.y != GetSpeedY()) SetSpeedY(NextSpeed.y);
- if (NextSpeed.z != GetSpeedZ()) SetSpeedZ(NextSpeed.z);
+ // We didn't hit anything, so move =]
+ NextPos += (NextSpeed * a_Dt);
}
}
+
+ BlockX = (int) floor(NextPos.x);
+ BlockZ = (int) floor(NextPos.z);
+
+ cChunk * NextChunk = a_Chunk.GetNeighborChunk(BlockX, BlockZ);
+ // See if we can commit our changes. If not, we will discard them.
+ if (NextChunk != NULL)
+ {
+ if (NextPos.x != GetPosX()) SetPosX(NextPos.x);
+ if (NextPos.y != GetPosY()) SetPosY(NextPos.y);
+ if (NextPos.z != GetPosZ()) SetPosZ(NextPos.z);
+ if (NextSpeed.x != GetSpeedX()) SetSpeedX(NextSpeed.x);
+ if (NextSpeed.y != GetSpeedY()) SetSpeedY(NextSpeed.y);
+ if (NextSpeed.z != GetSpeedZ()) SetSpeedZ(NextSpeed.z);
+ }
}
@@ -815,14 +818,13 @@ void cEntity::TickBurning(cChunk & a_Chunk)
{
int RelX = x;
int RelZ = z;
- cChunk * CurChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(RelX, RelZ);
- if (CurChunk == NULL)
- {
- continue;
- }
+
for (int y = MinY; y <= MaxY; y++)
{
- switch (CurChunk->GetBlock(RelX, y, RelZ))
+ BLOCKTYPE Block;
+ a_Chunk.UnboundedRelGetBlockType(RelX, y, RelZ, Block);
+
+ switch (Block)
{
case E_BLOCK_FIRE:
{
@@ -922,7 +924,7 @@ void cEntity::TickInVoid(cChunk & a_Chunk)
void cEntity::SetSwimState(cChunk & a_Chunk)
{
- int RelY = (int)floor(m_LastPosY + 0.1);
+ int RelY = (int)floor(GetPosY() + 0.1);
if ((RelY < 0) || (RelY >= cChunkDef::Height - 1))
{
m_IsSwimming = false;
@@ -931,11 +933,10 @@ void cEntity::SetSwimState(cChunk & a_Chunk)
}
BLOCKTYPE BlockIn;
- int RelX = (int)floor(m_LastPosX) - a_Chunk.GetPosX() * cChunkDef::Width;
- int RelZ = (int)floor(m_LastPosZ) - a_Chunk.GetPosZ() * cChunkDef::Width;
+ int RelX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width;
+ int RelZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width;
// Check if the player is swimming:
- // Use Unbounded, because we're being called *after* processing super::Tick(), which could have changed our chunk
if (!a_Chunk.UnboundedRelGetBlockType(RelX, RelY, RelZ, BlockIn))
{
// This sometimes happens on Linux machines
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index a73565de7..e41f74b09 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -69,6 +69,7 @@ public:
enum eEntityType
{
etEntity, // For all other types
+ etEnderCrystal,
etPlayer,
etPickup,
etMonster,
@@ -117,6 +118,7 @@ public:
BURN_TICKS = 200, ///< How long to keep an entity burning after it has stood in lava / fire
MAX_AIR_LEVEL = 300, ///< Maximum air an entity can have
DROWNING_TICKS = 20, ///< Number of ticks per heart of damage
+ VOID_BOUNDARY = -46 ///< At what position Y to begin applying void damage
} ;
cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, double a_Width, double a_Height);
@@ -129,18 +131,19 @@ public:
eEntityType GetEntityType(void) const { return m_EntityType; }
- bool IsPlayer (void) const { return (m_EntityType == etPlayer); }
- bool IsPickup (void) const { return (m_EntityType == etPickup); }
- bool IsMob (void) const { return (m_EntityType == etMonster); }
+ bool IsEnderCrystal(void) const { return (m_EntityType == etEnderCrystal); }
+ bool IsPlayer (void) const { return (m_EntityType == etPlayer); }
+ bool IsPickup (void) const { return (m_EntityType == etPickup); }
+ bool IsMob (void) const { return (m_EntityType == etMonster); }
bool IsFallingBlock(void) const { return (m_EntityType == etFallingBlock); }
- bool IsMinecart (void) const { return (m_EntityType == etMinecart); }
- bool IsBoat (void) const { return (m_EntityType == etBoat); }
- bool IsTNT (void) const { return (m_EntityType == etTNT); }
- bool IsProjectile (void) const { return (m_EntityType == etProjectile); }
- bool IsExpOrb (void) const { return (m_EntityType == etExpOrb); }
- bool IsFloater (void) const { return (m_EntityType == etFloater); }
- bool IsItemFrame (void) const { return (m_EntityType == etItemFrame); }
- bool IsPainting (void) const { return (m_EntityType == etPainting); }
+ bool IsMinecart (void) const { return (m_EntityType == etMinecart); }
+ bool IsBoat (void) const { return (m_EntityType == etBoat); }
+ bool IsTNT (void) const { return (m_EntityType == etTNT); }
+ bool IsProjectile (void) const { return (m_EntityType == etProjectile); }
+ bool IsExpOrb (void) const { return (m_EntityType == etExpOrb); }
+ bool IsFloater (void) const { return (m_EntityType == etFloater); }
+ bool IsItemFrame (void) const { return (m_EntityType == etItemFrame); }
+ bool IsPainting (void) const { return (m_EntityType == etPainting); }
/// Returns true if the entity is of the specified class or a subclass (cPawn's IsA("cEntity") returns true)
virtual bool IsA(const char * a_ClassName) const;
diff --git a/src/Entities/ExpOrb.cpp b/src/Entities/ExpOrb.cpp
index 3398f1c7b..3623c869a 100644
--- a/src/Entities/ExpOrb.cpp
+++ b/src/Entities/ExpOrb.cpp
@@ -5,20 +5,26 @@
#include "../ClientHandle.h"
-cExpOrb::cExpOrb(double a_X, double a_Y, double a_Z, int a_Reward) :
- cEntity(etExpOrb, a_X, a_Y, a_Z, 0.98, 0.98),
- m_Reward(a_Reward)
+cExpOrb::cExpOrb(double a_X, double a_Y, double a_Z, int a_Reward)
+ : cEntity(etExpOrb, a_X, a_Y, a_Z, 0.98, 0.98)
+ , m_Reward(a_Reward)
+ , m_Timer(0.f)
{
+ SetMaxHealth(5);
+ SetHealth(5);
}
-cExpOrb::cExpOrb(const Vector3d & a_Pos, int a_Reward) :
- cEntity(etExpOrb, a_Pos.x, a_Pos.y, a_Pos.z, 0.98, 0.98),
- m_Reward(a_Reward)
+cExpOrb::cExpOrb(const Vector3d & a_Pos, int a_Reward)
+ : cEntity(etExpOrb, a_Pos.x, a_Pos.y, a_Pos.z, 0.98, 0.98)
+ , m_Reward(a_Reward)
+ , m_Timer(0.f)
{
+ SetMaxHealth(5);
+ SetHealth(5);
}
@@ -52,7 +58,7 @@ void cExpOrb::Tick(float a_Dt, cChunk & a_Chunk)
LOGD("Player %s picked up an ExpOrb. His reward is %i", a_ClosestPlayer->GetName().c_str(), m_Reward);
a_ClosestPlayer->DeltaExperience(m_Reward);
- m_World->BroadcastSoundEffect("random.orb", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64));
+ m_World->BroadcastSoundEffect("random.orb", (int)(GetPosX() * 8), (int)(GetPosY() * 8), (int)(GetPosZ() * 8), 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64));
Destroy();
}
@@ -64,4 +70,10 @@ void cExpOrb::Tick(float a_Dt, cChunk & a_Chunk)
BroadcastMovementUpdate();
}
HandlePhysics(a_Dt, a_Chunk);
+
+ m_Timer += a_Dt;
+ if (m_Timer >= 1000 * 60 * 5) // 5 minutes
+ {
+ Destroy(true);
+ }
}
diff --git a/src/Entities/ExpOrb.h b/src/Entities/ExpOrb.h
index 47d86922c..c1150bd03 100644
--- a/src/Entities/ExpOrb.h
+++ b/src/Entities/ExpOrb.h
@@ -7,14 +7,17 @@
+// tolua_begin
class cExpOrb :
public cEntity
{
typedef cExpOrb super;
public:
+ // tolua_end
+
CLASS_PROTODEF(cExpOrb);
-
+
cExpOrb(double a_X, double a_Y, double a_Z, int a_Reward);
cExpOrb(const Vector3d & a_Pos, int a_Reward);
@@ -22,9 +25,21 @@ public:
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
virtual void SpawnOn(cClientHandle & a_Client) override;
- // cExpOrb functions
- int GetReward(void) const { return m_Reward; }
+ /** Returns the number of ticks that this entity has existed */
+ int GetAge(void) const { return (int)(m_Timer / 50); } // tolua_export
+
+ /** Set the number of ticks that this entity has existed */
+ void SetAge(int a_Age) { m_Timer = (float)(a_Age * 50); } // tolua_export
+
+ /** Get the exp amount */
+ int GetReward(void) const { return m_Reward; } // tolua_export
+
+ /** Set the exp amount */
+ void SetReward(int a_Reward) { m_Reward = a_Reward; } // tolua_export
protected:
int m_Reward;
-} ; \ No newline at end of file
+
+ /** The number of ticks that the entity has existed / timer between collect and destroy; in msec */
+ float m_Timer;
+} ; // tolua_export \ No newline at end of file
diff --git a/src/Entities/FallingBlock.cpp b/src/Entities/FallingBlock.cpp
index 9fcd9ac80..a66c7e4ae 100644
--- a/src/Entities/FallingBlock.cpp
+++ b/src/Entities/FallingBlock.cpp
@@ -33,20 +33,16 @@ void cFallingBlock::SpawnOn(cClientHandle & a_ClientHandle)
void cFallingBlock::Tick(float a_Dt, cChunk & a_Chunk)
{
- float MilliDt = a_Dt * 0.001f;
- AddSpeedY(MilliDt * -9.8f);
- AddPosY(GetSpeedY() * MilliDt);
-
// GetWorld()->BroadcastTeleportEntity(*this); // Test position
- int BlockX = m_OriginalPosition.x;
+ int BlockX = POSX_TOINT;
int BlockY = (int)(GetPosY() - 0.5);
- int BlockZ = m_OriginalPosition.z;
+ int BlockZ = POSZ_TOINT;
if (BlockY < 0)
{
// Fallen out of this world, just continue falling until out of sight, then destroy:
- if (BlockY < 100)
+ if (BlockY < VOID_BOUNDARY)
{
Destroy(true);
}
@@ -86,6 +82,15 @@ void cFallingBlock::Tick(float a_Dt, cChunk & a_Chunk)
Destroy(true);
return;
}
+
+ float MilliDt = a_Dt * 0.001f;
+ AddSpeedY(MilliDt * -9.8f);
+ AddPosition(GetSpeed() * MilliDt);
+
+ if ((GetSpeedX() != 0) || (GetSpeedZ() != 0))
+ {
+ BroadcastMovementUpdate();
+ }
}
diff --git a/src/Entities/HangingEntity.cpp b/src/Entities/HangingEntity.cpp
new file mode 100644
index 000000000..41ac86268
--- /dev/null
+++ b/src/Entities/HangingEntity.cpp
@@ -0,0 +1,53 @@
+
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "HangingEntity.h"
+#include "ClientHandle.h"
+#include "Player.h"
+
+
+
+
+
+cHangingEntity::cHangingEntity(eEntityType a_EntityType, eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z)
+ : cEntity(a_EntityType, a_X, a_Y, a_Z, 0.8, 0.8)
+ , m_BlockFace(a_BlockFace)
+{
+ SetMaxHealth(1);
+ SetHealth(1);
+}
+
+
+
+
+
+void cHangingEntity::SpawnOn(cClientHandle & a_ClientHandle)
+{
+ int Dir = 0;
+
+ // The client uses different values for item frame directions and block faces. Our constants are for the block faces, so we convert them here to item frame faces
+ switch (m_BlockFace)
+ {
+ case BLOCK_FACE_ZP: break; // Initialised to zero
+ case BLOCK_FACE_ZM: Dir = 2; break;
+ case BLOCK_FACE_XM: Dir = 1; break;
+ case BLOCK_FACE_XP: Dir = 3; break;
+ default: ASSERT(!"Unhandled block face when trying to spawn item frame!"); return;
+ }
+
+ if ((Dir == 0) || (Dir == 2)) // Probably a client bug, but two directions are flipped and contrary to the norm, so we do -180
+ {
+ SetYaw((Dir * 90) - 180);
+ }
+ else
+ {
+ SetYaw(Dir * 90);
+ }
+
+ a_ClientHandle.SendSpawnObject(*this, 71, Dir, (Byte)GetYaw(), (Byte)GetPitch());
+ a_ClientHandle.SendEntityMetadata(*this);
+}
+
+
+
+
diff --git a/src/Entities/HangingEntity.h b/src/Entities/HangingEntity.h
new file mode 100644
index 000000000..6498e4b5b
--- /dev/null
+++ b/src/Entities/HangingEntity.h
@@ -0,0 +1,49 @@
+
+#pragma once
+
+#include "Entity.h"
+
+
+
+
+
+// tolua_begin
+class cHangingEntity :
+ public cEntity
+{
+ // tolua_end
+ typedef cEntity super;
+
+public:
+
+ CLASS_PROTODEF(cHangingEntity);
+
+ cHangingEntity(eEntityType a_EntityType, eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z);
+
+ /** Returns the orientation from the hanging entity */
+ eBlockFace GetDirection() const { return m_BlockFace; } // tolua_export
+
+ /** Set the orientation from the hanging entity */
+ void SetDirection(eBlockFace a_BlockFace) { m_BlockFace = a_BlockFace; } // tolua_export
+
+ /** Returns the X coord. */
+ int GetTileX() const { return POSX_TOINT; } // tolua_export
+
+ /** Returns the Y coord. */
+ int GetTileY() const { return POSY_TOINT; } // tolua_export
+
+ /** Returns the Z coord. */
+ int GetTileZ() const { return POSZ_TOINT; } // tolua_export
+
+private:
+
+ virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
+ virtual void Tick(float a_Dt, cChunk & a_Chunk) override {};
+
+ eBlockFace m_BlockFace;
+
+}; // tolua_export
+
+
+
+
diff --git a/src/Entities/ItemFrame.cpp b/src/Entities/ItemFrame.cpp
index 8cfa5e18d..9dd909880 100644
--- a/src/Entities/ItemFrame.cpp
+++ b/src/Entities/ItemFrame.cpp
@@ -10,43 +10,10 @@
cItemFrame::cItemFrame(eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z)
- : cEntity(etItemFrame, a_X, a_Y, a_Z, 0.8, 0.8),
- m_BlockFace(a_BlockFace),
- m_Item(E_BLOCK_AIR),
- m_Rotation(0)
+ : cHangingEntity(etItemFrame, a_BlockFace, a_X, a_Y, a_Z)
+ , m_Item(E_BLOCK_AIR)
+ , m_Rotation(0)
{
- SetMaxHealth(1);
- SetHealth(1);
-}
-
-
-
-
-
-void cItemFrame::SpawnOn(cClientHandle & a_ClientHandle)
-{
- int Dir = 0;
-
- // The client uses different values for item frame directions and block faces. Our constants are for the block faces, so we convert them here to item frame faces
- switch (m_BlockFace)
- {
- case BLOCK_FACE_ZP: break; // Initialised to zero
- case BLOCK_FACE_ZM: Dir = 2; break;
- case BLOCK_FACE_XM: Dir = 1; break;
- case BLOCK_FACE_XP: Dir = 3; break;
- default: ASSERT(!"Unhandled block face when trying to spawn item frame!"); return;
- }
-
- if ((Dir == 0) || (Dir == 2)) // Probably a client bug, but two directions are flipped and contrary to the norm, so we do -180
- {
- SetYaw((Dir * 90) - 180);
- }
- else
- {
- SetYaw(Dir * 90);
- }
-
- a_ClientHandle.SendSpawnObject(*this, 71, Dir, (Byte)GetYaw(), (Byte)GetPitch());
}
diff --git a/src/Entities/ItemFrame.h b/src/Entities/ItemFrame.h
index 43915e3f9..6577e7d94 100644
--- a/src/Entities/ItemFrame.h
+++ b/src/Entities/ItemFrame.h
@@ -1,7 +1,7 @@
#pragma once
-#include "Entity.h"
+#include "HangingEntity.h"
@@ -9,10 +9,10 @@
// tolua_begin
class cItemFrame :
- public cEntity
+ public cHangingEntity
{
// tolua_end
- typedef cEntity super;
+ typedef cHangingEntity super;
public:
@@ -20,18 +20,24 @@ public:
cItemFrame(eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z);
- const cItem & GetItem(void) { return m_Item; }
- Byte GetRotation(void) const { return m_Rotation; }
+ /** Returns the item in the frame */
+ const cItem & GetItem(void) { return m_Item; } // tolua_export
+
+ /** Set the item in the frame */
+ void SetItem(cItem & a_Item) { m_Item = a_Item; }; // tolua_export
+
+ /** Returns the rotation from the item in the frame */
+ Byte GetRotation(void) const { return m_Rotation; } // tolua_export
+
+ /** Set the rotation from the item in the frame */
+ void SetRotation(Byte a_Rotation) { m_Rotation = a_Rotation; } // tolua_export
private:
- virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
virtual void OnRightClicked(cPlayer & a_Player) override;
- virtual void Tick(float a_Dt, cChunk & a_Chunk) override {};
virtual void KilledBy(cEntity * a_Killer) override;
virtual void GetDrops(cItems & a_Items, cEntity * a_Killer) override;
- eBlockFace m_BlockFace;
cItem m_Item;
Byte m_Rotation;
diff --git a/src/Entities/Pickup.cpp b/src/Entities/Pickup.cpp
index c5503c16a..7fc89b62b 100644
--- a/src/Entities/Pickup.cpp
+++ b/src/Entities/Pickup.cpp
@@ -82,7 +82,7 @@ cPickup::cPickup(double a_PosX, double a_PosY, double a_PosZ, const cItem & a_It
void cPickup::SpawnOn(cClientHandle & a_Client)
{
- a_Client.SendPickupSpawn(*this);
+ a_Client.SendPickupSpawn(*this);
}
diff --git a/src/Entities/Pickup.h b/src/Entities/Pickup.h
index c273567d1..74b917bce 100644
--- a/src/Entities/Pickup.h
+++ b/src/Entities/Pickup.h
@@ -26,31 +26,34 @@ public:
CLASS_PROTODEF(cPickup);
cPickup(double a_PosX, double a_PosY, double a_PosZ, const cItem & a_Item, bool IsPlayerCreated, float a_SpeedX = 0.f, float a_SpeedY = 0.f, float a_SpeedZ = 0.f);
-
+
cItem & GetItem(void) {return m_Item; } // tolua_export
const cItem & GetItem(void) const {return m_Item; }
virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
-
+
bool CollectedBy(cPlayer * a_Dest); // tolua_export
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
-
- /// Returns the number of ticks that this entity has existed
- int GetAge(void) const { return (int)(m_Timer / 50); } // tolua_export
-
- /// Returns true if the pickup has already been collected
+
+ /** Returns the number of ticks that this entity has existed */
+ int GetAge(void) const { return (int)(m_Timer / 50); } // tolua_export
+
+ /** Set the number of ticks that this entity has existed */
+ void SetAge(int a_Age) { m_Timer = (float)(a_Age * 50); } // tolua_export
+
+ /** Returns true if the pickup has already been collected */
bool IsCollected(void) const { return m_bCollected; } // tolua_export
- /// Returns true if created by player (i.e. vomiting), used for determining picking-up delay time
+ /** Returns true if created by player (i.e. vomiting), used for determining picking-up delay time */
bool IsPlayerCreated(void) const { return m_bIsPlayerCreated; } // tolua_export
-
+
private:
Vector3d m_ResultingSpeed; //Can be used to modify the resulting speed for the current tick ;)
Vector3d m_WaterSpeed;
- /// The number of ticks that the entity has existed / timer between collect and destroy; in msec
+ /** The number of ticks that the entity has existed / timer between collect and destroy; in msec */
float m_Timer;
cItem m_Item;
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 440d30595..646aad50f 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -43,8 +43,9 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName)
, m_GameMode(eGameMode_NotSet)
, m_IP("")
, m_ClientHandle(a_Client)
- , m_NormalMaxSpeed(0.1)
- , m_SprintingMaxSpeed(0.13)
+ , m_NormalMaxSpeed(1.0)
+ , m_SprintingMaxSpeed(1.3)
+ , m_FlyingMaxSpeed(1.0)
, m_IsCrouched(false)
, m_IsSprinting(false)
, m_IsFlying(false)
@@ -684,7 +685,21 @@ const cSlotNums & cPlayer::GetInventoryPaintSlots(void) const
double cPlayer::GetMaxSpeed(void) const
{
- return m_IsSprinting ? m_SprintingMaxSpeed : m_NormalMaxSpeed;
+ if (m_IsFlying)
+ {
+ return m_FlyingMaxSpeed;
+ }
+ else
+ {
+ if (m_IsSprinting)
+ {
+ return m_SprintingMaxSpeed;
+ }
+ else
+ {
+ return m_NormalMaxSpeed;
+ }
+ }
}
@@ -694,7 +709,7 @@ double cPlayer::GetMaxSpeed(void) const
void cPlayer::SetNormalMaxSpeed(double a_Speed)
{
m_NormalMaxSpeed = a_Speed;
- if (!m_IsSprinting)
+ if (!m_IsSprinting && !m_IsFlying)
{
m_ClientHandle->SendPlayerMaxSpeed();
}
@@ -707,7 +722,7 @@ void cPlayer::SetNormalMaxSpeed(double a_Speed)
void cPlayer::SetSprintingMaxSpeed(double a_Speed)
{
m_SprintingMaxSpeed = a_Speed;
- if (m_IsSprinting)
+ if (m_IsSprinting && !m_IsFlying)
{
m_ClientHandle->SendPlayerMaxSpeed();
}
@@ -717,6 +732,18 @@ void cPlayer::SetSprintingMaxSpeed(double a_Speed)
+void cPlayer::SetFlyingMaxSpeed(double a_Speed)
+{
+ m_FlyingMaxSpeed = a_Speed;
+
+ // Update the flying speed, always:
+ m_ClientHandle->SendPlayerAbilities();
+}
+
+
+
+
+
void cPlayer::SetCrouch(bool a_IsCrouched)
{
// Set the crouch status, broadcast to all visible players
@@ -1462,6 +1489,7 @@ bool cPlayer::MoveToWorld(const char * a_WorldName)
// Add player to all the necessary parts of the new world
SetWorld(World);
+ m_ClientHandle->StreamChunks();
World->AddEntity(this);
World->AddPlayer(this);
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index f9404dfaf..ea32dbfb9 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -47,19 +47,19 @@ public:
virtual void HandlePhysics(float a_Dt, cChunk &) override { UNUSED(a_Dt); };
- /// Returns the curently equipped weapon; empty item if none
+ /** Returns the curently equipped weapon; empty item if none */
virtual cItem GetEquippedWeapon(void) const override { return m_Inventory.GetEquippedItem(); }
- /// Returns the currently equipped helmet; empty item if none
+ /** Returns the currently equipped helmet; empty item if none */
virtual cItem GetEquippedHelmet(void) const override { return m_Inventory.GetEquippedHelmet(); }
- /// Returns the currently equipped chestplate; empty item if none
+ /** Returns the currently equipped chestplate; empty item if none */
virtual cItem GetEquippedChestplate(void) const override { return m_Inventory.GetEquippedChestplate(); }
- /// Returns the currently equipped leggings; empty item if none
+ /** Returns the currently equipped leggings; empty item if none */
virtual cItem GetEquippedLeggings(void) const override { return m_Inventory.GetEquippedLeggings(); }
- /// Returns the currently equipped boots; empty item if none
+ /** Returns the currently equipped boots; empty item if none */
virtual cItem GetEquippedBoots(void) const override { return m_Inventory.GetEquippedBoots(); }
@@ -77,36 +77,41 @@ public:
*/
short DeltaExperience(short a_Xp_delta);
- /// Gets the experience total - XpTotal for score on death
+ /** Gets the experience total - XpTotal for score on death */
inline short GetXpLifetimeTotal(void) { return m_LifetimeTotalXp; }
- /// Gets the currrent experience
+ /** Gets the currrent experience */
inline short GetCurrentXp(void) { return m_CurrentXp; }
- /// Gets the current level - XpLevel
+ /** Gets the current level - XpLevel */
short GetXpLevel(void);
- /// Gets the experience bar percentage - XpP
+ /** Gets the experience bar percentage - XpP */
float GetXpPercentage(void);
- /// Caculates the amount of XP needed for a given level, ref: http://minecraft.gamepedia.com/XP
+ /** Caculates the amount of XP needed for a given level
+ Ref: http://minecraft.gamepedia.com/XP
+ */
static short XpForLevel(short int a_Level);
- /// inverse of XpForLevel, ref: http://minecraft.gamepedia.com/XP values are as per this with pre-calculations
+ /** Inverse of XpForLevel
+ Ref: http://minecraft.gamepedia.com/XP
+ values are as per this with pre-calculations
+ */
static short CalcLevelFromXp(short int a_CurrentXp);
// tolua_end
- /// Starts charging the equipped bow
+ /** Starts charging the equipped bow */
void StartChargingBow(void);
- /// Finishes charging the current bow. Returns the number of ticks for which the bow has been charged
+ /** Finishes charging the current bow. Returns the number of ticks for which the bow has been charged */
int FinishChargingBow(void);
- /// Cancels the current bow charging
+ /** Cancels the current bow charging */
void CancelChargingBow(void);
- /// Returns true if the player is currently charging the bow
+ /** Returns true if the player is currently charging the bow */
bool IsChargingBow(void) const { return m_IsChargingBow; }
void SetTouchGround( bool a_bTouchGround );
@@ -124,16 +129,16 @@ public:
// tolua_begin
- /// Returns the position where projectiles thrown by this player should start, player eye position + adjustment
+ /** Returns the position where projectiles thrown by this player should start, player eye position + adjustment */
Vector3d GetThrowStartPos(void) const;
- /// Returns the initial speed vector of a throw, with a 3D length of a_SpeedCoeff.
+ /** Returns the initial speed vector of a throw, with a 3D length of a_SpeedCoeff. */
Vector3d GetThrowSpeed(double a_SpeedCoeff) const;
- /// Returns the current gamemode. Partly OBSOLETE, you should use IsGameModeXXX() functions wherever applicable
+ /** Returns the current gamemode. Partly OBSOLETE, you should use IsGameModeXXX() functions wherever applicable */
eGameMode GetGameMode(void) const { return m_GameMode; }
- /// Returns the current effective gamemode (inherited gamemode is resolved before returning)
+ /** Returns the current effective gamemode (inherited gamemode is resolved before returning) */
eGameMode GetEffectiveGameMode(void) const { return (m_GameMode == gmNotSet) ? m_World->GetGameMode() : m_GameMode; }
/** Sets the gamemode for the player.
@@ -142,24 +147,24 @@ public:
*/
void SetGameMode(eGameMode a_GameMode);
- /// Returns true if the player is in Creative mode, either explicitly, or by inheriting from current world
+ /** Returns true if the player is in Creative mode, either explicitly, or by inheriting from current world */
bool IsGameModeCreative(void) const;
- /// Returns true if the player is in Survival mode, either explicitly, or by inheriting from current world
+ /** Returns true if the player is in Survival mode, either explicitly, or by inheriting from current world */
bool IsGameModeSurvival(void) const;
- /// Returns true if the player is in Adventure mode, either explicitly, or by inheriting from current world
+ /** Returns true if the player is in Adventure mode, either explicitly, or by inheriting from current world */
bool IsGameModeAdventure(void) const;
AString GetIP(void) const { return m_IP; } // tolua_export
- /// Returns the associated team, NULL if none
+ /** Returns the associated team, NULL if none */
cTeam * GetTeam(void) { return m_Team; } // tolua_export
- /// Sets the player team, NULL if none
+ /** Sets the player team, NULL if none */
void SetTeam(cTeam * a_Team);
- /// Forces the player to query the scoreboard for his team
+ /** Forces the player to query the scoreboard for his team */
cTeam * UpdateTeam(void);
// tolua_end
@@ -169,24 +174,24 @@ public:
// Sets the current gamemode, doesn't check validity, doesn't send update packets to client
void LoginSetGameMode(eGameMode a_GameMode);
- /// Forces the player to move in the given direction.
+ /** Forces the player to move in the given direction. */
void ForceSetSpeed(Vector3d a_Direction); // tolua_export
- /// Tries to move to a new position, with attachment-related checks (y == -999)
+ /** Tries to move to a new position, with attachment-related checks (y == -999) */
void MoveTo(const Vector3d & a_NewPos); // tolua_export
cWindow * GetWindow(void) { return m_CurrentWindow; } // tolua_export
const cWindow * GetWindow(void) const { return m_CurrentWindow; }
- /// Opens the specified window; closes the current one first using CloseWindow()
+ /** Opens the specified window; closes the current one first using CloseWindow() */
void OpenWindow(cWindow * a_Window); // Exported in ManualBindings.cpp
// tolua_begin
- /// Closes the current window, resets current window to m_InventoryWindow. A plugin may refuse the closing if a_CanRefuse is true
+ /** Closes the current window, resets current window to m_InventoryWindow. A plugin may refuse the closing if a_CanRefuse is true */
void CloseWindow(bool a_CanRefuse = true);
- /// Closes the current window if it matches the specified ID, resets current window to m_InventoryWindow
+ /** Closes the current window if it matches the specified ID, resets current window to m_InventoryWindow */
void CloseWindowIfID(char a_WindowID, bool a_CanRefuse = true);
cClientHandle * GetClientHandle(void) const { return m_ClientHandle; }
@@ -208,10 +213,10 @@ public:
typedef std::list< cGroup* > GroupList;
typedef std::list< std::string > StringList;
- /// Adds a player to existing group or creates a new group when it doesn't exist
+ /** Adds a player to existing group or creates a new group when it doesn't exist */
void AddToGroup( const AString & a_GroupName ); // tolua_export
- /// Removes a player from the group, resolves permissions and group inheritance (case sensitive)
+ /** Removes a player from the group, resolves permissions and group inheritance (case sensitive) */
void RemoveFromGroup( const AString & a_GroupName ); // tolua_export
bool HasPermission( const AString & a_Permission ); // tolua_export
@@ -234,7 +239,7 @@ public:
/** tosses a pickup newly created from a_Item */
void TossPickup(const cItem & a_Item);
- /// Heals the player by the specified amount of HPs (positive only); sends health update
+ /** Heals the player by the specified amount of HPs (positive only); sends health update */
void Heal(int a_Health);
int GetFoodLevel (void) const { return m_FoodLevel; }
@@ -243,7 +248,7 @@ public:
double GetFoodExhaustionLevel (void) const { return m_FoodExhaustionLevel; }
int GetFoodPoisonedTicksRemaining(void) const { return m_FoodPoisonedTicksRemaining; }
- /// Returns true if the player is satiated, i. e. their foodlevel is at the max and they cannot eat anymore
+ /** Returns true if the player is satiated, i. e. their foodlevel is at the max and they cannot eat anymore */
bool IsSatiated(void) const { return (m_FoodLevel >= MAX_FOOD_LEVEL); }
void SetFoodLevel (int a_FoodLevel);
@@ -252,25 +257,28 @@ public:
void SetFoodExhaustionLevel (double a_FoodExhaustionLevel);
void SetFoodPoisonedTicksRemaining(int a_FoodPoisonedTicksRemaining);
- /// Adds to FoodLevel and FoodSaturationLevel, returns true if any food has been consumed, false if player "full"
+ /** Adds to FoodLevel and FoodSaturationLevel, returns true if any food has been consumed, false if player "full" */
bool Feed(int a_Food, double a_Saturation);
- /// Adds the specified exhaustion to m_FoodExhaustion. Expects only positive values.
+ /** Adds the specified exhaustion to m_FoodExhaustion. Expects only positive values. */
void AddFoodExhaustion(double a_Exhaustion)
{
m_FoodExhaustionLevel += a_Exhaustion;
}
- /// Starts the food poisoning for the specified amount of ticks; if already foodpoisoned, sets FoodPoisonedTicksRemaining to the larger of the two
+ /** Starts the food poisoning for the specified amount of ticks; if already foodpoisoned, sets FoodPoisonedTicksRemaining to the larger of the two */
void FoodPoison(int a_NumTicks);
- /// Returns true if the player is currently in the process of eating the currently equipped item
+ /** Returns true if the player is currently in the process of eating the currently equipped item */
bool IsEating(void) const { return (m_EatingFinishTick >= 0); }
- /// Returns true if the player is currently flying.
+ /** Returns true if the player is currently flying. */
bool IsFlying(void) const { return m_IsFlying; }
- /// returns true if the player has thrown out a floater.
+ /** Returns if a player is sleeping in a bed */
+ bool IsInBed(void) const { return m_bIsInBed; }
+
+ /** returns true if the player has thrown out a floater. */
bool IsFishing(void) const { return m_IsFishing; }
void SetIsFishing(bool a_IsFishing, int a_FloaterID = -1) { m_IsFishing = a_IsFishing; m_FloaterID = a_FloaterID; }
@@ -278,14 +286,17 @@ public:
int GetFloaterID(void) const { return m_FloaterID; }
// tolua_end
+
+ /** Sets a player's in-bed state; we can't be sure plugins will keep this value updated, so no exporting */
+ void SetIsInBed(bool a_Flag) { m_bIsInBed = a_Flag; }
- /// Starts eating the currently equipped item. Resets the eating timer and sends the proper animation packet
+ /** Starts eating the currently equipped item. Resets the eating timer and sends the proper animation packet */
void StartEating(void);
- /// Finishes eating the currently equipped item. Consumes the item, updates health and broadcasts the packets
+ /** Finishes eating the currently equipped item. Consumes the item, updates health and broadcasts the packets */
void FinishEating(void);
- /// Aborts the current eating operation
+ /** Aborts the current eating operation */
void AbortEating(void);
virtual void KilledBy(cEntity * a_Killer) override;
@@ -314,45 +325,51 @@ public:
cItem & GetDraggingItem(void) {return m_DraggingItem; }
// In UI windows, when inventory-painting:
- /// Clears the list of slots that are being inventory-painted. To be used by cWindow only
+ /** Clears the list of slots that are being inventory-painted. To be used by cWindow only */
void ClearInventoryPaintSlots(void);
- /// Adds a slot to the list for inventory painting. To be used by cWindow only
+ /** Adds a slot to the list for inventory painting. To be used by cWindow only */
void AddInventoryPaintSlot(int a_SlotNum);
- /// Returns the list of slots currently stored for inventory painting. To be used by cWindow only
+ /** Returns the list of slots currently stored for inventory painting. To be used by cWindow only */
const cSlotNums & GetInventoryPaintSlots(void) const;
// tolua_begin
- /// Returns the current maximum speed, as reported in the 1.6.1+ protocol (takes current sprinting state into account)
+ /** Returns the current relative maximum speed (takes current sprinting / flying state into account) */
double GetMaxSpeed(void) const;
- /// Gets the normal maximum speed, as reported in the 1.6.1+ protocol, in the protocol units
+ /** Gets the normal relative maximum speed */
double GetNormalMaxSpeed(void) const { return m_NormalMaxSpeed; }
- /// Gets the sprinting maximum speed, as reported in the 1.6.1+ protocol, in the protocol units
+ /** Gets the sprinting relative maximum speed */
double GetSprintingMaxSpeed(void) const { return m_SprintingMaxSpeed; }
- /// Sets the normal maximum speed, as reported in the 1.6.1+ protocol. Sends the update to player, if needed.
+ /** Gets the flying relative maximum speed */
+ double GetFlyingMaxSpeed(void) const { return m_FlyingMaxSpeed; }
+
+ /** Sets the normal relative maximum speed. Sends the update to player, if needed. */
void SetNormalMaxSpeed(double a_Speed);
- /// Sets the sprinting maximum speed, as reported in the 1.6.1+ protocol. Sends the update to player, if needed.
+ /** Sets the sprinting relative maximum speed. Sends the update to player, if needed. */
void SetSprintingMaxSpeed(double a_Speed);
- /// Sets the crouch status, broadcasts to all visible players
+ /** Sets the flying relative maximum speed. Sends the update to player, if needed. */
+ void SetFlyingMaxSpeed(double a_Speed);
+
+ /** Sets the crouch status, broadcasts to all visible players */
void SetCrouch(bool a_IsCrouched);
- /// Starts or stops sprinting, sends the max speed update to the client, if needed
+ /** Starts or stops sprinting, sends the max speed update to the client, if needed */
void SetSprint(bool a_IsSprinting);
- /// Flags the player as flying
+ /** Flags the player as flying */
void SetFlying(bool a_IsFlying);
- /// If true the player can fly even when he's not in creative.
+ /** If true the player can fly even when he's not in creative. */
void SetCanFly(bool a_CanFly);
- /// Returns wheter the player can fly or not.
+ /** Returns wheter the player can fly or not. */
virtual bool CanFly(void) const { return m_CanFly; }
// tolua_end
@@ -371,10 +388,10 @@ protected:
GroupList m_ResolvedGroups;
GroupList m_Groups;
- std::string m_PlayerName;
- std::string m_LoadedWorldName;
+ AString m_PlayerName;
+ AString m_LoadedWorldName;
- /// Xp Level stuff
+ /** Xp Level stuff */
enum
{
XP_TO_LEVEL15 = 255,
@@ -385,22 +402,22 @@ protected:
bool m_bVisible;
// Food-related variables:
- /// Represents the food bar, one point equals half a "drumstick"
+ /** Represents the food bar, one point equals half a "drumstick" */
int m_FoodLevel;
- /// "Overcharge" for the m_FoodLevel; is depleted before m_FoodLevel
+ /** "Overcharge" for the m_FoodLevel; is depleted before m_FoodLevel */
double m_FoodSaturationLevel;
- /// Count-up to the healing or damaging action, based on m_FoodLevel
+ /** Count-up to the healing or damaging action, based on m_FoodLevel */
int m_FoodTickTimer;
- /// A "buffer" which adds up hunger before it is substracted from m_FoodSaturationLevel or m_FoodLevel. Each action adds a little
+ /** A "buffer" which adds up hunger before it is substracted from m_FoodSaturationLevel or m_FoodLevel. Each action adds a little */
double m_FoodExhaustionLevel;
- /// Number of ticks remaining for the foodpoisoning effect; zero if not foodpoisoned
+ /** Number of ticks remaining for the foodpoisoning effect; zero if not foodpoisoned */
int m_FoodPoisonedTicksRemaining;
- /// Last position that has been recorded for food-related processing:
+ /** Last position that has been recorded for food-related processing: */
Vector3d m_LastFoodPos;
float m_LastJumpHeight;
@@ -416,7 +433,7 @@ protected:
eGameMode m_GameMode;
AString m_IP;
- /// The item being dragged by the cursor while in a UI window
+ /** The item being dragged by the cursor while in a UI window */
cItem m_DraggingItem;
long long m_LastPlayerListTime;
@@ -426,12 +443,21 @@ protected:
cSlotNums m_InventoryPaintSlots;
- /// Max speed, in ENTITY_PROPERTIES packet's units, when the player is walking. 0.1 by default
+ /** Max speed, relative to the game default.
+ 1 means regular speed, 2 means twice as fast, 0.5 means half-speed.
+ Default value is 1. */
double m_NormalMaxSpeed;
- /// Max speed, in ENTITY_PROPERTIES packet's units, when the player is sprinting. 0.13 by default
+ /** Max speed, relative to the game default max speed, when sprinting.
+ 1 means regular speed, 2 means twice as fast, 0.5 means half-speed.
+ Default value is 1.3. */
double m_SprintingMaxSpeed;
+ /** Max speed, relative to the game default flying max speed, when flying.
+ 1 means regular speed, 2 means twice as fast, 0.5 means half-speed.
+ Default value is 1. */
+ double m_FlyingMaxSpeed;
+
bool m_IsCrouched;
bool m_IsSprinting;
bool m_IsFlying;
@@ -441,10 +467,10 @@ protected:
bool m_CanFly; // If this is true the player can fly. Even if he is not in creative.
- /// The world tick in which eating will be finished. -1 if not eating
+ /** The world tick in which eating will be finished. -1 if not eating */
Int64 m_EatingFinishTick;
- /// Player Xp level
+ /** Player Xp level */
short int m_LifetimeTotalXp;
short int m_CurrentXp;
@@ -456,7 +482,7 @@ protected:
int m_FloaterID;
- cTeam* m_Team;
+ cTeam * m_Team;
@@ -465,20 +491,25 @@ protected:
virtual void Destroyed(void);
- /// Filters out damage for creative mode/friendly fire
+ /** Filters out damage for creative mode/friendly fire */
virtual void DoTakeDamage(TakeDamageInfo & TDI) override;
/** Stops players from burning in creative mode */
virtual void TickBurning(cChunk & a_Chunk) override;
- /// Called in each tick to handle food-related processing
+ /** Called in each tick to handle food-related processing */
void HandleFood(void);
- /// Called in each tick if the player is fishing to make sure the floater dissapears when the player doesn't have a fishing rod as equipped item.
+ /** Called in each tick if the player is fishing to make sure the floater dissapears when the player doesn't have a fishing rod as equipped item. */
void HandleFloater(void);
- /// Adds food exhaustion based on the difference between Pos and LastPos, sprinting status and swimming (in water block)
+ /** Adds food exhaustion based on the difference between Pos and LastPos, sprinting status and swimming (in water block) */
void ApplyFoodExhaustionFromMovement();
+
+ /** Flag representing whether the player is currently in a bed
+ Set by a right click on unoccupied bed, unset by a time fast forward or teleport */
+ bool m_bIsInBed;
+
} ; // tolua_export
diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp
index f4ab825f2..a9735a53c 100644
--- a/src/Entities/ProjectileEntity.cpp
+++ b/src/Entities/ProjectileEntity.cpp
@@ -4,6 +4,7 @@
// Implements the cProjectileEntity class representing the common base class for projectiles, as well as individual projectile types
#include "Globals.h"
+#include "../Bindings/PluginManager.h"
#include "ProjectileEntity.h"
#include "../ClientHandle.h"
#include "Player.h"
@@ -66,6 +67,11 @@ protected:
eBlockFace Face;
if (bb.CalcLineIntersection(Line1, Line2, LineCoeff, Face))
{
+ if (cPluginManager::Get()->CallHookProjectileHitBlock(*m_Projectile))
+ {
+ return false;
+ }
+
Vector3d Intersection = Line1 + m_Projectile->GetSpeed() * LineCoeff;
m_Projectile->OnHitSolidBlock(Intersection, Face);
return true;
@@ -147,7 +153,11 @@ public:
}
// TODO: Some entities don't interact with the projectiles (pickups, falling blocks)
- // TODO: Allow plugins to interfere about which entities can be hit
+ if (cPluginManager::Get()->CallHookProjectileHitEntity(*m_Projectile, *a_Entity))
+ {
+ // A plugin disagreed.
+ return false;
+ }
if (LineCoeff < m_MinCoeff)
{
diff --git a/src/ForEachChunkProvider.h b/src/ForEachChunkProvider.h
index 6017173ee..7a6e8c5c6 100644
--- a/src/ForEachChunkProvider.h
+++ b/src/ForEachChunkProvider.h
@@ -24,6 +24,8 @@ class cBlockArea;
class cForEachChunkProvider
{
public:
+ virtual ~cForEachChunkProvider() {}
+
/** Calls the callback for each chunk in the specified range. */
virtual bool ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ, cChunkDataCallback & a_Callback) = 0;
diff --git a/src/FurnaceRecipe.cpp b/src/FurnaceRecipe.cpp
index 2e2276981..1810d7c49 100644
--- a/src/FurnaceRecipe.cpp
+++ b/src/FurnaceRecipe.cpp
@@ -175,7 +175,7 @@ void cFurnaceRecipe::ReloadRecipes(void)
{
LOGERROR("ERROR: FurnaceRecipe, syntax error" );
}
- LOG("Loaded %u furnace recipes and %u fuels", m_pState->Recipes.size(), m_pState->Fuel.size());
+ LOG("Loaded " SIZE_T_FMT " furnace recipes and " SIZE_T_FMT " fuels", m_pState->Recipes.size(), m_pState->Fuel.size());
}
diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp
index 967deba6a..32a687201 100644
--- a/src/Generating/BioGen.cpp
+++ b/src/Generating/BioGen.cpp
@@ -371,8 +371,8 @@ void cBioGenDistortedVoronoi::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::B
Distort(BaseX + x * 4, BaseZ + z * 4, DistortX[4 * x][4 * z], DistortZ[4 * x][4 * z]);
}
- LinearUpscale2DArrayInPlace(&DistortX[0][0], cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4);
- LinearUpscale2DArrayInPlace(&DistortZ[0][0], cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4);
+ LinearUpscale2DArrayInPlace<cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4>(&DistortX[0][0]);
+ LinearUpscale2DArrayInPlace<cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4>(&DistortZ[0][0]);
for (int z = 0; z < cChunkDef::Width; z++)
{
@@ -477,8 +477,8 @@ void cBioGenMultiStepMap::DecideOceanLandMushroom(int a_ChunkX, int a_ChunkZ, cC
{
Distort(BaseX + x * 4, BaseZ + z * 4, DistortX[4 * x][4 * z], DistortZ[4 * x][4 * z], DistortSize);
}
- LinearUpscale2DArrayInPlace(&DistortX[0][0], cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4);
- LinearUpscale2DArrayInPlace(&DistortZ[0][0], cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4);
+ LinearUpscale2DArrayInPlace<cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4>(&DistortX[0][0]);
+ LinearUpscale2DArrayInPlace<cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4>(&DistortZ[0][0]);
// Prepare a 9x9 area of neighboring cell seeds
// (assuming that 7x7 cell area is larger than a chunk being generated)
@@ -651,8 +651,8 @@ void cBioGenMultiStepMap::BuildTemperatureHumidityMaps(int a_ChunkX, int a_Chunk
HumidityMap[x + 17 * z] = NoiseH;
} // for x
} // for z
- LinearUpscale2DArrayInPlace(TemperatureMap, 17, 17, 8, 8);
- LinearUpscale2DArrayInPlace(HumidityMap, 17, 17, 8, 8);
+ LinearUpscale2DArrayInPlace<17, 17, 8, 8>(TemperatureMap);
+ LinearUpscale2DArrayInPlace<17, 17, 8, 8>(HumidityMap);
// Re-map into integral values in [0 .. 255] range:
for (size_t idx = 0; idx < ARRAYCOUNT(a_TemperatureMap); idx++)
@@ -778,8 +778,8 @@ void cBioGenTwoLevel::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap
DistortZ[4 * x][4 * z] = BlockZ + (int)(64 * NoiseZ);
}
- LinearUpscale2DArrayInPlace(&DistortX[0][0], cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4);
- LinearUpscale2DArrayInPlace(&DistortZ[0][0], cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4);
+ LinearUpscale2DArrayInPlace<cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4>(&DistortX[0][0]);
+ LinearUpscale2DArrayInPlace<cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4>(&DistortZ[0][0]);
// Apply distortion to each block coord, then query the voronoi maps for biome group and biome index and choose biome based on that:
for (int z = 0; z < cChunkDef::Width; z++)
diff --git a/src/Generating/ChunkDesc.cpp b/src/Generating/ChunkDesc.cpp
index 308fbe423..7711723fc 100644
--- a/src/Generating/ChunkDesc.cpp
+++ b/src/Generating/ChunkDesc.cpp
@@ -343,9 +343,9 @@ void cChunkDesc::ReadBlockArea(cBlockArea & a_Dest, int a_MinRelX, int a_MaxRelX
int SizeY = a_MaxRelY - a_MinRelY;
int SizeZ = a_MaxRelZ - a_MinRelZ;
a_Dest.Clear();
- a_Dest.m_OriginX = m_ChunkX * cChunkDef::Width + a_MinRelX;
- a_Dest.m_OriginY = a_MinRelY;
- a_Dest.m_OriginZ = m_ChunkZ * cChunkDef::Width + a_MinRelZ;
+ a_Dest.m_Origin.x = m_ChunkX * cChunkDef::Width + a_MinRelX;
+ a_Dest.m_Origin.y = a_MinRelY;
+ a_Dest.m_Origin.z = m_ChunkZ * cChunkDef::Width + a_MinRelZ;
a_Dest.SetSize(SizeX, SizeY, SizeZ, cBlockArea::baTypes | cBlockArea::baMetas);
for (int y = 0; y < SizeY; y++)
diff --git a/src/Generating/ChunkGenerator.cpp b/src/Generating/ChunkGenerator.cpp
index ef38f1399..73f0223e8 100644
--- a/src/Generating/ChunkGenerator.cpp
+++ b/src/Generating/ChunkGenerator.cpp
@@ -116,7 +116,7 @@ void cChunkGenerator::QueueGenerateChunk(int a_ChunkX, int a_ChunkY, int a_Chunk
// Add to queue, issue a warning if too many:
if (m_Queue.size() >= QUEUE_WARNING_LIMIT)
{
- LOGWARN("WARNING: Adding chunk [%i, %i] to generation queue; Queue is too big! (%i)", a_ChunkX, a_ChunkZ, m_Queue.size());
+ LOGWARN("WARNING: Adding chunk [%i, %i] to generation queue; Queue is too big! (" SIZE_T_FMT ")", a_ChunkX, a_ChunkZ, m_Queue.size());
}
m_Queue.push_back(cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ));
}
@@ -180,7 +180,7 @@ BLOCKTYPE cChunkGenerator::GetIniBlock(cIniFile & a_IniFile, const AString & a_S
BLOCKTYPE Block = BlockStringToType(BlockType);
if (Block < 0)
{
- LOGWARN("[&s].%s Could not parse block value \"%s\". Using default: \"%s\".", a_SectionName.c_str(), a_ValueName.c_str(), BlockType.c_str(),a_Default.c_str());
+ LOGWARN("[%s].%s Could not parse block value \"%s\". Using default: \"%s\".", a_SectionName.c_str(), a_ValueName.c_str(), BlockType.c_str(),a_Default.c_str());
return BlockStringToType(a_Default);
}
return Block;
diff --git a/src/Generating/CompoGen.cpp b/src/Generating/CompoGen.cpp
index 60356fe46..578bb2481 100644
--- a/src/Generating/CompoGen.cpp
+++ b/src/Generating/CompoGen.cpp
@@ -566,7 +566,7 @@ void cCompoGenNether::ComposeTerrain(cChunkDesc & a_ChunkDesc)
m_Noise2.IntNoise3DInt(BaseX + INTERPOL_X * x, 0, BaseZ + INTERPOL_Z * z) /
256;
} // for x, z - FloorLo[]
- LinearUpscale2DArrayInPlace(FloorLo, 17, 17, INTERPOL_X, INTERPOL_Z);
+ LinearUpscale2DArrayInPlace<17, 17, INTERPOL_X, INTERPOL_Z>(FloorLo);
// Interpolate segments:
for (int Segment = 0; Segment < MaxHeight; Segment += SEGMENT_HEIGHT)
@@ -579,7 +579,7 @@ void cCompoGenNether::ComposeTerrain(cChunkDesc & a_ChunkDesc)
m_Noise2.IntNoise3DInt(BaseX + INTERPOL_Z * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z) /
256;
} // for x, z - FloorLo[]
- LinearUpscale2DArrayInPlace(FloorHi, 17, 17, INTERPOL_X, INTERPOL_Z);
+ LinearUpscale2DArrayInPlace<17, 17, INTERPOL_X, INTERPOL_Z>(FloorHi);
// Interpolate between FloorLo and FloorHi:
for (int z = 0; z < 16; z++) for (int x = 0; x < 16; x++)
diff --git a/src/Generating/HeiGen.cpp b/src/Generating/HeiGen.cpp
index 10710b4a1..3621421c2 100644
--- a/src/Generating/HeiGen.cpp
+++ b/src/Generating/HeiGen.cpp
@@ -428,7 +428,7 @@ void cHeiGenBiomal::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMa
Height[x + 17 * z] = GetHeightAt(x, z, a_ChunkX, a_ChunkZ, Biomes);
}
}
- LinearUpscale2DArrayInPlace(Height, 17, 17, STEPX, STEPZ);
+ LinearUpscale2DArrayInPlace<17, 17, STEPX, STEPZ>(Height);
// Copy into the heightmap
for (int z = 0; z < cChunkDef::Width; z++)
diff --git a/src/Generating/Noise3DGenerator.cpp b/src/Generating/Noise3DGenerator.cpp
index afa40c647..15a588d45 100644
--- a/src/Generating/Noise3DGenerator.cpp
+++ b/src/Generating/Noise3DGenerator.cpp
@@ -420,7 +420,7 @@ void cNoise3DComposable::GenerateNoiseArrayIfNeeded(int a_ChunkX, int a_ChunkZ)
}
}
// Linear-interpolate this XZ floor:
- LinearUpscale2DArrayInPlace(CurFloor, 17, 17, UPSCALE_X, UPSCALE_Z);
+ LinearUpscale2DArrayInPlace<17, 17, UPSCALE_X, UPSCALE_Z>(CurFloor);
}
// Finish the 3D linear interpolation by interpolating between each XZ-floors on the Y axis
diff --git a/src/Generating/PieceGenerator.cpp b/src/Generating/PieceGenerator.cpp
index cf5ab6226..8999a5ff7 100644
--- a/src/Generating/PieceGenerator.cpp
+++ b/src/Generating/PieceGenerator.cpp
@@ -31,14 +31,14 @@ public:
Gen.PlacePieces(500, 50, 500, 3, OutPieces);
// Print out the pieces:
- printf("OutPieces.size() = %u\n", OutPieces.size());
+ printf("OutPieces.size() = " SIZE_T_FMT "\n", OutPieces.size());
size_t idx = 0;
for (cPlacedPieces::const_iterator itr = OutPieces.begin(), end = OutPieces.end(); itr != end; ++itr, ++idx)
{
const Vector3i & Coords = (*itr)->GetCoords();
cCuboid Hitbox = (*itr)->GetHitBox();
Hitbox.Sort();
- printf("%u: {%d, %d, %d}, rot %d, hitbox {%d, %d, %d} - {%d, %d, %d} (%d * %d * %d)\n", idx,
+ printf(SIZE_T_FMT ": {%d, %d, %d}, rot %d, hitbox {%d, %d, %d} - {%d, %d, %d} (%d * %d * %d)\n", idx,
Coords.x, Coords.y, Coords.z,
(*itr)->GetNumCCWRotations(),
Hitbox.p1.x, Hitbox.p1.y, Hitbox.p1.z,
@@ -183,7 +183,6 @@ cPiece::cConnector cPiece::RotateMoveConnector(const cConnector & a_Connector, i
cPiece::cConnector res(a_Connector);
// Rotate the res connector:
- Vector3i Size = GetSize();
switch (a_NumCCWRotations)
{
case 0:
@@ -338,7 +337,7 @@ cPlacedPiece * cPieceGenerator::PlaceStartingPiece(int a_BlockX, int a_BlockY, i
// Choose a random supported rotation:
int Rotations[4] = {0};
int NumRotations = 1;
- for (int i = 1; i < ARRAYCOUNT(Rotations); i++)
+ for (size_t i = 1; i < ARRAYCOUNT(Rotations); i++)
{
if (StartingPiece->CanRotateCCW(i))
{
@@ -503,11 +502,11 @@ bool cPieceGenerator::CheckConnection(
// DEBUG:
void cPieceGenerator::DebugConnectorPool(const cPieceGenerator::cFreeConnectors & a_ConnectorPool, size_t a_NumProcessed)
{
- printf(" Connector pool: %u items\n", a_ConnectorPool.size() - a_NumProcessed);
+ printf(" Connector pool: " SIZE_T_FMT " items\n", a_ConnectorPool.size() - a_NumProcessed);
size_t idx = 0;
for (cPieceGenerator::cFreeConnectors::const_iterator itr = a_ConnectorPool.begin() + a_NumProcessed, end = a_ConnectorPool.end(); itr != end; ++itr, ++idx)
{
- printf(" %u: {%d, %d, %d}, type %d, direction %s, depth %d\n",
+ printf(" " SIZE_T_FMT ": {%d, %d, %d}, type %d, direction %s, depth %d\n",
idx,
itr->m_Connector.m_Pos.x, itr->m_Connector.m_Pos.y, itr->m_Connector.m_Pos.z,
itr->m_Connector.m_Type,
diff --git a/src/Generating/PieceGenerator.h b/src/Generating/PieceGenerator.h
index 9dd5bcfba..bef9d3463 100644
--- a/src/Generating/PieceGenerator.h
+++ b/src/Generating/PieceGenerator.h
@@ -122,9 +122,9 @@ public:
const cPiece & GetPiece (void) const { return *m_Piece; }
const Vector3i & GetCoords (void) const { return m_Coords; }
- const int GetNumCCWRotations(void) const { return m_NumCCWRotations; }
+ int GetNumCCWRotations(void) const { return m_NumCCWRotations; }
const cCuboid & GetHitBox (void) const { return m_HitBox; }
- const int GetDepth (void) const { return m_Depth; }
+ int GetDepth (void) const { return m_Depth; }
protected:
const cPlacedPiece * m_Parent;
diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp
new file mode 100644
index 000000000..a9e0a839d
--- /dev/null
+++ b/src/Generating/Prefab.cpp
@@ -0,0 +1,312 @@
+
+// Prefab.cpp
+
+/*
+Implements the cPrefab class, representing a cPiece descendant for the cPieceGenerator that
+uses a prefabricate in a cBlockArea for drawing itself.
+*/
+
+#include "Globals.h"
+#include "Prefab.h"
+#include "../WorldStorage/SchematicFileSerializer.h"
+#include "ChunkDesc.h"
+
+
+
+
+
+#ifdef SELF_TEST
+
+// Create one static prefab to test the parser:
+static const cPrefab::sDef g_TestPrefabDef =
+{
+ // Size:
+ 7, 6, 7, // SizeX = 7, SizeY = 6, SizeZ = 7
+
+ // Block definitions:
+ ".: 0: 0\n" /* 0 */
+ "a:112: 0\n" /* netherbrick */
+ "b:113: 0\n" /* netherbrickfence */,
+
+ // Block data:
+ // Level 1
+ "aaaaaaa"
+ "aaaaaaa"
+ "aaaaaaa"
+ "aaaaaaa"
+ "aaaaaaa"
+ "aaaaaaa"
+ "aaaaaaa"
+
+ // Level 2
+ "aa...aa"
+ "a.....a"
+ "......."
+ "......."
+ "......."
+ "a.....a"
+ "aa...aa"
+
+ // Level 3
+ "aa...aa"
+ "a.....a"
+ "......."
+ "......."
+ "......."
+ "a.....a"
+ "aa...aa"
+
+ // Level 4
+ "aa...aa"
+ "a.....a"
+ "......."
+ "......."
+ "......."
+ "a.....a"
+ "aa...aa"
+
+ // Level 5
+ "aabbbaa"
+ "a.....a"
+ "b.....b"
+ "b.....b"
+ "b.....b"
+ "a.....a"
+ "aabbbaa"
+
+ // Level 6
+ "aaaaaaa"
+ "a.....a"
+ "a.....a"
+ "a.....a"
+ "a.....a"
+ "a.....a"
+ "aaaaaaa",
+
+ // Connections:
+ "0: 0, 3, 2: 4\n"
+ "0: 2, 3, 0: 2\n",
+
+ // AllowedRotations:
+ 7, /* 1, 2, 3 CCW rotations */
+
+ // Merge strategy:
+ cBlockArea::msImprint
+};
+
+static cPrefab g_TestPrefab(g_TestPrefabDef);
+#endif
+
+
+
+
+
+cPrefab::cPrefab(const cPrefab::sDef & a_Def) :
+ m_Size(a_Def.m_SizeX, a_Def.m_SizeY, a_Def.m_SizeZ),
+ m_HitBox(0, 0, 0, a_Def.m_SizeX - 1, a_Def.m_SizeY - 1, a_Def.m_SizeZ - 1),
+ m_AllowedRotations(a_Def.m_AllowedRotations),
+ m_MergeStrategy(a_Def.m_MergeStrategy)
+{
+ m_BlockArea[0].Create(m_Size);
+ CharMap cm;
+ ParseCharMap(cm, a_Def.m_CharMap);
+ ParseBlockImage(cm, a_Def.m_Image);
+ ParseConnectors(a_Def.m_Connectors);
+
+ // 1 CCW rotation:
+ if ((m_AllowedRotations & 0x01) != 0)
+ {
+ m_BlockArea[1].CopyFrom(m_BlockArea[0]);
+ m_BlockArea[1].RotateCCW();
+ }
+
+ // 2 rotations are the same as mirroring twice; mirroring is faster because it has no reallocations
+ if ((m_AllowedRotations & 0x02) != 0)
+ {
+ m_BlockArea[2].CopyFrom(m_BlockArea[0]);
+ m_BlockArea[2].MirrorXY();
+ m_BlockArea[2].MirrorYZ();
+ }
+
+ // 3 CCW rotations = 1 CW rotation:
+ if ((m_AllowedRotations & 0x04) != 0)
+ {
+ m_BlockArea[3].CopyFrom(m_BlockArea[0]);
+ m_BlockArea[3].RotateCW();
+ }
+}
+
+
+
+
+
+void cPrefab::Draw(cChunkDesc & a_Dest, const cPlacedPiece * a_Placement) const
+{
+ Vector3i Placement = a_Placement->GetCoords();
+ int ChunkStartX = a_Dest.GetChunkX() * cChunkDef::Width;
+ int ChunkStartZ = a_Dest.GetChunkZ() * cChunkDef::Width;
+ Placement.Move(-ChunkStartX, 0, -ChunkStartZ);
+ a_Dest.WriteBlockArea(m_BlockArea[a_Placement->GetNumCCWRotations()], Placement.x, Placement.y, Placement.z, m_MergeStrategy);
+
+}
+
+
+
+
+
+bool cPrefab::HasConnectorType(int a_ConnectorType) const
+{
+ for (cConnectors::const_iterator itr = m_Connectors.begin(), end = m_Connectors.end(); itr != end; ++itr)
+ {
+ if (itr->m_Type == a_ConnectorType)
+ {
+ return true;
+ }
+ } // for itr - m_Connectors[]
+ return false;
+}
+
+
+
+
+
+void cPrefab::ParseCharMap(CharMap & a_CharMapOut, const char * a_CharMapDef)
+{
+ // Initialize the charmap to all-invalid values:
+ for (size_t i = 0; i < ARRAYCOUNT(a_CharMapOut); i++)
+ {
+ a_CharMapOut[i].m_BlockType = 0;
+ a_CharMapOut[i].m_BlockMeta = 16; // Mark unassigned entries with a meta that is impossible otherwise
+ }
+
+ // Process the lines in the definition:
+ AStringVector Lines = StringSplitAndTrim(a_CharMapDef, "\n");
+ for (AStringVector::const_iterator itr = Lines.begin(), end = Lines.end(); itr != end; ++itr)
+ {
+ AStringVector CharDef = StringSplitAndTrim(*itr, ":");
+ size_t NumElements = CharDef.size();
+ if ((NumElements < 2) || CharDef[0].empty() || CharDef[1].empty())
+ {
+ LOGWARNING("Bad prefab CharMap definition line: \"%s\", skipping.", itr->c_str());
+ continue;
+ }
+ unsigned char Src = (unsigned char)CharDef[0][0];
+ ASSERT(a_CharMapOut[Src].m_BlockMeta == 16); // This letter has not been assigned yet?
+ a_CharMapOut[Src].m_BlockType = (BLOCKTYPE)atoi(CharDef[1].c_str());
+ NIBBLETYPE BlockMeta = 0;
+ if ((NumElements >= 3) && !CharDef[2].empty())
+ {
+ BlockMeta = (NIBBLETYPE)atoi(CharDef[2].c_str());
+ ASSERT((BlockMeta >= 0) && (BlockMeta <= 15));
+ }
+ a_CharMapOut[Src].m_BlockMeta = BlockMeta;
+ } // for itr - Lines[]
+}
+
+
+
+
+
+void cPrefab::ParseBlockImage(const CharMap & a_CharMap, const char * a_BlockImage)
+{
+ // Map each letter in the a_BlockImage (from the in-source definition) to real blocktype / blockmeta:
+ for (int y = 0; y < m_Size.y; y++)
+ {
+ for (int z = 0; z < m_Size.z; z++)
+ {
+ const unsigned char * BlockImage = (const unsigned char *)a_BlockImage + y * m_Size.x * m_Size.z + z * m_Size.x;
+ for (int x = 0; x < m_Size.x; x++)
+ {
+ const sBlockTypeDef & MappedValue = a_CharMap[BlockImage[x]];
+ ASSERT(MappedValue.m_BlockMeta != 16); // Using a letter not defined in the CharMap?
+ m_BlockArea[0].SetRelBlockTypeMeta(x, y, z, MappedValue.m_BlockType, MappedValue.m_BlockMeta);
+ }
+ }
+ }
+}
+
+
+
+
+
+void cPrefab::ParseConnectors(const char * a_ConnectorsDef)
+{
+ AStringVector Lines = StringSplitAndTrim(a_ConnectorsDef, "\n");
+ for (AStringVector::const_iterator itr = Lines.begin(), end = Lines.end(); itr != end; ++itr)
+ {
+ if (itr->empty())
+ {
+ continue;
+ }
+ // Split into components: "Type: X, Y, Z: Face":
+ AStringVector Defs = StringSplitAndTrim(*itr, ":");
+ if (Defs.size() != 3)
+ {
+ LOGWARNING("Bad prefab Connector definition line: \"%s\", skipping.", itr->c_str());
+ continue;
+ }
+ AStringVector Coords = StringSplitAndTrim(Defs[1], ",");
+ if (Coords.size() != 3)
+ {
+ LOGWARNING("Bad prefab Connector coords definition: \"%s\", skipping.", Defs[1].c_str());
+ continue;
+ }
+
+ // Check that the BlockFace is within range:
+ int BlockFace = atoi(Defs[2].c_str());
+ if ((BlockFace < 0) || (BlockFace >= 6))
+ {
+ LOGWARNING("Bad prefab Connector Blockface: \"%s\", skipping.", Defs[2].c_str());
+ continue;
+ }
+
+ // Add the connector:
+ m_Connectors.push_back(cPiece::cConnector(
+ atoi(Coords[0].c_str()), atoi(Coords[1].c_str()), atoi(Coords[2].c_str()), // Connector pos
+ atoi(Defs[0].c_str()), // Connector type
+ (eBlockFace)BlockFace
+ ));
+ } // for itr - Lines[]
+}
+
+
+
+
+
+cPiece::cConnectors cPrefab::GetConnectors(void) const
+{
+ return m_Connectors;
+}
+
+
+
+
+
+Vector3i cPrefab::GetSize(void) const
+{
+ return m_Size;
+}
+
+
+
+
+
+cCuboid cPrefab::GetHitBox(void) const
+{
+ return m_HitBox;
+}
+
+
+
+
+
+bool cPrefab::CanRotateCCW(int a_NumRotations) const
+{
+ // Either zero rotations
+ // Or the proper bit in m_AllowedRotations is set
+ return (a_NumRotations == 0) || ((m_AllowedRotations & (1 << ((a_NumRotations + 3) % 4))) != 0);
+}
+
+
+
+
diff --git a/src/Generating/Prefab.h b/src/Generating/Prefab.h
new file mode 100644
index 000000000..04c4f09da
--- /dev/null
+++ b/src/Generating/Prefab.h
@@ -0,0 +1,105 @@
+
+// Prefab.h
+
+/*
+Declares the cPrefab class, representing a cPiece descendant for the cPieceGenerator that
+uses a prefabricate in a cBlockArea for drawing itself.
+The class can be constructed from data that is stored directly in the executable, in a sPrefabDef structure
+declared in this file as well; the Gallery server exports areas in this format.
+*/
+
+
+
+
+
+#pragma once
+
+#include "PieceGenerator.h"
+#include "../BlockArea.h"
+
+
+
+
+
+// fwd:
+class cChunkDesc;
+
+
+
+
+
+class cPrefab :
+ public cPiece
+{
+public:
+ struct sDef
+ {
+ int m_SizeX;
+ int m_SizeY;
+ int m_SizeZ;
+ const char * m_CharMap;
+ const char * m_Image;
+ const char * m_Connectors;
+ int m_AllowedRotations;
+ cBlockArea::eMergeStrategy m_MergeStrategy;
+ };
+
+ cPrefab(const sDef & a_Def);
+
+ /** Draws the prefab into the specified chunk, according to the placement stored in the PlacedPiece. */
+ void Draw(cChunkDesc & a_Dest, const cPlacedPiece * a_Placement) const;
+
+ /** Returns true if the prefab has any connector of the specified type. */
+ bool HasConnectorType(int a_ConnectorType) const;
+
+protected:
+ /** Packs complete definition of a single block, for per-letter assignment. */
+ struct sBlockTypeDef
+ {
+ BLOCKTYPE m_BlockType;
+ NIBBLETYPE m_BlockMeta;
+ };
+
+ /** Maps letters in the sDef::m_Image onto a number, BlockType * 16 | BlockMeta */
+ typedef sBlockTypeDef CharMap[256];
+
+
+ /** The cBlockArea that contains the block definitions for the prefab.
+ The index identifies the number of CCW rotations applied (0 = no rotation, 1 = 1 CCW rotation, ...). */
+ cBlockArea m_BlockArea[4];
+
+ /** The size of the prefab */
+ Vector3i m_Size;
+
+ /** The hitbox of the prefab. In first version is the same as the m_BlockArea dimensions */
+ cCuboid m_HitBox;
+
+ /** The connectors through which the piece connects to other pieces */
+ cConnectors m_Connectors;
+
+ /** Bitmask, bit N set -> N rotations CCW supported */
+ int m_AllowedRotations;
+
+ /** The merge strategy to use when drawing the prefab into a block area */
+ cBlockArea::eMergeStrategy m_MergeStrategy;
+
+
+ // cPiece overrides:
+ virtual cConnectors GetConnectors(void) const override;
+ virtual Vector3i GetSize(void) const override;
+ virtual cCuboid GetHitBox(void) const override;
+ virtual bool CanRotateCCW(int a_NumRotations) const override;
+
+ /** Parses the CharMap in the definition into a CharMap binary data used for translating the definition into BlockArea. */
+ void ParseCharMap(CharMap & a_CharMapOut, const char * a_CharMapDef);
+
+ /** Parses the Image in the definition into m_BlockArea[0]'s block types and metas, using the specified CharMap. */
+ void ParseBlockImage(const CharMap & a_CharMap, const char * a_BlockImage);
+
+ /** Parses the connectors definition text into m_Connectors member. */
+ void ParseConnectors(const char * a_ConnectorsDef);
+};
+
+
+
+
diff --git a/src/Generating/StructGen.cpp b/src/Generating/StructGen.cpp
index 3cc8a09c3..db9d5578c 100644
--- a/src/Generating/StructGen.cpp
+++ b/src/Generating/StructGen.cpp
@@ -578,7 +578,7 @@ void cStructGenDirectOverhangs::GenFinish(cChunkDesc & a_ChunkDesc)
m_Noise2.IntNoise3DInt(BaseX + INTERPOL_X * x, BaseY, BaseZ + INTERPOL_Z * z) /
256;
} // for x, z - FloorLo[]
- LinearUpscale2DArrayInPlace(FloorLo, 17, 17, INTERPOL_X, INTERPOL_Z);
+ LinearUpscale2DArrayInPlace<17, 17, INTERPOL_X, INTERPOL_Z>(FloorLo);
// Interpolate segments:
for (int Segment = BaseY; Segment < MaxHeight; Segment += SEGMENT_HEIGHT)
@@ -591,7 +591,7 @@ void cStructGenDirectOverhangs::GenFinish(cChunkDesc & a_ChunkDesc)
m_Noise2.IntNoise3DInt(BaseX + INTERPOL_Z * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z) /
256;
} // for x, z - FloorLo[]
- LinearUpscale2DArrayInPlace(FloorHi, 17, 17, INTERPOL_X, INTERPOL_Z);
+ LinearUpscale2DArrayInPlace<17, 17, INTERPOL_X, INTERPOL_Z>(FloorHi);
// Interpolate between FloorLo and FloorHi:
for (int z = 0; z < 16; z++) for (int x = 0; x < 16; x++)
diff --git a/src/Globals.h b/src/Globals.h
index b8acfca64..a1cee5c2f 100644
--- a/src/Globals.h
+++ b/src/Globals.h
@@ -38,6 +38,15 @@
// No alignment needed in MSVC
#define ALIGN_8
#define ALIGN_16
+
+ #define FORMATSTRING(formatIndex, va_argsIndex)
+
+ // MSVC has its own custom version of zu format
+ #define SIZE_T_FMT "%Iu"
+ #define SIZE_T_FMT_PRECISION(x) "%" #x "Iu"
+ #define SIZE_T_FMT_HEX "%Ix"
+
+ #define NORETURN __declspec(noreturn)
#elif defined(__GNUC__)
@@ -56,6 +65,14 @@
// Some portability macros :)
#define stricmp strcasecmp
+
+ #define FORMATSTRING(formatIndex, va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex)))
+
+ #define SIZE_T_FMT "%zu"
+ #define SIZE_T_FMT_PRECISION(x) "%" #x "zu"
+ #define SIZE_T_FMT_HEX "%zx"
+
+ #define NORETURN __attribute((__noreturn__))
#else
@@ -81,7 +98,14 @@
#endif
+#ifdef _DEBUG
+ #define NORETURNDEBUG NORETURN
+#else
+ #define NORETURNDEBUG
+#endif
+
+#include <stddef.h>
// Integral types with predefined sizes:
@@ -96,8 +120,23 @@ typedef unsigned short UInt16;
typedef unsigned char Byte;
+// If you get an error about specialization check the size of integral types
+template <typename T, size_t Size, bool x = sizeof(T) == Size>
+class SizeChecker;
+
+template <typename T, size_t Size>
+class SizeChecker<T, Size, true>
+{
+ T v;
+};
+template class SizeChecker<Int64, 8>;
+template class SizeChecker<Int32, 4>;
+template class SizeChecker<Int16, 2>;
+template class SizeChecker<UInt64, 8>;
+template class SizeChecker<UInt32, 4>;
+template class SizeChecker<UInt16, 2>;
// A macro to disallow the copy constructor and operator= functions
// This should be used in the private: declarations for any class that shouldn't allow copying itself
@@ -179,7 +218,7 @@ typedef unsigned char Byte;
#include <memory>
#include <set>
#include <queue>
-
+#include <limits>
@@ -220,15 +259,22 @@ typedef unsigned char Byte;
// Pretty much the same as ASSERT() but stays in Release builds
#define VERIFY( x ) ( !!(x) || ( LOGERROR("Verification failed: %s, file %s, line %i", #x, __FILE__, __LINE__ ), exit(1), 0 ) )
+// Same as assert but in all Self test builds
+#ifdef SELF_TEST
+#define assert_test(x) ( !!(x) || (assert(!#x), exit(1), 0))
+#endif
-/// A generic interface used mainly in ForEach() functions
+
+/** A generic interface used mainly in ForEach() functions */
template <typename Type> class cItemCallback
{
public:
- /// Called for each item in the internal list; return true to stop the loop, or false to continue enumerating
+ virtual ~cItemCallback() {}
+
+ /** Called for each item in the internal list; return true to stop the loop, or false to continue enumerating */
virtual bool Item(Type * a_Type) = 0;
} ;
@@ -262,5 +308,3 @@ T Clamp(T a_Value, T a_Min, T a_Max)
#include "Entities/Effects.h"
-
-
diff --git a/src/HTTPServer/HTTPServer.h b/src/HTTPServer/HTTPServer.h
index 24baf8c95..383abb4b6 100644
--- a/src/HTTPServer/HTTPServer.h
+++ b/src/HTTPServer/HTTPServer.h
@@ -37,6 +37,8 @@ public:
class cCallbacks
{
public:
+ virtual ~cCallbacks() {}
+
/** Called when a new request arrives over a connection and its headers have been parsed.
The request body needn't have arrived yet.
*/
@@ -50,7 +52,7 @@ public:
} ;
cHTTPServer(void);
- ~cHTTPServer();
+ virtual ~cHTTPServer();
/// Initializes the server on the specified ports
bool Initialize(const AString & a_PortsIPv4, const AString & a_PortsIPv6);
diff --git a/src/Inventory.h b/src/Inventory.h
index fd2089a13..1ad7c4776 100644
--- a/src/Inventory.h
+++ b/src/Inventory.h
@@ -52,6 +52,8 @@ public:
cInventory(cPlayer & a_Owner);
+ virtual ~cInventory() {}
+
// tolua_begin
/// Removes all items from the entire inventory
diff --git a/src/Item.cpp b/src/Item.cpp
index 61d57e763..856b68be6 100644
--- a/src/Item.cpp
+++ b/src/Item.cpp
@@ -216,7 +216,7 @@ cItem * cItems::Get(int a_Idx)
{
if ((a_Idx < 0) || (a_Idx >= (int)size()))
{
- LOGWARNING("cItems: Attempt to get an out-of-bounds item at index %d; there are currently %d items. Returning a nil.", a_Idx, size());
+ LOGWARNING("cItems: Attempt to get an out-of-bounds item at index %d; there are currently " SIZE_T_FMT " items. Returning a nil.", a_Idx, size());
return NULL;
}
return &at(a_Idx);
@@ -230,7 +230,7 @@ void cItems::Set(int a_Idx, const cItem & a_Item)
{
if ((a_Idx < 0) || (a_Idx >= (int)size()))
{
- LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %d items. Not setting.", a_Idx, size());
+ LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently " SIZE_T_FMT " items. Not setting.", a_Idx, size());
return;
}
at(a_Idx) = a_Item;
@@ -244,7 +244,7 @@ void cItems::Delete(int a_Idx)
{
if ((a_Idx < 0) || (a_Idx >= (int)size()))
{
- LOGWARNING("cItems: Attempt to delete an item at an out-of-bounds index %d; there are currently %d items. Ignoring.", a_Idx, size());
+ LOGWARNING("cItems: Attempt to delete an item at an out-of-bounds index %d; there are currently " SIZE_T_FMT " items. Ignoring.", a_Idx, size());
return;
}
erase(begin() + a_Idx);
@@ -258,7 +258,7 @@ void cItems::Set(int a_Idx, short a_ItemType, char a_ItemCount, short a_ItemDama
{
if ((a_Idx < 0) || (a_Idx >= (int)size()))
{
- LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %d items. Not setting.", a_Idx, size());
+ LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently " SIZE_T_FMT " items. Not setting.", a_Idx, size());
return;
}
at(a_Idx) = cItem(a_ItemType, a_ItemCount, a_ItemDamage);
diff --git a/src/ItemGrid.h b/src/ItemGrid.h
index b344e3daf..c34d5e9e2 100644
--- a/src/ItemGrid.h
+++ b/src/ItemGrid.h
@@ -20,11 +20,13 @@ class cItemGrid
public:
// tolua_end
- /// This class is used as a callback for when a slot changes
+ /** This class is used as a callback for when a slot changes */
class cListener
{
public:
- /// Called whenever a slot changes
+ virtual ~cListener() {}
+
+ /** Called whenever a slot changes */
virtual void OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) = 0;
} ;
typedef std::vector<cListener *> cListeners;
@@ -38,12 +40,12 @@ public:
int GetHeight (void) const { return m_Height; }
int GetNumSlots(void) const { return m_NumSlots; }
- /// Converts XY coords into slot number; returns -1 on invalid coords
+ /** Converts XY coords into slot number; returns -1 on invalid coords */
int GetSlotNum(int a_X, int a_Y) const;
// tolua_end
- /// Converts slot number into XY coords; sets coords to -1 on invalid slot number. Exported in ManualBindings.cpp
+ /** Converts slot number into XY coords; sets coords to -1 on invalid slot number. Exported in ManualBindings.cpp */
void GetSlotCoords(int a_SlotNum, int & a_X, int & a_Y) const;
// tolua_begin
@@ -62,16 +64,16 @@ public:
void EmptySlot(int a_X, int a_Y);
void EmptySlot(int a_SlotNum);
- /// Returns true if the specified slot is empty or the slot doesn't exist
+ /** Returns true if the specified slot is empty or the slot doesn't exist */
bool IsSlotEmpty(int a_SlotNum) const;
- /// Returns true if the specified slot is empty or the slot doesn't exist
+ /** Returns true if the specified slot is empty or the slot doesn't exist */
bool IsSlotEmpty(int a_X, int a_Y) const;
- /// Sets all items as empty
+ /** Sets all items as empty */
void Clear(void);
- /// Returns number of items out of a_ItemStack that can fit in the storage
+ /** Returns number of items out of a_ItemStack that can fit in the storage */
int HowManyCanFit(const cItem & a_ItemStack, bool a_AllowNewStacks = true);
/** Adds as many items out of a_ItemStack as can fit.
@@ -117,37 +119,37 @@ public:
*/
cItem RemoveOneItem(int a_X, int a_Y);
- /// Returns the number of items of type a_Item that are stored
+ /** Returns the number of items of type a_Item that are stored */
int HowManyItems(const cItem & a_Item);
- /// Returns true if there are at least as many items of type a_ItemStack as in a_ItemStack
+ /** Returns true if there are at least as many items of type a_ItemStack as in a_ItemStack */
bool HasItems(const cItem & a_ItemStack);
- /// Returns the index of the first empty slot; -1 if all full
+ /** Returns the index of the first empty slot; -1 if all full */
int GetFirstEmptySlot(void) const;
- /// Returns the index of the first non-empty slot; -1 if all empty
+ /** Returns the index of the first non-empty slot; -1 if all empty */
int GetFirstUsedSlot(void) const;
- /// Returns the index of the last empty slot; -1 if all full
+ /** Returns the index of the last empty slot; -1 if all full */
int GetLastEmptySlot(void) const;
- /// Returns the index of the last used slot; -1 if all empty
+ /** Returns the index of the last used slot; -1 if all empty */
int GetLastUsedSlot(void) const;
- /// Returns the index of the first empty slot following a_StartFrom (a_StartFrom is not checked)
+ /** Returns the index of the first empty slot following a_StartFrom (a_StartFrom is not checked) */
int GetNextEmptySlot(int a_StartFrom) const;
- /// Returns the index of the first used slot following a_StartFrom (a_StartFrom is not checked)
+ /** Returns the index of the first used slot following a_StartFrom (a_StartFrom is not checked) */
int GetNextUsedSlot(int a_StartFrom) const;
- /// Copies the contents into a cItems object; preserves the original a_Items contents
+ /** Copies the contents into a cItems object; preserves the original a_Items contents */
void CopyToItems(cItems & a_Items) const;
- /// Adds the specified damage to the specified item; returns true if the item broke (but the item is left intact)
+ /** Adds the specified damage to the specified item; returns true if the item broke (but the item is left intact) */
bool DamageItem(int a_SlotNum, short a_Amount);
- /// Adds the specified damage to the specified item; returns true if the item broke (but the item is left intact)
+ /** Adds the specified damage to the specified item; returns true if the item broke (but the item is left intact) */
bool DamageItem(int a_X, int a_Y, short a_Amount);
// tolua_end
@@ -159,10 +161,10 @@ public:
*/
void GenerateRandomLootWithBooks(const cLootProbab * a_LootProbabs, size_t a_CountLootProbabs, int a_NumSlots, int a_Seed);
- /// Adds a callback that gets called whenever a slot changes. Must not be called from within the listener callback!
+ /** Adds a callback that gets called whenever a slot changes. Must not be called from within the listener callback! */
void AddListener(cListener & a_Listener);
- /// Removes a slot-change-callback. Must not be called from within the listener callback!
+ /** Removes a slot-change-callback. Must not be called from within the listener callback! */
void RemoveListener(cListener & a_Listener);
// tolua_begin
@@ -177,7 +179,7 @@ protected:
cCriticalSection m_CSListeners; ///< CS that guards the m_Listeners against multi-thread access
bool m_IsInTriggerListeners; ///< Set to true while TriggerListeners is running, to detect attempts to manipulate listener list while triggerring
- /// Calls all m_Listeners for the specified slot number
+ /** Calls all m_Listeners for the specified slot number */
void TriggerListeners(int a_SlotNum);
/** Adds up to a_Num items out of a_ItemStack, as many as can fit, in specified slot
diff --git a/src/Items/ItemBucket.h b/src/Items/ItemBucket.h
index 72cb8fa0a..68c89dd85 100644
--- a/src/Items/ItemBucket.h
+++ b/src/Items/ItemBucket.h
@@ -172,12 +172,12 @@ public:
virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override
{
- if (a_BlockMeta != 0) // Even if it was a water block it would not be a source.
- {
- return false;
- }
if (IsBlockWater(a_BlockType) || IsBlockLava(a_BlockType))
{
+ if (a_BlockMeta != 0) // GetBlockFromTrace is called for scooping up fluids; the hit block should be a source
+ {
+ return false;
+ }
m_HasHitFluid = true;
m_Pos.Set(a_BlockX, a_BlockY, a_BlockZ);
return true;
diff --git a/src/Items/ItemCake.h b/src/Items/ItemCake.h
new file mode 100644
index 000000000..48e23ed59
--- /dev/null
+++ b/src/Items/ItemCake.h
@@ -0,0 +1,41 @@
+
+#pragma once
+
+#include "ItemHandler.h"
+
+
+
+
+
+class cItemCakeHandler :
+ public cItemHandler
+{
+public:
+ cItemCakeHandler(int a_ItemType) :
+ cItemHandler(a_ItemType)
+ {
+ }
+
+
+ virtual bool IsPlaceable(void) override
+ {
+ return true;
+ }
+
+
+ virtual bool GetPlacementBlockTypeMeta(
+ cWorld * a_World, cPlayer * a_Player,
+ int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
+ int a_CursorX, int a_CursorY, int a_CursorZ,
+ BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
+ ) override
+ {
+ a_BlockType = E_BLOCK_CAKE;
+ a_BlockMeta = 0;
+ return true;
+ }
+} ;
+
+
+
+
diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp
index 1d357fcf1..337b3a83c 100644
--- a/src/Items/ItemHandler.cpp
+++ b/src/Items/ItemHandler.cpp
@@ -13,6 +13,7 @@
#include "ItemBow.h"
#include "ItemBrewingStand.h"
#include "ItemBucket.h"
+#include "ItemCake.h"
#include "ItemCauldron.h"
#include "ItemCloth.h"
#include "ItemComparator.h"
@@ -26,6 +27,7 @@
#include "ItemHoe.h"
#include "ItemLeaves.h"
#include "ItemLighter.h"
+#include "ItemLilypad.h"
#include "ItemMap.h"
#include "ItemMinecart.h"
#include "ItemNetherWart.h"
@@ -94,6 +96,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType)
// Single item per handler, alphabetically sorted:
case E_BLOCK_LEAVES: return new cItemLeavesHandler(a_ItemType);
+ case E_BLOCK_NEW_LEAVES: return new cItemLeavesHandler(a_ItemType);
case E_BLOCK_SAPLING: return new cItemSaplingHandler(a_ItemType);
case E_BLOCK_WOOL: return new cItemClothHandler(a_ItemType);
case E_ITEM_BED: return new cItemBedHandler(a_ItemType);
@@ -101,16 +104,19 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType)
case E_ITEM_BOTTLE_O_ENCHANTING: return new cItemBottleOEnchantingHandler();
case E_ITEM_BOW: return new cItemBowHandler;
case E_ITEM_BREWING_STAND: return new cItemBrewingStandHandler(a_ItemType);
+ case E_ITEM_CAKE: return new cItemCakeHandler(a_ItemType);
case E_ITEM_CAULDRON: return new cItemCauldronHandler(a_ItemType);
case E_ITEM_COMPARATOR: return new cItemComparatorHandler(a_ItemType);
case E_ITEM_DYE: return new cItemDyeHandler(a_ItemType);
case E_ITEM_EGG: return new cItemEggHandler();
case E_ITEM_EMPTY_MAP: return new cItemEmptyMapHandler();
case E_ITEM_ENDER_PEARL: return new cItemEnderPearlHandler();
+ case E_ITEM_FIRE_CHARGE: return new cItemLighterHandler(a_ItemType);
case E_ITEM_FIREWORK_ROCKET: return new cItemFireworkHandler();
case E_ITEM_FISHING_ROD: return new cItemFishingRodHandler(a_ItemType);
case E_ITEM_FLINT_AND_STEEL: return new cItemLighterHandler(a_ItemType);
case E_ITEM_FLOWER_POT: return new cItemFlowerPotHandler(a_ItemType);
+ case E_BLOCK_LILY_PAD: return new cItemLilypadHandler(a_ItemType);
case E_ITEM_MAP: return new cItemMapHandler();
case E_ITEM_ITEM_FRAME: return new cItemItemFrameHandler(a_ItemType);
case E_ITEM_NETHER_WART: return new cItemNetherWartHandler(a_ItemType);
@@ -337,6 +343,7 @@ char cItemHandler::GetMaxStackSize(void)
case E_ITEM_BREWING_STAND: return 64;
case E_ITEM_BUCKET: return 16;
case E_ITEM_CARROT: return 64;
+ case E_ITEM_CAKE: return 1;
case E_ITEM_CAULDRON: return 64;
case E_ITEM_CLAY: return 64;
case E_ITEM_CLAY_BRICK: return 64;
diff --git a/src/Items/ItemItemFrame.h b/src/Items/ItemItemFrame.h
index 74e987445..27e7dba35 100644
--- a/src/Items/ItemItemFrame.h
+++ b/src/Items/ItemItemFrame.h
@@ -34,7 +34,11 @@ public:
if (Block == E_BLOCK_AIR)
{
cItemFrame * ItemFrame = new cItemFrame(a_Dir, a_BlockX, a_BlockY, a_BlockZ);
- ItemFrame->Initialize(a_World);
+ if (!ItemFrame->Initialize(a_World))
+ {
+ delete ItemFrame;
+ return false;
+ }
if (!a_Player->IsGameModeCreative())
{
diff --git a/src/Items/ItemLighter.h b/src/Items/ItemLighter.h
index 18873e911..32f49cab6 100644
--- a/src/Items/ItemLighter.h
+++ b/src/Items/ItemLighter.h
@@ -26,7 +26,26 @@ public:
return false;
}
- a_Player->UseEquippedItem();
+ if (!a_Player->IsGameModeCreative())
+ {
+ switch (m_ItemType)
+ {
+ case E_ITEM_FLINT_AND_STEEL:
+ {
+ a_Player->UseEquippedItem();
+ break;
+ }
+ case E_ITEM_FIRE_CHARGE:
+ {
+ a_Player->GetInventory().RemoveOneEquippedItem();
+ break;
+ }
+ default:
+ {
+ ASSERT(!"Unknown Lighter Item!");
+ }
+ }
+ }
switch (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ))
{
@@ -34,8 +53,8 @@ public:
{
// Activate the TNT:
a_World->BroadcastSoundEffect("game.tnt.primed", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 1.0f, 1.0f);
- a_World->SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5); // 80 ticks to boom
a_World->SetBlock(a_BlockX,a_BlockY,a_BlockZ, E_BLOCK_AIR, 0);
+ a_World->SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5); // 80 ticks to boom
break;
}
default:
@@ -49,6 +68,7 @@ public:
if (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_AIR)
{
a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_FIRE, 0);
+ a_World->BroadcastSoundEffect("fire.ignite", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 1.0F, 1.04F);
break;
}
}
diff --git a/src/Items/ItemLilypad.h b/src/Items/ItemLilypad.h
new file mode 100644
index 000000000..5a29abe94
--- /dev/null
+++ b/src/Items/ItemLilypad.h
@@ -0,0 +1,109 @@
+#pragma once
+
+#include "ItemHandler.h"
+#include "../Entities/Player.h"
+#include "Vector3.h"
+#include "../LineBlockTracer.h"
+#include "BlockInfo.h"
+
+
+
+
+
+class cItemLilypadHandler :
+ public cItemHandler
+{
+ typedef cItemHandler super;
+
+public:
+ cItemLilypadHandler(BLOCKTYPE a_BlockType)
+ : cItemHandler(a_BlockType)
+ {
+
+ }
+
+ virtual bool IsPlaceable(void) override
+ {
+ return false; // Set as not placeable so OnItemUse is called
+ }
+
+ virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override
+ {
+ if (a_BlockFace > BLOCK_FACE_NONE)
+ {
+ // Clicked on the side of a submerged block; vanilla allows placement, so should we
+ AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
+ a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_LILY_PAD, 0);
+ if (!a_Player->IsGameModeCreative())
+ {
+ a_Player->GetInventory().RemoveOneEquippedItem();
+ }
+ return true;
+ }
+
+ class cCallbacks :
+ public cBlockTracer::cCallbacks
+ {
+ public:
+ cCallbacks(cWorld * a_World) :
+ m_HasHitFluid(false),
+ m_World(a_World)
+ {
+ }
+
+ virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override
+ {
+ if (IsBlockWater(a_BlockType))
+ {
+ if ((a_BlockMeta != 0) || (a_EntryFace == BLOCK_FACE_NONE)) // The hit block should be a source. The FACE_NONE check is clicking whilst submerged
+ {
+ return false;
+ }
+ a_EntryFace = BLOCK_FACE_YP; // Always place pad at top of water block
+ AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, (eBlockFace)a_EntryFace);
+ BLOCKTYPE Block = m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
+ if (
+ !IsBlockWater(Block) &&
+ cBlockInfo::FullyOccupiesVoxel(Block)
+ )
+ {
+ // Can't place lilypad on air/in another block!
+ return true;
+ }
+ m_HasHitFluid = true;
+ m_Pos.Set(a_BlockX, a_BlockY, a_BlockZ);
+ return true;
+ }
+ return false;
+ }
+
+ Vector3i m_Pos;
+ bool m_HasHitFluid;
+ cWorld * m_World;
+
+ };
+
+ cCallbacks Callbacks(a_World);
+ cLineBlockTracer Tracer(*a_Player->GetWorld(), Callbacks);
+ Vector3d Start(a_Player->GetEyePosition() + a_Player->GetLookVector());
+ Vector3d End(a_Player->GetEyePosition() + a_Player->GetLookVector() * 5);
+
+ Tracer.Trace(Start.x, Start.y, Start.z, End.x, End.y, End.z);
+
+ if (Callbacks.m_HasHitFluid)
+ {
+ a_World->SetBlock(Callbacks.m_Pos.x, Callbacks.m_Pos.y, Callbacks.m_Pos.z, E_BLOCK_LILY_PAD, 0);
+ if (!a_Player->IsGameModeCreative())
+ {
+ a_Player->GetInventory().RemoveOneEquippedItem();
+ }
+ return true;
+ }
+
+ return false;
+ }
+};
+
+
+
+
diff --git a/src/Items/ItemMinecart.h b/src/Items/ItemMinecart.h
index bcaa5635a..25500aeb9 100644
--- a/src/Items/ItemMinecart.h
+++ b/src/Items/ItemMinecart.h
@@ -1,4 +1,3 @@
-
// ItemMinecart.h
// Declares the various minecart ItemHandlers
@@ -72,6 +71,11 @@ public:
}
} // switch (m_ItemType)
Minecart->Initialize(a_World);
+
+ if (!a_Player->IsGameModeCreative())
+ {
+ a_Player->GetInventory().RemoveOneEquippedItem();
+ }
return true;
}
diff --git a/src/Items/ItemShears.h b/src/Items/ItemShears.h
index b8f75f5ba..39d2776fa 100644
--- a/src/Items/ItemShears.h
+++ b/src/Items/ItemShears.h
@@ -28,10 +28,10 @@ public:
virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override
{
BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
- if (Block == E_BLOCK_LEAVES)
+ if ((Block == E_BLOCK_LEAVES) || (Block == E_BLOCK_NEW_LEAVES))
{
cItems Drops;
- Drops.push_back(cItem(E_BLOCK_LEAVES, 1, a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x03));
+ Drops.push_back(cItem(Block, 1, a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x03));
a_World->SpawnItemPickups(Drops, a_BlockX, a_BlockY, a_BlockZ);
a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
@@ -49,6 +49,7 @@ public:
case E_BLOCK_COBWEB:
case E_BLOCK_VINES:
case E_BLOCK_LEAVES:
+ case E_BLOCK_NEW_LEAVES:
{
return true;
}
diff --git a/src/LightingThread.cpp b/src/LightingThread.cpp
index 44dadb8a9..302473d71 100644
--- a/src/LightingThread.cpp
+++ b/src/LightingThread.cpp
@@ -13,12 +13,6 @@
-/// If more than this many chunks are in the queue, a warning is printed to the log
-#define WARN_ON_QUEUE_SIZE 800
-
-
-
-
/// Chunk data callback that takes the chunk data and puts them into cLightingThread's m_BlockTypes[] / m_HeightMap[]:
class cReader :
diff --git a/src/LinearUpscale.h b/src/LinearUpscale.h
index b337b3219..0b04408cf 100644
--- a/src/LinearUpscale.h
+++ b/src/LinearUpscale.h
@@ -18,7 +18,7 @@ Therefore, there is no cpp file.
InPlace upscaling works on a single array and assumes that the values to work on have already
been interspersed into the array to the cell boundaries.
-Specifically, a_Array[x * a_AnchorStepX + y * a_AnchorStepY] contains the anchor value.
+Specifically, a_Array[x * AnchorStepX + y * AnchorStepY] contains the anchor value.
Regular upscaling takes two arrays and "moves" the input from src to dst; src is expected packed.
*/
@@ -29,46 +29,48 @@ Regular upscaling takes two arrays and "moves" the input from src to dst; src is
/**
Linearly interpolates values in the array between the equidistant anchor points (upscales).
Works in-place (input is already present at the correct output coords)
+Uses templates to make it possible for the compiler to further optimizer the loops
*/
-template<typename TYPE> void LinearUpscale2DArrayInPlace(
- TYPE * a_Array,
- int a_SizeX, int a_SizeY, // Dimensions of the array
- int a_AnchorStepX, int a_AnchorStepY // Distances between the anchor points in each direction
-)
+template<
+ int SizeX, int SizeY, // Dimensions of the array
+ int AnchorStepX, int AnchorStepY,
+ typename TYPE
+>
+void LinearUpscale2DArrayInPlace(TYPE * a_Array)
{
// First interpolate columns where the anchor points are:
- int LastYCell = a_SizeY - a_AnchorStepY;
- for (int y = 0; y < LastYCell; y += a_AnchorStepY)
+ int LastYCell = SizeY - AnchorStepY;
+ for (int y = 0; y < LastYCell; y += AnchorStepY)
{
- int Idx = a_SizeX * y;
- for (int x = 0; x < a_SizeX; x += a_AnchorStepX)
+ int Idx = SizeX * y;
+ for (int x = 0; x < SizeX; x += AnchorStepX)
{
TYPE StartValue = a_Array[Idx];
- TYPE EndValue = a_Array[Idx + a_SizeX * a_AnchorStepY];
+ TYPE EndValue = a_Array[Idx + SizeX * AnchorStepY];
TYPE Diff = EndValue - StartValue;
- for (int CellY = 1; CellY < a_AnchorStepY; CellY++)
+ for (int CellY = 1; CellY < AnchorStepY; CellY++)
{
- a_Array[Idx + a_SizeX * CellY] = StartValue + Diff * CellY / a_AnchorStepY;
+ a_Array[Idx + SizeX * CellY] = StartValue + Diff * CellY / AnchorStepY;
} // for CellY
- Idx += a_AnchorStepX;
+ Idx += AnchorStepX;
} // for x
} // for y
// Now interpolate in rows, each row has values in the anchor columns
- int LastXCell = a_SizeX - a_AnchorStepX;
- for (int y = 0; y < a_SizeY; y++)
+ int LastXCell = SizeX - AnchorStepX;
+ for (int y = 0; y < SizeY; y++)
{
- int Idx = a_SizeX * y;
- for (int x = 0; x < LastXCell; x += a_AnchorStepX)
+ int Idx = SizeX * y;
+ for (int x = 0; x < LastXCell; x += AnchorStepX)
{
TYPE StartValue = a_Array[Idx];
- TYPE EndValue = a_Array[Idx + a_AnchorStepX];
+ TYPE EndValue = a_Array[Idx + AnchorStepX];
TYPE Diff = EndValue - StartValue;
- for (int CellX = 1; CellX < a_AnchorStepX; CellX++)
+ for (int CellX = 1; CellX < AnchorStepX; CellX++)
{
- a_Array[Idx + CellX] = StartValue + CellX * Diff / a_AnchorStepX;
+ a_Array[Idx + CellX] = StartValue + CellX * Diff / AnchorStepX;
} // for CellY
- Idx += a_AnchorStepX;
+ Idx += AnchorStepX;
}
}
}
diff --git a/src/Log.cpp b/src/Log.cpp
index 1ea327d5d..a7be04b1a 100644
--- a/src/Log.cpp
+++ b/src/Log.cpp
@@ -118,7 +118,7 @@ void cLog::Log(const char * a_Format, va_list argList)
AString Line;
#ifdef _DEBUG
- Printf(Line, "[%04x|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str());
+ Printf(Line, "[%04lx|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str());
#else
Printf(Line, "[%02d:%02d:%02d] %s", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str());
#endif
diff --git a/src/Log.h b/src/Log.h
index cba248dae..d6a406154 100644
--- a/src/Log.h
+++ b/src/Log.h
@@ -14,8 +14,8 @@ private:
public:
cLog(const AString & a_FileName);
~cLog();
- void Log(const char * a_Format, va_list argList);
- void Log(const char * a_Format, ...);
+ void Log(const char * a_Format, va_list argList) FORMATSTRING(2, 0);
+ void Log(const char * a_Format, ...) FORMATSTRING(2, 3);
// tolua_begin
void SimpleLog(const char * a_String);
void OpenLog(const char * a_FileName);
diff --git a/src/MCLogger.h b/src/MCLogger.h
index c949a4cdf..996e60329 100644
--- a/src/MCLogger.h
+++ b/src/MCLogger.h
@@ -21,10 +21,10 @@ public: // tolua_export
~cMCLogger(); // tolua_export
- void Log(const char* a_Format, va_list a_ArgList);
- void Info(const char* a_Format, va_list a_ArgList);
- void Warn(const char* a_Format, va_list a_ArgList);
- void Error(const char* a_Format, va_list a_ArgList);
+ void Log(const char* a_Format, va_list a_ArgList) FORMATSTRING(2, 0);
+ void Info(const char* a_Format, va_list a_ArgList) FORMATSTRING(2, 0);
+ void Warn(const char* a_Format, va_list a_ArgList) FORMATSTRING(2, 0);
+ void Error(const char* a_Format, va_list a_ArgList) FORMATSTRING(2, 0);
void LogSimple(const char* a_Text, int a_LogType = 0 ); // tolua_export
@@ -57,10 +57,10 @@ private:
-extern void LOG(const char* a_Format, ...);
-extern void LOGINFO(const char* a_Format, ...);
-extern void LOGWARN(const char* a_Format, ...);
-extern void LOGERROR(const char* a_Format, ...);
+extern void LOG(const char* a_Format, ...) FORMATSTRING(1, 2);
+extern void LOGINFO(const char* a_Format, ...) FORMATSTRING(1, 2);
+extern void LOGWARN(const char* a_Format, ...) FORMATSTRING(1, 2);
+extern void LOGERROR(const char* a_Format, ...) FORMATSTRING(1, 2);
diff --git a/src/Map.cpp b/src/Map.cpp
index 2d8f57168..79370b097 100644
--- a/src/Map.cpp
+++ b/src/Map.cpp
@@ -243,7 +243,7 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z)
{
for (unsigned int Z = m_RelZ; Z < m_RelZ + PixelWidth; ++Z)
{
- unsigned int WaterDepth = 0;
+ // unsigned int WaterDepth = 0;
BLOCKTYPE TargetBlock = E_BLOCK_AIR;
NIBBLETYPE TargetMeta = 0;
@@ -261,12 +261,14 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z)
continue;
}
// TODO 2014-02-22 xdot: Check if block is liquid
+ /*
else if (false)
{
--Height;
++WaterDepth;
continue;
}
+ */
break;
}
diff --git a/src/Map.h b/src/Map.h
index a313d5431..ee7c537b1 100644
--- a/src/Map.h
+++ b/src/Map.h
@@ -64,7 +64,7 @@ public:
unsigned int GetPixelX(void) const { return m_PixelX; }
unsigned int GetPixelZ(void) const { return m_PixelZ; }
- int GetRot(void) const { return m_Rot; }
+ unsigned int GetRot(void) const { return m_Rot; }
eType GetType(void) const { return m_Type; }
diff --git a/src/MersenneTwister.h b/src/MersenneTwister.h
index f4c7b0699..759b8a1ae 100644
--- a/src/MersenneTwister.h
+++ b/src/MersenneTwister.h
@@ -62,7 +62,7 @@
class MTRand {
// Data
public:
- typedef long uint32; // unsigned integer type, at least 32 bits
+ typedef UInt32 uint32; // unsigned integer type, at least 32 bits
enum { N = 624 }; // length of state vector
enum { SAVE = N + 1 }; // length of array for save()
@@ -72,7 +72,7 @@ protected:
uint32 state[N]; // internal state
uint32 *pNext; // next value to get from state
- int left; // number of values left before reload needed
+ uint32 left; // number of values left before reload needed
// Methods
public:
@@ -164,7 +164,7 @@ inline void MTRand::initialize( const uint32 seed )
// only MSBs of the state array. Modified 9 Jan 2002 by Makoto Matsumoto.
uint32 *s = state;
uint32 *r = state;
- int i = 1;
+ uint32 i = 1;
*s++ = seed & 0xffffffffUL;
for( ; i < N; ++i )
{
@@ -205,9 +205,9 @@ inline void MTRand::seed( uint32 *const bigSeed, const uint32 seedLength )
// in each element are discarded.
// Just call seed() if you want to get array from /dev/urandom
initialize(19650218UL);
- int i = 1;
+ uint32 i = 1;
uint32 j = 0;
- int k = ( (uint32)N > seedLength ? (uint32)N : seedLength );
+ uint32 k = ( (uint32)N > seedLength ? (uint32)N : seedLength );
for( ; k; --k )
{
state[i] =
diff --git a/src/MobSpawner.cpp b/src/MobSpawner.cpp
index 7704f6cf3..a0d0f5c54 100644
--- a/src/MobSpawner.cpp
+++ b/src/MobSpawner.cpp
@@ -169,7 +169,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R
(TargetBlock == E_BLOCK_AIR) &&
(BlockAbove == E_BLOCK_AIR) &&
(
- (BlockBelow == E_BLOCK_GRASS) || (BlockBelow == E_BLOCK_LEAVES)
+ (BlockBelow == E_BLOCK_GRASS) || (BlockBelow == E_BLOCK_LEAVES) || (BlockBelow == E_BLOCK_NEW_LEAVES)
) &&
(a_RelY >= 62) &&
(m_Random.NextInt(3, a_Biome) != 0)
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index 6e3c91d58..d3e0f1c26 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -82,11 +82,11 @@ cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString
, m_AttackRange(2)
, m_AttackInterval(0)
, m_SightDistance(25)
- , m_DropChanceWeapon(0.085)
- , m_DropChanceHelmet(0.085)
- , m_DropChanceChestplate(0.085)
- , m_DropChanceLeggings(0.085)
- , m_DropChanceBoots(0.085)
+ , m_DropChanceWeapon(0.085f)
+ , m_DropChanceHelmet(0.085f)
+ , m_DropChanceChestplate(0.085f)
+ , m_DropChanceLeggings(0.085f)
+ , m_DropChanceBoots(0.085f)
, m_CanPickUpLoot(true)
, m_BurnsInDaylight(false)
{
@@ -758,6 +758,7 @@ cMonster::eFamily cMonster::FamilyFromType(eType a_Type)
case mtSquid: return mfWater;
case mtVillager: return mfPassive;
case mtWitch: return mfHostile;
+ case mtWither: return mfHostile;
case mtWolf: return mfHostile;
case mtZombie: return mfHostile;
case mtZombiePigman: return mfHostile;
diff --git a/src/Mobs/Villager.h b/src/Mobs/Villager.h
index b99ae876f..5bba4d4ba 100644
--- a/src/Mobs/Villager.h
+++ b/src/Mobs/Villager.h
@@ -29,7 +29,7 @@ public:
CLASS_PROTODEF(cVillager);
- // Override functions
+ // cEntity overrides
virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override;
virtual void Tick (float a_Dt, cChunk & a_Chunk) override;
diff --git a/src/Mobs/Wither.cpp b/src/Mobs/Wither.cpp
index c46e0beab..0e42194ac 100644
--- a/src/Mobs/Wither.cpp
+++ b/src/Mobs/Wither.cpp
@@ -2,14 +2,64 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Wither.h"
+#include "../World.h"
cWither::cWither(void) :
- super("Wither", mtWither, "mob.wither.hurt", "mob.wither.death", 0.9, 4.0)
+ super("Wither", mtWither, "mob.wither.hurt", "mob.wither.death", 0.9, 4.0),
+ m_InvulnerableTicks(220)
{
+ SetMaxHealth(300);
+
+ SetHealth(GetMaxHealth() / 3);
+}
+
+
+
+
+
+void cWither::DoTakeDamage(TakeDamageInfo & a_TDI)
+{
+ if (a_TDI.DamageType == dtDrowning)
+ {
+ return;
+ }
+
+ if (m_InvulnerableTicks > 0)
+ {
+ return;
+ }
+
+ super::DoTakeDamage(a_TDI);
+}
+
+
+
+
+
+void cWither::Tick(float a_Dt, cChunk & a_Chunk)
+{
+ super::Tick(a_Dt, a_Chunk);
+
+ if (m_InvulnerableTicks > 0)
+ {
+ unsigned int NewTicks = m_InvulnerableTicks - 1;
+
+ if (NewTicks == 0)
+ {
+ m_World->DoExplosionAt(7.0, GetPosX(), GetPosY(), GetPosZ(), false, esWitherBirth, this);
+ }
+
+ m_InvulnerableTicks = NewTicks;
+
+ if ((NewTicks % 10) == 0)
+ {
+ Heal(10);
+ }
+ }
}
diff --git a/src/Mobs/Wither.h b/src/Mobs/Wither.h
index 56effc6bb..d09e3607a 100644
--- a/src/Mobs/Wither.h
+++ b/src/Mobs/Wither.h
@@ -16,8 +16,21 @@ public:
cWither(void);
CLASS_PROTODEF(cWither);
+
+ unsigned int GetNumInvulnerableTicks(void) const { return m_InvulnerableTicks; }
+
+ void SetNumInvulnerableTicks(unsigned int a_Ticks) { m_InvulnerableTicks = a_Ticks; }
+ // cEntity overrides
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override;
+ virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override;
+ virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
+
+private:
+
+ /** The number of ticks of invulnerability left after being initially created. Zero once invulnerability has expired. */
+ unsigned int m_InvulnerableTicks;
+
} ;
diff --git a/src/Noise.cpp b/src/Noise.cpp
index 5f23a47f9..a97ea70c6 100644
--- a/src/Noise.cpp
+++ b/src/Noise.cpp
@@ -3,14 +3,6 @@
#include "Noise.h"
-
-
-
-
-#if NOISE_USE_SSE
- #include <smmintrin.h> //_mm_mul_epi32
-#endif
-
#define FAST_FLOOR(x) (((x) < 0) ? (((int)x) - 1) : ((int)x))
diff --git a/src/OSSupport/BlockingTCPLink.cpp b/src/OSSupport/BlockingTCPLink.cpp
index e9c00d6d4..07f48b955 100644
--- a/src/OSSupport/BlockingTCPLink.cpp
+++ b/src/OSSupport/BlockingTCPLink.cpp
@@ -70,7 +70,7 @@ bool cBlockingTCPLink::Connect(const char * iAddress, unsigned int iPort)
}
}
- server.sin_addr.s_addr = *((unsigned long *)hp->h_addr);
+ memcpy(&server.sin_addr.s_addr,hp->h_addr, hp->h_length);
server.sin_family = AF_INET;
server.sin_port = htons( (unsigned short)iPort);
if (connect(m_Socket, (struct sockaddr *)&server, sizeof(server)))
diff --git a/src/OSSupport/File.h b/src/OSSupport/File.h
index 07fce6661..b394c5cb9 100644
--- a/src/OSSupport/File.h
+++ b/src/OSSupport/File.h
@@ -131,7 +131,7 @@ public:
/** Returns the list of all items in the specified folder (files, folders, nix pipes, whatever's there). */
static AStringVector GetFolderContents(const AString & a_Folder); // Exported in ManualBindings.cpp
- int Printf(const char * a_Fmt, ...);
+ int Printf(const char * a_Fmt, ...) FORMATSTRING(2, 3);
/** Flushes all the bufferef output into the file (only when writing) */
void Flush(void);
diff --git a/src/OSSupport/GZipFile.cpp b/src/OSSupport/GZipFile.cpp
index cbf6be6c4..b13e519e0 100644
--- a/src/OSSupport/GZipFile.cpp
+++ b/src/OSSupport/GZipFile.cpp
@@ -73,12 +73,15 @@ int cGZipFile::ReadRestOfFile(AString & a_Contents)
// Since the gzip format doesn't really support getting the uncompressed length, we need to read incrementally. Yuck!
int NumBytesRead = 0;
+ int TotalBytes = 0;
char Buffer[64 KiB];
while ((NumBytesRead = gzread(m_File, Buffer, sizeof(Buffer))) > 0)
{
+ TotalBytes += NumBytesRead;
a_Contents.append(Buffer, NumBytesRead);
}
- return NumBytesRead;
+ // NumBytesRead is < 0 on error
+ return (NumBytesRead >= 0) ? TotalBytes : NumBytesRead;
}
diff --git a/src/OSSupport/IsThread.h b/src/OSSupport/IsThread.h
index b8784ea33..42b8bfdda 100644
--- a/src/OSSupport/IsThread.h
+++ b/src/OSSupport/IsThread.h
@@ -34,7 +34,7 @@ protected:
public:
cIsThread(const AString & iThreadName);
- ~cIsThread();
+ virtual ~cIsThread();
/// Starts the thread; returns without waiting for the actual start
bool Start(void);
diff --git a/src/OSSupport/ListenThread.h b/src/OSSupport/ListenThread.h
index 4e337d814..b2d806c82 100644
--- a/src/OSSupport/ListenThread.h
+++ b/src/OSSupport/ListenThread.h
@@ -29,43 +29,45 @@ class cListenThread :
typedef cIsThread super;
public:
- /// Used as the callback for connection events
+ /** Used as the callback for connection events */
class cCallback
{
public:
- /// This callback is called whenever a socket connection is accepted
+ virtual ~cCallback() {}
+
+ /** This callback is called whenever a socket connection is accepted */
virtual void OnConnectionAccepted(cSocket & a_Socket) = 0;
} ;
cListenThread(cCallback & a_Callback, cSocket::eFamily a_Family, const AString & a_ServiceName = "");
~cListenThread();
- /// Creates all the sockets, returns trus if successful, false if not.
+ /** Creates all the sockets, returns trus if successful, false if not. */
bool Initialize(const AString & a_PortsString);
bool Start(void);
void Stop(void);
- /// Call before Initialize() to set the "reuse" flag on the sockets
+ /** Call before Initialize() to set the "reuse" flag on the sockets */
void SetReuseAddr(bool a_Reuse = true);
protected:
typedef std::vector<cSocket> cSockets;
- /// The callback which to notify of incoming connections
+ /** The callback which to notify of incoming connections */
cCallback & m_Callback;
- /// Socket address family to use
+ /** Socket address family to use */
cSocket::eFamily m_Family;
- /// Sockets that are being monitored
+ /** Sockets that are being monitored */
cSockets m_Sockets;
- /// If set to true, the SO_REUSEADDR socket option is set to true
+ /** If set to true, the SO_REUSEADDR socket option is set to true */
bool m_ShouldReuseAddr;
- /// Name of the service that's listening on the ports; for logging purposes only
+ /** Name of the service that's listening on the ports; for logging purposes only */
AString m_ServiceName;
diff --git a/src/OSSupport/Socket.cpp b/src/OSSupport/Socket.cpp
index 6afaceedf..c29e495c3 100644
--- a/src/OSSupport/Socket.cpp
+++ b/src/OSSupport/Socket.cpp
@@ -307,7 +307,8 @@ bool cSocket::ConnectIPv4(const AString & a_HostNameOrAddr, unsigned short a_Por
CloseSocket();
return false;
}
- addr = *((unsigned long*)hp->h_addr);
+ // Should be optimised to a single word copy
+ memcpy(&addr, hp->h_addr, hp->h_length);
}
sockaddr_in server;
diff --git a/src/OSSupport/SocketThreads.cpp b/src/OSSupport/SocketThreads.cpp
index a02661d2c..0bc1d6b55 100644
--- a/src/OSSupport/SocketThreads.cpp
+++ b/src/OSSupport/SocketThreads.cpp
@@ -54,7 +54,7 @@ bool cSocketThreads::AddClient(const cSocket & a_Socket, cCallback * a_Client)
}
// No thread has free space, create a new one:
- LOGD("Creating a new cSocketThread (currently have %d)", m_Threads.size());
+ LOGD("Creating a new cSocketThread (currently have " SIZE_T_FMT ")", m_Threads.size());
cSocketThread * Thread = new cSocketThread(this);
if (!Thread->Start())
{
diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp
index 50ebb6d43..69f4934d8 100644
--- a/src/Protocol/Protocol125.cpp
+++ b/src/Protocol/Protocol125.cpp
@@ -1269,19 +1269,6 @@ int cProtocol125::ParsePacket(unsigned char a_PacketType)
-#define HANDLE_PACKET_PARSE(Packet) \
- { \
- int res = Packet.Parse(m_ReceivedData); \
- if (res < 0) \
- { \
- return res; \
- } \
- }
-
-
-
-
-
int cProtocol125::ParseArmAnim(void)
{
HANDLE_PACKET_READ(ReadBEInt, int, EntityID);
diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp
index 8df550c7b..be9c503ed 100644
--- a/src/Protocol/Protocol132.cpp
+++ b/src/Protocol/Protocol132.cpp
@@ -100,7 +100,7 @@ cProtocol132::~cProtocol132()
{
if (!m_DataToSend.empty())
{
- LOGD("There are %d unsent bytes while deleting cProtocol132", m_DataToSend.size());
+ LOGD("There are " SIZE_T_FMT " unsent bytes while deleting cProtocol132", m_DataToSend.size());
}
}
diff --git a/src/Protocol/Protocol16x.cpp b/src/Protocol/Protocol16x.cpp
index f6ec0a199..ecb24254f 100644
--- a/src/Protocol/Protocol16x.cpp
+++ b/src/Protocol/Protocol16x.cpp
@@ -135,7 +135,7 @@ void cProtocol161::SendPlayerMaxSpeed(void)
WriteInt(m_Client->GetPlayer()->GetUniqueID());
WriteInt(1);
WriteString("generic.movementSpeed");
- WriteDouble(m_Client->GetPlayer()->GetMaxSpeed());
+ WriteDouble(0.1 * m_Client->GetPlayer()->GetMaxSpeed());
Flush();
}
@@ -267,7 +267,7 @@ void cProtocol162::SendPlayerMaxSpeed(void)
WriteInt(m_Client->GetPlayer()->GetUniqueID());
WriteInt(1);
WriteString("generic.movementSpeed");
- WriteDouble(m_Client->GetPlayer()->GetMaxSpeed());
+ WriteDouble(0.1 * m_Client->GetPlayer()->GetMaxSpeed());
WriteShort(0);
Flush();
}
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 8c800036e..721ed349e 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -687,9 +687,8 @@ void cProtocol172::SendPlayerAbilities(void)
Flags |= 0x04;
}
Pkt.WriteByte(Flags);
- // TODO: Pkt.WriteFloat(m_Client->GetPlayer()->GetMaxFlyingSpeed());
- Pkt.WriteFloat(0.05f);
- Pkt.WriteFloat((float)m_Client->GetPlayer()->GetMaxSpeed());
+ Pkt.WriteFloat((float)(0.05 * m_Client->GetPlayer()->GetFlyingMaxSpeed()));
+ Pkt.WriteFloat((float)(0.1 * m_Client->GetPlayer()->GetMaxSpeed()));
}
@@ -743,13 +742,14 @@ void cProtocol172::SendPlayerMaxSpeed(void)
Pkt.WriteInt(m_Client->GetPlayer()->GetUniqueID());
Pkt.WriteInt(1); // Count
Pkt.WriteString("generic.movementSpeed");
- Pkt.WriteDouble(0.1);
+ // The default game speed is 0.1, multiply that value by the relative speed:
+ Pkt.WriteDouble(0.1 * m_Client->GetPlayer()->GetNormalMaxSpeed());
if (m_Client->GetPlayer()->IsSprinting())
{
Pkt.WriteShort(1); // Modifier count
Pkt.WriteInt64(0x662a6b8dda3e4c1c);
Pkt.WriteInt64(0x881396ea6097278d); // UUID of the modifier
- Pkt.WriteDouble(0.3);
+ Pkt.WriteDouble(m_Client->GetPlayer()->GetSprintingMaxSpeed() - m_Client->GetPlayer()->GetNormalMaxSpeed());
Pkt.WriteByte(2);
}
else
@@ -1251,7 +1251,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size)
ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace);
AString Hex;
CreateHexDump(Hex, AllData.data(), AllData.size(), 16);
- m_CommLogFile.Printf("Incoming data, %d (0x%x) unparsed bytes already present in buffer:\n%s\n",
+ m_CommLogFile.Printf("Incoming data, " SIZE_T_FMT " (0x" SIZE_T_FMT_HEX ") unparsed bytes already present in buffer:\n%s\n",
AllData.size(), AllData.size(), Hex.c_str()
);
}
@@ -1344,14 +1344,14 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size)
if (bb.GetReadableSpace() != 1)
{
// Read more or less than packet length, report as error
- LOGWARNING("Protocol 1.7: Wrong number of bytes read for packet 0x%x, state %d. Read %u bytes, packet contained %u bytes",
+ LOGWARNING("Protocol 1.7: Wrong number of bytes read for packet 0x%x, state %d. Read " SIZE_T_FMT " bytes, packet contained %u bytes",
PacketType, m_State, bb.GetUsedSpace() - bb.GetReadableSpace(), PacketLen
);
// Put a message in the comm log:
if (g_ShouldLogCommIn)
{
- m_CommLogFile.Printf("^^^^^^ Wrong number of bytes read for this packet (exp %d left, got %d left) ^^^^^^\n\n\n",
+ m_CommLogFile.Printf("^^^^^^ Wrong number of bytes read for this packet (exp %d left, got " SIZE_T_FMT " left) ^^^^^^\n\n\n",
1, bb.GetReadableSpace()
);
m_CommLogFile.Flush();
@@ -1373,7 +1373,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size)
ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace);
AString Hex;
CreateHexDump(Hex, AllData.data(), AllData.size(), 16);
- m_CommLogFile.Printf("There are %d (0x%x) bytes of non-parse-able data left in the buffer:\n%s",
+ m_CommLogFile.Printf("There are " SIZE_T_FMT " (0x" SIZE_T_FMT_HEX ") bytes of non-parse-able data left in the buffer:\n%s",
m_ReceivedData.GetReadableSpace(), m_ReceivedData.GetReadableSpace(), Hex.c_str()
);
m_CommLogFile.Flush();
@@ -2062,7 +2062,7 @@ void cProtocol172::ParseItemMetadata(cItem & a_Item, const AString & a_Metadata)
{
AString HexDump;
CreateHexDump(HexDump, a_Metadata.data(), a_Metadata.size(), 16);
- LOGWARNING("Cannot unGZIP item metadata (%u bytes):\n%s", a_Metadata.size(), HexDump.c_str());
+ LOGWARNING("Cannot unGZIP item metadata (" SIZE_T_FMT " bytes):\n%s", a_Metadata.size(), HexDump.c_str());
return;
}
@@ -2072,7 +2072,7 @@ void cProtocol172::ParseItemMetadata(cItem & a_Item, const AString & a_Metadata)
{
AString HexDump;
CreateHexDump(HexDump, Uncompressed.data(), Uncompressed.size(), 16);
- LOGWARNING("Cannot parse NBT item metadata: (%u bytes)\n%s", Uncompressed.size(), HexDump.c_str());
+ LOGWARNING("Cannot parse NBT item metadata: (" SIZE_T_FMT " bytes)\n%s", Uncompressed.size(), HexDump.c_str());
return;
}
diff --git a/src/RCONServer.h b/src/RCONServer.h
index 0e89800a2..88aac4b5f 100644
--- a/src/RCONServer.h
+++ b/src/RCONServer.h
@@ -29,7 +29,7 @@ class cRCONServer :
{
public:
cRCONServer(cServer & a_Server);
- ~cRCONServer();
+ virtual ~cRCONServer();
void Initialize(cIniFile & a_IniFile);
diff --git a/src/Root.cpp b/src/Root.cpp
index 69f18104e..ba4398b35 100644
--- a/src/Root.cpp
+++ b/src/Root.cpp
@@ -304,6 +304,7 @@ void cRoot::LoadWorlds(cIniFile & IniFile)
{
if (IniFile.GetKeyComment("Worlds", 0) != " World=secondworld")
{
+ IniFile.DeleteKeyComment("Worlds", 0);
IniFile.AddKeyComment("Worlds", " World=secondworld");
}
}
@@ -778,11 +779,11 @@ void cRoot::LogChunkStats(cCommandOutputCallback & a_Output)
int Mem = NumValid * sizeof(cChunk);
a_Output.Out(" Memory used by chunks: %d KiB (%d MiB)", (Mem + 1023) / 1024, (Mem + 1024 * 1024 - 1) / (1024 * 1024));
a_Output.Out(" Per-chunk memory size breakdown:");
- a_Output.Out(" block types: %6d bytes (%3d KiB)", sizeof(cChunkDef::BlockTypes), (sizeof(cChunkDef::BlockTypes) + 1023) / 1024);
- a_Output.Out(" block metadata: %6d bytes (%3d KiB)", sizeof(cChunkDef::BlockNibbles), (sizeof(cChunkDef::BlockNibbles) + 1023) / 1024);
- a_Output.Out(" block lighting: %6d bytes (%3d KiB)", 2 * sizeof(cChunkDef::BlockNibbles), (2 * sizeof(cChunkDef::BlockNibbles) + 1023) / 1024);
- a_Output.Out(" heightmap: %6d bytes (%3d KiB)", sizeof(cChunkDef::HeightMap), (sizeof(cChunkDef::HeightMap) + 1023) / 1024);
- a_Output.Out(" biomemap: %6d bytes (%3d KiB)", sizeof(cChunkDef::BiomeMap), (sizeof(cChunkDef::BiomeMap) + 1023) / 1024);
+ a_Output.Out(" block types: " SIZE_T_FMT_PRECISION(6) " bytes (" SIZE_T_FMT_PRECISION(3) " KiB)", sizeof(cChunkDef::BlockTypes), (sizeof(cChunkDef::BlockTypes) + 1023) / 1024);
+ a_Output.Out(" block metadata: " SIZE_T_FMT_PRECISION(6) " bytes (" SIZE_T_FMT_PRECISION(3) " KiB)", sizeof(cChunkDef::BlockNibbles), (sizeof(cChunkDef::BlockNibbles) + 1023) / 1024);
+ a_Output.Out(" block lighting: " SIZE_T_FMT_PRECISION(6) " bytes (" SIZE_T_FMT_PRECISION(3) " KiB)", 2 * sizeof(cChunkDef::BlockNibbles), (2 * sizeof(cChunkDef::BlockNibbles) + 1023) / 1024);
+ a_Output.Out(" heightmap: " SIZE_T_FMT_PRECISION(6) " bytes (" SIZE_T_FMT_PRECISION(3) " KiB)", sizeof(cChunkDef::HeightMap), (sizeof(cChunkDef::HeightMap) + 1023) / 1024);
+ a_Output.Out(" biomemap: " SIZE_T_FMT_PRECISION(6) " bytes (" SIZE_T_FMT_PRECISION(3) " KiB)", sizeof(cChunkDef::BiomeMap), (sizeof(cChunkDef::BiomeMap) + 1023) / 1024);
int Rest = sizeof(cChunk) - sizeof(cChunkDef::BlockTypes) - 3 * sizeof(cChunkDef::BlockNibbles) - sizeof(cChunkDef::HeightMap) - sizeof(cChunkDef::BiomeMap);
a_Output.Out(" other: %6d bytes (%3d KiB)", Rest, (Rest + 1023) / 1024);
SumNumValid += NumValid;
diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp
index 8088e624b..4c89ce265 100644
--- a/src/Scoreboard.cpp
+++ b/src/Scoreboard.cpp
@@ -30,9 +30,13 @@ AString cObjective::TypeToString(eType a_Type)
case otStatBlockMine: return "stat.mineBlock";
case otStatEntityKill: return "stat.killEntity";
case otStatEntityKilledBy: return "stat.entityKilledBy";
-
+
+ // clang optimisises this line away then warns that it has done so.
+ #if !defined(__clang__)
default: return "";
+ #endif
}
+
}
diff --git a/src/Server.cpp b/src/Server.cpp
index 1b168ff20..d1e53bfff 100644
--- a/src/Server.cpp
+++ b/src/Server.cpp
@@ -550,7 +550,7 @@ void cServer::PrintHelp(const AStringVector & a_Split, cCommandOutputCallback &
for (AStringPairs::const_iterator itr = Callback.m_Commands.begin(), end = Callback.m_Commands.end(); itr != end; ++itr)
{
const AStringPair & cmd = *itr;
- a_Output.Out(Printf("%-*s%s\n", Callback.m_MaxLen, cmd.first.c_str(), cmd.second.c_str()));
+ a_Output.Out(Printf("%-*s%s\n", static_cast<int>(Callback.m_MaxLen), cmd.first.c_str(), cmd.second.c_str()));
} // for itr - Callback.m_Commands[]
a_Output.Finished();
}
diff --git a/src/Simulator/FireSimulator.cpp b/src/Simulator/FireSimulator.cpp
index 26712e6e6..470dfc791 100644
--- a/src/Simulator/FireSimulator.cpp
+++ b/src/Simulator/FireSimulator.cpp
@@ -6,6 +6,8 @@
#include "../BlockID.h"
#include "../Defines.h"
#include "../Chunk.h"
+#include "Root.h"
+#include "../Bindings/PluginManager.h"
@@ -315,9 +317,15 @@ void cFireSimulator::TrySpreadFire(cChunk * a_Chunk, int a_RelX, int a_RelY, int
*/
if (CanStartFireInBlock(a_Chunk, x, y, z))
{
- FLOG("FS: Starting new fire at {%d, %d, %d}.",
- x + a_Chunk->GetPosX() * cChunkDef::Width, y, z + a_Chunk->GetPosZ() * cChunkDef::Width
- );
+ int a_PosX = x + a_Chunk->GetPosX() * cChunkDef::Width;
+ int a_PosZ = z + a_Chunk->GetPosZ() * cChunkDef::Width;
+
+ if (cRoot::Get()->GetPluginManager()->CallHookBlockSpread(&m_World, a_PosX, y, a_PosZ, ssFireSpread))
+ {
+ return;
+ }
+
+ FLOG("FS: Starting new fire at {%d, %d, %d}.", a_PosX, y, a_PosZ);
a_Chunk->UnboundedRelSetBlock(x, y, z, E_BLOCK_FIRE, 0);
}
} // for y
diff --git a/src/Simulator/FluidSimulator.cpp b/src/Simulator/FluidSimulator.cpp
index 61c93ed73..7779573d7 100644
--- a/src/Simulator/FluidSimulator.cpp
+++ b/src/Simulator/FluidSimulator.cpp
@@ -36,6 +36,7 @@ bool cFluidSimulator::CanWashAway(BLOCKTYPE a_BlockType)
case E_BLOCK_COBWEB:
case E_BLOCK_CROPS:
case E_BLOCK_DEAD_BUSH:
+ case E_BLOCK_LILY_PAD:
case E_BLOCK_RAIL:
case E_BLOCK_REDSTONE_TORCH_OFF:
case E_BLOCK_REDSTONE_TORCH_ON:
diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp
index ca2ef4b1a..92659fab7 100644
--- a/src/Simulator/IncrementalRedstoneSimulator.cpp
+++ b/src/Simulator/IncrementalRedstoneSimulator.cpp
@@ -838,8 +838,8 @@ void cIncrementalRedstoneSimulator::HandleTNT(int a_BlockX, int a_BlockY, int a_
if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ))
{
m_World.BroadcastSoundEffect("game.tnt.primed", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.6f);
- m_World.SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5); // 80 ticks to boom
m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
+ m_World.SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5); // 80 ticks to boom
}
}
@@ -1062,7 +1062,7 @@ void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_BlockX, int a_Bloc
{
Vector3f EntityPos = a_Entity->GetPosition();
Vector3f BlockPos(m_X + 0.5f, (float)m_Y, m_Z + 0.5f);
- float Distance = (EntityPos - BlockPos).Length();
+ double Distance = (EntityPos - BlockPos).Length();
if (Distance <= 0.7)
{
diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp
index 3fe75d611..ad622d707 100644
--- a/src/StringUtils.cpp
+++ b/src/StringUtils.cpp
@@ -288,13 +288,13 @@ void ReplaceString(AString & iHayStack, const AString & iNeedle, const AString &
// Converts a stream of BE shorts into UTF-8 string; returns a ref to a_UTF8
-AString & RawBEToUTF8(short * a_RawData, int a_NumShorts, AString & a_UTF8)
+AString & RawBEToUTF8(const char * a_RawData, int a_NumShorts, AString & a_UTF8)
{
a_UTF8.clear();
a_UTF8.reserve(3 * a_NumShorts / 2); // a quick guess of the resulting size
for (int i = 0; i < a_NumShorts; i++)
{
- int c = ntohs(*(a_RawData + i));
+ int c = GetBEShort(&a_RawData[i * 2]);
if (c < 0x80)
{
a_UTF8.push_back((char)c);
@@ -364,10 +364,7 @@ Notice from the original file:
#define UNI_MAX_BMP 0x0000FFFF
#define UNI_MAX_UTF16 0x0010FFFF
-#define UNI_MAX_UTF32 0x7FFFFFFF
-#define UNI_MAX_LEGAL_UTF32 0x0010FFFF
#define UNI_SUR_HIGH_START 0xD800
-#define UNI_SUR_HIGH_END 0xDBFF
#define UNI_SUR_LOW_START 0xDC00
#define UNI_SUR_LOW_END 0xDFFF
@@ -457,7 +454,6 @@ AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a
if (!isLegalUTF8(source, extraBytesToRead + 1))
{
return a_UTF16;
- break;
}
// The cases all fall through. See "Note A" below.
diff --git a/src/StringUtils.h b/src/StringUtils.h
index dfbfc2a75..4feff7553 100644
--- a/src/StringUtils.h
+++ b/src/StringUtils.h
@@ -22,16 +22,16 @@ typedef std::list<AString> AStringList;
/** Add the formated string to the existing data in the string */
-extern AString & AppendVPrintf(AString & str, const char * format, va_list args);
+extern AString & AppendVPrintf(AString & str, const char * format, va_list args) FORMATSTRING(2, 0);
/// Output the formatted text into the string
-extern AString & Printf (AString & str, const char * format, ...);
+extern AString & Printf (AString & str, const char * format, ...) FORMATSTRING(2, 3);
/// Output the formatted text into string, return string by value
-extern AString Printf(const char * format, ...);
+extern AString Printf(const char * format, ...) FORMATSTRING(1, 2);
/// Add the formatted string to the existing data in the string
-extern AString & AppendPrintf (AString & str, const char * format, ...);
+extern AString & AppendPrintf (AString & str, const char * format, ...) FORMATSTRING(2, 3);
/// Split the string at any of the listed delimiters, return as a stringvector
extern AStringVector StringSplit(const AString & str, const AString & delim);
@@ -58,7 +58,7 @@ extern unsigned int RateCompareString(const AString & s1, const AString & s2 );
extern void ReplaceString(AString & iHayStack, const AString & iNeedle, const AString & iReplaceWith); // tolua_export
/// Converts a stream of BE shorts into UTF-8 string; returns a ref to a_UTF8
-extern AString & RawBEToUTF8(short * a_RawData, int a_NumShorts, AString & a_UTF8);
+extern AString & RawBEToUTF8(const char * a_RawData, int a_NumShorts, AString & a_UTF8);
/// Converts a UTF-8 string into a UTF-16 BE string, packing that back into AString; return a ref to a_UTF16
extern AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a_UTF16);
diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp
index 1a8456f70..aae7b99a3 100644
--- a/src/UI/Window.cpp
+++ b/src/UI/Window.cpp
@@ -637,7 +637,7 @@ int cWindow::DistributeItemToSlots(cPlayer & a_Player, const cItem & a_Item, int
{
if ((size_t)(a_Item.m_ItemCount) < a_SlotNums.size())
{
- LOGWARNING("%s: Distributing less items (%d) than slots (%u)", __FUNCTION__, (int)a_Item.m_ItemCount, a_SlotNums.size());
+ LOGWARNING("%s: Distributing less items (%d) than slots (" SIZE_T_FMT ")", __FUNCTION__, (int)a_Item.m_ItemCount, a_SlotNums.size());
// This doesn't seem to happen with the 1.5.1 client, so we don't worry about it for now
return 0;
}
diff --git a/src/UI/WindowOwner.h b/src/UI/WindowOwner.h
index d41abf66d..e3c73edc4 100644
--- a/src/UI/WindowOwner.h
+++ b/src/UI/WindowOwner.h
@@ -33,6 +33,10 @@ public:
{
}
+ virtual ~cWindowOwner()
+ {
+ }
+
void CloseWindow(void)
{
m_Window = NULL;
diff --git a/src/Vector3.h b/src/Vector3.h
index b7a810fc5..a00e14508 100644
--- a/src/Vector3.h
+++ b/src/Vector3.h
@@ -52,9 +52,9 @@ public:
{
double Len = 1.0 / Length();
- x *= Len;
- y *= Len;
- z *= Len;
+ x = (T)(x * Len);
+ y = (T)(y * Len);
+ z = (T)(z * Len);
}
inline Vector3<T> NormalizeCopy(void) const
@@ -62,9 +62,9 @@ public:
double Len = 1.0 / Length();
return Vector3<T>(
- x * Len,
- y * Len,
- z * Len
+ (T)(x * Len),
+ (T)(y * Len),
+ (T)(z * Len)
);
}
@@ -73,9 +73,9 @@ public:
double Len = 1.0 / Length();
a_Rhs.Set(
- x * Len,
- y * Len,
- z * Len
+ (T)(x * Len),
+ (T)(y * Len),
+ (T)(z * Len)
);
}
@@ -121,6 +121,13 @@ public:
z += a_Z;
}
+ inline void Move(const Vector3<T> & a_Diff)
+ {
+ x += a_Diff.x;
+ y += a_Diff.y;
+ z += a_Diff.z;
+ }
+
// tolua_end
inline void operator += (const Vector3<T> & a_Rhs)
diff --git a/src/World.cpp b/src/World.cpp
index 3d01dc40f..e39a605bb 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -60,9 +60,6 @@
-/// Up to this many m_SpreadQueue elements are handled each world tick
-const int MAX_LIGHTING_SPREAD_PER_TICK = 10;
-
const int TIME_SUNSET = 12000;
const int TIME_NIGHT_START = 13187;
const int TIME_NIGHT_END = 22812;
@@ -102,7 +99,7 @@ protected:
{
for (;;)
{
- LOG("%d chunks to load, %d chunks to generate",
+ LOG("" SIZE_T_FMT " chunks to load, %d chunks to generate",
m_World->GetStorage().GetLoadQueueLength(),
m_World->GetGenerator().GetQueueLength()
);
@@ -154,7 +151,7 @@ protected:
{
for (;;)
{
- LOG("%d chunks remaining to light", m_Lighting->GetQueueLength()
+ LOG("" SIZE_T_FMT " chunks remaining to light", m_Lighting->GetQueueLength()
);
// Wait for 2 sec, but be "reasonably wakeable" when the thread is to finish
@@ -250,8 +247,6 @@ cWorld::cWorld(const AString & a_WorldName) :
m_SkyDarkness(0),
m_Weather(eWeather_Sunny),
m_WeatherInterval(24000), // Guaranteed 1 day of sunshine at server start :)
- m_bCommandBlocksEnabled(false),
- m_bUseChatPrefixes(true),
m_Scoreboard(this),
m_MapManager(this),
m_GeneratorCallbacks(*this),
@@ -562,29 +557,33 @@ void cWorld::Start(void)
m_SpawnZ = IniFile.GetValueF("SpawnPosition", "Z", m_SpawnZ);
}
- m_StorageSchema = IniFile.GetValueSet ("Storage", "Schema", m_StorageSchema);
- m_StorageCompressionFactor = IniFile.GetValueSetI("Storage", "CompressionFactor", m_StorageCompressionFactor);
- m_MaxCactusHeight = IniFile.GetValueSetI("Plants", "MaxCactusHeight", 3);
- m_MaxSugarcaneHeight = IniFile.GetValueSetI("Plants", "MaxSugarcaneHeight", 3);
- m_IsCactusBonemealable = IniFile.GetValueSetB("Plants", "IsCactusBonemealable", false);
- m_IsCarrotsBonemealable = IniFile.GetValueSetB("Plants", "IsCarrotsBonemealable", true);
- m_IsCropsBonemealable = IniFile.GetValueSetB("Plants", "IsCropsBonemealable", true);
- m_IsGrassBonemealable = IniFile.GetValueSetB("Plants", "IsGrassBonemealable", true);
- m_IsMelonStemBonemealable = IniFile.GetValueSetB("Plants", "IsMelonStemBonemealable", true);
- m_IsMelonBonemealable = IniFile.GetValueSetB("Plants", "IsMelonBonemealable", false);
- m_IsPotatoesBonemealable = IniFile.GetValueSetB("Plants", "IsPotatoesBonemealable", true);
- m_IsPumpkinStemBonemealable = IniFile.GetValueSetB("Plants", "IsPumpkinStemBonemealable", true);
- m_IsPumpkinBonemealable = IniFile.GetValueSetB("Plants", "IsPumpkinBonemealable", false);
- m_IsSaplingBonemealable = IniFile.GetValueSetB("Plants", "IsSaplingBonemealable", true);
- m_IsSugarcaneBonemealable = IniFile.GetValueSetB("Plants", "IsSugarcaneBonemealable", false);
- m_IsDeepSnowEnabled = IniFile.GetValueSetB("Physics", "DeepSnow", true);
- m_ShouldLavaSpawnFire = IniFile.GetValueSetB("Physics", "ShouldLavaSpawnFire", true);
- m_bCommandBlocksEnabled = IniFile.GetValueSetB("Mechanics", "CommandBlocksEnabled", false);
- m_bEnabledPVP = IniFile.GetValueSetB("Mechanics", "PVPEnabled", true);
- m_bUseChatPrefixes = IniFile.GetValueSetB("Mechanics", "UseChatPrefixes", true);
- m_VillagersShouldHarvestCrops = IniFile.GetValueSetB("Monsters", "VillagersShouldHarvestCrops", true);
-
- m_GameMode = (eGameMode)IniFile.GetValueSetI("General", "Gamemode", m_GameMode);
+ m_StorageSchema = IniFile.GetValueSet ("Storage", "Schema", m_StorageSchema);
+ m_StorageCompressionFactor = IniFile.GetValueSetI("Storage", "CompressionFactor", m_StorageCompressionFactor);
+ m_MaxCactusHeight = IniFile.GetValueSetI("Plants", "MaxCactusHeight", 3);
+ m_MaxSugarcaneHeight = IniFile.GetValueSetI("Plants", "MaxSugarcaneHeight", 3);
+ m_IsCactusBonemealable = IniFile.GetValueSetB("Plants", "IsCactusBonemealable", false);
+ m_IsCarrotsBonemealable = IniFile.GetValueSetB("Plants", "IsCarrotsBonemealable", true);
+ m_IsCropsBonemealable = IniFile.GetValueSetB("Plants", "IsCropsBonemealable", true);
+ m_IsGrassBonemealable = IniFile.GetValueSetB("Plants", "IsGrassBonemealable", true);
+ m_IsMelonStemBonemealable = IniFile.GetValueSetB("Plants", "IsMelonStemBonemealable", true);
+ m_IsMelonBonemealable = IniFile.GetValueSetB("Plants", "IsMelonBonemealable", false);
+ m_IsPotatoesBonemealable = IniFile.GetValueSetB("Plants", "IsPotatoesBonemealable", true);
+ m_IsPumpkinStemBonemealable = IniFile.GetValueSetB("Plants", "IsPumpkinStemBonemealable", true);
+ m_IsPumpkinBonemealable = IniFile.GetValueSetB("Plants", "IsPumpkinBonemealable", false);
+ m_IsSaplingBonemealable = IniFile.GetValueSetB("Plants", "IsSaplingBonemealable", true);
+ m_IsSugarcaneBonemealable = IniFile.GetValueSetB("Plants", "IsSugarcaneBonemealable", false);
+ m_IsDeepSnowEnabled = IniFile.GetValueSetB("Physics", "DeepSnow", true);
+ m_ShouldLavaSpawnFire = IniFile.GetValueSetB("Physics", "ShouldLavaSpawnFire", true);
+ int TNTShrapnelLevel = IniFile.GetValueSetI("Physics", "TNTShrapnelLevel", (int)slNone);
+ m_bCommandBlocksEnabled = IniFile.GetValueSetB("Mechanics", "CommandBlocksEnabled", false);
+ m_bEnabledPVP = IniFile.GetValueSetB("Mechanics", "PVPEnabled", true);
+ m_bUseChatPrefixes = IniFile.GetValueSetB("Mechanics", "UseChatPrefixes", true);
+ m_VillagersShouldHarvestCrops = IniFile.GetValueSetB("Monsters", "VillagersShouldHarvestCrops", true);
+ int GameMode = IniFile.GetValueSetI("General", "Gamemode", (int)m_GameMode);
+
+ // Adjust the enum-backed variables into their respective bounds:
+ m_GameMode = (eGameMode) Clamp(GameMode, (int)gmSurvival, (int)gmAdventure);
+ m_TNTShrapnelLevel = (eShrapnelLevel)Clamp(TNTShrapnelLevel, (int)slNone, (int)slAll);
// Load allowed mobs:
const char * DefaultMonsters = "";
@@ -1727,10 +1726,13 @@ int cWorld::SpawnMinecart(double a_X, double a_Y, double a_Z, int a_MinecartType
void cWorld::SpawnPrimedTNT(double a_X, double a_Y, double a_Z, int a_FuseTicks, double a_InitialVelocityCoeff)
{
- UNUSED(a_InitialVelocityCoeff);
cTNTEntity * TNT = new cTNTEntity(a_X, a_Y, a_Z, a_FuseTicks);
TNT->Initialize(this);
- // TODO: Add a bit of speed in horiz and vert axes, based on the a_InitialVelocityCoeff
+ TNT->SetSpeed(
+ a_InitialVelocityCoeff * (GetTickRandomNumber(2) - 1), /** -1, 0, 1 */
+ a_InitialVelocityCoeff * 2,
+ a_InitialVelocityCoeff * (GetTickRandomNumber(2) - 1)
+ );
}
@@ -2453,14 +2455,14 @@ cPlayer * cWorld::FindClosestPlayer(const Vector3d & a_Pos, float a_SightLimit,
{
cTracer LineOfSight(this);
- float ClosestDistance = a_SightLimit;
- cPlayer* ClosestPlayer = NULL;
+ double ClosestDistance = a_SightLimit;
+ cPlayer * ClosestPlayer = NULL;
cCSLock Lock(m_CSPlayers);
for (cPlayerList::const_iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
{
Vector3f Pos = (*itr)->GetPosition();
- float Distance = (Pos - a_Pos).Length();
+ double Distance = (Pos - a_Pos).Length();
if (Distance < ClosestDistance)
{
diff --git a/src/World.h b/src/World.h
index a772710ab..bb2eb0b21 100644
--- a/src/World.h
+++ b/src/World.h
@@ -125,15 +125,16 @@ public:
// tolua_begin
int GetTicksUntilWeatherChange(void) const { return m_WeatherInterval; }
- virtual Int64 GetWorldAge(void) const { return m_WorldAge; }
- virtual Int64 GetTimeOfDay(void) const { return m_TimeOfDay; }
+
+ virtual Int64 GetWorldAge (void) const { return m_WorldAge; } // override, cannot specify due to tolua
+ virtual Int64 GetTimeOfDay(void) const { return m_TimeOfDay; } // override, cannot specify due to tolua
void SetTicksUntilWeatherChange(int a_WeatherInterval)
{
m_WeatherInterval = a_WeatherInterval;
}
- void SetTimeOfDay(Int64 a_TimeOfDay)
+ virtual void SetTimeOfDay(Int64 a_TimeOfDay) // override, cannot specify due to tolua
{
m_TimeOfDay = a_TimeOfDay;
m_TimeOfDaySecs = (double)a_TimeOfDay / 20.0;
@@ -191,35 +192,35 @@ public:
void BroadcastChat (const cCompositeChat & a_Message, const cClientHandle * a_Exclude = NULL);
// tolua_end
- void BroadcastChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude = NULL);
- void BroadcastCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL);
- void BroadcastDestroyEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
- void BroadcastEntityEffect (const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration, const cClientHandle * a_Exclude = NULL);
- void BroadcastEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item, const cClientHandle * a_Exclude = NULL);
- void BroadcastEntityHeadLook (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
- void BroadcastEntityLook (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
- void BroadcastEntityMetadata (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
- void BroadcastEntityRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude = NULL);
- void BroadcastEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude = NULL);
- void BroadcastEntityStatus (const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude = NULL);
- void BroadcastEntityVelocity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
- void BroadcastEntityAnimation (const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL);
- void BroadcastParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount, cClientHandle * a_Exclude = NULL); // tolua_export
- void BroadcastPlayerListItem (const cPlayer & a_Player, bool a_IsOnline, const cClientHandle * a_Exclude = NULL);
- void BroadcastRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID, const cClientHandle * a_Exclude = NULL);
- void BroadcastScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode);
- void BroadcastScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode);
- void BroadcastDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display);
- void BroadcastSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL); // tolua_export a_Src coords are Block * 8
- void BroadcastSoundParticleEffect(int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data, const cClientHandle * a_Exclude = NULL); // tolua_export
- void BroadcastSpawnEntity (cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
- void BroadcastTeleportEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
- void BroadcastThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL);
- void BroadcastTimeUpdate (const cClientHandle * a_Exclude = NULL);
- virtual void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ );
- void BroadcastWeather (eWeather a_Weather, const cClientHandle * a_Exclude = NULL);
-
- virtual cBroadcastInterface & GetBroadcastManager()
+ void BroadcastChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude = NULL);
+ void BroadcastCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL);
+ void BroadcastDestroyEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
+ void BroadcastEntityEffect (const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration, const cClientHandle * a_Exclude = NULL);
+ void BroadcastEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item, const cClientHandle * a_Exclude = NULL);
+ void BroadcastEntityHeadLook (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
+ void BroadcastEntityLook (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
+ void BroadcastEntityMetadata (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
+ void BroadcastEntityRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude = NULL);
+ void BroadcastEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude = NULL);
+ void BroadcastEntityStatus (const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude = NULL);
+ void BroadcastEntityVelocity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
+ virtual void BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL) override;
+ void BroadcastParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount, cClientHandle * a_Exclude = NULL); // tolua_export
+ void BroadcastPlayerListItem (const cPlayer & a_Player, bool a_IsOnline, const cClientHandle * a_Exclude = NULL);
+ void BroadcastRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID, const cClientHandle * a_Exclude = NULL);
+ void BroadcastScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode);
+ void BroadcastScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode);
+ void BroadcastDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display);
+ void BroadcastSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL); // tolua_export a_Src coords are Block * 8
+ void BroadcastSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data, const cClientHandle * a_Exclude = NULL); // tolua_export
+ void BroadcastSpawnEntity (cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
+ void BroadcastTeleportEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
+ void BroadcastThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL);
+ void BroadcastTimeUpdate (const cClientHandle * a_Exclude = NULL);
+ virtual void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) override;
+ void BroadcastWeather (eWeather a_Weather, const cClientHandle * a_Exclude = NULL);
+
+ virtual cBroadcastInterface & GetBroadcastManager(void) override
{
return *this;
}
@@ -273,7 +274,7 @@ public:
void RemovePlayer( cPlayer* a_Player );
/** Calls the callback for each player in the list; returns true if all players processed, false if the callback aborted by returning true */
- bool ForEachPlayer(cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS <<
+ virtual bool ForEachPlayer(cPlayerListCallback & a_Callback) override; // >> EXPORTED IN MANUALBINDINGS <<
/** Calls the callback for the player of the given name; returns true if the player was found and the callback called, false if player not found. Callback return ignored */
bool DoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS <<
@@ -365,7 +366,7 @@ public:
bool IsChunkLighted(int a_ChunkX, int a_ChunkZ);
/** Calls the callback for each chunk in the coords specified (all cords are inclusive). Returns true if all chunks have been processed successfully */
- virtual bool ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ, cChunkDataCallback & a_Callback);
+ virtual bool ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ, cChunkDataCallback & a_Callback) override;
// tolua_begin
@@ -456,7 +457,7 @@ public:
// tolua_begin
bool DigBlock (int a_X, int a_Y, int a_Z);
- virtual void SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer * a_Player);
+ virtual void SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer * a_Player); // override, cannot specify due to tolua
double GetSpawnX(void) const { return m_SpawnX; }
double GetSpawnY(void) const { return m_SpawnY; }
@@ -496,18 +497,18 @@ public:
/** Does an explosion with the specified strength at the specified coordinate
a_SourceData exact type depends on the a_Source:
- | esOther | void * |
- | esPrimedTNT | cTNTEntity * |
- | esMonster | cMonster * |
- | esBed | cVector3i * |
- | esEnderCrystal | Vector3i * |
- | esGhastFireball | cGhastFireball * |
- | esWitherSkullBlack | TBD |
- | esWitherSkullBlue | TBD |
- | esWitherBirth | TBD |
- | esPlugin | void * |
+ | esOther | void * |
+ | esPrimedTNT | cTNTEntity * |
+ | esMonster | cMonster * |
+ | esBed | cVector3i * |
+ | esEnderCrystal | Vector3i * |
+ | esGhastFireball | cGhastFireball * |
+ | esWitherSkullBlack | TBD |
+ | esWitherSkullBlue | TBD |
+ | esWitherBirth | cMonster * |
+ | esPlugin | void * |
*/
- virtual void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void * a_SourceData); // tolua_export
+ virtual void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void * a_SourceData); // tolua_export // override, cannot specify due to tolua
/** Calls the callback for the block entity at the specified coords; returns false if there's no block entity at those coords, true if found */
bool DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback & a_Callback); // Exported in ManualBindings.cpp
@@ -604,6 +605,9 @@ public:
bool AreCommandBlocksEnabled(void) const { return m_bCommandBlocksEnabled; }
void SetCommandBlocksEnabled(bool a_Flag) { m_bCommandBlocksEnabled = a_Flag; }
+ eShrapnelLevel GetTNTShrapnelLevel(void) const { return m_TNTShrapnelLevel; }
+ void SetTNTShrapnelLevel(eShrapnelLevel a_Flag) { m_TNTShrapnelLevel = a_Flag; }
+
bool ShouldUseChatPrefixes(void) const { return m_bUseChatPrefixes; }
void SetShouldUseChatPrefixes(bool a_Flag) { m_bUseChatPrefixes = a_Flag; }
@@ -703,7 +707,7 @@ public:
bool IsBlockDirectlyWatered(int a_BlockX, int a_BlockY, int a_BlockZ); // tolua_export
/** 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); // tolua_export
+ virtual int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, cMonster::eType a_MonsterType); // tolua_export // override, cannot specify due to tolua
int SpawnMobFinalize(cMonster* a_Monster);
/** Creates a projectile of the specified type. Returns the projectile's EntityID if successful, <0 otherwise */
@@ -861,6 +865,11 @@ private:
/** Whether prefixes such as [INFO] are prepended to SendMessageXXX() / BroadcastChatXXX() functions */
bool m_bUseChatPrefixes;
+
+ /** The level of DoExplosionAt() projecting random affected blocks as FallingBlock entities
+ See the eShrapnelLevel enumeration for details
+ */
+ eShrapnelLevel m_TNTShrapnelLevel;
cChunkGenerator m_Generator;
diff --git a/src/WorldStorage/FastNBT.cpp b/src/WorldStorage/FastNBT.cpp
index 8f80c3f75..be25fd1a4 100644
--- a/src/WorldStorage/FastNBT.cpp
+++ b/src/WorldStorage/FastNBT.cpp
@@ -506,22 +506,18 @@ void cFastNBTWriter::AddIntArray(const AString & a_Name, const int * a_Value, si
{
TagCommon(a_Name, TAG_IntArray);
Int32 len = htonl(a_NumElements);
+ size_t cap = m_Result.capacity();
+ size_t size = m_Result.length();
+ if ((cap - size) < (4 + a_NumElements * 4))
+ {
+ m_Result.reserve(size + 4 + (a_NumElements * 4));
+ }
m_Result.append((const char *)&len, 4);
-#if defined(ANDROID_NDK)
- // Android has alignment issues - cannot byteswap (htonl) an int that is not 32-bit-aligned, which happens in the regular version
for (size_t i = 0; i < a_NumElements; i++)
{
int Element = htonl(a_Value[i]);
m_Result.append((const char *)&Element, 4);
}
-#else
- int * Elements = (int *)(m_Result.data() + m_Result.size());
- m_Result.append(a_NumElements * 4, (char)0);
- for (size_t i = 0; i < a_NumElements; i++)
- {
- Elements[i] = htonl(a_Value[i]);
- }
-#endif
}
diff --git a/src/WorldStorage/FireworksSerializer.cpp b/src/WorldStorage/FireworksSerializer.cpp
index 1f05b470d..744fc731f 100644
--- a/src/WorldStorage/FireworksSerializer.cpp
+++ b/src/WorldStorage/FireworksSerializer.cpp
@@ -20,8 +20,14 @@ void cFireworkItem::WriteToNBTCompound(const cFireworkItem & a_FireworkItem, cFa
a_Writer.AddByte("Flicker", a_FireworkItem.m_HasFlicker);
a_Writer.AddByte("Trail", a_FireworkItem.m_HasTrail);
a_Writer.AddByte("Type", a_FireworkItem.m_Type);
- a_Writer.AddIntArray("Colors", &(a_FireworkItem.m_Colours[0]), a_FireworkItem.m_Colours.size());
- a_Writer.AddIntArray("FadeColors", &(a_FireworkItem.m_FadeColours[0]), a_FireworkItem.m_FadeColours.size());
+ if (!a_FireworkItem.m_Colours.empty())
+ {
+ a_Writer.AddIntArray("Colors", &(a_FireworkItem.m_Colours[0]), a_FireworkItem.m_Colours.size());
+ }
+ if (!a_FireworkItem.m_FadeColours.empty())
+ {
+ a_Writer.AddIntArray("FadeColors", &(a_FireworkItem.m_FadeColours[0]), a_FireworkItem.m_FadeColours.size());
+ }
a_Writer.EndCompound();
a_Writer.EndList();
a_Writer.EndCompound();
@@ -90,30 +96,34 @@ void cFireworkItem::ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNB
if (ExplosionName == "Colors")
{
// Divide by four as data length returned in bytes
- int DataLength = a_NBT.GetDataLength(explosiontag) / 4;
+ int DataLength = a_NBT.GetDataLength(explosiontag);
+ // round to the next highest multiple of four
+ DataLength -= DataLength % 4;
if (DataLength == 0)
{
continue;
}
- const int * ColourData = (const int *)(a_NBT.GetData(explosiontag));
- for (int i = 0; i < DataLength; i++)
+ const char * ColourData = (a_NBT.GetData(explosiontag));
+ for (int i = 0; i < DataLength; i += 4 /* Size of network int*/)
{
- a_FireworkItem.m_Colours.push_back(ntohl(ColourData[i]));
+ a_FireworkItem.m_Colours.push_back(GetBEInt(ColourData + i));
}
}
else if (ExplosionName == "FadeColors")
{
int DataLength = a_NBT.GetDataLength(explosiontag) / 4;
+ // round to the next highest multiple of four
+ DataLength -= DataLength % 4;
if (DataLength == 0)
{
continue;
}
- const int * FadeColourData = (const int *)(a_NBT.GetData(explosiontag));
- for (int i = 0; i < DataLength; i++)
+ const char * FadeColourData = (a_NBT.GetData(explosiontag));
+ for (int i = 0; i < DataLength; i += 4 /* Size of network int*/)
{
- a_FireworkItem.m_FadeColours.push_back(ntohl(FadeColourData[i]));
+ a_FireworkItem.m_FadeColours.push_back(GetBEInt(FadeColourData + i));
}
}
}
diff --git a/src/WorldStorage/MapSerializer.cpp b/src/WorldStorage/MapSerializer.cpp
index a4a0aab57..df72d1cc9 100644
--- a/src/WorldStorage/MapSerializer.cpp
+++ b/src/WorldStorage/MapSerializer.cpp
@@ -141,7 +141,11 @@ bool cMapSerializer::LoadMapFromNBT(const cParsedNBT & a_NBT)
{
eDimension Dimension = (eDimension) a_NBT.GetByte(CurrLine);
- ASSERT(Dimension == m_Map->m_World->GetDimension());
+ if (Dimension != m_Map->m_World->GetDimension())
+ {
+ // TODO 2014-03-20 xdot: We should store nether maps in nether worlds, e.t.c.
+ return false;
+ }
}
CurrLine = a_NBT.FindChildByName(Data, "width");
diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp
index 4cf3c62d7..415693ae2 100644
--- a/src/WorldStorage/NBTChunkSerializer.cpp
+++ b/src/WorldStorage/NBTChunkSerializer.cpp
@@ -23,12 +23,16 @@
#include "../BlockEntities/FlowerPotEntity.h"
#include "../Entities/Entity.h"
+#include "../Entities/EnderCrystal.h"
#include "../Entities/FallingBlock.h"
#include "../Entities/Boat.h"
#include "../Entities/Minecart.h"
#include "../Entities/Pickup.h"
#include "../Entities/ProjectileEntity.h"
#include "../Entities/TNTEntity.h"
+#include "../Entities/ExpOrb.h"
+#include "../Entities/HangingEntity.h"
+#include "../Entities/ItemFrame.h"
#include "../Mobs/Monster.h"
#include "../Mobs/Bat.h"
@@ -40,6 +44,7 @@
#include "../Mobs/Slime.h"
#include "../Mobs/Skeleton.h"
#include "../Mobs/Villager.h"
+#include "../Mobs/Wither.h"
#include "../Mobs/Wolf.h"
#include "../Mobs/Zombie.h"
@@ -332,6 +337,17 @@ void cNBTChunkSerializer::AddBoatEntity(cBoat * a_Boat)
+void cNBTChunkSerializer::AddEnderCrystalEntity(cEnderCrystal * a_EnderCrystal)
+{
+ m_Writer.BeginCompound("");
+ AddBasicEntity(a_EnderCrystal, "EnderCrystal");
+ m_Writer.EndCompound();
+}
+
+
+
+
+
void cNBTChunkSerializer::AddFallingBlockEntity(cFallingBlock * a_FallingBlock)
{
m_Writer.BeginCompound("");
@@ -419,7 +435,7 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster)
case cMonster::mtSquid: EntityClass = "Squid"; break;
case cMonster::mtVillager: EntityClass = "Villager"; break;
case cMonster::mtWitch: EntityClass = "Witch"; break;
- case cMonster::mtWither: EntityClass = "Wither"; break;
+ case cMonster::mtWither: EntityClass = "WitherBoss"; break;
case cMonster::mtWolf: EntityClass = "Wolf"; break;
case cMonster::mtZombie: EntityClass = "Zombie"; break;
case cMonster::mtZombiePigman: EntityClass = "PigZombie"; break;
@@ -498,6 +514,11 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster)
m_Writer.AddInt("Profession", ((const cVillager *)a_Monster)->GetVilType());
break;
}
+ case cMonster::mtWither:
+ {
+ m_Writer.AddInt("Invul", ((const cWither *)a_Monster)->GetNumInvulnerableTicks());
+ break;
+ }
case cMonster::mtWolf:
{
m_Writer.AddString("Owner", ((const cWolf *)a_Monster)->GetOwner());
@@ -526,8 +547,8 @@ void cNBTChunkSerializer::AddPickupEntity(cPickup * a_Pickup)
m_Writer.BeginCompound("");
AddBasicEntity(a_Pickup, "Item");
AddItem(a_Pickup->GetItem(), -1, "Item");
- m_Writer.AddShort("Health", a_Pickup->GetHealth());
- m_Writer.AddShort("Age", a_Pickup->GetAge());
+ m_Writer.AddShort("Health", (Int16)(unsigned char)a_Pickup->GetHealth());
+ m_Writer.AddShort("Age", (Int16)a_Pickup->GetAge());
m_Writer.EndCompound();
}
@@ -592,6 +613,25 @@ void cNBTChunkSerializer::AddProjectileEntity(cProjectileEntity * a_Projectile)
+void cNBTChunkSerializer::AddHangingEntity(cHangingEntity * a_Hanging)
+{
+ m_Writer.AddByte("Direction", (unsigned char)a_Hanging->GetDirection());
+ m_Writer.AddInt("TileX", a_Hanging->GetTileX());
+ m_Writer.AddInt("TileY", a_Hanging->GetTileY());
+ m_Writer.AddInt("TileZ", a_Hanging->GetTileZ());
+ switch (a_Hanging->GetDirection())
+ {
+ case 0: m_Writer.AddByte("Dir", (unsigned char)2); break;
+ case 1: m_Writer.AddByte("Dir", (unsigned char)1); break;
+ case 2: m_Writer.AddByte("Dir", (unsigned char)0); break;
+ case 3: m_Writer.AddByte("Dir", (unsigned char)3); break;
+ }
+}
+
+
+
+
+
void cNBTChunkSerializer::AddTNTEntity(cTNTEntity * a_TNT)
{
m_Writer.BeginCompound("");
@@ -604,6 +644,35 @@ void cNBTChunkSerializer::AddTNTEntity(cTNTEntity * a_TNT)
+void cNBTChunkSerializer::AddExpOrbEntity(cExpOrb * a_ExpOrb)
+{
+ m_Writer.BeginCompound("");
+ AddBasicEntity(a_ExpOrb, "XPOrb");
+ m_Writer.AddShort("Health", (Int16)(unsigned char)a_ExpOrb->GetHealth());
+ m_Writer.AddShort("Age", (Int16)a_ExpOrb->GetAge());
+ m_Writer.AddShort("Value", (Int16)a_ExpOrb->GetReward());
+ m_Writer.EndCompound();
+}
+
+
+
+
+
+void cNBTChunkSerializer::AddItemFrameEntity(cItemFrame * a_ItemFrame)
+{
+ m_Writer.BeginCompound("");
+ AddBasicEntity(a_ItemFrame, "ItemFrame");
+ AddHangingEntity(a_ItemFrame);
+ AddItem(a_ItemFrame->GetItem(), -1, "Item");
+ m_Writer.AddByte("ItemRotation", (unsigned char)a_ItemFrame->GetRotation());
+ m_Writer.AddFloat("ItemDropChance", 1.0F);
+ m_Writer.EndCompound();
+}
+
+
+
+
+
void cNBTChunkSerializer::AddMinecartChestContents(cMinecartWithChest * a_Minecart)
{
m_Writer.BeginList("Items", TAG_Compound);
@@ -678,14 +747,15 @@ void cNBTChunkSerializer::Entity(cEntity * a_Entity)
switch (a_Entity->GetEntityType())
{
case cEntity::etBoat: AddBoatEntity ((cBoat *) a_Entity); break;
+ case cEntity::etEnderCrystal: AddEnderCrystalEntity((cEnderCrystal *) a_Entity); break;
case cEntity::etFallingBlock: AddFallingBlockEntity((cFallingBlock *) a_Entity); break;
case cEntity::etMinecart: AddMinecartEntity ((cMinecart *) a_Entity); break;
case cEntity::etMonster: AddMonsterEntity ((cMonster *) a_Entity); break;
case cEntity::etPickup: AddPickupEntity ((cPickup *) a_Entity); break;
case cEntity::etProjectile: AddProjectileEntity ((cProjectileEntity *)a_Entity); break;
case cEntity::etTNT: AddTNTEntity ((cTNTEntity *) a_Entity); break;
- case cEntity::etExpOrb: /* TODO */ break;
- case cEntity::etItemFrame: /* TODO */ break;
+ case cEntity::etExpOrb: AddExpOrbEntity ((cExpOrb *) a_Entity); break;
+ case cEntity::etItemFrame: AddItemFrameEntity ((cItemFrame *) a_Entity); break;
case cEntity::etPainting: /* TODO */ break;
case cEntity::etPlayer: return; // Players aren't saved into the world
default:
diff --git a/src/WorldStorage/NBTChunkSerializer.h b/src/WorldStorage/NBTChunkSerializer.h
index 3b486d2bc..51d104970 100644
--- a/src/WorldStorage/NBTChunkSerializer.h
+++ b/src/WorldStorage/NBTChunkSerializer.h
@@ -24,6 +24,7 @@ class cChestEntity;
class cCommandBlockEntity;
class cDispenserEntity;
class cDropperEntity;
+class cEnderCrystal;
class cFurnaceEntity;
class cHopperEntity;
class cJukeboxEntity;
@@ -42,6 +43,9 @@ class cPickup;
class cItemGrid;
class cProjectileEntity;
class cTNTEntity;
+class cExpOrb;
+class cHangingEntity;
+class cItemFrame;
@@ -103,12 +107,16 @@ protected:
// Entities:
void AddBasicEntity (cEntity * a_Entity, const AString & a_ClassName);
void AddBoatEntity (cBoat * a_Boat);
+ void AddEnderCrystalEntity(cEnderCrystal * a_EnderCrystal);
void AddFallingBlockEntity(cFallingBlock * a_FallingBlock);
void AddMinecartEntity (cMinecart * a_Minecart);
void AddMonsterEntity (cMonster * a_Monster);
void AddPickupEntity (cPickup * a_Pickup);
void AddProjectileEntity (cProjectileEntity * a_Projectile);
+ void AddHangingEntity (cHangingEntity * a_Hanging);
void AddTNTEntity (cTNTEntity * a_TNT);
+ void AddExpOrbEntity (cExpOrb * a_ExpOrb);
+ void AddItemFrameEntity (cItemFrame * a_ItemFrame);
void AddMinecartChestContents(cMinecartWithChest * a_Minecart);
diff --git a/src/WorldStorage/SchematicFileSerializer.cpp b/src/WorldStorage/SchematicFileSerializer.cpp
index ef67fdb13..d8531d965 100644
--- a/src/WorldStorage/SchematicFileSerializer.cpp
+++ b/src/WorldStorage/SchematicFileSerializer.cpp
@@ -197,7 +197,7 @@ bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, cP
}
// Copy the block types and metas:
- int NumBytes = a_BlockArea.m_SizeX * a_BlockArea.m_SizeY * a_BlockArea.m_SizeZ;
+ int NumBytes = a_BlockArea.GetBlockCount();
if (a_NBT.GetDataLength(TBlockTypes) < NumBytes)
{
LOG("BlockTypes truncated in the schematic file (exp %d, got %d bytes). Loading partial.",
@@ -209,7 +209,7 @@ bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, cP
if (AreMetasPresent)
{
- int NumBytes = a_BlockArea.m_SizeX * a_BlockArea.m_SizeY * a_BlockArea.m_SizeZ;
+ int NumBytes = a_BlockArea.GetBlockCount();
if (a_NBT.GetDataLength(TBlockMetas) < NumBytes)
{
LOG("BlockMetas truncated in the schematic file (exp %d, got %d bytes). Loading partial.",
@@ -230,9 +230,9 @@ bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, cP
AString cSchematicFileSerializer::SaveToSchematicNBT(const cBlockArea & a_BlockArea)
{
cFastNBTWriter Writer("Schematic");
- Writer.AddShort("Width", a_BlockArea.m_SizeX);
- Writer.AddShort("Height", a_BlockArea.m_SizeY);
- Writer.AddShort("Length", a_BlockArea.m_SizeZ);
+ Writer.AddShort("Width", a_BlockArea.m_Size.x);
+ Writer.AddShort("Height", a_BlockArea.m_Size.y);
+ Writer.AddShort("Length", a_BlockArea.m_Size.z);
Writer.AddString("Materials", "Alpha");
if (a_BlockArea.HasBlockTypes())
{
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index eb159f28d..48934d074 100644
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -32,11 +32,15 @@
#include "../Mobs/IncludeAllMonsters.h"
#include "../Entities/Boat.h"
+#include "../Entities/EnderCrystal.h"
#include "../Entities/FallingBlock.h"
#include "../Entities/Minecart.h"
#include "../Entities/Pickup.h"
#include "../Entities/ProjectileEntity.h"
#include "../Entities/TNTEntity.h"
+#include "../Entities/ExpOrb.h"
+#include "../Entities/HangingEntity.h"
+#include "../Entities/ItemFrame.h"
@@ -366,6 +370,7 @@ bool cWSSAnvil::LoadChunkFromNBT(const cChunkCoords & a_Chunk, const cParsedNBT
{
case E_BLOCK_AIR:
case E_BLOCK_LEAVES:
+ case E_BLOCK_NEW_LEAVES:
{
// nothing needed
break;
@@ -507,10 +512,10 @@ cChunkDef::BiomeMap * cWSSAnvil::LoadBiomeMapFromNBT(cChunkDef::BiomeMap * a_Bio
// The biomes stored don't match in size
return NULL;
}
- const int * BiomeData = (const int *)(a_NBT.GetData(a_TagIdx));
+ const char * BiomeData = (a_NBT.GetData(a_TagIdx));
for (size_t i = 0; i < ARRAYCOUNT(*a_BiomeMap); i++)
{
- (*a_BiomeMap)[i] = (EMCSBiome)(ntohl(BiomeData[i]));
+ (*a_BiomeMap)[i] = (EMCSBiome)(GetBEInt(&BiomeData[i * 4]));
if ((*a_BiomeMap)[i] == 0xff)
{
// Unassigned biomes
@@ -1053,6 +1058,10 @@ void cWSSAnvil::LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a
{
LoadBoatFromNBT(a_Entities, a_NBT, a_EntityTagIdx);
}
+ else if (strncmp(a_IDTag, "EnderCrystal", a_IDTagLength) == 0)
+ {
+ LoadEnderCrystalFromNBT(a_Entities, a_NBT, a_EntityTagIdx);
+ }
else if (strncmp(a_IDTag, "FallingBlock", a_IDTagLength) == 0)
{
LoadFallingBlockFromNBT(a_Entities, a_NBT, a_EntityTagIdx);
@@ -1098,6 +1107,18 @@ void cWSSAnvil::LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a
{
LoadPickupFromNBT(a_Entities, a_NBT, a_EntityTagIdx);
}
+ else if (strncmp(a_IDTag, "PrimedTnt", a_IDTagLength) == 0)
+ {
+ LoadTNTFromNBT(a_Entities, a_NBT, a_EntityTagIdx);
+ }
+ else if (strncmp(a_IDTag, "XPOrb", a_IDTagLength) == 0)
+ {
+ LoadExpOrbFromNBT(a_Entities, a_NBT, a_EntityTagIdx);
+ }
+ else if (strncmp(a_IDTag, "ItemFrame", a_IDTagLength) == 0)
+ {
+ LoadItemFrameFromNBT(a_Entities, a_NBT, a_EntityTagIdx);
+ }
else if (strncmp(a_IDTag, "Arrow", a_IDTagLength) == 0)
{
LoadArrowFromNBT(a_Entities, a_NBT, a_EntityTagIdx);
@@ -1222,7 +1243,7 @@ void cWSSAnvil::LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a
{
LoadWitchFromNBT(a_Entities, a_NBT, a_EntityTagIdx);
}
- else if (strncmp(a_IDTag, "Wither", a_IDTagLength) == 0)
+ else if (strncmp(a_IDTag, "WitherBoss", a_IDTagLength) == 0)
{
LoadWitherFromNBT(a_Entities, a_NBT, a_EntityTagIdx);
}
@@ -1238,10 +1259,6 @@ void cWSSAnvil::LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a
{
LoadPigZombieFromNBT(a_Entities, a_NBT, a_EntityTagIdx);
}
- else if (strncmp(a_IDTag, "PrimedTnt", a_IDTagLength) == 0)
- {
- LoadTNTFromNBT(a_Entities, a_NBT, a_EntityTagIdx);
- }
// TODO: other entities
}
@@ -1263,6 +1280,20 @@ void cWSSAnvil::LoadBoatFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N
+void cWSSAnvil::LoadEnderCrystalFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx)
+{
+ std::auto_ptr<cEnderCrystal> EnderCrystal(new cEnderCrystal(0, 0, 0));
+ if (!LoadEntityBaseFromNBT(*EnderCrystal.get(), a_NBT, a_TagIdx))
+ {
+ return;
+ }
+ a_Entities.push_back(EnderCrystal.release());
+}
+
+
+
+
+
void cWSSAnvil::LoadFallingBlockFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx)
{
int TypeIdx = a_NBT.FindChildByName(a_TagIdx, "TileID");
@@ -1384,6 +1415,7 @@ void cWSSAnvil::LoadMinecartHFromNBT(cEntityList & a_Entities, const cParsedNBT
void cWSSAnvil::LoadPickupFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx)
{
+ // Load item:
int ItemTag = a_NBT.FindChildByName(a_TagIdx, "Item");
if ((ItemTag < 0) || (a_NBT.GetType(ItemTag) != TAG_Compound))
{
@@ -1394,11 +1426,27 @@ void cWSSAnvil::LoadPickupFromNBT(cEntityList & a_Entities, const cParsedNBT & a
{
return;
}
+
std::auto_ptr<cPickup> Pickup(new cPickup(0, 0, 0, Item, false)); // Pickup delay doesn't matter, just say false
if (!LoadEntityBaseFromNBT(*Pickup.get(), a_NBT, a_TagIdx))
{
return;
}
+
+ // Load health:
+ int Health = a_NBT.FindChildByName(a_TagIdx, "Health");
+ if (Health > 0)
+ {
+ Pickup->SetHealth((int) (a_NBT.GetShort(Health) & 0xFF));
+ }
+
+ // Load age:
+ int Age = a_NBT.FindChildByName(a_TagIdx, "Age");
+ if (Age > 0)
+ {
+ Pickup->SetAge(a_NBT.GetShort(Age));
+ }
+
a_Entities.push_back(Pickup.release());
}
@@ -1406,6 +1454,148 @@ void cWSSAnvil::LoadPickupFromNBT(cEntityList & a_Entities, const cParsedNBT & a
+void cWSSAnvil::LoadTNTFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx)
+{
+ std::auto_ptr<cTNTEntity> TNT(new cTNTEntity(0.0, 0.0, 0.0, 0));
+ if (!LoadEntityBaseFromNBT(*TNT.get(), a_NBT, a_TagIdx))
+ {
+ return;
+ }
+
+ // Load Fuse Ticks:
+ int FuseTicks = a_NBT.FindChildByName(a_TagIdx, "Fuse");
+ if (FuseTicks > 0)
+ {
+ TNT->SetFuseTicks((int) a_NBT.GetByte(FuseTicks));
+ }
+
+ a_Entities.push_back(TNT.release());
+}
+
+
+
+
+
+void cWSSAnvil::LoadExpOrbFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx)
+{
+ std::auto_ptr<cExpOrb> ExpOrb(new cExpOrb(0.0, 0.0, 0.0, 0));
+ if (!LoadEntityBaseFromNBT(*ExpOrb.get(), a_NBT, a_TagIdx))
+ {
+ return;
+ }
+
+ // Load Health:
+ int Health = a_NBT.FindChildByName(a_TagIdx, "Health");
+ if (Health > 0)
+ {
+ ExpOrb->SetHealth((int) (a_NBT.GetShort(Health) & 0xFF));
+ }
+
+ // Load Age:
+ int Age = a_NBT.FindChildByName(a_TagIdx, "Age");
+ if (Age > 0)
+ {
+ ExpOrb->SetAge(a_NBT.GetShort(Age));
+ }
+
+ // Load Reward (Value):
+ int Reward = a_NBT.FindChildByName(a_TagIdx, "Value");
+ if (Reward > 0)
+ {
+ ExpOrb->SetReward(a_NBT.GetShort(Reward));
+ }
+
+ a_Entities.push_back(ExpOrb.release());
+}
+
+
+
+
+
+void cWSSAnvil::LoadHangingFromNBT(cHangingEntity & a_Hanging, const cParsedNBT & a_NBT, int a_TagIdx)
+{
+ int Direction = a_NBT.FindChildByName(a_TagIdx, "Direction");
+ if (Direction > 0)
+ {
+ Direction = (int)a_NBT.GetByte(Direction);
+ if ((Direction < 0) || (Direction > 5))
+ {
+ a_Hanging.SetDirection(BLOCK_FACE_NORTH);
+ }
+ else
+ {
+ a_Hanging.SetDirection(static_cast<eBlockFace>(Direction));
+ }
+ }
+ else
+ {
+ Direction = a_NBT.FindChildByName(a_TagIdx, "Dir");
+ if (Direction > 0)
+ {
+ switch ((int)a_NBT.GetByte(Direction))
+ {
+ case 0: a_Hanging.SetDirection(BLOCK_FACE_NORTH); break;
+ case 1: a_Hanging.SetDirection(BLOCK_FACE_TOP); break;
+ case 2: a_Hanging.SetDirection(BLOCK_FACE_BOTTOM); break;
+ case 3: a_Hanging.SetDirection(BLOCK_FACE_SOUTH); break;
+ }
+ }
+ }
+
+ int TileX = a_NBT.FindChildByName(a_TagIdx, "TileX");
+ int TileY = a_NBT.FindChildByName(a_TagIdx, "TileY");
+ int TileZ = a_NBT.FindChildByName(a_TagIdx, "TileZ");
+ if ((TileX > 0) && (TileY > 0) && (TileZ > 0))
+ {
+ a_Hanging.SetPosition(
+ (double)a_NBT.GetInt(TileX),
+ (double)a_NBT.GetInt(TileY),
+ (double)a_NBT.GetInt(TileZ)
+ );
+ }
+}
+
+
+
+
+
+void cWSSAnvil::LoadItemFrameFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx)
+{
+ // Load item:
+ int ItemTag = a_NBT.FindChildByName(a_TagIdx, "Item");
+ if ((ItemTag < 0) || (a_NBT.GetType(ItemTag) != TAG_Compound))
+ {
+ return;
+ }
+ cItem Item;
+ if (!LoadItemFromNBT(Item, a_NBT, ItemTag))
+ {
+ return;
+ }
+
+ std::auto_ptr<cItemFrame> ItemFrame(new cItemFrame(BLOCK_FACE_NONE, 0.0, 0.0, 0.0));
+ if (!LoadEntityBaseFromNBT(*ItemFrame.get(), a_NBT, a_TagIdx))
+ {
+ return;
+ }
+ ItemFrame->SetItem(Item);
+
+ LoadHangingFromNBT(*ItemFrame.get(), a_NBT, a_TagIdx);
+
+ // Load Rotation:
+ int Rotation = a_NBT.FindChildByName(a_TagIdx, "ItemRotation");
+ if (Rotation > 0)
+ {
+ ItemFrame->SetRotation((Byte)a_NBT.GetByte(Rotation));
+ }
+
+ a_Entities.push_back(ItemFrame.release());
+}
+
+
+
+
+
void cWSSAnvil::LoadArrowFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx)
{
std::auto_ptr<cArrowEntity> Arrow(new cArrowEntity(NULL, 0, 0, 0, Vector3d(0, 0, 0)));
@@ -2079,6 +2269,12 @@ void cWSSAnvil::LoadWitherFromNBT(cEntityList & a_Entities, const cParsedNBT & a
return;
}
+ int CurrLine = a_NBT.FindChildByName(a_TagIdx, "Invul");
+ if (CurrLine > 0)
+ {
+ Monster->SetNumInvulnerableTicks(a_NBT.GetInt(CurrLine));
+ }
+
a_Entities.push_back(Monster.release());
}
@@ -2178,28 +2374,6 @@ void cWSSAnvil::LoadPigZombieFromNBT(cEntityList & a_Entities, const cParsedNBT
-void cWSSAnvil::LoadTNTFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx)
-{
- std::auto_ptr<cTNTEntity> TNT(new cTNTEntity(0.0, 0.0, 0.0, 0));
- if (!LoadEntityBaseFromNBT(*TNT.get(), a_NBT, a_TagIdx))
- {
- return;
- }
-
- // Load Fuse Ticks:
- int FuseTicks = a_NBT.FindChildByName(a_TagIdx, "Fuse");
- if (FuseTicks > 0)
- {
- TNT->SetFuseTicks((int) a_NBT.GetByte(FuseTicks));
- }
-
- a_Entities.push_back(TNT.release());
-}
-
-
-
-
-
bool cWSSAnvil::LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx)
{
double Pos[3];
diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h
index fe93d16c3..1773ee882 100644
--- a/src/WorldStorage/WSSAnvil.h
+++ b/src/WorldStorage/WSSAnvil.h
@@ -20,6 +20,7 @@
class cItemGrid;
class cProjectileEntity;
+class cHangingEntity;
@@ -147,8 +148,13 @@ protected:
void LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_EntityTagIdx, const char * a_IDTag, int a_IDTagLength);
void LoadBoatFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
+ void LoadEnderCrystalFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadFallingBlockFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadPickupFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
+ void LoadTNTFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
+ void LoadExpOrbFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
+ void LoadHangingFromNBT (cHangingEntity & a_Hanging,const cParsedNBT & a_NBT, int a_TagIdx);
+ void LoadItemFrameFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadMinecartRFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadMinecartCFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
@@ -192,7 +198,6 @@ protected:
void LoadWolfFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadZombieFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadPigZombieFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
- void LoadTNTFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
/// Loads entity common data from the NBT compound; returns true if successful
bool LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx);
diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp
index 5e49e4909..bb9d4b9e6 100644
--- a/src/WorldStorage/WSSCompact.cpp
+++ b/src/WorldStorage/WSSCompact.cpp
@@ -39,7 +39,7 @@ struct cWSSCompact::sChunkHeader
/// The maximum number of PAK files that are cached
-const int MAX_PAK_FILES = 16;
+const size_t MAX_PAK_FILES = 16;
/// The maximum number of unsaved chunks before the cPAKFile saves them to disk
const int MAX_DIRTY_CHUNKS = 16;
@@ -569,7 +569,7 @@ void cWSSCompact::cPAKFile::UpdateChunk1To2()
if( ChunksConverted % 32 == 0 )
{
- LOGINFO("Updating \"%s\" version 1 to version 2: %d %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() );
+ LOGINFO("Updating \"%s\" version 1 to version 2: " SIZE_T_FMT " %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() );
}
ChunksConverted++;
@@ -607,7 +607,7 @@ void cWSSCompact::cPAKFile::UpdateChunk1To2()
if (UncompressedSize != (int)UncompressedData.size())
{
- LOGWARNING("Uncompressed data size differs (exp %d bytes, got %d) for chunk [%d, %d]",
+ LOGWARNING("Uncompressed data size differs (exp %d bytes, got " SIZE_T_FMT ") for chunk [%d, %d]",
UncompressedSize, UncompressedData.size(),
Header->m_ChunkX, Header->m_ChunkZ
);
@@ -713,7 +713,7 @@ void cWSSCompact::cPAKFile::UpdateChunk2To3()
if( ChunksConverted % 32 == 0 )
{
- LOGINFO("Updating \"%s\" version 2 to version 3: %d %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() );
+ LOGINFO("Updating \"%s\" version 2 to version 3: " SIZE_T_FMT " %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() );
}
ChunksConverted++;
@@ -751,7 +751,7 @@ void cWSSCompact::cPAKFile::UpdateChunk2To3()
if (UncompressedSize != (int)UncompressedData.size())
{
- LOGWARNING("Uncompressed data size differs (exp %d bytes, got %d) for chunk [%d, %d]",
+ LOGWARNING("Uncompressed data size differs (exp %d bytes, got " SIZE_T_FMT ") for chunk [%d, %d]",
UncompressedSize, UncompressedData.size(),
Header->m_ChunkX, Header->m_ChunkZ
);
@@ -764,7 +764,6 @@ void cWSSCompact::cPAKFile::UpdateChunk2To3()
// Cannot use cChunk::MakeIndex because it might change again?????????
// For compatibility, use what we know is current
- #define MAKE_2_INDEX( x, y, z ) ( y + (z * 256) + (x * 256 * 16) )
#define MAKE_3_INDEX( x, y, z ) ( x + (z * 16) + (y * 16 * 16) )
unsigned int InChunkOffset = 0;
@@ -867,7 +866,7 @@ bool cWSSCompact::LoadChunkFromData(const cChunkCoords & a_Chunk, int & a_Uncomp
if (a_UncompressedSize != (int)UncompressedData.size())
{
- LOGWARNING("Uncompressed data size differs (exp %d bytes, got %d) for chunk [%d, %d]",
+ LOGWARNING("Uncompressed data size differs (exp %d bytes, got " SIZE_T_FMT ") for chunk [%d, %d]",
a_UncompressedSize, UncompressedData.size(),
a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ
);
diff --git a/src/main.cpp b/src/main.cpp
index 2ae8a413b..68eea7f4d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -72,7 +72,6 @@ void NonCtrlHandler(int a_Signal)
LOGERROR(" D: | MCServer has encountered an error and needs to close");
LOGERROR("Details | SIGABRT: Server self-terminated due to an internal fault");
exit(EXIT_FAILURE);
- break;
}
case SIGINT:
case SIGTERM: