summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Bindings/LuaState.cpp6
-rw-r--r--src/Bindings/ManualBindings.cpp45
-rw-r--r--src/Bindings/PluginLua.cpp52
-rw-r--r--src/Generating/ChunkDesc.cpp25
-rw-r--r--src/Generating/ChunkDesc.h40
-rw-r--r--src/Mobs/Chicken.cpp1
-rw-r--r--src/Mobs/Chicken.h3
-rw-r--r--src/Mobs/Cow.cpp2
-rw-r--r--src/Mobs/Cow.h3
-rw-r--r--src/Mobs/Mooshroom.cpp2
-rw-r--r--src/Mobs/Mooshroom.h2
-rw-r--r--src/Mobs/PassiveMonster.cpp16
-rw-r--r--src/Mobs/PassiveMonster.h3
-rw-r--r--src/Mobs/Pig.cpp2
-rw-r--r--src/Mobs/Pig.h3
-rw-r--r--src/Mobs/Sheep.cpp1
-rw-r--r--src/Mobs/Sheep.h2
-rw-r--r--src/Protocol/Protocol17x.cpp9
-rw-r--r--src/World.cpp3
19 files changed, 156 insertions, 64 deletions
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp
index 2fca7142c..d49cd8ef3 100644
--- a/src/Bindings/LuaState.cpp
+++ b/src/Bindings/LuaState.cpp
@@ -289,9 +289,13 @@ bool cLuaState::PushFunction(const cTableRef & a_TableRef)
if (lua_isnil(m_LuaState, -1) || !lua_isfunction(m_LuaState, -1))
{
// Not a valid function, bail out
- lua_pop(m_LuaState, 2);
+ lua_pop(m_LuaState, 3);
return false;
}
+
+ // Pop the table off the stack:
+ lua_remove(m_LuaState, -2);
+
Printf(m_CurrentFunctionName, "<table-callback %s>", a_TableRef.GetFnName());
m_NumCurrentFunctionArgs = 0;
return true;
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index e7c66c6fb..dbaf32756 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -1429,7 +1429,10 @@ static int tolua_cPluginManager_BindCommand(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++;
}
@@ -2128,26 +2131,40 @@ protected:
static int tolua_cLineBlockTracer_Trace(lua_State * tolua_S)
{
- // cLineBlockTracer.Trace(World, Callbacks, StartX, StartY, StartZ, EndX, EndY, EndZ)
+ /* Supported function signatures:
+ cLineBlockTracer:Trace(World, Callbacks, StartX, StartY, StartZ, EndX, EndY, EndZ) // Canonical
+ cLineBlockTracer.Trace(World, Callbacks, StartX, StartY, StartZ, EndX, EndY, EndZ)
+ */
+
+ // If the first param is the cLineBlockTracer class, shift param index by one:
+ int idx = 1;
+ tolua_Error err;
+ if (tolua_isusertable(tolua_S, 1, "cLineBlockTracer", 0, &err))
+ {
+ idx = 2;
+ }
+
+ // Check params:
cLuaState L(tolua_S);
if (
- !L.CheckParamUserType(1, "cWorld") ||
- !L.CheckParamTable (2) ||
- !L.CheckParamNumber (3, 8) ||
- !L.CheckParamEnd (9)
+ !L.CheckParamUserType(idx, "cWorld") ||
+ !L.CheckParamTable (idx + 1) ||
+ !L.CheckParamNumber (idx + 2, idx + 7) ||
+ !L.CheckParamEnd (idx + 8)
)
{
return 0;
}
- cWorld * World = (cWorld *)tolua_tousertype(L, 1, NULL);
- cLuaBlockTracerCallbacks Callbacks(L, 2);
- double StartX = tolua_tonumber(L, 3, 0);
- double StartY = tolua_tonumber(L, 4, 0);
- double StartZ = tolua_tonumber(L, 5, 0);
- double EndX = tolua_tonumber(L, 6, 0);
- double EndY = tolua_tonumber(L, 7, 0);
- double EndZ = tolua_tonumber(L, 8, 0);
+ // Trace:
+ cWorld * World = (cWorld *)tolua_tousertype(L, idx, NULL);
+ cLuaBlockTracerCallbacks Callbacks(L, idx + 1);
+ double StartX = tolua_tonumber(L, idx + 2, 0);
+ double StartY = tolua_tonumber(L, idx + 3, 0);
+ double StartZ = tolua_tonumber(L, idx + 4, 0);
+ double EndX = tolua_tonumber(L, idx + 5, 0);
+ double EndY = tolua_tonumber(L, idx + 6, 0);
+ double EndZ = tolua_tonumber(L, idx + 7, 0);
bool res = cLineBlockTracer::Trace(*World, Callbacks, StartX, StartY, StartZ, EndX, EndY, EndZ);
tolua_pushboolean(L, res ? 1 : 0);
return 1;
diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp
index 1d8c4c6ed..7b2362887 100644
--- a/src/Bindings/PluginLua.cpp
+++ b/src/Bindings/PluginLua.cpp
@@ -88,36 +88,55 @@ bool cPluginLua::Initialize(void)
std::string PluginPath = FILE_IO_PREFIX + GetLocalFolder() + "/";
- // Load all files for this plugin, and execute them
+ // List all Lua files for this plugin. Info.lua has a special handling - make it the last to load:
AStringVector Files = cFile::GetFolderContents(PluginPath.c_str());
-
- int numFiles = 0;
- for (AStringVector::const_iterator itr = Files.begin(); itr != Files.end(); ++itr)
+ AStringVector LuaFiles;
+ bool HasInfoLua = false;
+ for (AStringVector::const_iterator itr = Files.begin(), end = Files.end(); itr != end; ++itr)
{
- if (itr->rfind(".lua") == AString::npos)
+ if (itr->rfind(".lua") != AString::npos)
{
- continue;
+ if (*itr == "Info.lua")
+ {
+ HasInfoLua = true;
+ }
+ else
+ {
+ LuaFiles.push_back(*itr);
+ }
}
+ }
+ std::sort(LuaFiles.begin(), LuaFiles.end());
+
+ // Warn if there are no Lua files in the plugin folder:
+ if (LuaFiles.empty())
+ {
+ LOGWARNING("No lua files found: plugin %s is missing.", GetName().c_str());
+ Close();
+ return false;
+ }
+
+ // Load all files in the list, including the Info.lua as last, if it exists:
+ for (AStringVector::const_iterator itr = LuaFiles.begin(), end = LuaFiles.end(); itr != end; ++itr)
+ {
AString Path = PluginPath + *itr;
if (!m_LuaState.LoadFile(Path))
{
Close();
return false;
- }
- else
- {
- numFiles++;
}
} // for itr - Files[]
-
- if (numFiles == 0)
+ if (HasInfoLua)
{
- LOGWARNING("No lua files found: plugin %s is missing.", GetName().c_str());
- Close();
- return false;
+ AString Path = PluginPath + "Info.lua";
+ if (!m_LuaState.LoadFile(Path))
+ {
+ Close();
+ return false;
+ }
}
- // Call intialize function
+ // Call the Initialize function:
bool res = false;
if (!m_LuaState.Call("Initialize", this, cLuaState::Return, res))
{
@@ -125,7 +144,6 @@ bool cPluginLua::Initialize(void)
Close();
return false;
}
-
if (!res)
{
LOGINFO("Plugin %s: Initialize() call failed, plugin is temporarily disabled.", GetName().c_str());
diff --git a/src/Generating/ChunkDesc.cpp b/src/Generating/ChunkDesc.cpp
index af1a8a6c7..87566aa78 100644
--- a/src/Generating/ChunkDesc.cpp
+++ b/src/Generating/ChunkDesc.cpp
@@ -562,6 +562,31 @@ cBlockEntity * cChunkDesc::GetBlockEntity(int a_RelX, int a_RelY, int a_RelZ)
+void cChunkDesc::UpdateHeightmap(void)
+{
+ for (int x = 0; x < cChunkDef::Width; x++)
+ {
+ for (int z = 0; z < cChunkDef::Width; z++)
+ {
+ int Height = 0;
+ for (int y = cChunkDef::Height - 1; y > 0; y--)
+ {
+ BLOCKTYPE BlockType = GetBlockType(x, y, z);
+ if (BlockType != E_BLOCK_AIR)
+ {
+ Height = y;
+ break;
+ }
+ } // for y
+ SetHeight(x, z, Height);
+ } // for z
+ } // for x
+}
+
+
+
+
+
void cChunkDesc::CompressBlockMetas(cChunkDef::BlockNibbles & a_DestMetas)
{
const NIBBLETYPE * AreaMetas = m_BlockArea.GetBlockMetas();
diff --git a/src/Generating/ChunkDesc.h b/src/Generating/ChunkDesc.h
index e130c463f..e258383d5 100644
--- a/src/Generating/ChunkDesc.h
+++ b/src/Generating/ChunkDesc.h
@@ -30,7 +30,7 @@ class cChunkDesc
public:
// tolua_end
- /// Uncompressed block metas, 1 meta per byte
+ /** Uncompressed block metas, 1 meta per byte */
typedef NIBBLETYPE BlockNibbleBytes[cChunkDef::NumBlocks];
cChunkDesc(int a_ChunkX, int a_ChunkZ);
@@ -56,6 +56,8 @@ public:
void SetBiome(int a_RelX, int a_RelZ, int a_BiomeID);
EMCSBiome GetBiome(int a_RelX, int a_RelZ);
+ // These operate on the heightmap, so they could get out of sync with the data
+ // Use UpdateHeightmap() to re-sync
void SetHeight(int a_RelX, int a_RelZ, int a_Height);
int GetHeight(int a_RelX, int a_RelZ);
@@ -71,16 +73,16 @@ public:
void SetUseDefaultFinish(bool a_bUseDefaultFinish);
bool IsUsingDefaultFinish(void) const;
- /// Writes the block area into the chunk, with its origin set at the specified relative coords. Area's data overwrite everything in the chunk.
+ /** Writes the block area into the chunk, with its origin set at the specified relative coords. Area's data overwrite everything in the chunk. */
void WriteBlockArea(const cBlockArea & a_BlockArea, int a_RelX, int a_RelY, int a_RelZ, cBlockArea::eMergeStrategy a_MergeStrategy = cBlockArea::msOverwrite);
- /// Reads an area from the chunk into a cBlockArea, blocktypes and blockmetas
+ /** Reads an area from the chunk into a cBlockArea, blocktypes and blockmetas */
void ReadBlockArea(cBlockArea & a_Dest, int a_MinRelX, int a_MaxRelX, int a_MinRelY, int a_MaxRelY, int a_MinRelZ, int a_MaxRelZ);
- /// Returns the maximum height value in the heightmap
+ /** Returns the maximum height value in the heightmap */
HEIGHTTYPE GetMaxHeight(void) const;
- /// Fills the relative cuboid with specified block; allows cuboid out of range of this chunk
+ /** Fills the relative cuboid with specified block; allows cuboid out of range of this chunk */
void FillRelCuboid(
int a_MinX, int a_MaxX,
int a_MinY, int a_MaxY,
@@ -88,7 +90,7 @@ public:
BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta
);
- /// Fills the relative cuboid with specified block; allows cuboid out of range of this chunk
+ /** Fills the relative cuboid with specified block; allows cuboid out of range of this chunk */
void FillRelCuboid(const cCuboid & a_RelCuboid, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{
FillRelCuboid(
@@ -99,7 +101,7 @@ public:
);
}
- /// Replaces the specified src blocks in the cuboid by the dst blocks; allows cuboid out of range of this chunk
+ /** Replaces the specified src blocks in the cuboid by the dst blocks; allows cuboid out of range of this chunk */
void ReplaceRelCuboid(
int a_MinX, int a_MaxX,
int a_MinY, int a_MaxY,
@@ -108,7 +110,7 @@ public:
BLOCKTYPE a_DstType, NIBBLETYPE a_DstMeta
);
- /// Replaces the specified src blocks in the cuboid by the dst blocks; allows cuboid out of range of this chunk
+ /** Replaces the specified src blocks in the cuboid by the dst blocks; allows cuboid out of range of this chunk */
void ReplaceRelCuboid(
const cCuboid & a_RelCuboid,
BLOCKTYPE a_SrcType, NIBBLETYPE a_SrcMeta,
@@ -124,7 +126,7 @@ public:
);
}
- /// Replaces the blocks in the cuboid by the dst blocks if they are considered non-floor (air, water); allows cuboid out of range of this chunk
+ /** Replaces the blocks in the cuboid by the dst blocks if they are considered non-floor (air, water); allows cuboid out of range of this chunk */
void FloorRelCuboid(
int a_MinX, int a_MaxX,
int a_MinY, int a_MaxY,
@@ -132,7 +134,7 @@ public:
BLOCKTYPE a_DstType, NIBBLETYPE a_DstMeta
);
- /// Replaces the blocks in the cuboid by the dst blocks if they are considered non-floor (air, water); allows cuboid out of range of this chunk
+ /** Replaces the blocks in the cuboid by the dst blocks if they are considered non-floor (air, water); allows cuboid out of range of this chunk */
void FloorRelCuboid(
const cCuboid & a_RelCuboid,
BLOCKTYPE a_DstType, NIBBLETYPE a_DstMeta
@@ -146,7 +148,7 @@ public:
);
}
- /// Fills the relative cuboid with specified block with a random chance; allows cuboid out of range of this chunk
+ /** Fills the relative cuboid with specified block with a random chance; allows cuboid out of range of this chunk */
void RandomFillRelCuboid(
int a_MinX, int a_MaxX,
int a_MinY, int a_MaxY,
@@ -155,7 +157,7 @@ public:
int a_RandomSeed, int a_ChanceOutOf10k
);
- /// Fills the relative cuboid with specified block with a random chance; allows cuboid out of range of this chunk
+ /** Fills the relative cuboid with specified block with a random chance; allows cuboid out of range of this chunk */
void RandomFillRelCuboid(
const cCuboid & a_RelCuboid, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta,
int a_RandomSeed, int a_ChanceOutOf10k
@@ -170,11 +172,15 @@ public:
);
}
- /// Returns the block entity at the specified coords.
- /// If there is no block entity at those coords, tries to create one, based on the block type
- /// If the blocktype doesn't support a block entity, returns NULL.
+ /** Returns the block entity at the specified coords.
+ If there is no block entity at those coords, tries to create one, based on the block type
+ If the blocktype doesn't support a block entity, returns NULL. */
cBlockEntity * GetBlockEntity(int a_RelX, int a_RelY, int a_RelZ);
+ /** Updates the heightmap to match the current contents.
+ Useful for plugins when writing custom block areas into the chunk */
+ void UpdateHeightmap(void);
+
// tolua_end
// Accessors used by cChunkGenerator::Generator descendants:
@@ -187,11 +193,11 @@ public:
inline cEntityList & GetEntities (void) { return m_Entities; }
inline cBlockEntityList & GetBlockEntities (void) { return m_BlockEntities; }
- /// Compresses the metas from the BlockArea format (1 meta per byte) into regular format (2 metas per byte)
+ /** Compresses the metas from the BlockArea format (1 meta per byte) into regular format (2 metas per byte) */
void CompressBlockMetas(cChunkDef::BlockNibbles & a_DestMetas);
#ifdef _DEBUG
- /// Verifies that the heightmap corresponds to blocktype contents; if not, asserts on that column
+ /** Verifies that the heightmap corresponds to blocktype contents; if not, asserts on that column */
void VerifyHeightmap(void);
#endif // _DEBUG
diff --git a/src/Mobs/Chicken.cpp b/src/Mobs/Chicken.cpp
index 087fd088a..fab92ce49 100644
--- a/src/Mobs/Chicken.cpp
+++ b/src/Mobs/Chicken.cpp
@@ -9,7 +9,6 @@
-
cChicken::cChicken(void) :
super("Chicken", mtChicken, "mob.chicken.hurt", "mob.chicken.hurt", 0.3, 0.4),
m_EggDropTimer(0)
diff --git a/src/Mobs/Chicken.h b/src/Mobs/Chicken.h
index 979c4d8a0..a4c1d6b9e 100644
--- a/src/Mobs/Chicken.h
+++ b/src/Mobs/Chicken.h
@@ -19,8 +19,9 @@ public:
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override;
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
-private:
+ virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_SEEDS); }
+private:
int m_EggDropTimer;
} ;
diff --git a/src/Mobs/Cow.cpp b/src/Mobs/Cow.cpp
index 9eb74dac2..d8e905217 100644
--- a/src/Mobs/Cow.cpp
+++ b/src/Mobs/Cow.cpp
@@ -41,5 +41,3 @@ void cCow::OnRightClicked(cPlayer & a_Player)
}
}
-
-
diff --git a/src/Mobs/Cow.h b/src/Mobs/Cow.h
index 0391d4a31..973171ab5 100644
--- a/src/Mobs/Cow.h
+++ b/src/Mobs/Cow.h
@@ -19,6 +19,9 @@ public:
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override;
virtual void OnRightClicked(cPlayer & a_Player) override;
+
+ virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); }
+
} ;
diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp
index 940e2db44..88101cd83 100644
--- a/src/Mobs/Mooshroom.cpp
+++ b/src/Mobs/Mooshroom.cpp
@@ -6,7 +6,6 @@
-
// TODO: Milk Cow
@@ -30,4 +29,3 @@ void cMooshroom::GetDrops(cItems & a_Drops, cEntity * a_Killer)
-
diff --git a/src/Mobs/Mooshroom.h b/src/Mobs/Mooshroom.h
index 73f6348b6..c94301098 100644
--- a/src/Mobs/Mooshroom.h
+++ b/src/Mobs/Mooshroom.h
@@ -18,6 +18,8 @@ public:
CLASS_PROTODEF(cMooshroom);
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override;
+
+ virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); }
} ;
diff --git a/src/Mobs/PassiveMonster.cpp b/src/Mobs/PassiveMonster.cpp
index d774d3170..904cd63cc 100644
--- a/src/Mobs/PassiveMonster.cpp
+++ b/src/Mobs/PassiveMonster.cpp
@@ -3,7 +3,7 @@
#include "PassiveMonster.h"
#include "../World.h"
-
+#include "../Entities/Player.h"
@@ -39,6 +39,20 @@ void cPassiveMonster::Tick(float a_Dt, cChunk & a_Chunk)
{
CheckEventLostPlayer();
}
+ cItem FollowedItem = GetFollowedItem();
+ if (FollowedItem.IsEmpty())
+ {
+ return;
+ }
+ cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance);
+ if (a_Closest_Player != NULL)
+ {
+ if (a_Closest_Player->GetEquippedItem().IsEqual(FollowedItem))
+ {
+ Vector3d PlayerPos = a_Closest_Player->GetPosition();
+ MoveToPosition(PlayerPos);
+ }
+ }
}
diff --git a/src/Mobs/PassiveMonster.h b/src/Mobs/PassiveMonster.h
index 14a6be6b1..0b3c155da 100644
--- a/src/Mobs/PassiveMonster.h
+++ b/src/Mobs/PassiveMonster.h
@@ -19,6 +19,9 @@ public:
/// When hit by someone, run away
virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override;
+ /** Returns the item that the animal of this class follows when a player holds it in hand
+ Return an empty item not to follow (default). */
+ virtual const cItem GetFollowedItem(void) const { return cItem(); }
} ;
diff --git a/src/Mobs/Pig.cpp b/src/Mobs/Pig.cpp
index 0871a38a9..d8f3dda37 100644
--- a/src/Mobs/Pig.cpp
+++ b/src/Mobs/Pig.cpp
@@ -73,5 +73,3 @@ void cPig::OnRightClicked(cPlayer & a_Player)
-
-
diff --git a/src/Mobs/Pig.h b/src/Mobs/Pig.h
index 4fd0d8db8..d434324c1 100644
--- a/src/Mobs/Pig.h
+++ b/src/Mobs/Pig.h
@@ -19,6 +19,9 @@ public:
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override;
virtual void OnRightClicked(cPlayer & a_Player) override;
+
+ virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_CARROT); }
+
bool IsSaddled(void) const { return m_bIsSaddled; }
private:
diff --git a/src/Mobs/Sheep.cpp b/src/Mobs/Sheep.cpp
index 702108ae4..4761103e5 100644
--- a/src/Mobs/Sheep.cpp
+++ b/src/Mobs/Sheep.cpp
@@ -97,3 +97,4 @@ void cSheep::Tick(float a_Dt, cChunk & a_Chunk)
}
}
}
+
diff --git a/src/Mobs/Sheep.h b/src/Mobs/Sheep.h
index 4eee3db1c..402e8e61c 100644
--- a/src/Mobs/Sheep.h
+++ b/src/Mobs/Sheep.h
@@ -21,6 +21,8 @@ public:
virtual void OnRightClicked(cPlayer & a_Player) override;
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
+ virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); }
+
bool IsSheared(void) const { return m_IsSheared; }
int GetFurColor(void) const { return m_WoolColor; }
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 0e9759194..04bade867 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -985,10 +985,11 @@ void cProtocol172::SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, cons
Pkt.WriteInt(a_BlockX);
Pkt.WriteShort((short)a_BlockY);
Pkt.WriteInt(a_BlockZ);
- Pkt.WriteString(a_Line1);
- Pkt.WriteString(a_Line2);
- Pkt.WriteString(a_Line3);
- Pkt.WriteString(a_Line4);
+ // Need to send only up to 15 chars, otherwise the client crashes (#598)
+ Pkt.WriteString(a_Line1.substr(0, 15));
+ Pkt.WriteString(a_Line2.substr(0, 15));
+ Pkt.WriteString(a_Line3.substr(0, 15));
+ Pkt.WriteString(a_Line4.substr(0, 15));
}
diff --git a/src/World.cpp b/src/World.cpp
index 88bbf5f8a..5739098e4 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -1,4 +1,3 @@
-
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "BlockID.h"
@@ -234,7 +233,7 @@ cWorld::cWorld(const AString & a_WorldName) :
m_WorldName(a_WorldName),
m_IniFileName(m_WorldName + "/world.ini"),
m_StorageSchema("Default"),
-#ifdef _arm_
+#ifdef __arm__
m_StorageCompressionFactor(0),
#else
m_StorageCompressionFactor(6),