1
0

Fixed a crash in creative inventory (FS 235, patch submitted by l0udPL)

git-svn-id: http://mc-server.googlecode.com/svn/trunk@722 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2012-08-10 19:01:36 +00:00
parent 521087fc07
commit 6711fcd636
6 changed files with 76 additions and 48 deletions

View File

@ -1,6 +1,6 @@
/* /*
** Lua binding: AllToLua ** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 08/03/12 10:35:41. ** Generated automatically by tolua++-1.0.92 on 08/10/12 20:57:53.
*/ */
#ifndef __cplusplus #ifndef __cplusplus
@ -6461,7 +6461,9 @@ static int tolua_AllToLua_cPlayer_TossItem00(lua_State* tolua_S)
!tolua_isusertype(tolua_S,1,"cPlayer",0,&tolua_err) || !tolua_isusertype(tolua_S,1,"cPlayer",0,&tolua_err) ||
!tolua_isboolean(tolua_S,2,0,&tolua_err) || !tolua_isboolean(tolua_S,2,0,&tolua_err) ||
!tolua_isnumber(tolua_S,3,1,&tolua_err) || !tolua_isnumber(tolua_S,3,1,&tolua_err) ||
!tolua_isnoobj(tolua_S,4,&tolua_err) !tolua_isnumber(tolua_S,4,1,&tolua_err) ||
!tolua_isnumber(tolua_S,5,1,&tolua_err) ||
!tolua_isnoobj(tolua_S,6,&tolua_err)
) )
goto tolua_lerror; goto tolua_lerror;
else else
@ -6470,11 +6472,13 @@ static int tolua_AllToLua_cPlayer_TossItem00(lua_State* tolua_S)
cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0); cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0);
bool a_bDraggingItem = ((bool) tolua_toboolean(tolua_S,2,0)); bool a_bDraggingItem = ((bool) tolua_toboolean(tolua_S,2,0));
int a_Amount = ((int) tolua_tonumber(tolua_S,3,1)); int a_Amount = ((int) tolua_tonumber(tolua_S,3,1));
int a_CreateType = ((int) tolua_tonumber(tolua_S,4,0));
int a_CreateHealth = ((int) tolua_tonumber(tolua_S,5,0));
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'TossItem'", NULL); if (!self) tolua_error(tolua_S,"invalid 'self' in function 'TossItem'", NULL);
#endif #endif
{ {
self->TossItem(a_bDraggingItem,a_Amount); self->TossItem(a_bDraggingItem,a_Amount,a_CreateType,a_CreateHealth);
} }
} }
return 0; return 0;
@ -7880,7 +7884,7 @@ static int tolua_AllToLua_cPlugin_OnChunkGenerating00(lua_State* tolua_S)
#endif #endif
{ {
cPlugin* self = (cPlugin*) tolua_tousertype(tolua_S,1,0); cPlugin* self = (cPlugin*) tolua_tousertype(tolua_S,1,0);
cWorld* a_Wordl = ((cWorld*) tolua_tousertype(tolua_S,2,0)); cWorld* a_World = ((cWorld*) tolua_tousertype(tolua_S,2,0));
int a_ChunkX = ((int) tolua_tonumber(tolua_S,3,0)); int a_ChunkX = ((int) tolua_tonumber(tolua_S,3,0));
int a_ChunkZ = ((int) tolua_tonumber(tolua_S,4,0)); int a_ChunkZ = ((int) tolua_tonumber(tolua_S,4,0));
cLuaChunk* a_pLuaChunk = ((cLuaChunk*) tolua_tousertype(tolua_S,5,0)); cLuaChunk* a_pLuaChunk = ((cLuaChunk*) tolua_tousertype(tolua_S,5,0));
@ -7888,7 +7892,7 @@ static int tolua_AllToLua_cPlugin_OnChunkGenerating00(lua_State* tolua_S)
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'OnChunkGenerating'", NULL); if (!self) tolua_error(tolua_S,"invalid 'self' in function 'OnChunkGenerating'", NULL);
#endif #endif
{ {
bool tolua_ret = (bool) self->OnChunkGenerating(a_Wordl,a_ChunkX,a_ChunkZ,a_pLuaChunk); bool tolua_ret = (bool) self->OnChunkGenerating(a_World,a_ChunkX,a_ChunkZ,a_pLuaChunk);
tolua_pushboolean(tolua_S,(bool)tolua_ret); tolua_pushboolean(tolua_S,(bool)tolua_ret);
} }
} }
@ -8433,9 +8437,9 @@ static int tolua_AllToLua_cPlugin_AddCommand00(lua_State* tolua_S)
#endif #endif
{ {
cPlugin* self = (cPlugin*) tolua_tousertype(tolua_S,1,0); cPlugin* self = (cPlugin*) tolua_tousertype(tolua_S,1,0);
std::string a_Command = ((std::string) tolua_tocppstring(tolua_S,2,0)); const AString a_Command = ((const AString) tolua_tocppstring(tolua_S,2,0));
std::string a_Description = ((std::string) tolua_tocppstring(tolua_S,3,0)); const AString a_Description = ((const AString) tolua_tocppstring(tolua_S,3,0));
std::string a_Permission = ((std::string) tolua_tocppstring(tolua_S,4,0)); const AString a_Permission = ((const AString) tolua_tocppstring(tolua_S,4,0));
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'AddCommand'", NULL); if (!self) tolua_error(tolua_S,"invalid 'self' in function 'AddCommand'", NULL);
#endif #endif
@ -8618,9 +8622,9 @@ public:
return ( void ) cPlugin:: OnChunkGenerated(a_World,a_ChunkX,a_ChunkZ); return ( void ) cPlugin:: OnChunkGenerated(a_World,a_ChunkX,a_ChunkZ);
}; };
}; };
bool OnChunkGenerating( cWorld* a_Wordl, int a_ChunkX, int a_ChunkZ, cLuaChunk* a_pLuaChunk) { bool OnChunkGenerating( cWorld* a_World, int a_ChunkX, int a_ChunkZ, cLuaChunk* a_pLuaChunk) {
if (push_method("OnChunkGenerating", tolua_AllToLua_cPlugin_OnChunkGenerating00)) { if (push_method("OnChunkGenerating", tolua_AllToLua_cPlugin_OnChunkGenerating00)) {
tolua_pushusertype(lua_state, (void*)a_Wordl, "cWorld"); tolua_pushusertype(lua_state, (void*)a_World, "cWorld");
tolua_pushnumber(lua_state, (lua_Number)a_ChunkX); tolua_pushnumber(lua_state, (lua_Number)a_ChunkX);
tolua_pushnumber(lua_state, (lua_Number)a_ChunkZ); tolua_pushnumber(lua_state, (lua_Number)a_ChunkZ);
tolua_pushusertype(lua_state, (void*)a_pLuaChunk, "cLuaChunk"); tolua_pushusertype(lua_state, (void*)a_pLuaChunk, "cLuaChunk");
@ -8629,7 +8633,7 @@ public:
lua_pop(lua_state, 1); lua_pop(lua_state, 1);
return tolua_ret; return tolua_ret;
} else { } else {
return ( bool ) cPlugin:: OnChunkGenerating(a_Wordl,a_ChunkX,a_ChunkZ,a_pLuaChunk); return ( bool ) cPlugin:: OnChunkGenerating(a_World,a_ChunkX,a_ChunkZ,a_pLuaChunk);
}; };
}; };
bool OnPreCrafting( const cPlayer* a_Player, const cCraftingGrid* a_Grid, cCraftingRecipe* a_Recipe) { bool OnPreCrafting( const cPlayer* a_Player, const cCraftingGrid* a_Grid, cCraftingRecipe* a_Recipe) {
@ -8776,8 +8780,8 @@ public:
void cPlugin__OnChunkGenerated( cWorld* a_World, int a_ChunkX, int a_ChunkZ) { void cPlugin__OnChunkGenerated( cWorld* a_World, int a_ChunkX, int a_ChunkZ) {
return ( void )cPlugin::OnChunkGenerated(a_World,a_ChunkX,a_ChunkZ); return ( void )cPlugin::OnChunkGenerated(a_World,a_ChunkX,a_ChunkZ);
}; };
bool cPlugin__OnChunkGenerating( cWorld* a_Wordl, int a_ChunkX, int a_ChunkZ, cLuaChunk* a_pLuaChunk) { bool cPlugin__OnChunkGenerating( cWorld* a_World, int a_ChunkX, int a_ChunkZ, cLuaChunk* a_pLuaChunk) {
return ( bool )cPlugin::OnChunkGenerating(a_Wordl,a_ChunkX,a_ChunkZ,a_pLuaChunk); return ( bool )cPlugin::OnChunkGenerating(a_World,a_ChunkX,a_ChunkZ,a_pLuaChunk);
}; };
bool cPlugin__OnPreCrafting( const cPlayer* a_Player, const cCraftingGrid* a_Grid, cCraftingRecipe* a_Recipe) { bool cPlugin__OnPreCrafting( const cPlayer* a_Player, const cCraftingGrid* a_Grid, cCraftingRecipe* a_Recipe) {
return ( bool )cPlugin::OnPreCrafting(a_Player,a_Grid,a_Recipe); return ( bool )cPlugin::OnPreCrafting(a_Player,a_Grid,a_Recipe);
@ -9344,7 +9348,7 @@ static int tolua_AllToLua_Lua__cPlugin_cPlugin__OnChunkGenerating00(lua_State* t
#endif #endif
{ {
Lua__cPlugin* self = (Lua__cPlugin*) tolua_tousertype(tolua_S,1,0); Lua__cPlugin* self = (Lua__cPlugin*) tolua_tousertype(tolua_S,1,0);
cWorld* a_Wordl = ((cWorld*) tolua_tousertype(tolua_S,2,0)); cWorld* a_World = ((cWorld*) tolua_tousertype(tolua_S,2,0));
int a_ChunkX = ((int) tolua_tonumber(tolua_S,3,0)); int a_ChunkX = ((int) tolua_tonumber(tolua_S,3,0));
int a_ChunkZ = ((int) tolua_tonumber(tolua_S,4,0)); int a_ChunkZ = ((int) tolua_tonumber(tolua_S,4,0));
cLuaChunk* a_pLuaChunk = ((cLuaChunk*) tolua_tousertype(tolua_S,5,0)); cLuaChunk* a_pLuaChunk = ((cLuaChunk*) tolua_tousertype(tolua_S,5,0));
@ -9352,7 +9356,7 @@ static int tolua_AllToLua_Lua__cPlugin_cPlugin__OnChunkGenerating00(lua_State* t
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cPlugin__OnChunkGenerating'", NULL); if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cPlugin__OnChunkGenerating'", NULL);
#endif #endif
{ {
bool tolua_ret = (bool) self->cPlugin__OnChunkGenerating(a_Wordl,a_ChunkX,a_ChunkZ,a_pLuaChunk); bool tolua_ret = (bool) self->cPlugin__OnChunkGenerating(a_World,a_ChunkX,a_ChunkZ,a_pLuaChunk);
tolua_pushboolean(tolua_S,(bool)tolua_ret); tolua_pushboolean(tolua_S,(bool)tolua_ret);
} }
} }
@ -10043,9 +10047,9 @@ public:
return ( void ) cPlugin_NewLua:: OnChunkGenerated(a_World,a_ChunkX,a_ChunkZ); return ( void ) cPlugin_NewLua:: OnChunkGenerated(a_World,a_ChunkX,a_ChunkZ);
}; };
}; };
bool OnChunkGenerating( cWorld* a_Wordl, int a_ChunkX, int a_ChunkZ, cLuaChunk* a_pLuaChunk) { bool OnChunkGenerating( cWorld* a_World, int a_ChunkX, int a_ChunkZ, cLuaChunk* a_pLuaChunk) {
if (push_method("OnChunkGenerating", tolua_AllToLua_cPlugin_OnChunkGenerating00)) { if (push_method("OnChunkGenerating", tolua_AllToLua_cPlugin_OnChunkGenerating00)) {
tolua_pushusertype(lua_state, (void*)a_Wordl, "cWorld"); tolua_pushusertype(lua_state, (void*)a_World, "cWorld");
tolua_pushnumber(lua_state, (lua_Number)a_ChunkX); tolua_pushnumber(lua_state, (lua_Number)a_ChunkX);
tolua_pushnumber(lua_state, (lua_Number)a_ChunkZ); tolua_pushnumber(lua_state, (lua_Number)a_ChunkZ);
tolua_pushusertype(lua_state, (void*)a_pLuaChunk, "cLuaChunk"); tolua_pushusertype(lua_state, (void*)a_pLuaChunk, "cLuaChunk");
@ -10054,7 +10058,7 @@ public:
lua_pop(lua_state, 1); lua_pop(lua_state, 1);
return tolua_ret; return tolua_ret;
} else { } else {
return ( bool ) cPlugin_NewLua:: OnChunkGenerating(a_Wordl,a_ChunkX,a_ChunkZ,a_pLuaChunk); return ( bool ) cPlugin_NewLua:: OnChunkGenerating(a_World,a_ChunkX,a_ChunkZ,a_pLuaChunk);
}; };
}; };
bool OnPreCrafting( const cPlayer* a_Player, const cCraftingGrid* a_Grid, cCraftingRecipe* a_Recipe) { bool OnPreCrafting( const cPlayer* a_Player, const cCraftingGrid* a_Grid, cCraftingRecipe* a_Recipe) {
@ -10204,8 +10208,8 @@ public:
void cPlugin_NewLua__OnChunkGenerated( cWorld* a_World, int a_ChunkX, int a_ChunkZ) { void cPlugin_NewLua__OnChunkGenerated( cWorld* a_World, int a_ChunkX, int a_ChunkZ) {
return ( void )cPlugin_NewLua::OnChunkGenerated(a_World,a_ChunkX,a_ChunkZ); return ( void )cPlugin_NewLua::OnChunkGenerated(a_World,a_ChunkX,a_ChunkZ);
}; };
bool cPlugin_NewLua__OnChunkGenerating( cWorld* a_Wordl, int a_ChunkX, int a_ChunkZ, cLuaChunk* a_pLuaChunk) { bool cPlugin_NewLua__OnChunkGenerating( cWorld* a_World, int a_ChunkX, int a_ChunkZ, cLuaChunk* a_pLuaChunk) {
return ( bool )cPlugin_NewLua::OnChunkGenerating(a_Wordl,a_ChunkX,a_ChunkZ,a_pLuaChunk); return ( bool )cPlugin_NewLua::OnChunkGenerating(a_World,a_ChunkX,a_ChunkZ,a_pLuaChunk);
}; };
bool cPlugin_NewLua__OnPreCrafting( const cPlayer* a_Player, const cCraftingGrid* a_Grid, cCraftingRecipe* a_Recipe) { bool cPlugin_NewLua__OnPreCrafting( const cPlayer* a_Player, const cCraftingGrid* a_Grid, cCraftingRecipe* a_Recipe) {
return ( bool )cPlugin_NewLua::OnPreCrafting(a_Player,a_Grid,a_Recipe); return ( bool )cPlugin_NewLua::OnPreCrafting(a_Player,a_Grid,a_Recipe);

View File

@ -1,6 +1,6 @@
/* /*
** Lua binding: AllToLua ** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 08/03/12 10:35:42. ** Generated automatically by tolua++-1.0.92 on 08/10/12 20:57:53.
*/ */
/* Exported function */ /* Exported function */

View File

@ -28,8 +28,20 @@ void cCreativeInventory::Clicked( cPacket* a_ClickPacket )
{ {
cPacket_CreativeInventoryAction* Packet = reinterpret_cast<cPacket_CreativeInventoryAction *>(a_ClickPacket); cPacket_CreativeInventoryAction* Packet = reinterpret_cast<cPacket_CreativeInventoryAction *>(a_ClickPacket);
short Slot = Packet->m_Slot; short Slot = Packet->m_Slot;
if (Slot == -1)
{
// object thrown out
m_Owner->TossItem(false, Packet->m_Quantity, Packet->m_ItemID, Packet->m_Damage);
return;
}
cItem* SlotItem = &(this->m_Slots[Slot]); if ((Slot < c_HotOffset) || (Slot >= c_NumSlots))
{
LOG("%s: Invalid slot (%d) in CreativeInventoryAction packet. Ignoring...", m_Owner->GetName().c_str(), Slot);
return;
}
cItem * SlotItem = &(this->m_Slots[Slot]);
SlotItem->m_ItemID = (ENUM_ITEM_ID) Packet->m_ItemID; SlotItem->m_ItemID = (ENUM_ITEM_ID) Packet->m_ItemID;
SlotItem->m_ItemHealth = Packet->m_Damage; SlotItem->m_ItemHealth = Packet->m_Damage;

View File

@ -792,9 +792,22 @@ AString cPlayer::GetColor(void) const
void cPlayer::TossItem( bool a_bDraggingItem, int a_Amount /* = 1 */ ) void cPlayer::TossItem(
bool a_bDraggingItem,
int a_Amount /* = 1 */,
int a_CreateType /* = 0 */,
int a_CreateHealth /* = 0 */
)
{ {
cItems Drops; cItems Drops;
if (a_CreateType)
{
// Just create item without touching the inventory (used in creative mode)
Drops.push_back(cItem((ENUM_ITEM_ID)a_CreateType, (char)a_Amount, a_CreateHealth));
}
else
{
// Drop an item from the inventory:
if (a_bDraggingItem) if (a_bDraggingItem)
{ {
cItem * Item = GetInventory().GetWindow()->GetDraggingItem(); cItem * Item = GetInventory().GetWindow()->GetDraggingItem();
@ -821,9 +834,10 @@ void cPlayer::TossItem( bool a_bDraggingItem, int a_Amount /* = 1 */ )
} }
} }
} }
}
float vX = 0, vY = 0, vZ = 0; float vX = 0, vY = 0, vZ = 0;
EulerToVector( -GetRotation(), GetPitch(), vZ, vX, vY ); EulerToVector(-GetRotation(), GetPitch(), vZ, vX, vY);
vY = -vY*2 + 1.f; vY = -vY * 2 + 1.f;
m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY() + 1.6f, GetPosZ(), vX * 2, vY * 2, vZ * 2); m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY() + 1.6f, GetPosZ(), vX * 2, vY * 2, vZ * 2);
} }

View File

@ -79,7 +79,7 @@ public:
AString GetColor(void) const; //tolua_export AString GetColor(void) const; //tolua_export
void TossItem( bool a_bDraggingItem, int a_Amount = 1 ); //tolua_export void TossItem(bool a_bDraggingItem, int a_Amount = 1, int a_CreateType = 0, int a_CreateHealth = 0); //tolua_export
void Heal( int a_Health ); //tolua_export void Heal( int a_Health ); //tolua_export

View File

@ -33,9 +33,9 @@ public:
// 9-35 = inventory // 9-35 = inventory
// 36-44 = Hot bar // 36-44 = Hot bar
char m_RightMouse; // 0 = left 1 = Right mb char m_RightMouse; // 0 = Left 1 = Right mb
short m_NumClicks; // Num clicks short m_NumClicks; // Num clicks
bool m_Bool; // unkown???????????? SHIFT clicked bool m_Bool; // Shift pressed when clicked?
// Below = item // Below = item
short m_ItemID; // if this is -1 the next stuff dont exist short m_ItemID; // if this is -1 the next stuff dont exist
@ -43,8 +43,6 @@ public:
short m_ItemUses; short m_ItemUses;
short m_EnchantNums; short m_EnchantNums;
static const unsigned int c_Size = 1 + 1 + 2 + 1 + 2 + 2; // Minimal size ( +1+1 = max)
}; };