summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--source/Bindings.cpp253
-rw-r--r--source/Bindings.h2
-rw-r--r--source/BlockEntity.h49
-rw-r--r--source/BlockID.h6
-rw-r--r--source/ChestEntity.cpp54
-rw-r--r--source/ChestEntity.h25
-rw-r--r--source/Chunk.cpp10
-rw-r--r--source/Generating/ChunkDesc.cpp9
-rw-r--r--source/Generating/ChunkDesc.h1
-rw-r--r--source/Generating/MineShafts.cpp59
-rw-r--r--source/Item.h14
-rw-r--r--source/SignEntity.cpp2
-rw-r--r--source/SignEntity.h2
13 files changed, 420 insertions, 66 deletions
diff --git a/source/Bindings.cpp b/source/Bindings.cpp
index da51018d1..56195bab8 100644
--- a/source/Bindings.cpp
+++ b/source/Bindings.cpp
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 03/31/13 21:21:48.
+** Generated automatically by tolua++-1.0.92 on 04/06/13 23:17:20.
*/
#ifndef __cplusplus
@@ -84,9 +84,9 @@ static int tolua_collect_cPickup (lua_State* tolua_S)
return 0;
}
-static int tolua_collect_cTracer (lua_State* tolua_S)
+static int tolua_collect_cChestEntity (lua_State* tolua_S)
{
- cTracer* self = (cTracer*) tolua_tousertype(tolua_S,1,0);
+ cChestEntity* self = (cChestEntity*) tolua_tousertype(tolua_S,1,0);
Mtolua_delete(self);
return 0;
}
@@ -119,6 +119,13 @@ static int tolua_collect_cBlockArea (lua_State* tolua_S)
return 0;
}
+static int tolua_collect_cTracer (lua_State* tolua_S)
+{
+ cTracer* self = (cTracer*) tolua_tousertype(tolua_S,1,0);
+ Mtolua_delete(self);
+ return 0;
+}
+
static int tolua_collect_Vector3d (lua_State* tolua_S)
{
Vector3d* self = (Vector3d*) tolua_tousertype(tolua_S,1,0);
@@ -4218,6 +4225,38 @@ static int tolua_AllToLua_cEntity_GetWorld00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+/* method: GetHeadYaw of class cEntity */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cEntity_GetHeadYaw00
+static int tolua_AllToLua_cEntity_GetHeadYaw00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"const cEntity",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,2,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ const cEntity* self = (const cEntity*) tolua_tousertype(tolua_S,1,0);
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetHeadYaw'", NULL);
+#endif
+ {
+ double tolua_ret = (double) self->GetHeadYaw();
+ tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'GetHeadYaw'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
/* method: GetPosition of class cEntity */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cEntity_GetPosition00
static int tolua_AllToLua_cEntity_GetPosition00(lua_State* tolua_S)
@@ -4740,6 +4779,39 @@ static int tolua_AllToLua_cEntity_GetChunkZ00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+/* method: SetHeadYaw of class cEntity */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cEntity_SetHeadYaw00
+static int tolua_AllToLua_cEntity_SetHeadYaw00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cEntity",0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cEntity* self = (cEntity*) tolua_tousertype(tolua_S,1,0);
+ double a_HeadYaw = ((double) tolua_tonumber(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetHeadYaw'", NULL);
+#endif
+ {
+ self->SetHeadYaw(a_HeadYaw);
+ }
+ }
+ return 0;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'SetHeadYaw'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
/* method: SetPosX of class cEntity */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cEntity_SetPosX00
static int tolua_AllToLua_cEntity_SetPosX00(lua_State* tolua_S)
@@ -13470,6 +13542,75 @@ tolua_lerror:
}
#endif //#ifndef TOLUA_DISABLE
+/* method: new of class cChestEntity */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cChestEntity_new00
+static int tolua_AllToLua_cChestEntity_new00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertable(tolua_S,1,"cChestEntity",0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,3,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,4,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,5,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ int a_BlockX = ((int) tolua_tonumber(tolua_S,2,0));
+ int a_BlockY = ((int) tolua_tonumber(tolua_S,3,0));
+ int a_BlockZ = ((int) tolua_tonumber(tolua_S,4,0));
+ {
+ cChestEntity* tolua_ret = (cChestEntity*) Mtolua_new((cChestEntity)(a_BlockX,a_BlockY,a_BlockZ));
+ tolua_pushusertype(tolua_S,(void*)tolua_ret,"cChestEntity");
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'new'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: new_local of class cChestEntity */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cChestEntity_new00_local
+static int tolua_AllToLua_cChestEntity_new00_local(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertable(tolua_S,1,"cChestEntity",0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,3,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,4,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,5,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ int a_BlockX = ((int) tolua_tonumber(tolua_S,2,0));
+ int a_BlockY = ((int) tolua_tonumber(tolua_S,3,0));
+ int a_BlockZ = ((int) tolua_tonumber(tolua_S,4,0));
+ {
+ cChestEntity* tolua_ret = (cChestEntity*) Mtolua_new((cChestEntity)(a_BlockX,a_BlockY,a_BlockZ));
+ tolua_pushusertype(tolua_S,(void*)tolua_ret,"cChestEntity");
+ tolua_register_gc(tolua_S,lua_gettop(tolua_S));
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'new'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
/* method: GetSlot of class cChestEntity */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cChestEntity_GetSlot00
static int tolua_AllToLua_cChestEntity_GetSlot00(lua_State* tolua_S)
@@ -13603,6 +13744,7 @@ public:
void cChestEntity__UsedBy( cPlayer* a_Player) {
return ( void )cChestEntity::UsedBy(a_Player);
};
+ Lua__cChestEntity( int a_BlockX, int a_BlockY, int a_BlockZ): cChestEntity(a_BlockX,a_BlockY,a_BlockZ){};
};
/* method: tolua__set_instance of class Lua__cChestEntity */
@@ -13671,6 +13813,87 @@ static int tolua_AllToLua_Lua__cChestEntity_cChestEntity__UsedBy00(lua_State* to
}
#endif //#ifndef TOLUA_DISABLE
+/* method: new of class Lua__cChestEntity */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cChestEntity_new00
+static int tolua_AllToLua_Lua__cChestEntity_new00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertable(tolua_S,1,"Lua__cChestEntity",0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,3,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,4,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,5,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ int a_BlockX = ((int) tolua_tonumber(tolua_S,2,0));
+ int a_BlockY = ((int) tolua_tonumber(tolua_S,3,0));
+ int a_BlockZ = ((int) tolua_tonumber(tolua_S,4,0));
+ {
+ Lua__cChestEntity* tolua_ret = (Lua__cChestEntity*) Mtolua_new((Lua__cChestEntity)(a_BlockX,a_BlockY,a_BlockZ));
+ tolua_pushusertype(tolua_S,(void*)tolua_ret,"Lua__cChestEntity");
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'new'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: new_local of class Lua__cChestEntity */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cChestEntity_new00_local
+static int tolua_AllToLua_Lua__cChestEntity_new00_local(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertable(tolua_S,1,"Lua__cChestEntity",0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,3,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,4,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,5,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ int a_BlockX = ((int) tolua_tonumber(tolua_S,2,0));
+ int a_BlockY = ((int) tolua_tonumber(tolua_S,3,0));
+ int a_BlockZ = ((int) tolua_tonumber(tolua_S,4,0));
+ {
+ Lua__cChestEntity* tolua_ret = (Lua__cChestEntity*) Mtolua_new((Lua__cChestEntity)(a_BlockX,a_BlockY,a_BlockZ));
+ tolua_pushusertype(tolua_S,(void*)tolua_ret,"Lua__cChestEntity");
+ tolua_register_gc(tolua_S,lua_gettop(tolua_S));
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'new'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+
+/* function to release collected object via destructor */
+#ifdef __cplusplus
+
+static int tolua_collect_Lua__cChestEntity (lua_State* tolua_S)
+{
+ Lua__cChestEntity* self = (Lua__cChestEntity*) tolua_tousertype(tolua_S,1,0);
+ delete self;
+ return 0;
+}
+#endif
+
/* get function: Name of class HTTPFormData */
#ifndef TOLUA_DISABLE_tolua_get_HTTPFormData_Name
static int tolua_get_HTTPFormData_Name(lua_State* tolua_S)
@@ -23229,6 +23452,14 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_constant(tolua_S,"E_META_TORCH_SOUTH",E_META_TORCH_SOUTH);
tolua_constant(tolua_S,"E_META_TORCH_NORTH",E_META_TORCH_NORTH);
tolua_constant(tolua_S,"E_META_TORCH_FLOOR",E_META_TORCH_FLOOR);
+ tolua_constant(tolua_S,"E_META_TORCH_XM",E_META_TORCH_XM);
+ tolua_constant(tolua_S,"E_META_TORCH_XP",E_META_TORCH_XP);
+ tolua_constant(tolua_S,"E_META_TORCH_ZM",E_META_TORCH_ZM);
+ tolua_constant(tolua_S,"E_META_TORCH_ZP",E_META_TORCH_ZP);
+ tolua_constant(tolua_S,"E_META_CHEST_FACING_ZM",E_META_CHEST_FACING_ZM);
+ tolua_constant(tolua_S,"E_META_CHEST_FACING_ZP",E_META_CHEST_FACING_ZP);
+ tolua_constant(tolua_S,"E_META_CHEST_FACING_XM",E_META_CHEST_FACING_XM);
+ tolua_constant(tolua_S,"E_META_CHEST_FACING_XP",E_META_CHEST_FACING_XP);
tolua_constant(tolua_S,"E_META_DOUBLE_STEP_STONE",E_META_DOUBLE_STEP_STONE);
tolua_constant(tolua_S,"E_META_DOUBLE_STEP_SANDSTONE",E_META_DOUBLE_STEP_SANDSTONE);
tolua_constant(tolua_S,"E_META_DOUBLE_STEP_WOODEN",E_META_DOUBLE_STEP_WOODEN);
@@ -23456,6 +23687,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"GetClassStatic",tolua_AllToLua_cEntity_GetClassStatic00);
tolua_function(tolua_S,"GetParentClass",tolua_AllToLua_cEntity_GetParentClass00);
tolua_function(tolua_S,"GetWorld",tolua_AllToLua_cEntity_GetWorld00);
+ tolua_function(tolua_S,"GetHeadYaw",tolua_AllToLua_cEntity_GetHeadYaw00);
tolua_function(tolua_S,"GetPosition",tolua_AllToLua_cEntity_GetPosition00);
tolua_function(tolua_S,"GetPosX",tolua_AllToLua_cEntity_GetPosX00);
tolua_function(tolua_S,"GetPosY",tolua_AllToLua_cEntity_GetPosY00);
@@ -23472,6 +23704,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"GetChunkX",tolua_AllToLua_cEntity_GetChunkX00);
tolua_function(tolua_S,"GetChunkY",tolua_AllToLua_cEntity_GetChunkY00);
tolua_function(tolua_S,"GetChunkZ",tolua_AllToLua_cEntity_GetChunkZ00);
+ tolua_function(tolua_S,"SetHeadYaw",tolua_AllToLua_cEntity_SetHeadYaw00);
tolua_function(tolua_S,"SetPosX",tolua_AllToLua_cEntity_SetPosX00);
tolua_function(tolua_S,"SetPosY",tolua_AllToLua_cEntity_SetPosY00);
tolua_function(tolua_S,"SetPosZ",tolua_AllToLua_cEntity_SetPosZ00);
@@ -23829,17 +24062,31 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"Add",tolua_AllToLua_cItems_Add01);
tolua_function(tolua_S,"Set",tolua_AllToLua_cItems_Set01);
tolua_endmodule(tolua_S);
+ #ifdef __cplusplus
+ tolua_cclass(tolua_S,"cChestEntity","cChestEntity","cBlockEntity",tolua_collect_cChestEntity);
+ #else
tolua_cclass(tolua_S,"cChestEntity","cChestEntity","cBlockEntity",NULL);
+ #endif
tolua_beginmodule(tolua_S,"cChestEntity");
+ tolua_function(tolua_S,"new",tolua_AllToLua_cChestEntity_new00);
+ tolua_function(tolua_S,"new_local",tolua_AllToLua_cChestEntity_new00_local);
+ tolua_function(tolua_S,".call",tolua_AllToLua_cChestEntity_new00_local);
tolua_function(tolua_S,"GetSlot",tolua_AllToLua_cChestEntity_GetSlot00);
tolua_function(tolua_S,"SetSlot",tolua_AllToLua_cChestEntity_SetSlot00);
tolua_function(tolua_S,"UsedBy",tolua_AllToLua_cChestEntity_UsedBy00);
tolua_variable(tolua_S,"__cBlockEntityWindowOwner__",tolua_get_cChestEntity___cBlockEntityWindowOwner__,NULL);
tolua_endmodule(tolua_S);
+ #ifdef __cplusplus
+ tolua_cclass(tolua_S,"Lua__cChestEntity","Lua__cChestEntity","cChestEntity",tolua_collect_Lua__cChestEntity);
+ #else
tolua_cclass(tolua_S,"Lua__cChestEntity","Lua__cChestEntity","cChestEntity",NULL);
+ #endif
tolua_beginmodule(tolua_S,"Lua__cChestEntity");
tolua_function(tolua_S,"tolua__set_instance",tolua_AllToLua_Lua__cChestEntity_tolua__set_instance00);
tolua_function(tolua_S,"cChestEntity__UsedBy",tolua_AllToLua_Lua__cChestEntity_cChestEntity__UsedBy00);
+ tolua_function(tolua_S,"new",tolua_AllToLua_Lua__cChestEntity_new00);
+ tolua_function(tolua_S,"new_local",tolua_AllToLua_Lua__cChestEntity_new00_local);
+ tolua_function(tolua_S,".call",tolua_AllToLua_Lua__cChestEntity_new00_local);
tolua_endmodule(tolua_S);
tolua_cclass(tolua_S,"HTTPFormData","HTTPFormData","",NULL);
tolua_beginmodule(tolua_S,"HTTPFormData");
diff --git a/source/Bindings.h b/source/Bindings.h
index b92bd1cfb..726dbd1ac 100644
--- a/source/Bindings.h
+++ b/source/Bindings.h
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 03/31/13 21:21:49.
+** Generated automatically by tolua++-1.0.92 on 04/06/13 23:17:21.
*/
/* Exported function */
diff --git a/source/BlockEntity.h b/source/BlockEntity.h
index d62f8aa5e..b3273b9c9 100644
--- a/source/BlockEntity.h
+++ b/source/BlockEntity.h
@@ -8,23 +8,12 @@
-#ifndef _WIN32
-#include "BlockID.h"
-#else
-enum ENUM_BLOCK_ID;
-#endif
-
-
-
-
-
namespace Json
{
class Value;
};
class cPlayer;
-class cWorld;
class cPacket;
@@ -34,23 +23,41 @@ class cPacket;
class cBlockEntity
{
protected:
- cBlockEntity(ENUM_BLOCK_ID a_BlockType, int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World)
- : m_PosX( a_BlockX )
- , m_PosY( a_BlockY )
- , m_PosZ( a_BlockZ )
- , m_BlockType( a_BlockType )
- , m_World( a_World )
- {}
+ cBlockEntity(BLOCKTYPE a_BlockType, int a_BlockX, int a_BlockY, int a_BlockZ) : // Used when generating
+ m_PosX(a_BlockX),
+ m_PosY(a_BlockY),
+ m_PosZ(a_BlockZ),
+ m_BlockType(a_BlockType),
+ m_World(NULL)
+ {
+ }
+
+
+ cBlockEntity(BLOCKTYPE a_BlockType, int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) :
+ m_PosX(a_BlockX),
+ m_PosY(a_BlockY),
+ m_PosZ(a_BlockZ),
+ m_BlockType(a_BlockType),
+ m_World(a_World)
+ {
+ }
+
public:
- virtual ~cBlockEntity() {};
+ virtual ~cBlockEntity() {}; // force a virtual destructor in all descendants
+
virtual void Destroy(void) {};
+ void SetWorld(cWorld * a_World)
+ {
+ m_World = a_World;
+ }
+
// Position, in absolute block coordinates:
int GetPosX(void) const { return m_PosX; }
int GetPosY(void) const { return m_PosY; }
int GetPosZ(void) const { return m_PosZ; }
- ENUM_BLOCK_ID GetBlockType(void) const { return m_BlockType; }
+ BLOCKTYPE GetBlockType(void) const { return m_BlockType; }
cWorld * GetWorld(void) const {return m_World; }
@@ -71,7 +78,7 @@ protected:
int m_PosY;
int m_PosZ;
- ENUM_BLOCK_ID m_BlockType;
+ BLOCKTYPE m_BlockType;
cWorld * m_World;
};
diff --git a/source/BlockID.h b/source/BlockID.h
index 2a912cff2..c567644c9 100644
--- a/source/BlockID.h
+++ b/source/BlockID.h
@@ -428,6 +428,12 @@ enum
E_META_TORCH_XP = 2, // Torch attached to the XP side of its block
E_META_TORCH_ZM = 3, // Torch attached to the ZM side of its block
E_META_TORCH_ZP = 4, // Torch attached to the ZP side of its block
+
+ // E_BLOCK_CHEST metas:
+ E_META_CHEST_FACING_ZM = 2,
+ E_META_CHEST_FACING_ZP = 3,
+ E_META_CHEST_FACING_XM = 4,
+ E_META_CHEST_FACING_XP = 5,
// E_BLOCK_DOUBLE_STEP metas:
E_META_DOUBLE_STEP_STONE = 0,
diff --git a/source/ChestEntity.cpp b/source/ChestEntity.cpp
index 2f038897c..d3c062924 100644
--- a/source/ChestEntity.cpp
+++ b/source/ChestEntity.cpp
@@ -9,6 +9,7 @@
#include "World.h"
#include "Root.h"
#include "Pickup.h"
+#include "Noise.h"
#include <json/json.h>
@@ -22,11 +23,20 @@ class cRoot;
+cChestEntity::cChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ) :
+ super(E_BLOCK_CHEST, a_BlockX, a_BlockY, a_BlockZ)
+{
+ cBlockEntityWindowOwner::SetBlockEntity(this);
+}
+
+
+
+
+
cChestEntity::cChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) :
- cBlockEntity(E_BLOCK_CHEST, a_BlockX, a_BlockY, a_BlockZ, a_World)
+ super(E_BLOCK_CHEST, a_BlockX, a_BlockY, a_BlockZ, a_World)
{
- m_Content = new cItem[ c_ChestHeight * c_ChestWidth ];
- SetBlockEntity(this); // cBlockEntityWindowOwner
+ cBlockEntityWindowOwner::SetBlockEntity(this);
}
@@ -40,8 +50,6 @@ cChestEntity::~cChestEntity()
{
Window->OwnerDestroyed();
}
-
- delete [] m_Content;
}
@@ -92,13 +100,37 @@ void cChestEntity::SetSlot(int a_Slot, const cItem & a_Item)
-#define READ(File, Var) \
- if (File.Read(&Var, sizeof(Var)) != sizeof(Var)) \
- { \
- LOGERROR("ERROR READING cChestEntity %s FROM FILE (line %d)", #Var, __LINE__); \
- return false; \
+void cChestEntity::GenerateRandomLootWithBooks(const cLootProbab * a_LootProbabs, int a_CountLootProbabs, int a_NumSlots, int a_Seed)
+{
+ // Calculate the total weight:
+ int TotalProbab = 1;
+ for (int i = 0; i < a_CountLootProbabs; i++)
+ {
+ TotalProbab += a_LootProbabs[i].m_Weight;
}
-
+
+ // Pick the loot items:
+ cNoise Noise(a_Seed);
+ for (int i = 0; i < a_NumSlots; i++)
+ {
+ int Rnd = (Noise.IntNoise1DInt(i) / 7);
+ int LootRnd = Rnd % TotalProbab;
+ Rnd >>= 8;
+ cItem CurrentLoot = cItem(E_ITEM_BOOK, 1, 0); // TODO: enchantment
+ for (int j = 0; j < a_CountLootProbabs; j++)
+ {
+ LootRnd -= a_LootProbabs[i].m_Weight;
+ if (LootRnd < 0)
+ {
+ CurrentLoot = a_LootProbabs[i].m_Item;
+ CurrentLoot.m_ItemCount = a_LootProbabs[i].m_MinAmount + (Rnd % (a_LootProbabs[i].m_MaxAmount - a_LootProbabs[i].m_MinAmount));
+ Rnd >>= 8;
+ break;
+ }
+ } // for j - a_LootProbabs[]
+ SetSlot(Rnd % ARRAYCOUNT(m_Content), CurrentLoot);
+ } // for i - NumSlots
+}
diff --git a/source/ChestEntity.h b/source/ChestEntity.h
index cef53f037..03102a80b 100644
--- a/source/ChestEntity.h
+++ b/source/ChestEntity.h
@@ -16,18 +16,26 @@ namespace Json
class cClientHandle;
class cServer;
class cItem;
+class cLootProbab;
class cNBTData;
-class cChestEntity : // tolua_export
- public cBlockEntity, // tolua_export
- public cBlockEntityWindowOwner // tolua_export
-{ // tolua_export
+// tolua_begin
+class cChestEntity :
+ public cBlockEntity,
+ public cBlockEntityWindowOwner
+{
+ typedef cBlockEntity super;
+
public:
+ cChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ); // Used while generating
+ // tolua_end
+
cChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
+
virtual ~cChestEntity();
virtual void Destroy();
@@ -35,6 +43,11 @@ public:
const cItem * GetSlot(int a_Slot) const; // tolua_export
void SetSlot(int a_Slot, const cItem & a_Item ); // tolua_export
+
+ /** Generates random loot from the specified loot probability table, with a chance of enchanted books added.
+ A total of a_NumSlots are taken by the loot
+ */
+ void GenerateRandomLootWithBooks(const cLootProbab * a_LootProbabs, int a_CountLootProbabs, int a_NumSlots, int a_Seed);
bool LoadFromJson( const Json::Value& a_Value );
@@ -53,8 +66,8 @@ public:
private:
- cItem * m_Content;
-}; // tolua_export
+ cItem m_Content[c_ChestWidth * c_ChestHeight]; // TODO: replace this by a generic ItemGridHolder
+} ; // tolua_export
diff --git a/source/Chunk.cpp b/source/Chunk.cpp
index 9856e67b3..0a7b39f12 100644
--- a/source/Chunk.cpp
+++ b/source/Chunk.cpp
@@ -306,6 +306,12 @@ void cChunk::SetAllData(
}
std::swap(a_BlockEntities, m_BlockEntities);
+ // Set all block entities' World variable:
+ for (cBlockEntityList::iterator itr = m_BlockEntities.begin(); itr != m_BlockEntities.end(); ++itr)
+ {
+ (*itr)->SetWorld(m_World);
+ }
+
// Create block entities that the loader didn't load; fill them with defaults
CreateBlockEntities();
@@ -1015,8 +1021,8 @@ void cChunk::CreateBlockEntities(void)
{
for (int y = 0; y < Height; y++)
{
- ENUM_BLOCK_ID BlockType = (ENUM_BLOCK_ID)cChunkDef::GetBlock(m_BlockTypes, x, y, z);
- switch ( BlockType )
+ BLOCKTYPE BlockType = cChunkDef::GetBlock(m_BlockTypes, x, y, z);
+ switch (BlockType)
{
case E_BLOCK_CHEST:
{
diff --git a/source/Generating/ChunkDesc.cpp b/source/Generating/ChunkDesc.cpp
index f0927f294..68feb463d 100644
--- a/source/Generating/ChunkDesc.cpp
+++ b/source/Generating/ChunkDesc.cpp
@@ -526,6 +526,15 @@ void cChunkDesc::RandomFillRelCuboid(
+void cChunkDesc::AddBlockEntity(cBlockEntity * a_BlockEntity)
+{
+ m_BlockEntities.push_back(a_BlockEntity);
+}
+
+
+
+
+
void cChunkDesc::CompressBlockMetas(cChunkDef::BlockNibbles & a_DestMetas)
{
const NIBBLETYPE * AreaMetas = m_BlockArea.GetBlockMetas();
diff --git a/source/Generating/ChunkDesc.h b/source/Generating/ChunkDesc.h
index 5ec3759a9..a25d0a720 100644
--- a/source/Generating/ChunkDesc.h
+++ b/source/Generating/ChunkDesc.h
@@ -169,6 +169,7 @@ public:
// tolua_end
+ void AddBlockEntity(cBlockEntity * a_BlockEntity);
// Accessors used by cChunkGenerator::Generator descendants:
inline cChunkDef::BiomeMap & GetBiomeMap (void) { return m_BiomeMap; }
diff --git a/source/Generating/MineShafts.cpp b/source/Generating/MineShafts.cpp
index 330a87576..b4c17aa27 100644
--- a/source/Generating/MineShafts.cpp
+++ b/source/Generating/MineShafts.cpp
@@ -19,6 +19,7 @@ in a depth-first processing. Each of the descendants will branch randomly, if no
#include "Globals.h"
#include "MineShafts.h"
#include "../Cuboid.h"
+#include "../ChestEntity.h"
@@ -747,6 +748,22 @@ void cMineShaftCorridor::ProcessChunk(cChunkDesc & a_ChunkDesc)
void cMineShaftCorridor::PlaceChest(cChunkDesc & a_ChunkDesc)
{
+ static const cLootProbab LootProbab[] =
+ {
+ // Item, MinAmount, MaxAmount, Weight
+ { cItem(E_ITEM_IRON), 1, 5, 10 },
+ { cItem(E_ITEM_GOLD), 1, 3, 5 },
+ { cItem(E_ITEM_REDSTONE_DUST), 4, 9, 5 },
+ { cItem(E_ITEM_DIAMOND), 1, 2, 3 },
+ { cItem(E_ITEM_DYE, 1, 4), 4, 9, 5 }, // lapis lazuli dye
+ { cItem(E_ITEM_COAL), 3, 8, 10 },
+ { cItem(E_ITEM_BREAD), 1, 3, 15 },
+ { cItem(E_ITEM_IRON_PICKAXE), 1, 1, 1 },
+ { cItem(E_BLOCK_MINECART_TRACKS), 4, 8, 1 },
+ { cItem(E_ITEM_MELON_SEEDS), 2, 4, 10 },
+ { cItem(E_ITEM_PUMPKIN_SEEDS), 2, 4, 10 },
+ } ;
+
if (m_ChestPosition < 0)
{
return;
@@ -754,40 +771,42 @@ void cMineShaftCorridor::PlaceChest(cChunkDesc & a_ChunkDesc)
int BlockX = a_ChunkDesc.GetChunkX() * cChunkDef::Width;
int BlockZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width;
+ int x, z;
+ NIBBLETYPE Meta = 0;
switch (m_Direction)
{
case dirXM:
case dirXP:
{
- int x = m_BoundingBox.p1.x + m_ChestPosition - BlockX;
- int z = m_BoundingBox.p1.z - BlockZ;
- if (
- (x >= 0) && (x < cChunkDef::Width) &&
- (z >= 0) && (z < cChunkDef::Width)
- )
- {
- a_ChunkDesc.SetBlockTypeMeta(x, m_BoundingBox.p1.y + 1, z, E_BLOCK_CHEST, 0);
- // TODO: Fill the chest with loot
- }
+ x = m_BoundingBox.p1.x + m_ChestPosition - BlockX;
+ z = m_BoundingBox.p1.z - BlockZ;
+ Meta = E_META_CHEST_FACING_ZP;
break;
}
case dirZM:
case dirZP:
{
- int x = m_BoundingBox.p1.x - BlockX;
- int z = m_BoundingBox.p1.z + m_ChestPosition - BlockZ;
- if (
- (x >= 0) && (x < cChunkDef::Width) &&
- (z >= 0) && (z < cChunkDef::Width)
- )
- {
- a_ChunkDesc.SetBlockTypeMeta(x, m_BoundingBox.p1.y + 1, z, E_BLOCK_CHEST, 0);
- // TODO: Fill the chest with loot
- }
+ x = m_BoundingBox.p1.x - BlockX;
+ z = m_BoundingBox.p1.z + m_ChestPosition - BlockZ;
+ Meta = E_META_CHEST_FACING_XP;
break;
}
} // switch (Dir)
+
+ if (
+ (x >= 0) && (x < cChunkDef::Width) &&
+ (z >= 0) && (z < cChunkDef::Width)
+ )
+ {
+ a_ChunkDesc.SetBlockTypeMeta(x, m_BoundingBox.p1.y + 1, z, E_BLOCK_CHEST, Meta);
+ cChestEntity * ChestEntity = new cChestEntity(BlockX + x, m_BoundingBox.p1.y + 1, BlockZ + z);
+ cNoise Noise(a_ChunkDesc.GetChunkX() ^ a_ChunkDesc.GetChunkZ());
+ int NumSlots = 3 + ((Noise.IntNoise3DInt(x, m_BoundingBox.p1.y, z) / 11) % 4);
+ int Seed = Noise.IntNoise2DInt(x, z);
+ ChestEntity->GenerateRandomLootWithBooks(LootProbab, ARRAYCOUNT(LootProbab), NumSlots, Seed);
+ a_ChunkDesc.AddBlockEntity(ChestEntity);
+ }
}
diff --git a/source/Item.h b/source/Item.h
index 2fcef91cf..9384ece22 100644
--- a/source/Item.h
+++ b/source/Item.h
@@ -152,3 +152,17 @@ public:
+
+/// Used to store loot probability tables
+class cLootProbab
+{
+public:
+ cItem m_Item;
+ int m_MinAmount;
+ int m_MaxAmount;
+ int m_Weight;
+} ;
+
+
+
+
diff --git a/source/SignEntity.cpp b/source/SignEntity.cpp
index f2ac4b0b1..0f952426a 100644
--- a/source/SignEntity.cpp
+++ b/source/SignEntity.cpp
@@ -14,7 +14,7 @@
-cSignEntity::cSignEntity(ENUM_BLOCK_ID a_BlockType, int a_X, int a_Y, int a_Z, cWorld * a_World)
+cSignEntity::cSignEntity(BLOCKTYPE a_BlockType, int a_X, int a_Y, int a_Z, cWorld * a_World)
: cBlockEntity(a_BlockType, a_X, a_Y, a_Z, a_World)
{
}
diff --git a/source/SignEntity.h b/source/SignEntity.h
index 6455afbe7..b4e7a141f 100644
--- a/source/SignEntity.h
+++ b/source/SignEntity.h
@@ -17,7 +17,7 @@ class cSignEntity :
public cBlockEntity
{
public:
- cSignEntity(ENUM_BLOCK_ID a_BlockType, int a_X, int a_Y, int a_Z, cWorld * a_World);
+ cSignEntity(BLOCKTYPE a_BlockType, int a_X, int a_Y, int a_Z, cWorld * a_World);
virtual ~cSignEntity();
bool LoadFromJson( const Json::Value& a_Value );