Inventory code cleanup, players can now see each other's armor
git-svn-id: http://mc-server.googlecode.com/svn/trunk@1493 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
8311ee5ec6
commit
90c398a392
@ -1,6 +1,6 @@
|
||||
/*
|
||||
** Lua binding: AllToLua
|
||||
** Generated automatically by tolua++-1.0.92 on 05/12/13 17:56:56.
|
||||
** Generated automatically by tolua++-1.0.92 on 05/19/13 20:19:49.
|
||||
*/
|
||||
|
||||
#ifndef __cplusplus
|
||||
@ -8057,20 +8057,20 @@ static int tolua_AllToLua_cPlayer_GetEquippedItem00(lua_State* tolua_S)
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S,1,"cPlayer",0,&tolua_err) ||
|
||||
!tolua_isusertype(tolua_S,1,"const cPlayer",0,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,2,&tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0);
|
||||
const cPlayer* self = (const cPlayer*) tolua_tousertype(tolua_S,1,0);
|
||||
#ifndef TOLUA_RELEASE
|
||||
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetEquippedItem'", NULL);
|
||||
#endif
|
||||
{
|
||||
cItem& tolua_ret = (cItem&) self->GetEquippedItem();
|
||||
tolua_pushusertype(tolua_S,(void*)&tolua_ret,"cItem");
|
||||
const cItem& tolua_ret = (const cItem&) self->GetEquippedItem();
|
||||
tolua_pushusertype(tolua_S,(void*)&tolua_ret,"const cItem");
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
@ -12664,7 +12664,7 @@ static int tolua_AllToLua_cInventory_GetSlot00(lua_State* tolua_S)
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S,1,"cInventory",0,&tolua_err) ||
|
||||
!tolua_isusertype(tolua_S,1,"const cInventory",0,&tolua_err) ||
|
||||
!tolua_isnumber(tolua_S,2,0,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,3,&tolua_err)
|
||||
)
|
||||
@ -12672,14 +12672,14 @@ static int tolua_AllToLua_cInventory_GetSlot00(lua_State* tolua_S)
|
||||
else
|
||||
#endif
|
||||
{
|
||||
cInventory* self = (cInventory*) tolua_tousertype(tolua_S,1,0);
|
||||
const cInventory* self = (const cInventory*) 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 'GetSlot'", NULL);
|
||||
#endif
|
||||
{
|
||||
cItem* tolua_ret = (cItem*) self->GetSlot(a_SlotNum);
|
||||
tolua_pushusertype(tolua_S,(void*)tolua_ret,"cItem");
|
||||
const cItem& tolua_ret = (const cItem&) self->GetSlot(a_SlotNum);
|
||||
tolua_pushusertype(tolua_S,(void*)&tolua_ret,"const cItem");
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
@ -12691,14 +12691,14 @@ static int tolua_AllToLua_cInventory_GetSlot00(lua_State* tolua_S)
|
||||
}
|
||||
#endif //#ifndef TOLUA_DISABLE
|
||||
|
||||
/* method: GetFromHotBar of class cInventory */
|
||||
#ifndef TOLUA_DISABLE_tolua_AllToLua_cInventory_GetFromHotBar00
|
||||
static int tolua_AllToLua_cInventory_GetFromHotBar00(lua_State* tolua_S)
|
||||
/* method: GetHotBarSlot of class cInventory */
|
||||
#ifndef TOLUA_DISABLE_tolua_AllToLua_cInventory_GetHotBarSlot00
|
||||
static int tolua_AllToLua_cInventory_GetHotBarSlot00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S,1,"cInventory",0,&tolua_err) ||
|
||||
!tolua_isusertype(tolua_S,1,"const cInventory",0,&tolua_err) ||
|
||||
!tolua_isnumber(tolua_S,2,0,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,3,&tolua_err)
|
||||
)
|
||||
@ -12706,20 +12706,20 @@ static int tolua_AllToLua_cInventory_GetFromHotBar00(lua_State* tolua_S)
|
||||
else
|
||||
#endif
|
||||
{
|
||||
cInventory* self = (cInventory*) tolua_tousertype(tolua_S,1,0);
|
||||
const cInventory* self = (const cInventory*) tolua_tousertype(tolua_S,1,0);
|
||||
int a_HotBarSlotNum = ((int) tolua_tonumber(tolua_S,2,0));
|
||||
#ifndef TOLUA_RELEASE
|
||||
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetFromHotBar'", NULL);
|
||||
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetHotBarSlot'", NULL);
|
||||
#endif
|
||||
{
|
||||
cItem* tolua_ret = (cItem*) self->GetFromHotBar(a_HotBarSlotNum);
|
||||
tolua_pushusertype(tolua_S,(void*)tolua_ret,"cItem");
|
||||
const cItem& tolua_ret = (const cItem&) self->GetHotBarSlot(a_HotBarSlotNum);
|
||||
tolua_pushusertype(tolua_S,(void*)&tolua_ret,"const cItem");
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'GetFromHotBar'.",&tolua_err);
|
||||
tolua_error(tolua_S,"#ferror in function 'GetHotBarSlot'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
@ -12732,20 +12732,20 @@ static int tolua_AllToLua_cInventory_GetEquippedItem00(lua_State* tolua_S)
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S,1,"cInventory",0,&tolua_err) ||
|
||||
!tolua_isusertype(tolua_S,1,"const cInventory",0,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,2,&tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
cInventory* self = (cInventory*) tolua_tousertype(tolua_S,1,0);
|
||||
const cInventory* self = (const cInventory*) tolua_tousertype(tolua_S,1,0);
|
||||
#ifndef TOLUA_RELEASE
|
||||
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetEquippedItem'", NULL);
|
||||
#endif
|
||||
{
|
||||
cItem& tolua_ret = (cItem&) self->GetEquippedItem();
|
||||
tolua_pushusertype(tolua_S,(void*)&tolua_ret,"cItem");
|
||||
const cItem& tolua_ret = (const cItem&) self->GetEquippedItem();
|
||||
tolua_pushusertype(tolua_S,(void*)&tolua_ret,"const cItem");
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
@ -12757,9 +12757,79 @@ static int tolua_AllToLua_cInventory_GetEquippedItem00(lua_State* tolua_S)
|
||||
}
|
||||
#endif //#ifndef TOLUA_DISABLE
|
||||
|
||||
/* method: SetEquippedSlot of class cInventory */
|
||||
#ifndef TOLUA_DISABLE_tolua_AllToLua_cInventory_SetEquippedSlot00
|
||||
static int tolua_AllToLua_cInventory_SetEquippedSlot00(lua_State* tolua_S)
|
||||
/* method: SetSlot of class cInventory */
|
||||
#ifndef TOLUA_DISABLE_tolua_AllToLua_cInventory_SetSlot00
|
||||
static int tolua_AllToLua_cInventory_SetSlot00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S,1,"cInventory",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
|
||||
{
|
||||
cInventory* self = (cInventory*) 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 'SetSlot'", NULL);
|
||||
#endif
|
||||
{
|
||||
self->SetSlot(a_SlotNum,*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: SetHotBarSlot of class cInventory */
|
||||
#ifndef TOLUA_DISABLE_tolua_AllToLua_cInventory_SetHotBarSlot00
|
||||
static int tolua_AllToLua_cInventory_SetHotBarSlot00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S,1,"cInventory",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
|
||||
{
|
||||
cInventory* self = (cInventory*) tolua_tousertype(tolua_S,1,0);
|
||||
int a_HotBarSlotNum = ((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 'SetHotBarSlot'", NULL);
|
||||
#endif
|
||||
{
|
||||
self->SetHotBarSlot(a_HotBarSlotNum,*a_Item);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'SetHotBarSlot'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#endif //#ifndef TOLUA_DISABLE
|
||||
|
||||
/* method: SetEquippedSlotNum of class cInventory */
|
||||
#ifndef TOLUA_DISABLE_tolua_AllToLua_cInventory_SetEquippedSlotNum00
|
||||
static int tolua_AllToLua_cInventory_SetEquippedSlotNum00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
@ -12775,24 +12845,24 @@ static int tolua_AllToLua_cInventory_SetEquippedSlot00(lua_State* tolua_S)
|
||||
cInventory* self = (cInventory*) 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 'SetEquippedSlot'", NULL);
|
||||
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetEquippedSlotNum'", NULL);
|
||||
#endif
|
||||
{
|
||||
self->SetEquippedSlot(a_SlotNum);
|
||||
self->SetEquippedSlotNum(a_SlotNum);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'SetEquippedSlot'.",&tolua_err);
|
||||
tolua_error(tolua_S,"#ferror in function 'SetEquippedSlotNum'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#endif //#ifndef TOLUA_DISABLE
|
||||
|
||||
/* method: GetEquippedSlot of class cInventory */
|
||||
#ifndef TOLUA_DISABLE_tolua_AllToLua_cInventory_GetEquippedSlot00
|
||||
static int tolua_AllToLua_cInventory_GetEquippedSlot00(lua_State* tolua_S)
|
||||
/* method: GetEquippedSlotNum of class cInventory */
|
||||
#ifndef TOLUA_DISABLE_tolua_AllToLua_cInventory_GetEquippedSlotNum00
|
||||
static int tolua_AllToLua_cInventory_GetEquippedSlotNum00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
@ -12806,17 +12876,87 @@ static int tolua_AllToLua_cInventory_GetEquippedSlot00(lua_State* tolua_S)
|
||||
{
|
||||
cInventory* self = (cInventory*) tolua_tousertype(tolua_S,1,0);
|
||||
#ifndef TOLUA_RELEASE
|
||||
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetEquippedSlot'", NULL);
|
||||
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetEquippedSlotNum'", NULL);
|
||||
#endif
|
||||
{
|
||||
short tolua_ret = (short) self->GetEquippedSlot();
|
||||
int tolua_ret = (int) self->GetEquippedSlotNum();
|
||||
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'GetEquippedSlot'.",&tolua_err);
|
||||
tolua_error(tolua_S,"#ferror in function 'GetEquippedSlotNum'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#endif //#ifndef TOLUA_DISABLE
|
||||
|
||||
/* method: cInventory::DamageItem of class cInventory */
|
||||
#ifndef TOLUA_DISABLE_tolua_AllToLua_cInventory_cInventory__DamageItem00
|
||||
static int tolua_AllToLua_cInventory_cInventory__DamageItem00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S,1,"cInventory",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
|
||||
{
|
||||
cInventory* self = (cInventory*) tolua_tousertype(tolua_S,1,0);
|
||||
int a_SlotNum = ((int) tolua_tonumber(tolua_S,2,0));
|
||||
short a_Amount = ((short) tolua_tonumber(tolua_S,3,0));
|
||||
#ifndef TOLUA_RELEASE
|
||||
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cInventory::DamageItem'", NULL);
|
||||
#endif
|
||||
{
|
||||
bool tolua_ret = (bool) self->cInventory::DamageItem(a_SlotNum,a_Amount);
|
||||
tolua_pushboolean(tolua_S,(bool)tolua_ret);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'cInventory__DamageItem'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#endif //#ifndef TOLUA_DISABLE
|
||||
|
||||
/* method: DamageEquippedItem of class cInventory */
|
||||
#ifndef TOLUA_DISABLE_tolua_AllToLua_cInventory_DamageEquippedItem00
|
||||
static int tolua_AllToLua_cInventory_DamageEquippedItem00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S,1,"cInventory",0,&tolua_err) ||
|
||||
!tolua_isnumber(tolua_S,2,1,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,3,&tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
cInventory* self = (cInventory*) tolua_tousertype(tolua_S,1,0);
|
||||
short a_Amount = ((short) tolua_tonumber(tolua_S,2,1));
|
||||
#ifndef TOLUA_RELEASE
|
||||
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'DamageEquippedItem'", NULL);
|
||||
#endif
|
||||
{
|
||||
bool tolua_ret = (bool) self->DamageEquippedItem(a_Amount);
|
||||
tolua_pushboolean(tolua_S,(bool)tolua_ret);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'DamageEquippedItem'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
@ -13296,18 +13436,20 @@ static int tolua_AllToLua_cItem_DamageItem00(lua_State* tolua_S)
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S,1,"cItem",0,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,2,&tolua_err)
|
||||
!tolua_isnumber(tolua_S,2,1,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,3,&tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
cItem* self = (cItem*) tolua_tousertype(tolua_S,1,0);
|
||||
short a_Amount = ((short) tolua_tonumber(tolua_S,2,1));
|
||||
#ifndef TOLUA_RELEASE
|
||||
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'DamageItem'", NULL);
|
||||
#endif
|
||||
{
|
||||
bool tolua_ret = (bool) self->DamageItem();
|
||||
bool tolua_ret = (bool) self->DamageItem(a_Amount);
|
||||
tolua_pushboolean(tolua_S,(bool)tolua_ret);
|
||||
}
|
||||
}
|
||||
@ -25037,10 +25179,14 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
|
||||
tolua_function(tolua_S,"AddItemAnyAmount",tolua_AllToLua_cInventory_AddItemAnyAmount00);
|
||||
tolua_function(tolua_S,"RemoveItem",tolua_AllToLua_cInventory_RemoveItem00);
|
||||
tolua_function(tolua_S,"GetSlot",tolua_AllToLua_cInventory_GetSlot00);
|
||||
tolua_function(tolua_S,"GetFromHotBar",tolua_AllToLua_cInventory_GetFromHotBar00);
|
||||
tolua_function(tolua_S,"GetHotBarSlot",tolua_AllToLua_cInventory_GetHotBarSlot00);
|
||||
tolua_function(tolua_S,"GetEquippedItem",tolua_AllToLua_cInventory_GetEquippedItem00);
|
||||
tolua_function(tolua_S,"SetEquippedSlot",tolua_AllToLua_cInventory_SetEquippedSlot00);
|
||||
tolua_function(tolua_S,"GetEquippedSlot",tolua_AllToLua_cInventory_GetEquippedSlot00);
|
||||
tolua_function(tolua_S,"SetSlot",tolua_AllToLua_cInventory_SetSlot00);
|
||||
tolua_function(tolua_S,"SetHotBarSlot",tolua_AllToLua_cInventory_SetHotBarSlot00);
|
||||
tolua_function(tolua_S,"SetEquippedSlotNum",tolua_AllToLua_cInventory_SetEquippedSlotNum00);
|
||||
tolua_function(tolua_S,"GetEquippedSlotNum",tolua_AllToLua_cInventory_GetEquippedSlotNum00);
|
||||
tolua_function(tolua_S,"cInventory__DamageItem",tolua_AllToLua_cInventory_cInventory__DamageItem00);
|
||||
tolua_function(tolua_S,"DamageEquippedItem",tolua_AllToLua_cInventory_DamageEquippedItem00);
|
||||
tolua_function(tolua_S,"GetEquippedHelmet",tolua_AllToLua_cInventory_GetEquippedHelmet00);
|
||||
tolua_function(tolua_S,"GetEquippedChestplate",tolua_AllToLua_cInventory_GetEquippedChestplate00);
|
||||
tolua_function(tolua_S,"GetEquippedLeggings",tolua_AllToLua_cInventory_GetEquippedLeggings00);
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
** Lua binding: AllToLua
|
||||
** Generated automatically by tolua++-1.0.92 on 05/12/13 17:56:56.
|
||||
** Generated automatically by tolua++-1.0.92 on 05/19/13 20:19:50.
|
||||
*/
|
||||
|
||||
/* Exported function */
|
||||
|
@ -641,7 +641,7 @@ void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_Bloc
|
||||
Handler->OnDigging(World, m_Player, a_BlockX, a_BlockY, a_BlockZ);
|
||||
|
||||
cItemHandler * ItemHandler = cItemHandler::GetItemHandler(m_Player->GetEquippedItem());
|
||||
ItemHandler->OnDiggingBlock(World, m_Player, &m_Player->GetEquippedItem(), a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
|
||||
ItemHandler->OnDiggingBlock(World, m_Player, m_Player->GetEquippedItem(), a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
|
||||
|
||||
// Check for clickthrough-blocks:
|
||||
if (a_BlockFace != BLOCK_FACE_NONE)
|
||||
@ -701,7 +701,7 @@ void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_Blo
|
||||
}
|
||||
|
||||
cWorld * World = m_Player->GetWorld();
|
||||
ItemHandler->OnBlockDestroyed(World, m_Player, &m_Player->GetEquippedItem(), a_BlockX, a_BlockY, a_BlockZ);
|
||||
ItemHandler->OnBlockDestroyed(World, m_Player, m_Player->GetEquippedItem(), a_BlockX, a_BlockY, a_BlockZ);
|
||||
|
||||
BlockHandler(a_OldBlock)->OnDestroyedByPlayer(World, m_Player, a_BlockX, a_BlockY, a_BlockZ);
|
||||
World->BroadcastSoundParticleEffect(2001, a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, a_OldBlock, this);
|
||||
@ -738,7 +738,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, c
|
||||
return;
|
||||
}
|
||||
|
||||
cItem & Equipped = m_Player->GetInventory().GetEquippedItem();
|
||||
const cItem & Equipped = m_Player->GetInventory().GetEquippedItem();
|
||||
|
||||
if ((Equipped.m_ItemType != a_HeldItem.m_ItemType) && (a_HeldItem.m_ItemType != -1))
|
||||
{
|
||||
@ -802,7 +802,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, c
|
||||
// A plugin doesn't agree with using the item, abort
|
||||
return;
|
||||
}
|
||||
ItemHandler->OnItemUse(World, m_Player, &Equipped, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
|
||||
ItemHandler->OnItemUse(World, m_Player, Equipped, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
|
||||
PlgMgr->CallHookPlayerUsedItem(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ);
|
||||
}
|
||||
}
|
||||
@ -993,7 +993,7 @@ void cClientHandle::HandleAnimation(char a_Animation)
|
||||
|
||||
void cClientHandle::HandleSlotSelected(short a_SlotNum)
|
||||
{
|
||||
m_Player->GetInventory().SetEquippedSlot(a_SlotNum);
|
||||
m_Player->GetInventory().SetEquippedSlotNum(a_SlotNum);
|
||||
m_Player->GetWorld()->BroadcastEntityEquipment(*m_Player, 0, m_Player->GetInventory().GetEquippedItem(), this);
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "UI/Window.h"
|
||||
#include "Item.h"
|
||||
#include "Root.h"
|
||||
#include "World.h"
|
||||
|
||||
#include <json/json.h>
|
||||
|
||||
@ -16,6 +17,21 @@
|
||||
|
||||
|
||||
|
||||
cInventory::cInventory(cPlayer & a_Owner) :
|
||||
m_Owner(a_Owner)
|
||||
{
|
||||
m_CraftSlots = m_Slots + c_CraftOffset;
|
||||
m_ArmorSlots = m_Slots + c_ArmorOffset;
|
||||
m_MainSlots = m_Slots + c_MainOffset;
|
||||
m_HotSlots = m_Slots + c_HotOffset;
|
||||
|
||||
SetEquippedSlotNum(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cInventory::~cInventory()
|
||||
{
|
||||
/*
|
||||
@ -33,26 +49,6 @@ cInventory::~cInventory()
|
||||
|
||||
|
||||
|
||||
cInventory::cInventory(cPlayer & a_Owner) :
|
||||
m_Owner(a_Owner)
|
||||
{
|
||||
for (unsigned int i = 0; i < c_NumSlots; i++)
|
||||
{
|
||||
m_Slots[i].Empty();
|
||||
}
|
||||
|
||||
m_CraftSlots = m_Slots + c_CraftOffset;
|
||||
m_ArmorSlots = m_Slots + c_ArmorOffset;
|
||||
m_MainSlots = m_Slots + c_MainOffset;
|
||||
m_HotSlots = m_Slots + c_HotOffset;
|
||||
|
||||
SetEquippedSlot(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cInventory::AddItem( cItem & a_Item )
|
||||
{
|
||||
cItem BackupSlots[c_NumSlots];
|
||||
@ -120,25 +116,25 @@ bool cInventory::AddItemAnyAmount( cItem & a_Item )
|
||||
|
||||
|
||||
// TODO: Right now if you dont have enough items, the items you did have are removed, and the function returns false anyway
|
||||
bool cInventory::RemoveItem( cItem & a_Item )
|
||||
bool cInventory::RemoveItem(cItem & a_Item)
|
||||
{
|
||||
// First check equipped slot
|
||||
if ((m_EquippedSlot >= 0) && (m_EquippedSlot < 9))
|
||||
if ((m_EquippedSlotNum >= 0) && (m_EquippedSlotNum < 9))
|
||||
{
|
||||
if (m_HotSlots[m_EquippedSlot].m_ItemType == a_Item.m_ItemType)
|
||||
if (m_HotSlots[m_EquippedSlotNum].m_ItemType == a_Item.m_ItemType)
|
||||
{
|
||||
cItem & Item = m_HotSlots[m_EquippedSlot];
|
||||
if(Item.m_ItemCount > a_Item.m_ItemCount)
|
||||
cItem & Item = m_HotSlots[m_EquippedSlotNum];
|
||||
if (Item.m_ItemCount > a_Item.m_ItemCount)
|
||||
{
|
||||
Item.m_ItemCount -= a_Item.m_ItemCount;
|
||||
SendSlot( m_EquippedSlot + c_HotOffset );
|
||||
SendSlot(m_EquippedSlotNum + c_HotOffset);
|
||||
return true;
|
||||
}
|
||||
else if(Item.m_ItemCount > 0 )
|
||||
else if (Item.m_ItemCount > 0)
|
||||
{
|
||||
a_Item.m_ItemCount -= Item.m_ItemCount;
|
||||
Item.Empty();
|
||||
SendSlot( m_EquippedSlot + c_HotOffset );
|
||||
SendSlot(m_EquippedSlotNum + c_HotOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -146,22 +142,22 @@ bool cInventory::RemoveItem( cItem & a_Item )
|
||||
// Then check other slotz
|
||||
if (a_Item.m_ItemCount > 0)
|
||||
{
|
||||
for(int i = 0; i < 36; i++)
|
||||
for (int i = 0; i < c_MainSlots; i++)
|
||||
{
|
||||
cItem & Item = m_MainSlots[i];
|
||||
if( Item.m_ItemType == a_Item.m_ItemType )
|
||||
if (Item.m_ItemType == a_Item.m_ItemType)
|
||||
{
|
||||
if(Item.m_ItemCount > a_Item.m_ItemCount)
|
||||
if (Item.m_ItemCount > a_Item.m_ItemCount)
|
||||
{
|
||||
Item.m_ItemCount -= a_Item.m_ItemCount;
|
||||
SendSlot( i + c_MainOffset );
|
||||
SendSlot(i + c_MainOffset);
|
||||
return true;
|
||||
}
|
||||
else if(Item.m_ItemCount > 0 )
|
||||
else if (Item.m_ItemCount > 0)
|
||||
{
|
||||
a_Item.m_ItemCount -= Item.m_ItemCount;
|
||||
Item.Empty();
|
||||
SendSlot( i + c_MainOffset );
|
||||
SendSlot(i + c_MainOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -176,104 +172,69 @@ bool cInventory::RemoveItem( cItem & a_Item )
|
||||
|
||||
void cInventory::Clear()
|
||||
{
|
||||
for(unsigned int i = 0; i < c_NumSlots; i++)
|
||||
for (unsigned int i = 0; i < ARRAYCOUNT(m_Slots); i++)
|
||||
{
|
||||
m_Slots[i].Empty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cItem * cInventory::GetSlotsForType( int a_Type )
|
||||
{
|
||||
switch( a_Type )
|
||||
{
|
||||
case -1:
|
||||
return m_MainSlots;
|
||||
case -2:
|
||||
return m_CraftSlots;
|
||||
case -3:
|
||||
return m_ArmorSlots;
|
||||
}
|
||||
return 0;
|
||||
// TODO: Broadcast / send the changes to wherever needed
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
int cInventory::GetSlotCountForType( int a_Type )
|
||||
void cInventory::SetSlot(int a_SlotNum, const cItem & a_Item)
|
||||
{
|
||||
switch (a_Type)
|
||||
if ((a_SlotNum < 0) || (a_SlotNum >= ARRAYCOUNT(m_Slots)))
|
||||
{
|
||||
case -1:
|
||||
return 36;
|
||||
case -2:
|
||||
case -3:
|
||||
return 4;
|
||||
LOGWARNING("%s requesting an invalid slot index: %d out of %d. Ignoring.", __FUNCTION__, a_SlotNum, ARRAYCOUNT(m_Slots));
|
||||
return;
|
||||
}
|
||||
m_Slots[a_SlotNum] = a_Item;
|
||||
|
||||
// If an armor slot was touched, broadcast an EntityEquipment packet
|
||||
if ((a_SlotNum >= c_ArmorOffset) && (a_SlotNum < c_MainOffset))
|
||||
{
|
||||
m_Owner.GetWorld()->BroadcastEntityEquipment(m_Owner, SlotNumToEntityEquipmentID(a_SlotNum), a_Item, m_Owner.GetClientHandle());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cItem* cInventory::GetSlot( int a_SlotNum )
|
||||
void cInventory::SetHotBarSlot(int a_HotBarSlotNum, const cItem & a_Item)
|
||||
{
|
||||
if( a_SlotNum < 0 || a_SlotNum >= (short)c_NumSlots ) return 0;
|
||||
return &m_Slots[a_SlotNum];
|
||||
SetSlot(a_HotBarSlotNum + c_HotSlots, a_Item);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cItem* cInventory::GetFromHotBar( int a_SlotNum )
|
||||
const cItem & cInventory::GetSlot(int a_SlotNum) const
|
||||
{
|
||||
if ((a_SlotNum < 0) || (a_SlotNum >= ARRAYCOUNT(m_Slots)))
|
||||
{
|
||||
LOGWARNING("%s requesting an invalid slot index: %d out of %d. Returning the first one instead.", __FUNCTION__, a_SlotNum, ARRAYCOUNT(m_Slots));
|
||||
return m_Slots[0];
|
||||
}
|
||||
|
||||
return m_Slots[a_SlotNum];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const cItem & cInventory::GetHotBarSlot(int a_SlotNum) const
|
||||
{
|
||||
if ((a_SlotNum < 0) || (a_SlotNum >= 9))
|
||||
{
|
||||
return NULL;
|
||||
LOGWARNING("%s requesting an invalid slot index: %d out of 9. Returning the first one instead", __FUNCTION__, a_SlotNum);
|
||||
return m_HotSlots[0];
|
||||
}
|
||||
return &m_HotSlots[a_SlotNum];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cInventory::SetEquippedSlot(int a_SlotNum)
|
||||
{
|
||||
if ((a_SlotNum < 0) || (a_SlotNum >= 9))
|
||||
{
|
||||
m_EquippedSlot = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_EquippedSlot = (short)a_SlotNum;
|
||||
}
|
||||
m_EquippedItem = GetFromHotBar(m_EquippedSlot);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cItem & cInventory::GetEquippedItem(void)
|
||||
{
|
||||
cItem* Item = GetFromHotBar( m_EquippedSlot );
|
||||
if( Item )
|
||||
{
|
||||
*m_EquippedItem = *Item;
|
||||
return *Item;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_EquippedItem->Empty();
|
||||
}
|
||||
return *m_EquippedItem;
|
||||
return m_HotSlots[a_SlotNum];
|
||||
}
|
||||
|
||||
|
||||
@ -282,7 +243,58 @@ cItem & cInventory::GetEquippedItem(void)
|
||||
|
||||
const cItem & cInventory::GetEquippedItem(void) const
|
||||
{
|
||||
return *m_EquippedItem;
|
||||
return GetHotBarSlot(m_EquippedSlotNum);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cInventory::SetEquippedSlotNum(int a_SlotNum)
|
||||
{
|
||||
if ((a_SlotNum < 0) || (a_SlotNum >= 9))
|
||||
{
|
||||
LOGWARNING("%s requesting invalid slot index: %d out of 9. Setting 0 instead.", __FUNCTION__, a_SlotNum);
|
||||
m_EquippedSlotNum = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_EquippedSlotNum = (short)a_SlotNum;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cInventory::DamageEquippedItem(short a_Amount)
|
||||
{
|
||||
return DamageItem(c_HotOffset + m_EquippedSlotNum, a_Amount);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cInventory::DamageItem(int a_SlotNum, short a_Amount)
|
||||
{
|
||||
if ((a_SlotNum < 0) || (a_SlotNum >= ARRAYCOUNT(m_Slots)))
|
||||
{
|
||||
LOGWARNING("%s requesting an invalid slot index: %d out of %d", __FUNCTION__, a_SlotNum, ARRAYCOUNT(m_Slots));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_Slots[a_SlotNum].DamageItem(a_Amount))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// The item has broken, remove it:
|
||||
m_Slots[a_SlotNum].Empty();
|
||||
SendSlot(a_SlotNum);
|
||||
|
||||
// TODO: If it was a special slot (armor / equipped), broadcast the change
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -300,16 +312,13 @@ void cInventory::SendWholeInventory(cClientHandle & a_Client)
|
||||
|
||||
void cInventory::SendSlot(int a_SlotNum)
|
||||
{
|
||||
cItem * Item = GetSlot(a_SlotNum);
|
||||
if (Item != NULL)
|
||||
cItem Item(GetSlot(a_SlotNum));
|
||||
if (Item.IsEmpty())
|
||||
{
|
||||
if (Item->IsEmpty())
|
||||
{
|
||||
// Sanitize items that are not completely empty (ie. count == 0, but type != empty)
|
||||
Item->Empty();
|
||||
}
|
||||
m_Owner.GetClientHandle()->SendInventorySlot(0, a_SlotNum, *Item);
|
||||
// Sanitize items that are not completely empty (ie. count == 0, but type != empty)
|
||||
Item.Empty();
|
||||
}
|
||||
m_Owner.GetClientHandle()->SendInventorySlot(0, a_SlotNum, Item);
|
||||
}
|
||||
|
||||
|
||||
@ -372,6 +381,23 @@ int cInventory::MoveItem(short a_ItemType, short a_ItemDamage, int a_Count, int
|
||||
|
||||
|
||||
|
||||
int cInventory::SlotNumToEntityEquipmentID(short a_SlotNum)
|
||||
{
|
||||
switch (a_SlotNum)
|
||||
{
|
||||
case 5: return 4; // Helmet
|
||||
case 6: return 3; // Chestplate
|
||||
case 7: return 2; // Leggings
|
||||
case 8: return 1; // Boots
|
||||
}
|
||||
LOGWARN("%s: invalid slot number: %d", __FUNCTION__, a_SlotNum);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cInventory::AddToBar( cItem & a_Item, const int a_Offset, const int a_Size, bool* a_bChangedSlots, int a_Mode /* = 0 */ )
|
||||
{
|
||||
// Fill already present stacks
|
||||
@ -442,13 +468,14 @@ bool cInventory::LoadFromJson(Json::Value & a_Value)
|
||||
{
|
||||
int SlotIdx = 0;
|
||||
|
||||
// TODO: Limit the number of slots written to the actual number of slots,
|
||||
// otherwise an invalid json will crash the server!
|
||||
|
||||
for( Json::Value::iterator itr = a_Value.begin(); itr != a_Value.end(); ++itr )
|
||||
{
|
||||
m_Slots[SlotIdx].FromJson( *itr );
|
||||
SlotIdx++;
|
||||
if (SlotIdx >= ARRAYCOUNT(m_Slots))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -27,8 +27,8 @@ public:
|
||||
|
||||
void Clear(); // tolua_export
|
||||
|
||||
cItem* GetSlotsForType( int a_Type );
|
||||
int GetSlotCountForType( int a_Type );
|
||||
// cItem * GetSlotsForType( int a_Type );
|
||||
// int GetSlotCountForType( int a_Type );
|
||||
|
||||
bool AddItem( cItem & a_Item ); // tolua_export
|
||||
bool AddItemAnyAmount( cItem & a_Item ); // tolua_export
|
||||
@ -39,21 +39,30 @@ public:
|
||||
|
||||
void SendWholeInventory(cClientHandle & a_Client);
|
||||
|
||||
cItem * GetSlot(int a_SlotNum ); // tolua_export
|
||||
cItem * GetSlots(void) { return m_Slots; }
|
||||
const cItem * GetSlots(void) const { return m_Slots; }
|
||||
cItem * GetFromHotBar(int a_HotBarSlotNum); // tolua_export
|
||||
|
||||
cItem & GetEquippedItem(void); // tolua_export
|
||||
const cItem & GetEquippedItem(void) const;
|
||||
void SetEquippedSlot(int a_SlotNum); // tolua_export
|
||||
short GetEquippedSlot(void) { return m_EquippedSlot; } // tolua_export
|
||||
|
||||
// tolua_begin
|
||||
|
||||
const cItem & GetSlot(int a_SlotNum) const;
|
||||
const cItem & GetHotBarSlot(int a_HotBarSlotNum) const;
|
||||
const cItem & GetEquippedItem(void) const;
|
||||
void SetSlot(int a_SlotNum, const cItem & a_Item);
|
||||
void SetHotBarSlot(int a_HotBarSlotNum, const cItem & a_Item);
|
||||
|
||||
void SetEquippedSlotNum(int a_SlotNum);
|
||||
int GetEquippedSlotNum(void) { return m_EquippedSlotNum; }
|
||||
|
||||
/// Adds the specified damage to the specified item; deletes the item and returns true if the item broke.
|
||||
bool cInventory::DamageItem(int a_SlotNum, short a_Amount);
|
||||
|
||||
/// Adds the specified damage to the currently held item; deletes the item and returns true if the item broke.
|
||||
bool DamageEquippedItem(short a_Amount = 1);
|
||||
|
||||
const cItem & GetEquippedHelmet (void) const { return m_Slots[c_ArmorOffset]; }
|
||||
const cItem & GetEquippedChestplate(void) const { return m_Slots[c_ArmorOffset + 1]; }
|
||||
const cItem & GetEquippedLeggings (void) const { return m_Slots[c_ArmorOffset + 2]; }
|
||||
const cItem & GetEquippedBoots (void) const { return m_Slots[c_ArmorOffset + 3]; }
|
||||
|
||||
// tolua_end
|
||||
|
||||
void SendSlot( int a_SlotNum ); // tolua_export
|
||||
@ -74,6 +83,9 @@ public:
|
||||
static const unsigned int c_ArmorOffset = 5;
|
||||
static const unsigned int c_MainOffset = 9;
|
||||
static const unsigned int c_HotOffset = 36;
|
||||
|
||||
/// Converts a slot number into the ID for the EntityEquipment packet
|
||||
static int SlotNumToEntityEquipmentID(short a_SlotNum);
|
||||
|
||||
protected:
|
||||
bool AddToBar( cItem & a_Item, const int a_Offset, const int a_Size, bool* a_bChangedSlots, int a_Mode = 0 );
|
||||
@ -85,8 +97,7 @@ protected:
|
||||
cItem * m_ArmorSlots;
|
||||
cItem * m_HotSlots;
|
||||
|
||||
cItem * m_EquippedItem;
|
||||
short m_EquippedSlot;
|
||||
int m_EquippedSlotNum;
|
||||
|
||||
cPlayer & m_Owner;
|
||||
}; // tolua_export
|
||||
|
@ -58,7 +58,7 @@ short cItem::GetMaxDamage(void) const
|
||||
|
||||
|
||||
|
||||
bool cItem::DamageItem(void)
|
||||
bool cItem::DamageItem(short a_Amount)
|
||||
{
|
||||
short MaxDamage = GetMaxDamage();
|
||||
if (MaxDamage == 0)
|
||||
@ -67,7 +67,7 @@ bool cItem::DamageItem(void)
|
||||
return false;
|
||||
}
|
||||
|
||||
m_ItemDamage++;
|
||||
m_ItemDamage += a_Amount;
|
||||
return (m_ItemDamage >= MaxDamage);
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ public:
|
||||
short GetMaxDamage(void) const;
|
||||
|
||||
/// Damages a weapon / tool. Returns true when damage reaches max value and the item should be destroyed
|
||||
bool DamageItem(void);
|
||||
bool DamageItem(short a_Amount = 1);
|
||||
|
||||
inline bool IsDamageable(void) const { return (GetMaxDamage() > 0); }
|
||||
|
||||
|
@ -20,7 +20,7 @@ public:
|
||||
|
||||
}
|
||||
|
||||
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override
|
||||
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override
|
||||
{
|
||||
switch (m_ItemType)
|
||||
{
|
||||
@ -37,7 +37,7 @@ public:
|
||||
|
||||
|
||||
|
||||
bool ScoopUpFluid(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace)
|
||||
bool ScoopUpFluid(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace)
|
||||
{
|
||||
if (a_BlockFace < 0)
|
||||
{
|
||||
@ -54,7 +54,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (a_Player->GetGameMode() == eGameMode_Creative)
|
||||
if (a_Player->GetGameMode() == gmCreative)
|
||||
{
|
||||
// In creative mode don't modify the inventory, just remove the fluid:
|
||||
a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
|
||||
@ -81,7 +81,7 @@ public:
|
||||
}
|
||||
|
||||
// Remove the bucket from the inventory
|
||||
cItem Item(a_Item->m_ItemType, 1);
|
||||
cItem Item(a_Item.m_ItemType, 1);
|
||||
if (!a_Player->GetInventory().RemoveItem(Item))
|
||||
{
|
||||
LOG("Clicked with an empty bucket, but cannot remove one from the inventory? WTF?");
|
||||
@ -100,7 +100,7 @@ public:
|
||||
}
|
||||
|
||||
|
||||
bool PlaceFluid(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_FluidBlock)
|
||||
bool PlaceFluid(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_FluidBlock)
|
||||
{
|
||||
if (a_BlockFace < 0)
|
||||
{
|
||||
@ -128,10 +128,10 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (a_Player->GetGameMode() != eGameMode_Creative)
|
||||
if (a_Player->GetGameMode() != gmCreative)
|
||||
{
|
||||
// Remove fluid bucket, add empty bucket:
|
||||
cItem Item(a_Item->m_ItemType, 1);
|
||||
cItem Item(a_Item.m_ItemType, 1);
|
||||
if (!a_Player->GetInventory().RemoveItem(Item))
|
||||
{
|
||||
LOG("Clicked with a full bucket, but cannot remove one from the inventory? WTF?");
|
||||
|
@ -19,17 +19,17 @@ public:
|
||||
|
||||
}
|
||||
|
||||
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override
|
||||
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override
|
||||
{
|
||||
// TODO: Handle coloring the sheep, too (OnItemUseOnEntity maybe)
|
||||
// Handle growing the plants:
|
||||
if (a_Item->m_ItemDamage == E_META_DYE_WHITE)
|
||||
if (a_Item.m_ItemDamage == E_META_DYE_WHITE)
|
||||
{
|
||||
if (a_World->GrowRipePlant(a_BlockX, a_BlockY, a_BlockZ, true))
|
||||
{
|
||||
if (a_Player->GetGameMode() != eGameMode_Creative)
|
||||
{
|
||||
cItem Item(a_Item->m_ItemType, 1, a_Item->m_ItemDamage);
|
||||
cItem Item(a_Item.m_ItemType, 1, a_Item.m_ItemDamage);
|
||||
a_Player->GetInventory().RemoveItem(Item);
|
||||
return true;
|
||||
}
|
||||
|
@ -214,7 +214,7 @@ cItemHandler::cItemHandler(int a_ItemType)
|
||||
|
||||
|
||||
|
||||
bool cItemHandler::OnItemUse(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir)
|
||||
bool cItemHandler::OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -223,7 +223,7 @@ bool cItemHandler::OnItemUse(cWorld * a_World, cPlayer * a_Player, cItem * a_Ite
|
||||
|
||||
|
||||
|
||||
bool cItemHandler::OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir)
|
||||
bool cItemHandler::OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -232,12 +232,12 @@ bool cItemHandler::OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, cItem *
|
||||
|
||||
|
||||
|
||||
void cItemHandler::OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_BlockX, int a_BlockY, int a_BlockZ)
|
||||
void cItemHandler::OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ)
|
||||
{
|
||||
BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
|
||||
cBlockHandler * Handler = cBlockHandler::GetBlockHandler(Block);
|
||||
|
||||
if (a_Player->GetGameMode() == eGameMode_Survival)
|
||||
if (a_Player->GetGameMode() == gmSurvival)
|
||||
{
|
||||
if (!BlockRequiresSpecialTool(Block) || CanHarvestBlock(Block))
|
||||
{
|
||||
|
@ -22,13 +22,13 @@ public:
|
||||
cItemHandler(int a_ItemType);
|
||||
|
||||
/// Called when the player tries to use the item. Return false to make the item unusable. DEFAULT: False
|
||||
virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir); //eg for fishing or hoes
|
||||
virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir); //eg for fishing or hoes
|
||||
|
||||
/// Called while the player diggs a block using this item
|
||||
virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, cItem * a_HeldItem, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace);
|
||||
virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_HeldItem, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace);
|
||||
|
||||
/// Called when the player destroys a block using this item. This also calls the drop function for the destroyed block
|
||||
virtual void OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z);
|
||||
virtual void OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_X, int a_Y, int a_Z);
|
||||
|
||||
/// Called after the player has eaten this item.
|
||||
virtual void OnFoodEaten(cWorld *a_World, cPlayer *a_Player, cItem *a_Item);
|
||||
|
@ -14,7 +14,7 @@ public:
|
||||
|
||||
}
|
||||
|
||||
virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override
|
||||
virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override
|
||||
{
|
||||
BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
|
||||
|
||||
|
@ -18,7 +18,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) override
|
||||
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) override
|
||||
{
|
||||
if (a_BlockFace < 0)
|
||||
{
|
||||
@ -29,7 +29,7 @@ public:
|
||||
|
||||
AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
|
||||
|
||||
a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_FIRE, 0); //0 -> new fire TODO: Make Firesimulator use this
|
||||
a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_FIRE, 0); //0 -> new fire
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override
|
||||
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override
|
||||
{
|
||||
if (a_Dir < 0)
|
||||
{
|
||||
|
@ -25,7 +25,7 @@ public:
|
||||
}
|
||||
|
||||
|
||||
virtual bool OnDiggingBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override
|
||||
virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override
|
||||
{
|
||||
BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
|
||||
if (Block == E_BLOCK_LEAVES)
|
||||
|
@ -20,7 +20,7 @@ public:
|
||||
|
||||
}
|
||||
|
||||
virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override
|
||||
virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override
|
||||
{
|
||||
BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
|
||||
if (Block == E_BLOCK_SNOW)
|
||||
|
@ -17,7 +17,7 @@ public:
|
||||
|
||||
}
|
||||
|
||||
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override
|
||||
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override
|
||||
{
|
||||
BLOCKTYPE Block;
|
||||
NIBBLETYPE Meta;
|
||||
@ -26,8 +26,8 @@ public:
|
||||
if (
|
||||
((a_Dir == 0) || (a_Dir == 1)) // Only when clicking on top or on bottom of the block
|
||||
&& ((Block == E_BLOCK_WOODEN_SLAB) || (Block == E_BLOCK_STONE_SLAB)) // It is a slab
|
||||
&& (Block == a_Item->m_ItemType) // Same slab
|
||||
&& ((Meta & 0x7) == (a_Item->m_ItemDamage & 0x7))) // Same Texture
|
||||
&& (Block == a_Item.m_ItemType) // Same slab
|
||||
&& ((Meta & 0x7) == (a_Item.m_ItemDamage & 0x7))) // Same Texture
|
||||
{
|
||||
if (a_Player->GetGameMode() == eGameMode_Creative)
|
||||
{
|
||||
@ -36,7 +36,7 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
cItem Item(a_Item->m_ItemType, 1);
|
||||
cItem Item(a_Item.m_ItemType, 1);
|
||||
if (a_Player->GetInventory().RemoveItem(Item))
|
||||
{
|
||||
a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, Block - 1, Meta); // Block - 1 simple hack to save one if statement
|
||||
|
@ -19,7 +19,7 @@ public:
|
||||
}
|
||||
|
||||
|
||||
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) override
|
||||
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) override
|
||||
{
|
||||
if (a_BlockFace < 0)
|
||||
{
|
||||
@ -33,12 +33,13 @@ public:
|
||||
a_BlockY--;
|
||||
}
|
||||
|
||||
if (a_World->SpawnMob(a_BlockX + 0.5, a_BlockY, a_BlockZ + 0.5, a_Item->m_ItemDamage) >= 0)
|
||||
if (a_World->SpawnMob(a_BlockX + 0.5, a_BlockY, a_BlockZ + 0.5, a_Item.m_ItemDamage) >= 0)
|
||||
{
|
||||
if (a_Player->GetGameMode() != 1)
|
||||
{
|
||||
// The mob was spawned, "use" the item:
|
||||
a_Player->GetInventory().RemoveItem(a_Player->GetInventory().GetEquippedItem());
|
||||
cItem Equipped(a_Player->GetEquippedItem());
|
||||
a_Player->GetInventory().RemoveItem(Equipped);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ cJukeboxEntity::~cJukeboxEntity()
|
||||
|
||||
|
||||
|
||||
void cJukeboxEntity::UsedBy( cPlayer * a_Player )
|
||||
void cJukeboxEntity::UsedBy(cPlayer * a_Player)
|
||||
{
|
||||
if (m_Record == 0)
|
||||
{
|
||||
@ -40,7 +40,8 @@ void cJukeboxEntity::UsedBy( cPlayer * a_Player )
|
||||
if (HeldItem.m_ItemType >= 2256 && HeldItem.m_ItemType <= 2267)
|
||||
{
|
||||
m_Record = HeldItem.m_ItemType;
|
||||
a_Player->GetInventory().RemoveItem(a_Player->GetInventory().GetEquippedItem());
|
||||
cItem Equipped(a_Player->GetInventory().GetEquippedItem());
|
||||
a_Player->GetInventory().RemoveItem(Equipped);
|
||||
PlayRecord();
|
||||
}
|
||||
}
|
||||
|
@ -149,6 +149,10 @@ void cPlayer::SpawnOn(cClientHandle & a_Client)
|
||||
a_Client.SendPlayerSpawn(*this);
|
||||
a_Client.SendEntHeadLook(*this);
|
||||
a_Client.SendEntityEquipment(*this, 0, m_Inventory.GetEquippedItem() );
|
||||
a_Client.SendEntityEquipment(*this, 1, m_Inventory.GetEquippedBoots() );
|
||||
a_Client.SendEntityEquipment(*this, 2, m_Inventory.GetEquippedLeggings() );
|
||||
a_Client.SendEntityEquipment(*this, 3, m_Inventory.GetEquippedChestplate() );
|
||||
a_Client.SendEntityEquipment(*this, 4, m_Inventory.GetEquippedHelmet() );
|
||||
}
|
||||
}
|
||||
|
||||
@ -356,16 +360,16 @@ void cPlayer::KilledBy(cPawn * a_Killer)
|
||||
m_bVisible = false; // So new clients don't see the player
|
||||
|
||||
// Puke out all the items
|
||||
cItem * Items = m_Inventory.GetSlots();
|
||||
const cItem * Items = m_Inventory.GetSlots();
|
||||
cItems Pickups;
|
||||
for (unsigned int i = 1; i < m_Inventory.c_NumSlots; ++i)
|
||||
{
|
||||
if( !Items[i].IsEmpty() )
|
||||
if (!Items[i].IsEmpty())
|
||||
{
|
||||
Pickups.push_back(Items[i]);
|
||||
}
|
||||
Items[i].Empty();
|
||||
}
|
||||
m_Inventory.Clear();
|
||||
m_World->SpawnItemPickups(Pickups, GetPosX(), GetPosY(), GetPosZ(), 10);
|
||||
SaveToDisk(); // Save it, yeah the world is a tough place !
|
||||
}
|
||||
@ -793,7 +797,7 @@ void cPlayer::TossItem(
|
||||
else
|
||||
{
|
||||
// Else drop equipped item
|
||||
cItem DroppedItem = GetInventory().GetEquippedItem();
|
||||
cItem DroppedItem(GetInventory().GetEquippedItem());
|
||||
if (!DroppedItem.IsEmpty())
|
||||
{
|
||||
DroppedItem.m_ItemCount = 1;
|
||||
@ -1026,14 +1030,12 @@ cPlayer::StringList cPlayer::GetResolvedPermissions()
|
||||
|
||||
void cPlayer::UseEquippedItem()
|
||||
{
|
||||
if(GetGameMode() != 1) //No damage in creative
|
||||
if (GetGameMode() == gmCreative) // No damage in creative
|
||||
{
|
||||
if (GetInventory().GetEquippedItem().DamageItem())
|
||||
{
|
||||
LOG("Player %s Broke ID: %i", GetClientHandle()->GetUsername().c_str(), GetInventory().GetEquippedItem().m_ItemType);
|
||||
GetInventory().RemoveItem( GetInventory().GetEquippedItem());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
GetInventory().DamageEquippedItem();
|
||||
}
|
||||
|
||||
|
||||
|
@ -67,8 +67,7 @@ public:
|
||||
inline cInventory & GetInventory(void) { return m_Inventory; } // tolua_export
|
||||
inline const cInventory & GetInventory(void) const { return m_Inventory; }
|
||||
|
||||
inline cItem & GetEquippedItem(void) { return GetInventory().GetEquippedItem(); } // tolua_export
|
||||
inline const cItem & GetEquippedItem(void) const { return GetInventory().GetEquippedItem(); }
|
||||
inline const cItem & GetEquippedItem(void) const { return GetInventory().GetEquippedItem(); } // tolua_export
|
||||
|
||||
virtual void TeleportTo(double a_PosX, double a_PosY, double a_PosZ) override;
|
||||
|
||||
|
@ -614,7 +614,7 @@ void cSlotAreaInventoryBase::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAc
|
||||
const cItem * cSlotAreaInventoryBase::GetSlot(int a_SlotNum, cPlayer & a_Player)
|
||||
{
|
||||
// a_SlotNum ranges from 0 to 35, map that to the player's inventory slots 9 to 44
|
||||
return a_Player.GetInventory().GetSlot(a_SlotNum + m_SlotOffset);
|
||||
return &a_Player.GetInventory().GetSlot(a_SlotNum + m_SlotOffset);
|
||||
}
|
||||
|
||||
|
||||
@ -623,7 +623,7 @@ const cItem * cSlotAreaInventoryBase::GetSlot(int a_SlotNum, cPlayer & a_Player)
|
||||
|
||||
void cSlotAreaInventoryBase::SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item)
|
||||
{
|
||||
*(a_Player.GetInventory().GetSlot(a_SlotNum + m_SlotOffset)) = a_Item;
|
||||
a_Player.GetInventory().SetSlot(a_SlotNum + m_SlotOffset, a_Item);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user