summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlapayo94@gmail.com <lapayo94@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-01-01 19:45:28 +0100
committerlapayo94@gmail.com <lapayo94@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-01-01 19:45:28 +0100
commitac63775297cffb56b05702c0a3c6575f1bcd7d3b (patch)
tree9a5355be1d74a613a71ca43e2b85d53688eb6de2
parentFixed the numchunks console command. (diff)
downloadcuberite-ac63775297cffb56b05702c0a3c6575f1bcd7d3b.tar
cuberite-ac63775297cffb56b05702c0a3c6575f1bcd7d3b.tar.gz
cuberite-ac63775297cffb56b05702c0a3c6575f1bcd7d3b.tar.bz2
cuberite-ac63775297cffb56b05702c0a3c6575f1bcd7d3b.tar.lz
cuberite-ac63775297cffb56b05702c0a3c6575f1bcd7d3b.tar.xz
cuberite-ac63775297cffb56b05702c0a3c6575f1bcd7d3b.tar.zst
cuberite-ac63775297cffb56b05702c0a3c6575f1bcd7d3b.zip
-rw-r--r--source/Bindings.cpp99
-rw-r--r--source/Bindings.h2
-rw-r--r--source/cInventory.cpp10
-rw-r--r--source/cInventory.h2
-rw-r--r--source/cPlayer.cpp56
-rw-r--r--source/cPlayer.h3
-rw-r--r--source/cSurvivalInventory.cpp11
-rw-r--r--source/cSurvivalInventory.h3
-rw-r--r--source/cWindow.cpp6
9 files changed, 107 insertions, 85 deletions
diff --git a/source/Bindings.cpp b/source/Bindings.cpp
index 83a9e1518..8b0724d9f 100644
--- a/source/Bindings.cpp
+++ b/source/Bindings.cpp
@@ -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
diff --git a/source/Bindings.h b/source/Bindings.h
index b0ca12919..3a43ccb32 100644
--- a/source/Bindings.h
+++ b/source/Bindings.h
@@ -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 */
diff --git a/source/cInventory.cpp b/source/cInventory.cpp
index 9236a2387..166ef6ad5 100644
--- a/source/cInventory.cpp
+++ b/source/cInventory.cpp
@@ -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 )
diff --git a/source/cInventory.h b/source/cInventory.h
index 849cfb440..8d4b13fcb 100644
--- a/source/cInventory.h
+++ b/source/cInventory.h
@@ -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;
diff --git a/source/cPlayer.cpp b/source/cPlayer.cpp
index 12f3c5a30..9071a31b1 100644
--- a/source/cPlayer.cpp
+++ b/source/cPlayer.cpp
@@ -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();
diff --git a/source/cPlayer.h b/source/cPlayer.h
index d2d1e91d7..b3344c410 100644
--- a/source/cPlayer.h
+++ b/source/cPlayer.h
@@ -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
diff --git a/source/cSurvivalInventory.cpp b/source/cSurvivalInventory.cpp
index 1618e04ae..59f634ca5 100644
--- a/source/cSurvivalInventory.cpp
+++ b/source/cSurvivalInventory.cpp
@@ -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 )
diff --git a/source/cSurvivalInventory.h b/source/cSurvivalInventory.h
index 525387b08..270f18dcd 100644
--- a/source/cSurvivalInventory.h
+++ b/source/cSurvivalInventory.h
@@ -3,8 +3,7 @@
#include "cInventory.h"
class cSurvivalInventory //tolua_export
- : public cInventory
- , public cWindowOwner
+ : public cInventory
{ //tolua_export
public:
cSurvivalInventory(cPlayer* a_Owner);
diff --git a/source/cWindow.cpp b/source/cWindow.cpp
index 02ee3c541..68c8d4142 100644
--- a/source/cWindow.cpp
+++ b/source/cWindow.cpp
@@ -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 );