1
0

CreativeInventory Update

- Fixed various problems with the new creative inventory (Crafting, furnace, etc)
- Creative inventory will now be saved to disk, so you keep your creative inventory also for the next sessions

git-svn-id: http://mc-server.googlecode.com/svn/trunk@162 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
lapayo94@gmail.com 2012-01-01 18:45:28 +00:00
parent 01398f8424
commit ac63775297
9 changed files with 107 additions and 85 deletions

View File

@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 01/01/12 17:14:14.
** Generated automatically by tolua++-1.0.92 on 01/01/12 19:41:18.
*/
#ifndef __cplusplus
@ -162,51 +162,50 @@ static void tolua_reg_types (lua_State* tolua_S)
tolua_usertype(tolua_S,"cPlugin");
tolua_usertype(tolua_S,"cStringMap");
tolua_usertype(tolua_S,"Json::Value");
tolua_usertype(tolua_S,"cInventory");
tolua_usertype(tolua_S,"cServer");
tolua_usertype(tolua_S,"cRoot");
tolua_usertype(tolua_S,"cGroupManager");
tolua_usertype(tolua_S,"cPlugin::CommandStruct");
tolua_usertype(tolua_S,"cPickup");
tolua_usertype(tolua_S,"Lua__cPacket_BlockDig");
tolua_usertype(tolua_S,"cRecipeChecker");
tolua_usertype(tolua_S,"cPacket_Login");
tolua_usertype(tolua_S,"cSurvivalInventory");
tolua_usertype(tolua_S,"Vector3i");
tolua_usertype(tolua_S,"cClientHandle");
tolua_usertype(tolua_S,"Lua__cPacket_BlockDig");
tolua_usertype(tolua_S,"cFurnaceRecipe");
tolua_usertype(tolua_S,"cCuboid");
tolua_usertype(tolua_S,"cChatColor");
tolua_usertype(tolua_S,"cGroup");
tolua_usertype(tolua_S,"cMCLogger");
tolua_usertype(tolua_S,"cPacket_PickupSpawn");
tolua_usertype(tolua_S,"Lua__cWebPlugin");
tolua_usertype(tolua_S,"Lua__cPawn");
tolua_usertype(tolua_S,"cTracer");
tolua_usertype(tolua_S,"cGroup");
tolua_usertype(tolua_S,"cItem");
tolua_usertype(tolua_S,"Vector3f");
tolua_usertype(tolua_S,"cPlugin_Lua");
tolua_usertype(tolua_S,"cMCLogger");
tolua_usertype(tolua_S,"cTracer");
tolua_usertype(tolua_S,"Lua__cPlayer");
tolua_usertype(tolua_S,"cPacket");
tolua_usertype(tolua_S,"cPacket_BlockDig");
tolua_usertype(tolua_S,"cWebAdmin");
tolua_usertype(tolua_S,"cClientHandle");
tolua_usertype(tolua_S,"Vector3i");
tolua_usertype(tolua_S,"cBlockEntity");
tolua_usertype(tolua_S,"cWebPlugin");
tolua_usertype(tolua_S,"Lua__cTCPLink");
tolua_usertype(tolua_S,"cTCPLink");
tolua_usertype(tolua_S,"Lua__cPlugin");
tolua_usertype(tolua_S,"cRecipeChecker");
tolua_usertype(tolua_S,"cTCPLink");
tolua_usertype(tolua_S,"cPacket_BlockPlace");
tolua_usertype(tolua_S,"cLadder");
tolua_usertype(tolua_S,"Lua__cPickup");
tolua_usertype(tolua_S,"cPluginManager");
tolua_usertype(tolua_S,"cIniFile");
tolua_usertype(tolua_S,"cGroupManager");
tolua_usertype(tolua_S,"cWorld");
tolua_usertype(tolua_S,"cIniFile");
tolua_usertype(tolua_S,"cPluginManager");
tolua_usertype(tolua_S,"HTTPRequest");
tolua_usertype(tolua_S,"cPawn");
tolua_usertype(tolua_S,"cPlayer");
tolua_usertype(tolua_S,"cTorch");
tolua_usertype(tolua_S,"Lua__cPickup");
tolua_usertype(tolua_S,"cEntity");
tolua_usertype(tolua_S,"cInventory");
tolua_usertype(tolua_S,"Lua__cEntity");
tolua_usertype(tolua_S,"cWebPlugin");
tolua_usertype(tolua_S,"cServer");
tolua_usertype(tolua_S,"cStairs");
tolua_usertype(tolua_S,"Vector3d");
}
@ -5032,38 +5031,6 @@ static int tolua_AllToLua_cPlayer_GetInventory00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
/* method: GetSurvivalInventory of class cPlayer */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_GetSurvivalInventory00
static int tolua_AllToLua_cPlayer_GetSurvivalInventory00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"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);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetSurvivalInventory'", NULL);
#endif
{
cSurvivalInventory& tolua_ret = (cSurvivalInventory&) self->GetSurvivalInventory();
tolua_pushusertype(tolua_S,(void*)&tolua_ret,"cSurvivalInventory");
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'GetSurvivalInventory'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: TeleportTo of class cPlayer */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_TeleportTo00
static int tolua_AllToLua_cPlayer_TeleportTo00(lua_State* tolua_S)
@ -9304,6 +9271,38 @@ static int tolua_AllToLua_cInventory_SetEquippedSlot00(lua_State* tolua_S)
}
#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)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"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);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetEquippedSlot'", NULL);
#endif
{
short tolua_ret = (short) self->GetEquippedSlot();
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);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: SendSlot of class cInventory */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cInventory_SendSlot00
static int tolua_AllToLua_cInventory_SendSlot00(lua_State* tolua_S)
@ -16020,7 +16019,6 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"GetFlying",tolua_AllToLua_cPlayer_GetFlying00);
tolua_function(tolua_S,"GetStance",tolua_AllToLua_cPlayer_GetStance00);
tolua_function(tolua_S,"GetInventory",tolua_AllToLua_cPlayer_GetInventory00);
tolua_function(tolua_S,"GetSurvivalInventory",tolua_AllToLua_cPlayer_GetSurvivalInventory00);
tolua_function(tolua_S,"TeleportTo",tolua_AllToLua_cPlayer_TeleportTo00);
tolua_function(tolua_S,"GetGameMode",tolua_AllToLua_cPlayer_GetGameMode00);
tolua_function(tolua_S,"GetIP",tolua_AllToLua_cPlayer_GetIP00);
@ -16186,6 +16184,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"GetFromHotBar",tolua_AllToLua_cInventory_GetFromHotBar00);
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,"SendSlot",tolua_AllToLua_cInventory_SendSlot00);
tolua_endmodule(tolua_S);
#ifdef __cplusplus

