From cc26f1646308a71ea78f0656efa670915e5e7345 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Wed, 10 Apr 2013 19:52:03 +0000 Subject: Added cItemGrid to represent an XY grid of items; converted chests to use cItemGrid. http://forum.mc-server.org/showthread.php?tid=831 git-svn-id: http://mc-server.googlecode.com/svn/trunk@1380 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- VC2008/MCServer.vcproj | 8 + source/AllToLua.pkg | 1 + source/Bindings.cpp | 1057 ++++++++++++++++++++++++---- source/Bindings.h | 2 +- source/ChestEntity.cpp | 86 +-- source/ChestEntity.h | 20 +- source/Generating/MineShafts.cpp | 2 +- source/Item.cpp | 15 + source/Item.h | 3 + source/ItemGrid.cpp | 349 +++++++++ source/ItemGrid.h | 94 +++ source/ManualBindings.cpp | 42 ++ source/UI/SlotArea.cpp | 6 +- source/WorldStorage/NBTChunkSerializer.cpp | 30 +- source/WorldStorage/NBTChunkSerializer.h | 5 + 15 files changed, 1463 insertions(+), 257 deletions(-) create mode 100644 source/ItemGrid.cpp create mode 100644 source/ItemGrid.h diff --git a/VC2008/MCServer.vcproj b/VC2008/MCServer.vcproj index d089ecbab..053f8283f 100644 --- a/VC2008/MCServer.vcproj +++ b/VC2008/MCServer.vcproj @@ -456,6 +456,14 @@ RelativePath="..\source\Item.h" > + + + + diff --git a/source/AllToLua.pkg b/source/AllToLua.pkg index 7a7c54412..f85264fa8 100644 --- a/source/AllToLua.pkg +++ b/source/AllToLua.pkg @@ -38,6 +38,7 @@ $cfile "Server.h" $cfile "World.h" $cfile "Inventory.h" $cfile "Item.h" +$cfile "ItemGrid.h" $cfile "ChestEntity.h" $cfile "WebAdmin.h" $cfile "WebPlugin.h" diff --git a/source/Bindings.cpp b/source/Bindings.cpp index 56195bab8..d88fb39c5 100644 --- a/source/Bindings.cpp +++ b/source/Bindings.cpp @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 04/06/13 23:17:20. +** Generated automatically by tolua++-1.0.92 on 04/10/13 21:35:56. */ #ifndef __cplusplus @@ -37,6 +37,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S); #include "World.h" #include "Inventory.h" #include "Item.h" +#include "ItemGrid.h" #include "ChestEntity.h" #include "WebAdmin.h" #include "WebPlugin.h" @@ -142,6 +143,7 @@ static void tolua_reg_types (lua_State* tolua_S) tolua_usertype(tolua_S,"cCraftingRecipe"); tolua_usertype(tolua_S,"cPlugin_NewLua"); tolua_usertype(tolua_S,"cStringMap"); + tolua_usertype(tolua_S,"cItemGrid"); tolua_usertype(tolua_S,"cBlockArea"); tolua_usertype(tolua_S,"cInventory"); tolua_usertype(tolua_S,"cRoot"); @@ -162,30 +164,30 @@ static void tolua_reg_types (lua_State* tolua_S) tolua_usertype(tolua_S,"Vector3i"); tolua_usertype(tolua_S,"cCraftingRecipes"); tolua_usertype(tolua_S,"Lua__cPlayer"); - tolua_usertype(tolua_S,"cPawn"); + tolua_usertype(tolua_S,"cStairs"); tolua_usertype(tolua_S,"cChestEntity"); tolua_usertype(tolua_S,"cWebAdmin"); tolua_usertype(tolua_S,"cGroupManager"); tolua_usertype(tolua_S,"cBlockEntity"); tolua_usertype(tolua_S,"Lua__cPickup"); - tolua_usertype(tolua_S,"Lua__cEntity"); - tolua_usertype(tolua_S,"cPluginManager"); tolua_usertype(tolua_S,"cWebPlugin"); + tolua_usertype(tolua_S,"cPluginManager"); tolua_usertype(tolua_S,"HTTPRequest"); - tolua_usertype(tolua_S,"cLadder"); tolua_usertype(tolua_S,"HTTPFormData"); + tolua_usertype(tolua_S,"cLadder"); + tolua_usertype(tolua_S,"cWorld"); tolua_usertype(tolua_S,"cEntity"); tolua_usertype(tolua_S,"cIniFile"); - tolua_usertype(tolua_S,"cServer"); + tolua_usertype(tolua_S,"cPlugin"); tolua_usertype(tolua_S,"AStringVector"); tolua_usertype(tolua_S,"cVine"); tolua_usertype(tolua_S,"cPlayer"); tolua_usertype(tolua_S,"cTorch"); tolua_usertype(tolua_S,"cBlockEntityWindowOwner"); - tolua_usertype(tolua_S,"cPlugin"); + tolua_usertype(tolua_S,"cServer"); tolua_usertype(tolua_S,"Lua__cChestEntity"); - tolua_usertype(tolua_S,"cWorld"); - tolua_usertype(tolua_S,"cStairs"); + tolua_usertype(tolua_S,"cPawn"); + tolua_usertype(tolua_S,"Lua__cEntity"); tolua_usertype(tolua_S,"Vector3d"); } @@ -13158,6 +13160,40 @@ static int tolua_AllToLua_cItem_HasDuration00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE +/* method: IsStackableWith of class cItem */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItem_IsStackableWith00 +static int tolua_AllToLua_cItem_IsStackableWith00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cItem",0,&tolua_err) || + (tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"const cItem",0,&tolua_err)) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cItem* self = (cItem*) tolua_tousertype(tolua_S,1,0); + const cItem* a_OtherStack = ((const cItem*) tolua_tousertype(tolua_S,2,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'IsStackableWith'", NULL); +#endif + { + bool tolua_ret = (bool) self->IsStackableWith(*a_OtherStack); + tolua_pushboolean(tolua_S,(bool)tolua_ret); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'IsStackableWith'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + /* method: IsEnchantable of class cItem */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cItem_IsEnchantable00 static int tolua_AllToLua_cItem_IsEnchantable00(lua_State* tolua_S) @@ -13542,323 +13578,1013 @@ 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) +/* method: GetWidth of class cItemGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItemGrid_GetWidth00 +static int tolua_AllToLua_cItemGrid_GetWidth00(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) + !tolua_isusertype(tolua_S,1,"const cItemGrid",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&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)); + const cItemGrid* self = (const cItemGrid*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetWidth'", NULL); +#endif { - cChestEntity* tolua_ret = (cChestEntity*) Mtolua_new((cChestEntity)(a_BlockX,a_BlockY,a_BlockZ)); - tolua_pushusertype(tolua_S,(void*)tolua_ret,"cChestEntity"); + int tolua_ret = (int) self->GetWidth(); + tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); } } return 1; #ifndef TOLUA_RELEASE tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'new'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'GetWidth'.",&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) +/* method: GetHeight of class cItemGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItemGrid_GetHeight00 +static int tolua_AllToLua_cItemGrid_GetHeight00(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) + !tolua_isusertype(tolua_S,1,"const cItemGrid",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&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)); + const cItemGrid* self = (const cItemGrid*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetHeight'", NULL); +#endif { - 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)); + int tolua_ret = (int) self->GetHeight(); + tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); } } return 1; #ifndef TOLUA_RELEASE tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'new'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'GetHeight'.",&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) +/* method: GetNumSlots of class cItemGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItemGrid_GetNumSlots00 +static int tolua_AllToLua_cItemGrid_GetNumSlots00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( - !tolua_isusertype(tolua_S,1,"const cChestEntity",0,&tolua_err) || - !tolua_isnumber(tolua_S,2,0,&tolua_err) || - !tolua_isnoobj(tolua_S,3,&tolua_err) + !tolua_isusertype(tolua_S,1,"const cItemGrid",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) ) goto tolua_lerror; else #endif { - const cChestEntity* self = (const cChestEntity*) tolua_tousertype(tolua_S,1,0); - int a_Slot = ((int) tolua_tonumber(tolua_S,2,0)); + const cItemGrid* self = (const cItemGrid*) tolua_tousertype(tolua_S,1,0); #ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetSlot'", NULL); + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetNumSlots'", NULL); #endif { - const cItem* tolua_ret = (const cItem*) self->GetSlot(a_Slot); - tolua_pushusertype(tolua_S,(void*)tolua_ret,"const cItem"); + int tolua_ret = (int) self->GetNumSlots(); + tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); } } return 1; #ifndef TOLUA_RELEASE tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'GetSlot'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'GetNumSlots'.",&tolua_err); return 0; #endif } #endif //#ifndef TOLUA_DISABLE -/* method: SetSlot of class cChestEntity */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cChestEntity_SetSlot00 -static int tolua_AllToLua_cChestEntity_SetSlot00(lua_State* tolua_S) +/* method: GetSlotNum of class cItemGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItemGrid_GetSlotNum00 +static int tolua_AllToLua_cItemGrid_GetSlotNum00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( - !tolua_isusertype(tolua_S,1,"cChestEntity",0,&tolua_err) || + !tolua_isusertype(tolua_S,1,"const cItemGrid",0,&tolua_err) || !tolua_isnumber(tolua_S,2,0,&tolua_err) || - (tolua_isvaluenil(tolua_S,3,&tolua_err) || !tolua_isusertype(tolua_S,3,"const cItem",0,&tolua_err)) || + !tolua_isnumber(tolua_S,3,0,&tolua_err) || !tolua_isnoobj(tolua_S,4,&tolua_err) ) goto tolua_lerror; else #endif { - cChestEntity* self = (cChestEntity*) tolua_tousertype(tolua_S,1,0); - int a_Slot = ((int) tolua_tonumber(tolua_S,2,0)); - const cItem* a_Item = ((const cItem*) tolua_tousertype(tolua_S,3,0)); + const cItemGrid* self = (const cItemGrid*) tolua_tousertype(tolua_S,1,0); + int a_X = ((int) tolua_tonumber(tolua_S,2,0)); + int a_Y = ((int) tolua_tonumber(tolua_S,3,0)); #ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetSlot'", NULL); + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetSlotNum'", NULL); #endif { - self->SetSlot(a_Slot,*a_Item); + int tolua_ret = (int) self->GetSlotNum(a_X,a_Y); + tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); } } - return 0; + return 1; #ifndef TOLUA_RELEASE tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'SetSlot'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'GetSlotNum'.",&tolua_err); return 0; #endif } #endif //#ifndef TOLUA_DISABLE -/* method: UsedBy of class cChestEntity */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cChestEntity_UsedBy00 -static int tolua_AllToLua_cChestEntity_UsedBy00(lua_State* tolua_S) +/* method: GetItem of class cItemGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItemGrid_GetItem00 +static int tolua_AllToLua_cItemGrid_GetItem00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( - !tolua_isusertype(tolua_S,1,"cChestEntity",0,&tolua_err) || - !tolua_isusertype(tolua_S,2,"cPlayer",0,&tolua_err) || - !tolua_isnoobj(tolua_S,3,&tolua_err) + !tolua_isusertype(tolua_S,1,"const cItemGrid",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnumber(tolua_S,3,0,&tolua_err) || + !tolua_isnoobj(tolua_S,4,&tolua_err) ) goto tolua_lerror; else #endif { - cChestEntity* self = (cChestEntity*) tolua_tousertype(tolua_S,1,0); - cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,2,0)); + const cItemGrid* self = (const cItemGrid*) tolua_tousertype(tolua_S,1,0); + int a_X = ((int) tolua_tonumber(tolua_S,2,0)); + int a_Y = ((int) tolua_tonumber(tolua_S,3,0)); #ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'UsedBy'", NULL); + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetItem'", NULL); #endif { - self->UsedBy(a_Player); + const cItem& tolua_ret = (const cItem&) self->GetItem(a_X,a_Y); + tolua_pushusertype(tolua_S,(void*)&tolua_ret,"const cItem"); } } - return 0; + return 1; #ifndef TOLUA_RELEASE tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'UsedBy'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'GetItem'.",&tolua_err); return 0; #endif } #endif //#ifndef TOLUA_DISABLE -/* get function: __cBlockEntityWindowOwner__ of class cChestEntity */ -#ifndef TOLUA_DISABLE_tolua_get_cChestEntity___cBlockEntityWindowOwner__ -static int tolua_get_cChestEntity___cBlockEntityWindowOwner__(lua_State* tolua_S) +/* method: GetItem of class cItemGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItemGrid_GetItem01 +static int tolua_AllToLua_cItemGrid_GetItem01(lua_State* tolua_S) { - cChestEntity* self = (cChestEntity*) tolua_tousertype(tolua_S,1,0); + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cItemGrid",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnumber(tolua_S,3,0,&tolua_err) || + !tolua_isnoobj(tolua_S,4,&tolua_err) + ) + goto tolua_lerror; + else + { + cItemGrid* self = (cItemGrid*) tolua_tousertype(tolua_S,1,0); + int a_X = ((int) tolua_tonumber(tolua_S,2,0)); + int a_Y = ((int) tolua_tonumber(tolua_S,3,0)); #ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable '__cBlockEntityWindowOwner__'",NULL); -#endif -#ifdef __cplusplus - tolua_pushusertype(tolua_S,(void*)static_cast(self), "cBlockEntityWindowOwner"); -#else - tolua_pushusertype(tolua_S,(void*)((cBlockEntityWindowOwner*)self), "cBlockEntityWindowOwner"); + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetItem'", NULL); #endif + { + cItem& tolua_ret = (cItem&) self->GetItem(a_X,a_Y); + tolua_pushusertype(tolua_S,(void*)&tolua_ret,"cItem"); + } + } return 1; +tolua_lerror: + return tolua_AllToLua_cItemGrid_GetItem00(tolua_S); } #endif //#ifndef TOLUA_DISABLE - class Lua__cChestEntity : public cChestEntity, public ToluaBase { -public: - void UsedBy( cPlayer* a_Player) { - if (push_method("UsedBy", tolua_AllToLua_cChestEntity_UsedBy00)) { - tolua_pushusertype(lua_state, (void*)a_Player, "cPlayer"); - ToluaBase::dbcall(lua_state, 2, 0); - } else { - return ( void ) cChestEntity:: UsedBy(a_Player); - }; - }; - - 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 */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cChestEntity_tolua__set_instance00 -static int tolua_AllToLua_Lua__cChestEntity_tolua__set_instance00(lua_State* tolua_S) +/* method: GetItem of class cItemGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItemGrid_GetItem02 +static int tolua_AllToLua_cItemGrid_GetItem02(lua_State* tolua_S) { -#ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( - !tolua_isusertype(tolua_S,1,"Lua__cChestEntity",0,&tolua_err) || + !tolua_isusertype(tolua_S,1,"const cItemGrid",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || !tolua_isnoobj(tolua_S,3,&tolua_err) ) goto tolua_lerror; else -#endif { - Lua__cChestEntity* self = (Lua__cChestEntity*) tolua_tousertype(tolua_S,1,0); - lua_State* L = tolua_S; - lua_Object lo = ((lua_Object) tolua_tovalue(tolua_S,2,0)); + const cItemGrid* self = (const cItemGrid*) tolua_tousertype(tolua_S,1,0); + int a_SlotNum = ((int) tolua_tonumber(tolua_S,2,0)); #ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'tolua__set_instance'", NULL); + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetItem'", NULL); #endif { - self->tolua__set_instance(L,lo); + const cItem& tolua_ret = (const cItem&) self->GetItem(a_SlotNum); + tolua_pushusertype(tolua_S,(void*)&tolua_ret,"const cItem"); } } - return 0; -#ifndef TOLUA_RELEASE - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'tolua__set_instance'.",&tolua_err); - return 0; -#endif + return 1; +tolua_lerror: + return tolua_AllToLua_cItemGrid_GetItem01(tolua_S); } #endif //#ifndef TOLUA_DISABLE -/* method: cChestEntity__UsedBy of class Lua__cChestEntity */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cChestEntity_cChestEntity__UsedBy00 -static int tolua_AllToLua_Lua__cChestEntity_cChestEntity__UsedBy00(lua_State* tolua_S) +/* method: GetItem of class cItemGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItemGrid_GetItem03 +static int tolua_AllToLua_cItemGrid_GetItem03(lua_State* tolua_S) { -#ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( - !tolua_isusertype(tolua_S,1,"Lua__cChestEntity",0,&tolua_err) || - !tolua_isusertype(tolua_S,2,"cPlayer",0,&tolua_err) || + !tolua_isusertype(tolua_S,1,"cItemGrid",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || !tolua_isnoobj(tolua_S,3,&tolua_err) ) goto tolua_lerror; else -#endif { - Lua__cChestEntity* self = (Lua__cChestEntity*) tolua_tousertype(tolua_S,1,0); - cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,2,0)); + cItemGrid* self = (cItemGrid*) tolua_tousertype(tolua_S,1,0); + int a_SlotNum = ((int) tolua_tonumber(tolua_S,2,0)); #ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cChestEntity__UsedBy'", NULL); + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetItem'", NULL); #endif { - self->cChestEntity__UsedBy(a_Player); + cItem& tolua_ret = (cItem&) self->GetItem(a_SlotNum); + tolua_pushusertype(tolua_S,(void*)&tolua_ret,"cItem"); } } - return 0; -#ifndef TOLUA_RELEASE - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'cChestEntity__UsedBy'.",&tolua_err); - return 0; -#endif + return 1; +tolua_lerror: + return tolua_AllToLua_cItemGrid_GetItem02(tolua_S); } #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) +/* method: SetItem of class cItemGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItemGrid_SetItem00 +static int tolua_AllToLua_cItemGrid_SetItem00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( - !tolua_isusertable(tolua_S,1,"Lua__cChestEntity",0,&tolua_err) || + !tolua_isusertype(tolua_S,1,"cItemGrid",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_isvaluenil(tolua_S,4,&tolua_err) || !tolua_isusertype(tolua_S,4,"const cItem",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)); + cItemGrid* self = (cItemGrid*) tolua_tousertype(tolua_S,1,0); + int a_X = ((int) tolua_tonumber(tolua_S,2,0)); + int a_Y = ((int) tolua_tonumber(tolua_S,3,0)); + const cItem* a_Item = ((const cItem*) tolua_tousertype(tolua_S,4,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetItem'", NULL); +#endif { - 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"); + self->SetItem(a_X,a_Y,*a_Item); } } - return 1; + return 0; #ifndef TOLUA_RELEASE tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'new'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'SetItem'.",&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) +/* method: SetItem of class cItemGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItemGrid_SetItem01 +static int tolua_AllToLua_cItemGrid_SetItem01(lua_State* tolua_S) { -#ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( - !tolua_isusertable(tolua_S,1,"Lua__cChestEntity",0,&tolua_err) || + !tolua_isusertype(tolua_S,1,"cItemGrid",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) + !tolua_isnumber(tolua_S,5,0,&tolua_err) || + !tolua_isnumber(tolua_S,6,0,&tolua_err) || + !tolua_isnoobj(tolua_S,7,&tolua_err) + ) + goto tolua_lerror; + else + { + cItemGrid* self = (cItemGrid*) tolua_tousertype(tolua_S,1,0); + int a_X = ((int) tolua_tonumber(tolua_S,2,0)); + int a_Y = ((int) tolua_tonumber(tolua_S,3,0)); + short a_ItemType = ((short) tolua_tonumber(tolua_S,4,0)); + char a_ItemCount = ((char) tolua_tonumber(tolua_S,5,0)); + short a_ItemDamage = ((short) tolua_tonumber(tolua_S,6,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetItem'", NULL); +#endif + { + self->SetItem(a_X,a_Y,a_ItemType,a_ItemCount,a_ItemDamage); + } + } + return 0; +tolua_lerror: + return tolua_AllToLua_cItemGrid_SetItem00(tolua_S); +} +#endif //#ifndef TOLUA_DISABLE + +/* method: SetItem of class cItemGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItemGrid_SetItem02 +static int tolua_AllToLua_cItemGrid_SetItem02(lua_State* tolua_S) +{ + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cItemGrid",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + (tolua_isvaluenil(tolua_S,3,&tolua_err) || !tolua_isusertype(tolua_S,3,"const cItem",0,&tolua_err)) || + !tolua_isnoobj(tolua_S,4,&tolua_err) + ) + goto tolua_lerror; + else + { + cItemGrid* self = (cItemGrid*) tolua_tousertype(tolua_S,1,0); + int a_SlotNum = ((int) tolua_tonumber(tolua_S,2,0)); + const cItem* a_Item = ((const cItem*) tolua_tousertype(tolua_S,3,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetItem'", NULL); +#endif + { + self->SetItem(a_SlotNum,*a_Item); + } + } + return 0; +tolua_lerror: + return tolua_AllToLua_cItemGrid_SetItem01(tolua_S); +} +#endif //#ifndef TOLUA_DISABLE + +/* method: SetItem of class cItemGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItemGrid_SetItem03 +static int tolua_AllToLua_cItemGrid_SetItem03(lua_State* tolua_S) +{ + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cItemGrid",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_isnumber(tolua_S,5,0,&tolua_err) || + !tolua_isnoobj(tolua_S,6,&tolua_err) + ) + goto tolua_lerror; + else + { + cItemGrid* self = (cItemGrid*) tolua_tousertype(tolua_S,1,0); + int a_SlotNum = ((int) tolua_tonumber(tolua_S,2,0)); + short a_ItemType = ((short) tolua_tonumber(tolua_S,3,0)); + char a_ItemCount = ((char) tolua_tonumber(tolua_S,4,0)); + short a_ItemDamage = ((short) tolua_tonumber(tolua_S,5,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetItem'", NULL); +#endif + { + self->SetItem(a_SlotNum,a_ItemType,a_ItemCount,a_ItemDamage); + } + } + return 0; +tolua_lerror: + return tolua_AllToLua_cItemGrid_SetItem02(tolua_S); +} +#endif //#ifndef TOLUA_DISABLE + +/* method: Clear of class cItemGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItemGrid_Clear00 +static int tolua_AllToLua_cItemGrid_Clear00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cItemGrid",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cItemGrid* self = (cItemGrid*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Clear'", NULL); +#endif + { + self->Clear(); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'Clear'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: HowManyCanFit of class cItemGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItemGrid_HowManyCanFit00 +static int tolua_AllToLua_cItemGrid_HowManyCanFit00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cItemGrid",0,&tolua_err) || + (tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"const cItem",0,&tolua_err)) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cItemGrid* self = (cItemGrid*) tolua_tousertype(tolua_S,1,0); + const cItem* a_ItemStack = ((const cItem*) tolua_tousertype(tolua_S,2,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'HowManyCanFit'", NULL); +#endif + { + int tolua_ret = (int) self->HowManyCanFit(*a_ItemStack); + tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'HowManyCanFit'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: AddItem of class cItemGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItemGrid_AddItem00 +static int tolua_AllToLua_cItemGrid_AddItem00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cItemGrid",0,&tolua_err) || + (tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"cItem",0,&tolua_err)) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cItemGrid* self = (cItemGrid*) tolua_tousertype(tolua_S,1,0); + cItem* a_ItemStack = ((cItem*) tolua_tousertype(tolua_S,2,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'AddItem'", NULL); +#endif + { + bool tolua_ret = (bool) self->AddItem(*a_ItemStack); + tolua_pushboolean(tolua_S,(bool)tolua_ret); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'AddItem'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: AddItems of class cItemGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItemGrid_AddItems00 +static int tolua_AllToLua_cItemGrid_AddItems00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cItemGrid",0,&tolua_err) || + (tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"cItems",0,&tolua_err)) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cItemGrid* self = (cItemGrid*) tolua_tousertype(tolua_S,1,0); + cItems* a_ItemStackList = ((cItems*) tolua_tousertype(tolua_S,2,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'AddItems'", NULL); +#endif + { + bool tolua_ret = (bool) self->AddItems(*a_ItemStackList); + tolua_pushboolean(tolua_S,(bool)tolua_ret); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'AddItems'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: GetFirstEmptySlot of class cItemGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItemGrid_GetFirstEmptySlot00 +static int tolua_AllToLua_cItemGrid_GetFirstEmptySlot00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"const cItemGrid",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + const cItemGrid* self = (const cItemGrid*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetFirstEmptySlot'", NULL); +#endif + { + int tolua_ret = (int) self->GetFirstEmptySlot(); + tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'GetFirstEmptySlot'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: GetLastEmptySlot of class cItemGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItemGrid_GetLastEmptySlot00 +static int tolua_AllToLua_cItemGrid_GetLastEmptySlot00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"const cItemGrid",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + const cItemGrid* self = (const cItemGrid*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetLastEmptySlot'", NULL); +#endif + { + int tolua_ret = (int) self->GetLastEmptySlot(); + tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'GetLastEmptySlot'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: GetNextEmptySlot of class cItemGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItemGrid_GetNextEmptySlot00 +static int tolua_AllToLua_cItemGrid_GetNextEmptySlot00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"const cItemGrid",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + const cItemGrid* self = (const cItemGrid*) tolua_tousertype(tolua_S,1,0); + int a_StartFrom = ((int) tolua_tonumber(tolua_S,2,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetNextEmptySlot'", NULL); +#endif + { + int tolua_ret = (int) self->GetNextEmptySlot(a_StartFrom); + tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'GetNextEmptySlot'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: CopyToItems of class cItemGrid */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItemGrid_CopyToItems00 +static int tolua_AllToLua_cItemGrid_CopyToItems00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"const cItemGrid",0,&tolua_err) || + (tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"cItems",0,&tolua_err)) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + const cItemGrid* self = (const cItemGrid*) tolua_tousertype(tolua_S,1,0); + cItems* a_Items = ((cItems*) tolua_tousertype(tolua_S,2,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'CopyToItems'", NULL); +#endif + { + self->CopyToItems(*a_Items); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'CopyToItems'.",&tolua_err); + return 0; +#endif +} +#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) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"const cChestEntity",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + const cChestEntity* self = (const cChestEntity*) tolua_tousertype(tolua_S,1,0); + int a_Slot = ((int) tolua_tonumber(tolua_S,2,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetSlot'", NULL); +#endif + { + const cItem& tolua_ret = (const cItem&) self->GetSlot(a_Slot); + tolua_pushusertype(tolua_S,(void*)&tolua_ret,"const cItem"); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'GetSlot'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: SetSlot of class cChestEntity */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cChestEntity_SetSlot00 +static int tolua_AllToLua_cChestEntity_SetSlot00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cChestEntity",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + (tolua_isvaluenil(tolua_S,3,&tolua_err) || !tolua_isusertype(tolua_S,3,"const cItem",0,&tolua_err)) || + !tolua_isnoobj(tolua_S,4,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cChestEntity* self = (cChestEntity*) tolua_tousertype(tolua_S,1,0); + int a_Slot = ((int) tolua_tonumber(tolua_S,2,0)); + const cItem* a_Item = ((const cItem*) tolua_tousertype(tolua_S,3,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetSlot'", NULL); +#endif + { + self->SetSlot(a_Slot,*a_Item); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'SetSlot'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: UsedBy of class cChestEntity */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cChestEntity_UsedBy00 +static int tolua_AllToLua_cChestEntity_UsedBy00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cChestEntity",0,&tolua_err) || + !tolua_isusertype(tolua_S,2,"cPlayer",0,&tolua_err) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cChestEntity* self = (cChestEntity*) tolua_tousertype(tolua_S,1,0); + cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,2,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'UsedBy'", NULL); +#endif + { + self->UsedBy(a_Player); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'UsedBy'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: GetContents of class cChestEntity */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cChestEntity_GetContents00 +static int tolua_AllToLua_cChestEntity_GetContents00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cChestEntity",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cChestEntity* self = (cChestEntity*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetContents'", NULL); +#endif + { + cItemGrid& tolua_ret = (cItemGrid&) self->GetContents(); + tolua_pushusertype(tolua_S,(void*)&tolua_ret,"cItemGrid"); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'GetContents'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* get function: __cBlockEntityWindowOwner__ of class cChestEntity */ +#ifndef TOLUA_DISABLE_tolua_get_cChestEntity___cBlockEntityWindowOwner__ +static int tolua_get_cChestEntity___cBlockEntityWindowOwner__(lua_State* tolua_S) +{ + cChestEntity* self = (cChestEntity*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable '__cBlockEntityWindowOwner__'",NULL); +#endif +#ifdef __cplusplus + tolua_pushusertype(tolua_S,(void*)static_cast(self), "cBlockEntityWindowOwner"); +#else + tolua_pushusertype(tolua_S,(void*)((cBlockEntityWindowOwner*)self), "cBlockEntityWindowOwner"); +#endif + return 1; +} +#endif //#ifndef TOLUA_DISABLE + + class Lua__cChestEntity : public cChestEntity, public ToluaBase { +public: + void UsedBy( cPlayer* a_Player) { + if (push_method("UsedBy", tolua_AllToLua_cChestEntity_UsedBy00)) { + tolua_pushusertype(lua_state, (void*)a_Player, "cPlayer"); + ToluaBase::dbcall(lua_state, 2, 0); + } else { + return ( void ) cChestEntity:: UsedBy(a_Player); + }; + }; + + 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 */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cChestEntity_tolua__set_instance00 +static int tolua_AllToLua_Lua__cChestEntity_tolua__set_instance00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"Lua__cChestEntity",0,&tolua_err) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + Lua__cChestEntity* self = (Lua__cChestEntity*) tolua_tousertype(tolua_S,1,0); + lua_State* L = tolua_S; + lua_Object lo = ((lua_Object) tolua_tovalue(tolua_S,2,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'tolua__set_instance'", NULL); +#endif + { + self->tolua__set_instance(L,lo); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'tolua__set_instance'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: cChestEntity__UsedBy of class Lua__cChestEntity */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cChestEntity_cChestEntity__UsedBy00 +static int tolua_AllToLua_Lua__cChestEntity_cChestEntity__UsedBy00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"Lua__cChestEntity",0,&tolua_err) || + !tolua_isusertype(tolua_S,2,"cPlayer",0,&tolua_err) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + Lua__cChestEntity* self = (Lua__cChestEntity*) tolua_tousertype(tolua_S,1,0); + cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,2,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cChestEntity__UsedBy'", NULL); +#endif + { + self->cChestEntity__UsedBy(a_Player); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'cChestEntity__UsedBy'.",&tolua_err); + return 0; +#endif +} +#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 @@ -24046,6 +24772,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"GetMaxDuration",tolua_AllToLua_cItem_GetMaxDuration00); tolua_function(tolua_S,"DamageItem",tolua_AllToLua_cItem_DamageItem00); tolua_function(tolua_S,"HasDuration",tolua_AllToLua_cItem_HasDuration00); + tolua_function(tolua_S,"IsStackableWith",tolua_AllToLua_cItem_IsStackableWith00); tolua_function(tolua_S,"IsEnchantable",tolua_AllToLua_cItem_IsEnchantable00); tolua_variable(tolua_S,"m_ItemType",tolua_get_cItem_m_ItemType,tolua_set_cItem_m_ItemType); tolua_variable(tolua_S,"m_ItemCount",tolua_get_cItem_m_ItemCount,tolua_set_cItem_m_ItemCount); @@ -24062,6 +24789,29 @@ 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); + tolua_cclass(tolua_S,"cItemGrid","cItemGrid","",NULL); + tolua_beginmodule(tolua_S,"cItemGrid"); + tolua_function(tolua_S,"GetWidth",tolua_AllToLua_cItemGrid_GetWidth00); + tolua_function(tolua_S,"GetHeight",tolua_AllToLua_cItemGrid_GetHeight00); + tolua_function(tolua_S,"GetNumSlots",tolua_AllToLua_cItemGrid_GetNumSlots00); + tolua_function(tolua_S,"GetSlotNum",tolua_AllToLua_cItemGrid_GetSlotNum00); + tolua_function(tolua_S,"GetItem",tolua_AllToLua_cItemGrid_GetItem00); + tolua_function(tolua_S,"GetItem",tolua_AllToLua_cItemGrid_GetItem01); + tolua_function(tolua_S,"GetItem",tolua_AllToLua_cItemGrid_GetItem02); + tolua_function(tolua_S,"GetItem",tolua_AllToLua_cItemGrid_GetItem03); + tolua_function(tolua_S,"SetItem",tolua_AllToLua_cItemGrid_SetItem00); + tolua_function(tolua_S,"SetItem",tolua_AllToLua_cItemGrid_SetItem01); + tolua_function(tolua_S,"SetItem",tolua_AllToLua_cItemGrid_SetItem02); + tolua_function(tolua_S,"SetItem",tolua_AllToLua_cItemGrid_SetItem03); + tolua_function(tolua_S,"Clear",tolua_AllToLua_cItemGrid_Clear00); + tolua_function(tolua_S,"HowManyCanFit",tolua_AllToLua_cItemGrid_HowManyCanFit00); + tolua_function(tolua_S,"AddItem",tolua_AllToLua_cItemGrid_AddItem00); + tolua_function(tolua_S,"AddItems",tolua_AllToLua_cItemGrid_AddItems00); + tolua_function(tolua_S,"GetFirstEmptySlot",tolua_AllToLua_cItemGrid_GetFirstEmptySlot00); + tolua_function(tolua_S,"GetLastEmptySlot",tolua_AllToLua_cItemGrid_GetLastEmptySlot00); + tolua_function(tolua_S,"GetNextEmptySlot",tolua_AllToLua_cItemGrid_GetNextEmptySlot00); + tolua_function(tolua_S,"CopyToItems",tolua_AllToLua_cItemGrid_CopyToItems00); + tolua_endmodule(tolua_S); #ifdef __cplusplus tolua_cclass(tolua_S,"cChestEntity","cChestEntity","cBlockEntity",tolua_collect_cChestEntity); #else @@ -24074,6 +24824,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) 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_function(tolua_S,"GetContents",tolua_AllToLua_cChestEntity_GetContents00); tolua_variable(tolua_S,"__cBlockEntityWindowOwner__",tolua_get_cChestEntity___cBlockEntityWindowOwner__,NULL); tolua_endmodule(tolua_S); #ifdef __cplusplus diff --git a/source/Bindings.h b/source/Bindings.h index 726dbd1ac..b52c58a1a 100644 --- a/source/Bindings.h +++ b/source/Bindings.h @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 04/06/13 23:17:21. +** Generated automatically by tolua++-1.0.92 on 04/10/13 21:35:56. */ /* Exported function */ diff --git a/source/ChestEntity.cpp b/source/ChestEntity.cpp index d3c062924..aad8844c6 100644 --- a/source/ChestEntity.cpp +++ b/source/ChestEntity.cpp @@ -24,7 +24,8 @@ class cRoot; cChestEntity::cChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ) : - super(E_BLOCK_CHEST, a_BlockX, a_BlockY, a_BlockZ) + super(E_BLOCK_CHEST, a_BlockX, a_BlockY, a_BlockZ), + m_Contents(c_ChestWidth, c_ChestHeight) { cBlockEntityWindowOwner::SetBlockEntity(this); } @@ -34,7 +35,8 @@ cChestEntity::cChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ) : cChestEntity::cChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : - super(E_BLOCK_CHEST, a_BlockX, a_BlockY, a_BlockZ, a_World) + super(E_BLOCK_CHEST, a_BlockX, a_BlockY, a_BlockZ, a_World), + m_Contents(c_ChestWidth, c_ChestHeight) { cBlockEntityWindowOwner::SetBlockEntity(this); } @@ -60,14 +62,8 @@ void cChestEntity::Destroy(void) { // Drop items cItems Pickups; - for (int i = 0; i < c_ChestHeight * c_ChestWidth; ++i) - { - if (!m_Content[i].IsEmpty()) - { - Pickups.push_back(m_Content[i]); - m_Content[i].Empty(); - } - } + m_Contents.CopyToItems(Pickups); + m_Contents.Clear(); m_World->SpawnItemPickups(Pickups, m_PosX, m_PosY, m_PosZ); } @@ -75,67 +71,6 @@ void cChestEntity::Destroy(void) -const cItem * cChestEntity::GetSlot(int a_Slot) const -{ - if ((a_Slot > -1) && (a_Slot < c_ChestHeight * c_ChestWidth)) - { - return &m_Content[a_Slot]; - } - return NULL; -} - - - - - -void cChestEntity::SetSlot(int a_Slot, const cItem & a_Item) -{ - if ((a_Slot > -1) && (a_Slot < c_ChestHeight * c_ChestWidth)) - { - m_Content[a_Slot] = a_Item; - } -} - - - - - -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 -} - - - - - bool cChestEntity::LoadFromJson(const Json::Value & a_Value) { m_PosX = a_Value.get("x", 0).asInt(); @@ -164,16 +99,11 @@ void cChestEntity::SaveToJson(Json::Value & a_Value) a_Value["y"] = m_PosY; a_Value["z"] = m_PosZ; - unsigned int NumSlots = c_ChestHeight*c_ChestWidth; Json::Value AllSlots; - for (unsigned int i = 0; i < NumSlots; i++) + for (int i = m_Contents.GetNumSlots(); i >= 0; i--) { Json::Value Slot; - const cItem * Item = GetSlot(i); - if (Item != NULL) - { - Item->GetJson(Slot); - } + m_Contents.GetItem(i).GetJson(Slot); AllSlots.append(Slot); } a_Value["Slots"] = AllSlots; diff --git a/source/ChestEntity.h b/source/ChestEntity.h index 03102a80b..be8172073 100644 --- a/source/ChestEntity.h +++ b/source/ChestEntity.h @@ -3,6 +3,7 @@ #include "BlockEntity.h" #include "UI/WindowOwner.h" +#include "ItemGrid.h" @@ -15,8 +16,6 @@ namespace Json class cClientHandle; class cServer; -class cItem; -class cLootProbab; class cNBTData; @@ -41,14 +40,11 @@ public: static const char * GetClassStatic() { return "cChestEntity"; } - const cItem * GetSlot(int a_Slot) const; // tolua_export - void SetSlot(int a_Slot, const cItem & a_Item ); // tolua_export + // tolua_begin + const cItem & GetSlot(int a_Slot) const { return m_Contents.GetItem(a_Slot); } + void SetSlot(int a_Slot, const cItem & a_Item ) { m_Contents.SetItem(a_Slot, a_Item); } + // tolua_end - /** 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 ); // cBlockEntity overrides: @@ -59,14 +55,16 @@ public: /// Opens a new chest window for this chests. Scans for neighbors to open a double chest window, if appropriate. void OpenNewWindow(void); - cItem * GetContents(void) { return m_Content; } + const cItemGrid & GetContents(void) const { return m_Contents; } + + cItemGrid & GetContents(void) { return m_Contents; } // tolua_export static const int c_ChestWidth = 9; static const int c_ChestHeight = 3; private: - cItem m_Content[c_ChestWidth * c_ChestHeight]; // TODO: replace this by a generic ItemGridHolder + cItemGrid m_Contents; } ; // tolua_export diff --git a/source/Generating/MineShafts.cpp b/source/Generating/MineShafts.cpp index 4a56b1f4a..fe93cec65 100644 --- a/source/Generating/MineShafts.cpp +++ b/source/Generating/MineShafts.cpp @@ -798,7 +798,7 @@ void cMineShaftCorridor::PlaceChest(cChunkDesc & a_ChunkDesc) 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); + ChestEntity->GetContents().GenerateRandomLootWithBooks(LootProbab, ARRAYCOUNT(LootProbab), NumSlots, Seed); a_ChunkDesc.AddBlockEntity(ChestEntity); } } diff --git a/source/Item.cpp b/source/Item.cpp index 759b23042..b96500a30 100644 --- a/source/Item.cpp +++ b/source/Item.cpp @@ -8,6 +8,21 @@ +bool cItem::IsStackableWith(const cItem & a_OtherStack) +{ + if (a_OtherStack.m_ItemType != m_ItemType) + { + return false; + } + + // TODO: match enchantments etc. + return true; +} + + + + + void cItem::GetJson( Json::Value & a_OutValue ) const { a_OutValue["ID"] = m_ItemType; diff --git a/source/Item.h b/source/Item.h index 9384ece22..194b6bff6 100644 --- a/source/Item.h +++ b/source/Item.h @@ -106,6 +106,9 @@ public: } inline bool HasDuration() { return GetMaxDuration() > 0; } + + /// Returns true if this itemstack can stack with the specified stack (types match, enchantments etc.) ItemCounts are ignored! + bool IsStackableWith(const cItem & a_OtherStack); // tolua_end void GetJson( Json::Value & a_OutValue ) const; diff --git a/source/ItemGrid.cpp b/source/ItemGrid.cpp new file mode 100644 index 000000000..f79bb5537 --- /dev/null +++ b/source/ItemGrid.cpp @@ -0,0 +1,349 @@ + +// ItemGrid.cpp + +// Implements the cItemGrid class representing a storage for items in a XY grid (chests, dispensers, inventory etc.) + +#include "Globals.h" +#include "ItemGrid.h" +#include "Items/ItemHandler.h" +#include "Noise.h" + + + + + +cItemGrid::cItemGrid(int a_Width, int a_Height) : + m_Width(a_Width), + m_Height(a_Height), + m_NumSlots(a_Width * a_Height), + m_Items(new cItem[a_Width * a_Height]) +{ +} + + + + + +cItemGrid::~cItemGrid() +{ + delete[] m_Items; +} + + + + + +int cItemGrid::GetSlotNum(int a_X, int a_Y) const +{ + if ( + (a_X < 0) || (a_X >= m_Width) || + (a_Y < 0) || (a_Y >= m_Height) + ) + { + LOGWARNING("%s: coords out of range: (%d, %d) in grid of size (%d, %d)", + __FUNCTION__, a_X, a_Y, m_Width, m_Height + ); + return -1; + } + return a_X + m_Width * a_Y; +} + + + + + +void cItemGrid::GetSlotCoords(int a_SlotNum, int & a_X, int & a_Y) const +{ + if ((a_SlotNum < 0) || (a_SlotNum >= m_NumSlots)) + { + LOGWARNING("%s: SlotNum out of range: %d in grid of range %d", + __FUNCTION__, a_SlotNum, m_NumSlots + ); + a_X = -1; + a_Y = -1; + return; + } + a_X = a_SlotNum % m_Width; + a_Y = a_SlotNum / m_Width; +} + + + + + +const cItem & cItemGrid::GetItem(int a_X, int a_Y) const +{ + return GetItem(GetSlotNum(a_X, a_Y)); +} + + + + + +cItem & cItemGrid::GetItem(int a_X, int a_Y) +{ + return GetItem(GetSlotNum(a_X, a_Y)); +} + + + + + +const cItem & cItemGrid::GetItem(int a_SlotNum) const +{ + if ((a_SlotNum < 0) || (a_SlotNum >= m_NumSlots)) + { + LOGWARNING("%s: Invalid slot number, %d out of %d slots", + __FUNCTION__, a_SlotNum, m_NumSlots + ); + return m_Items[0]; + } + return m_Items[a_SlotNum]; +} + + + + + +cItem & cItemGrid::GetItem(int a_SlotNum) +{ + if ((a_SlotNum < 0) || (a_SlotNum >= m_NumSlots)) + { + LOGWARNING("%s: Invalid slot number, %d out of %d slots", + __FUNCTION__, a_SlotNum, m_NumSlots + ); + return m_Items[0]; + } + return m_Items[a_SlotNum]; +} + + + + + +void cItemGrid::SetItem(int a_X, int a_Y, const cItem & a_Item) +{ + SetItem(GetSlotNum(a_X, a_Y), a_Item); +} + + + + + +void cItemGrid::SetItem(int a_X, int a_Y, short a_ItemType, char a_ItemCount, short a_ItemDamage) +{ + SetItem(GetSlotNum(a_X, a_Y), cItem(a_ItemType, a_ItemCount, a_ItemDamage)); +} + + + + + +void cItemGrid::SetItem(int a_SlotNum, const cItem & a_Item) +{ + if ((a_SlotNum < 0) || (a_SlotNum >= m_NumSlots)) + { + LOGWARNING("%s: Invalid slot number %d out of %d slots", + __FUNCTION__, a_SlotNum, m_NumSlots + ); + return; + } + m_Items[a_SlotNum] = a_Item; +} + + + + + +void cItemGrid::SetItem(int a_SlotNum, short a_ItemType, char a_ItemCount, short a_ItemDamage) +{ + SetItem(a_SlotNum, cItem(a_ItemType, a_ItemCount, a_ItemDamage)); +} + + + + + +void cItemGrid::Clear(void) +{ + for (int i = 0; i < m_NumSlots; i++) + { + m_Items[i].Empty(); + } +} + + + + + +int cItemGrid::HowManyCanFit(const cItem & a_ItemStack) +{ + char NumLeft = a_ItemStack.m_ItemCount; + int MaxStack = ItemHandler(a_ItemStack.m_ItemType)->GetMaxStackSize(); + for (int i = m_NumSlots - 1; i >= 0; i--) + { + if (m_Items[i].IsEmpty()) + { + NumLeft -= MaxStack; + } + else if (m_Items[i].IsStackableWith(a_ItemStack)) + { + NumLeft -= MaxStack - m_Items[i].m_ItemCount; + } + if (NumLeft <= 0) + { + // All items fit + return a_ItemStack.m_ItemCount; + } + } // for i - m_Items[] + return a_ItemStack.m_ItemCount - NumLeft; +} + + + + + +bool cItemGrid::AddItem(cItem & a_ItemStack) +{ + int NumLeft = a_ItemStack.m_ItemCount; + int MaxStack = ItemHandler(a_ItemStack.m_ItemType)->GetMaxStackSize(); + for (int i = m_NumSlots - 1; i >= 0; i--) + { + if (m_Items[i].IsEmpty()) + { + m_Items[i] = a_ItemStack; + m_Items[i].m_ItemCount = std::min(MaxStack, NumLeft); + NumLeft -= m_Items[i].m_ItemCount; + } + else if (m_Items[i].IsStackableWith(a_ItemStack)) + { + int PrevCount = m_Items[i].m_ItemCount; + m_Items[i].m_ItemCount = std::min(MaxStack, PrevCount + NumLeft); + NumLeft -= m_Items[i].m_ItemCount - PrevCount; + } + if (NumLeft <= 0) + { + // All items fit + return true; + } + } // for i - m_Items[] + return (a_ItemStack.m_ItemCount > NumLeft); +} + + + + + +bool cItemGrid::AddItems(cItems & a_ItemStackList) +{ + bool res; + for (cItems::iterator itr = a_ItemStackList.begin(); itr != a_ItemStackList.end();) + { + res = AddItem(*itr) | res; + if (itr->IsEmpty()) + { + itr = a_ItemStackList.erase(itr); + } + else + { + ++itr; + } + } + return res; +} + + + + + +int cItemGrid::GetFirstEmptySlot(void) const +{ + return GetNextEmptySlot(-1); +} + + + + + +int cItemGrid::GetLastEmptySlot(void) const +{ + for (int i = m_NumSlots - 1; i >= 0; i--) + { + if (m_Items[i].IsEmpty()) + { + return i; + } + } + return -1; +} + + + + + +int cItemGrid::GetNextEmptySlot(int a_StartFrom) const +{ + for (int i = a_StartFrom + 1; i < m_NumSlots; i++) + { + if (m_Items[i].IsEmpty()) + { + return i; + } + } + return -1; +} + + + + + +void cItemGrid::CopyToItems(cItems & a_Items) const +{ + for (int i = 0; i < m_NumSlots; i++) + { + if (!m_Items[i].IsEmpty()) + { + a_Items.push_back(m_Items[i]); + } + } // for i - m_Items[] +} + + + + + +void cItemGrid::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[] + SetItem(Rnd % m_NumSlots, CurrentLoot); + } // for i - NumSlots +} + + + + diff --git a/source/ItemGrid.h b/source/ItemGrid.h new file mode 100644 index 000000000..91eba6f33 --- /dev/null +++ b/source/ItemGrid.h @@ -0,0 +1,94 @@ + +// ItemGrid.h + +// Declares the cItemGrid class representing a storage for items in a XY grid (chests, dispensers, inventory etc.) + + + + +#pragma once + +#include "Item.h" + + + + + +// tolua_begin +class cItemGrid +{ +public: + // tolua_end + cItemGrid(int a_Width, int a_Height); + + ~cItemGrid(); + + // tolua_begin + int GetWidth (void) const { return m_Width; } + 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 + 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 + void GetSlotCoords(int a_SlotNum, int & a_X, int & a_Y) const; + // tolua_begin + + // Retrieve items by coords or slot number; Logs warning and returns the first item on invalid coords / slotnum + const cItem & GetItem(int a_X, int a_Y) const; + cItem & GetItem(int a_X, int a_Y); + const cItem & GetItem(int a_SlotNum) const; + cItem & GetItem(int a_SlotNum); + + // Set item by coords or slot number; Logs warning and doesn't set on invalid coords / slotnum + void SetItem(int a_X, int a_Y, const cItem & a_Item); + void SetItem(int a_X, int a_Y, short a_ItemType, char a_ItemCount, short a_ItemDamage); + void SetItem(int a_SlotNum, const cItem & a_Item); + void SetItem(int a_SlotNum, short a_ItemType, char a_ItemCount, short a_ItemDamage); + + /// Sets all items as empty + void Clear(void); + + /// Returns number of items out of a_ItemStack that can fit in the storage + int HowManyCanFit(const cItem & a_ItemStack); + + /// Adds as many items out of a_ItemStack as can fit; the rest is left in a_ItemStack; returns true if any items fit. + bool AddItem(cItem & a_ItemStack); + + /// Same as AddItem, but works on an entire list of item stacks + bool AddItems(cItems & a_ItemStackList); + + /// Returns the index of the first empty slot; -1 if all full + int GetFirstEmptySlot(void) const; + + /// Returns the index of the last empty slot; -1 if all full + int GetLastEmptySlot(void) const; + + /// Returns the index of the first empty slot following a_StartFrom (a_StartFrom is not checked) + int GetNextEmptySlot(int a_StartFrom) const; + + /// Copies the contents into a cItems object + void CopyToItems(cItems & a_Items) const; + + // tolua_end + + /** 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. + Cannot export to Lua due to raw array a_LootProbabs. + */ + void GenerateRandomLootWithBooks(const cLootProbab * a_LootProbabs, int a_CountLootProbabs, int a_NumSlots, int a_Seed); + + // tolua_begin + +protected: + int m_Width; + int m_Height; + int m_NumSlots; // m_Width * m_Height, for easier validity checking in the access functions + cItem * m_Items; // x + m_Width * y +} ; +// tolua_end + + + diff --git a/source/ManualBindings.cpp b/source/ManualBindings.cpp index 358e582ee..bf8776457 100644 --- a/source/ManualBindings.cpp +++ b/source/ManualBindings.cpp @@ -968,6 +968,10 @@ static int copy_lua_values(lua_State * a_Source, lua_State * a_Destination, int return 1; } + + + + static int tolua_cPlugin_Call(lua_State* tolua_S) { cPlugin_NewLua * self = (cPlugin_NewLua *) tolua_tousertype(tolua_S, 1, 0); @@ -1095,6 +1099,40 @@ static int tolua_get_HTTPRequest_FormData(lua_State* tolua_S) +static int Lua_ItemGrid_GetSlotCoords(lua_State * L) +{ + tolua_Error tolua_err; + if ( + !tolua_isusertype(L, 1, "const cItemGrid", 0, &tolua_err) || + !tolua_isnumber (L, 2, 0, &tolua_err) || + !tolua_isnoobj (L, 3, &tolua_err) + ) + { + goto tolua_lerror; + } + + const cItemGrid * self = (const cItemGrid *)tolua_tousertype(L, 1, 0); + int SlotNum = (int)tolua_tonumber(L, 2, 0); + if (self == NULL) + { + tolua_error(L, "invalid 'self' in function 'cItemGrid:GetSlotCoords'", NULL); + return 0; + } + int X, Y; + self->GetSlotCoords(SlotNum, X, Y); + tolua_pushnumber(L, (lua_Number)X); + tolua_pushnumber(L, (lua_Number)Y); + return 2; + +tolua_lerror: + tolua_error(L, "#ferror in function 'FindKey'.", &tolua_err); + return 0; +} + + + + + void ManualBindings::Bind( lua_State* tolua_S ) { tolua_beginmodule(tolua_S,NULL); @@ -1158,6 +1196,10 @@ void ManualBindings::Bind( lua_State* tolua_S ) tolua_constant(tolua_S, "MAX_VIEW_DISTANCE", cClientHandle::MAX_VIEW_DISTANCE); tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cItemGrid"); + tolua_function(tolua_S, "GetSlotCoords", Lua_ItemGrid_GetSlotCoords); + tolua_endmodule(tolua_S); + tolua_function(tolua_S, "md5", tolua_md5); tolua_endmodule(tolua_S); diff --git a/source/UI/SlotArea.cpp b/source/UI/SlotArea.cpp index 881346c45..dd68f029d 100644 --- a/source/UI/SlotArea.cpp +++ b/source/UI/SlotArea.cpp @@ -224,7 +224,7 @@ cSlotAreaChest::cSlotAreaChest(cChestEntity * a_Chest, cWindow & a_ParentWindow) const cItem * cSlotAreaChest::GetSlot(int a_SlotNum, cPlayer & a_Player) { // a_SlotNum ranges from 0 to 26, use that to index the chest entity's inventory directly: - return m_Chest->GetSlot(a_SlotNum); + return &(m_Chest->GetSlot(a_SlotNum)); } @@ -259,11 +259,11 @@ const cItem * cSlotAreaDoubleChest::GetSlot(int a_SlotNum, cPlayer & a_Player) // a_SlotNum ranges from 0 to 53, use that to index the correct chest's inventory: if (a_SlotNum < 27) { - return m_TopChest->GetSlot(a_SlotNum); + return &(m_TopChest->GetSlot(a_SlotNum)); } else { - return m_BottomChest->GetSlot(a_SlotNum - 27); + return &(m_BottomChest->GetSlot(a_SlotNum - 27)); } } diff --git a/source/WorldStorage/NBTChunkSerializer.cpp b/source/WorldStorage/NBTChunkSerializer.cpp index 992fa7f69..e033bfb9b 100644 --- a/source/WorldStorage/NBTChunkSerializer.cpp +++ b/source/WorldStorage/NBTChunkSerializer.cpp @@ -11,7 +11,7 @@ #include "../SignEntity.h" #include "../NoteEntity.h" #include "../JukeboxEntity.h" -#include "../Item.h" +#include "../ItemGrid.h" #include "../StringCompression.h" #include "../Entity.h" #include "../OSSupport/MakeDir.h" @@ -74,6 +74,24 @@ void cNBTChunkSerializer::AddItem(const cItem & a_Item, int a_Slot, const AStrin +void cNBTChunkSerializer::AddItemGrid(const cItemGrid & a_Grid, int a_BeginSlotNum) +{ + int NumSlots = a_Grid.GetNumSlots(); + for (int i = 0; i < NumSlots; i++) + { + const cItem & Item = a_Grid.GetItem(i); + if (Item.IsEmpty()) + { + continue; + } + AddItem(Item, i + a_BeginSlotNum); + } // for i - chest slots[] +} + + + + + void cNBTChunkSerializer::AddBasicTileEntity(cBlockEntity * a_Entity, const char * a_EntityTypeID) { m_Writer.AddInt ("x", a_Entity->GetPosX()); @@ -91,15 +109,7 @@ void cNBTChunkSerializer::AddChestEntity(cChestEntity * a_Entity) m_Writer.BeginCompound(""); AddBasicTileEntity(a_Entity, "Chest"); m_Writer.BeginList("Items", TAG_Compound); - for (int i = 0; i < cChestEntity::c_ChestHeight * cChestEntity::c_ChestWidth; i++) - { - const cItem * Item = a_Entity->GetSlot(i); - if ((Item == NULL) || Item->IsEmpty()) - { - continue; - } - AddItem(*Item, i); - } // for i - chest slots[] + AddItemGrid(a_Entity->GetContents()); m_Writer.EndList(); m_Writer.EndCompound(); } diff --git a/source/WorldStorage/NBTChunkSerializer.h b/source/WorldStorage/NBTChunkSerializer.h index 78847dbc0..5c59ca490 100644 --- a/source/WorldStorage/NBTChunkSerializer.h +++ b/source/WorldStorage/NBTChunkSerializer.h @@ -31,6 +31,8 @@ class cMinecartWithChest; class cMinecartWithFurnace; class cMonster; class cPickup; +class cItemGrid; + @@ -71,6 +73,9 @@ protected: /// Writes an item into the writer, if slot >= 0, adds the Slot tag. The compound is named as requested. void AddItem(const cItem & a_Item, int a_Slot, const AString & a_CompoundName = ""); + /// Writes an item grid into the writer; begins the stored slot numbers with a_BeginSlotNum + void AddItemGrid(const cItemGrid & a_Grid, int a_BeginSlotNum = 0); + // Block entities: void AddBasicTileEntity(cBlockEntity * a_Entity, const char * a_EntityTypeID); void AddChestEntity(cChestEntity * a_Entity); -- cgit v1.2.3