View File

@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 01/01/12 17:14:15.
** Generated automatically by tolua++-1.0.92 on 01/01/12 19:41:18.
*/
/* Exported function */

View File

@ -18,6 +18,8 @@ cInventory::~cInventory()
{
delete [] m_Slots;
delete m_EquippedItem;
if( GetWindow() ) GetWindow()->Close( *m_Owner );
CloseWindow();
}
cInventory::cInventory(cPlayer* a_Owner)
@ -35,6 +37,14 @@ cInventory::cInventory(cPlayer* a_Owner)
m_EquippedItem = new cItem();
m_EquippedSlot = 0;
if( !GetWindow() )
{
cWindow* Window = new cWindow( this, false );
Window->SetSlots( m_Slots, c_NumSlots );
Window->SetWindowID( 0 );
OpenWindow( Window );
}
}
bool cInventory::AddItem( cItem & a_Item )

View File

@ -15,6 +15,7 @@ class cPlayer;
class cPacket;
class cPacket_EntityEquipment;
class cInventory //tolua_export
: public cWindowOwner
{ //tolua_export
public:
cInventory(cPlayer* a_Owner);
@ -39,6 +40,7 @@ public:
cItem & GetEquippedItem(); //tolua_export
void SetEquippedSlot( int a_SlotNum ); //tolua_export
short GetEquippedSlot() { return m_EquippedSlot; } //tolua_export
virtual void Clicked( cPacket* a_ClickPacket ) = 0;

View File

@ -97,6 +97,7 @@ cPlayer::cPlayer(cClientHandle* a_Client, const char* a_PlayerName)
if( !LoadFromDisk() )
{
m_Inventory->Clear();
m_CreativeInventory->Clear();
SetPosX( cRoot::Get()->GetDefaultWorld()->GetSpawnX() );
SetPosY( cRoot::Get()->GetDefaultWorld()->GetSpawnY() );
SetPosZ( cRoot::Get()->GetDefaultWorld()->GetSpawnZ() );
@ -425,23 +426,27 @@ void cPlayer::CloseWindow(char a_WindowType)
Item->Empty();
}
}
if (a_WindowType == 1 && strcmp(m_CurrentWindow->GetWindowTitle().c_str(), "UberChest") == 0) { // Chest
cBlockEntity *block = m_CurrentWindow->GetOwner()->GetEntity();
cPacket_BlockAction ChestClose;
ChestClose.m_PosX = block->GetPosX();
ChestClose.m_PosY = (short)block->GetPosY();
ChestClose.m_PosZ = block->GetPosZ();
ChestClose.m_Byte1 = 1;
ChestClose.m_Byte2 = 0;
cWorld::PlayerList PlayerList = cRoot::Get()->GetWorld()->GetAllPlayers();
for( cWorld::PlayerList::iterator itr = PlayerList.begin(); itr != PlayerList.end(); ++itr )
{
if ((*itr) && (*itr)->GetClientHandle() && !((*itr)->GetClientHandle()->IsDestroyed())) {
(*itr)->GetClientHandle()->Send( ChestClose );
if (m_CurrentWindow)
{
if (a_WindowType == 1 && strcmp(m_CurrentWindow->GetWindowTitle().c_str(), "UberChest") == 0) { // Chest
cBlockEntity *block = m_CurrentWindow->GetOwner()->GetEntity();
cPacket_BlockAction ChestClose;
ChestClose.m_PosX = block->GetPosX();
ChestClose.m_PosY = (short)block->GetPosY();
ChestClose.m_PosZ = block->GetPosZ();
ChestClose.m_Byte1 = 1;
ChestClose.m_Byte2 = 0;
cWorld::PlayerList PlayerList = cRoot::Get()->GetWorld()->GetAllPlayers();
for( cWorld::PlayerList::iterator itr = PlayerList.begin(); itr != PlayerList.end(); ++itr )
{
if ((*itr) && (*itr)->GetClientHandle() && !((*itr)->GetClientHandle()->IsDestroyed())) {
(*itr)->GetClientHandle()->Send( ChestClose );
}
}
}
m_CurrentWindow->Close( *this );
}
if( m_CurrentWindow ) m_CurrentWindow->Close( *this );
m_CurrentWindow = 0;
}
@ -457,14 +462,24 @@ void cPlayer::SetLastBlockActionCnt( int a_LastBlockActionCnt )
void cPlayer::SetGameMode( int a_GameMode )
{
if ( (a_GameMode < 2) && (a_GameMode >= 0) ) {
if (m_GameMode != a_GameMode) {
if ( (a_GameMode < 2) && (a_GameMode >= 0) )
{
if (m_GameMode != a_GameMode)
{
cInventory *OldInventory = 0;
if(m_GameMode == 0)
OldInventory = m_Inventory;
else
OldInventory = m_CreativeInventory;
m_GameMode = a_GameMode;
cPacket_NewInvalidState GameModePacket;
GameModePacket.m_Reason = 3; //GameModeChange
GameModePacket.m_GameMode = (char)a_GameMode; //GameModeChange
m_ClientHandle->Send ( GameModePacket );
GetInventory().SendWholeInventory(m_ClientHandle);
OldInventory->SetEquippedSlot(GetInventory().GetEquippedSlot());
}
}
}
@ -658,7 +673,7 @@ void cPlayer::TossItem( bool a_bDraggingItem, int a_Amount /* = 1 */ )
{
if( a_bDraggingItem )
{
cItem* Item = GetSurvivalInventory().GetWindow()->GetDraggingItem();
cItem* Item = GetInventory().GetWindow()->GetDraggingItem();
if( Item->m_ItemID > 0 && Item->m_ItemCount >= a_Amount )
{
float vX = 0, vY = 0, vZ = 0;
@ -778,7 +793,7 @@ bool cPlayer::LoadFromDisk() // TODO - This should also get/set/whatever the cor
{
LOGERROR("ERROR WHILE PARSING JSON FROM FILE %s", SourceFile);
}
delete [] buffer;
Json::Value & JSON_PlayerPosition = root["position"];
@ -800,6 +815,7 @@ bool cPlayer::LoadFromDisk() // TODO - This should also get/set/whatever the cor
m_Health = (short)root.get("health", 0 ).asInt();
m_FoodLevel = (short)root.get("food", 0 ).asInt();
m_Inventory->LoadFromJson(root["inventory"]);
m_CreativeInventory->LoadFromJson(root["creativeinventory"]);
m_pState->LoadedWorldName = root.get("world", "world").asString();
@ -826,10 +842,14 @@ bool cPlayer::SaveToDisk()
Json::Value JSON_Inventory;
m_Inventory->SaveToJson( JSON_Inventory );
Json::Value JSON_CreativeInventory;
m_CreativeInventory->SaveToJson( JSON_CreativeInventory );
Json::Value root;
root["position"] = JSON_PlayerPosition;
root["rotation"] = JSON_PlayerRotation;
root["inventory"] = JSON_Inventory;
root["creativeinventory"] = JSON_CreativeInventory;
root["health"] = m_Health;
root["food"] = m_FoodLevel;
root["world"] = GetWorld()->GetName();

View File

@ -31,8 +31,7 @@ public:
Vector3d GetEyePosition(); //tolua_export
inline bool GetFlying() { return m_bTouchGround; } //tolua_export
inline const double & GetStance() { return m_Stance; } //tolua_export
cInventory & GetInventory() { if(GetGameMode() == 0) return *m_Inventory; else return *m_CreativeInventory; } //tolua_export
cSurvivalInventory & GetSurvivalInventory() { return *m_Inventory; } //tolua_export
inline cInventory & GetInventory() { if(GetGameMode() == 0) return *m_Inventory; else return *m_CreativeInventory; } //tolua_export
virtual void TeleportTo( const double & a_PosX, const double & a_PosY, const double & a_PosZ ); //tolua_export

View File

@ -11,20 +11,13 @@
cSurvivalInventory::~cSurvivalInventory()
{
if( GetWindow() ) GetWindow()->Close( *m_Owner );
CloseWindow();
}
cSurvivalInventory::cSurvivalInventory(cPlayer* a_Owner)
: cInventory(a_Owner)
{
if( !GetWindow() )
{
cWindow* Window = new cWindow( this, false );
Window->SetSlots( m_Slots, c_NumSlots );
Window->SetWindowID( 0 );
OpenWindow( Window );
}
}
void cSurvivalInventory::Clicked( cPacket* a_ClickPacket )

View File

@ -3,8 +3,7 @@
#include "cInventory.h"
class cSurvivalInventory //tolua_export
: public cInventory
, public cWindowOwner
: public cInventory
{ //tolua_export
public:
cSurvivalInventory(cPlayer* a_Owner);

View File

@ -48,7 +48,7 @@ cItem* cWindow::GetDraggingItem( cPlayer * a_Player /* = 0 */ )
{
if( m_bInventoryVisible && a_Player )
{
cWindow* Window = a_Player->GetSurvivalInventory().GetWindow();
cWindow* Window = a_Player->GetInventory().GetWindow();
if( Window )
{
return Window->GetDraggingItem();
@ -68,7 +68,7 @@ void cWindow::Clicked( cPacket_WindowClick* a_ClickPacket, cPlayer & a_Player )
if( m_bInventoryVisible )
{
cWindow* Window = a_Player.GetSurvivalInventory().GetWindow();
cWindow* Window = a_Player.GetInventory().GetWindow();
if( Window )
{
m_DraggingItem = Window->GetDraggingItem();
@ -170,7 +170,7 @@ void cWindow::Clicked( cPacket_WindowClick* a_ClickPacket, cPlayer & a_Player )
{
a_ClickPacket->m_WindowID = 0;
a_ClickPacket->m_SlotNum -= (short)(m_NumSlots - 9);
cWindow* Window = a_Player.GetSurvivalInventory().GetWindow();
cWindow* Window = a_Player.GetInventory().GetWindow();
if( Window )
{
Window->Clicked( a_ClickPacket, a_Player );