1
0

Added cWindow property manipulation API.

Now enchantment table and furnace properties can be set by a plugin
This commit is contained in:
madmaxoft 2013-08-18 13:26:37 +02:00
parent 40e9e5b95b
commit 0d323563e4
13 changed files with 154 additions and 48 deletions

View File

@ -35,6 +35,7 @@ function Initialize(Plugin)
PluginManager:BindCommand("/starve", "debuggers", HandleStarveCmd, "- Sets the food level to zero");
PluginManager:BindCommand("/fl", "debuggers", HandleFoodLevelCmd, "- Sets the food level to the given value");
PluginManager:BindCommand("/spidey", "debuggers", HandleSpideyCmd, "- Shoots a line of web blocks until it hits non-air");
PluginManager:BindCommand("/ench", "debuggers", HandleEnchCmd, "- Provides an instant dummy enchantment window");
-- Enable the following line for BlockArea / Generator interface testing:
-- PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHUNK_GENERATED);
@ -739,3 +740,11 @@ end
function HandleEnchCmd(a_Split, a_Player)
local Wnd = cLuaWindow(cWindow.Enchantment, 1, 1, "Ench")
a_Player:OpenWindow(Wnd)
Wnd:SetProperty(0, 10)
Wnd:SetProperty(1, 15)
Wnd:SetProperty(2, 25)
end

View File

@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 08/18/13 10:47:30.
** Generated automatically by tolua++-1.0.92 on 08/18/13 13:15:34.
*/
#ifndef __cplusplus
@ -26657,6 +26657,73 @@ static int tolua_AllToLua_cWindow_SetWindowTitle00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
/* method: SetProperty of class cWindow */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cWindow_SetProperty00
static int tolua_AllToLua_cWindow_SetProperty00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cWindow",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
{
cWindow* self = (cWindow*) tolua_tousertype(tolua_S,1,0);
int a_Property = ((int) tolua_tonumber(tolua_S,2,0));
int a_Value = ((int) tolua_tonumber(tolua_S,3,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetProperty'", NULL);
#endif
{
self->SetProperty(a_Property,a_Value);
}
}
return 0;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'SetProperty'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: SetProperty of class cWindow */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cWindow_SetProperty01
static int tolua_AllToLua_cWindow_SetProperty01(lua_State* tolua_S)
{
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cWindow",0,&tolua_err) ||
!tolua_isnumber(tolua_S,2,0,&tolua_err) ||
!tolua_isnumber(tolua_S,3,0,&tolua_err) ||
(tolua_isvaluenil(tolua_S,4,&tolua_err) || !tolua_isusertype(tolua_S,4,"cPlayer",0,&tolua_err)) ||
!tolua_isnoobj(tolua_S,5,&tolua_err)
)
goto tolua_lerror;
else
{
cWindow* self = (cWindow*) tolua_tousertype(tolua_S,1,0);
int a_Property = ((int) tolua_tonumber(tolua_S,2,0));
int a_Value = ((int) tolua_tonumber(tolua_S,3,0));
cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,4,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetProperty'", NULL);
#endif
{
self->SetProperty(a_Property,a_Value,*a_Player);
}
}
return 0;
tolua_lerror:
return tolua_AllToLua_cWindow_SetProperty00(tolua_S);
}
#endif //#ifndef TOLUA_DISABLE
/* method: new of class cLuaWindow */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cLuaWindow_new00
static int tolua_AllToLua_cLuaWindow_new00(lua_State* tolua_S)
@ -28610,6 +28677,8 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"IsSlotInPlayerInventory",tolua_AllToLua_cWindow_IsSlotInPlayerInventory00);
tolua_function(tolua_S,"GetWindowTitle",tolua_AllToLua_cWindow_GetWindowTitle00);
tolua_function(tolua_S,"SetWindowTitle",tolua_AllToLua_cWindow_SetWindowTitle00);
tolua_function(tolua_S,"SetProperty",tolua_AllToLua_cWindow_SetProperty00);
tolua_function(tolua_S,"SetProperty",tolua_AllToLua_cWindow_SetProperty01);
tolua_endmodule(tolua_S);
#ifdef __cplusplus
tolua_cclass(tolua_S,"cLuaWindow","cLuaWindow","cWindow",tolua_collect_cLuaWindow);

View File

@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 08/18/13 10:47:31.
** Generated automatically by tolua++-1.0.92 on 08/18/13 13:15:34.
*/
/* Exported function */

View File

@ -220,7 +220,7 @@ void cFurnaceEntity::BroadcastProgress(int a_ProgressbarID, short a_Value)
cWindow * Window = GetWindow();
if (Window != NULL)
{
Window->BroadcastInventoryProgress(a_ProgressbarID, a_Value);
Window->BroadcastProgress(a_ProgressbarID, a_Value);
}
}

View File

@ -1718,15 +1718,6 @@ void cClientHandle::SendHealth(void)
void cClientHandle::SendInventoryProgress(char a_WindowID, short a_ProgressBar, short a_Value)
{
m_Protocol->SendInventoryProgress(a_WindowID, a_ProgressBar, a_Value);
}
void cClientHandle::SendInventorySlot(char a_WindowID, short a_SlotNum, const cItem & a_Item)
{
m_Protocol->SendInventorySlot(a_WindowID, a_SlotNum, a_Item);
@ -1954,6 +1945,24 @@ void cClientHandle::SendWeather(eWeather a_Weather)
void cClientHandle::SendWholeInventory(const cInventory & a_Inventory)
{
m_Protocol->SendWholeInventory(a_Inventory);
}
void cClientHandle::SendWholeInventory(const cWindow & a_Window)
{
m_Protocol->SendWholeInventory(a_Window);
}
void cClientHandle::SendWindowClose(const cWindow & a_Window)
{
m_Protocol->SendWindowClose(a_Window);
@ -1972,18 +1981,9 @@ void cClientHandle::SendWindowOpen(char a_WindowID, char a_WindowType, const ASt
void cClientHandle::SendWholeInventory(const cInventory & a_Inventory)
void cClientHandle::SendWindowProperty(const cWindow & a_Window, int a_Property, int a_Value)
{
m_Protocol->SendWholeInventory(a_Inventory);
}
void cClientHandle::SendWholeInventory(const cWindow & a_Window)
{
m_Protocol->SendWholeInventory(a_Window);
m_Protocol->SendWindowProperty(a_Window, a_Property, a_Value);
}

View File

@ -111,7 +111,6 @@ public:
void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion);
void SendGameMode (eGameMode a_GameMode);
void SendHealth (void);
void SendInventoryProgress (char a_WindowID, short a_Progressbar, short a_Value);
void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item);
void SendPickupSpawn (const cPickup & a_Pickup);
void SendPlayerAnimation (const cPlayer & a_Player, char a_Animation);
@ -139,6 +138,7 @@ public:
void SendWholeInventory (const cWindow & a_Window);
void SendWindowClose (const cWindow & a_Window);
void SendWindowOpen (char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots);
void SendWindowProperty (const cWindow & a_Window, int a_Property, int a_Value);
const AString & GetUsername(void) const; // tolua_export
void SetUsername( const AString & a_Username ); // tolua_export

View File

@ -73,7 +73,6 @@ public:
virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) = 0;
virtual void SendGameMode (eGameMode a_GameMode) = 0;
virtual void SendHealth (void) = 0;
virtual void SendInventoryProgress (char a_WindowID, short a_Progressbar, short a_Value) = 0;
virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) = 0;
virtual void SendKeepAlive (int a_PingID) = 0;
virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) = 0;
@ -103,6 +102,7 @@ public:
virtual void SendWholeInventory (const cWindow & a_Window) = 0;
virtual void SendWindowClose (const cWindow & a_Window) = 0;
virtual void SendWindowOpen (char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) = 0;
virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) = 0;
/// Returns the ServerID used for authentication through session.minecraft.net
virtual AString GetAuthServerID(void) = 0;

View File

@ -82,7 +82,7 @@ enum
PACKET_WINDOW_CLICK = 0x66,
PACKET_INVENTORY_SLOT = 0x67,
PACKET_INVENTORY_WHOLE = 0x68,
PACKET_INVENTORY_PROGRESS = 0x69,
PACKET_WINDOW_PROPERTY = 0x69,
PACKET_CREATIVE_INVENTORY_ACTION = 0x6B,
PACKET_UPDATE_SIGN = 0x82,
PACKET_PLAYER_LIST_ITEM = 0xC9,
@ -491,20 +491,6 @@ void cProtocol125::SendHealth(void)
void cProtocol125::SendInventoryProgress(char a_WindowID, short a_ProgressBar, short a_Value)
{
cCSLock Lock(m_CSPacket);
WriteByte (PACKET_INVENTORY_PROGRESS);
WriteByte (a_WindowID);
WriteShort(a_ProgressBar);
WriteShort(a_Value);
Flush();
}
void cProtocol125::SendInventorySlot(char a_WindowID, short a_SlotNum, const cItem & a_Item)
{
cCSLock Lock(m_CSPacket);
@ -975,6 +961,20 @@ void cProtocol125::SendWindowOpen(char a_WindowID, char a_WindowType, const AStr
void cProtocol125::SendWindowProperty(const cWindow & a_Window, short a_Property, short a_Value)
{
cCSLock Lock(m_CSPacket);
WriteByte (PACKET_WINDOW_PROPERTY);
WriteByte (a_Window.GetWindowID());
WriteShort(a_Property);
WriteShort(a_Value);
Flush();
}
AString cProtocol125::GetAuthServerID(void)
{
// http://wiki.vg/wiki/index.php?title=Session&oldid=2262

View File

@ -50,7 +50,6 @@ public:
virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override;
virtual void SendGameMode (eGameMode a_GameMode) override;
virtual void SendHealth (void) override;
virtual void SendInventoryProgress (char a_WindowID, short a_Progressbar, short a_Value) override;
virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override;
virtual void SendKeepAlive (int a_PingID) override;
virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override;
@ -80,6 +79,7 @@ public:
virtual void SendWholeInventory (const cWindow & a_Window) override;
virtual void SendWindowClose (const cWindow & a_Window) override;
virtual void SendWindowOpen (char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) override;
virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) override;
virtual AString GetAuthServerID(void) override;

View File

@ -332,10 +332,10 @@ void cProtocolRecognizer::SendHealth(void)
void cProtocolRecognizer::SendInventoryProgress(char a_WindowID, short a_Progressbar, short a_Value)
void cProtocolRecognizer::SendWindowProperty(const cWindow & a_Window, short a_Property, short a_Value)
{
ASSERT(m_Protocol != NULL);
m_Protocol->SendInventoryProgress(a_WindowID, a_Progressbar, a_Value);
m_Protocol->SendWindowProperty(a_Window, a_Property, a_Value);
}

View File

@ -80,7 +80,6 @@ public:
virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override;
virtual void SendGameMode (eGameMode a_GameMode) override;
virtual void SendHealth (void) override;
virtual void SendInventoryProgress (char a_WindowID, short a_Progressbar, short a_Value) override;
virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override;
virtual void SendKeepAlive (int a_PingID) override;
virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override;
@ -110,6 +109,7 @@ public:
virtual void SendWholeInventory (const cWindow & a_Window) override;
virtual void SendWindowClose (const cWindow & a_Window) override;
virtual void SendWindowOpen (char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) override;
virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) override;
virtual AString GetAuthServerID(void) override;

View File

@ -664,12 +664,12 @@ void cWindow::BroadcastWholeWindow(void)
void cWindow::BroadcastInventoryProgress(short a_Progressbar, short a_Value)
void cWindow::BroadcastProgress(int a_Progressbar, int a_Value)
{
cCSLock Lock(m_CS);
for (cPlayerList::iterator itr = m_OpenedBy.begin(); itr != m_OpenedBy.end(); ++itr)
{
(*itr)->GetClientHandle()->SendInventoryProgress(m_WindowID, a_Progressbar, a_Value);
(*itr)->GetClientHandle()->SendWindowProperty(*this, a_Progressbar, a_Value);
} // for itr - m_OpenedBy[]
}
@ -677,6 +677,28 @@ void cWindow::BroadcastInventoryProgress(short a_Progressbar, short a_Value)
void cWindow::SetProperty(int a_Property, int a_Value)
{
cCSLock Lock(m_CS);
for (cPlayerList::iterator itr = m_OpenedBy.begin(), end = m_OpenedBy.end(); itr != end; ++itr)
{
(*itr)->GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value);
} // for itr - m_OpenedBy[]
}
void cWindow::SetProperty(int a_Property, int a_Value, cPlayer & a_Player)
{
a_Player.GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cInventoryWindow:

View File

@ -120,14 +120,20 @@ public:
/// Sends the contents of the whole window to all clients of this window.
void BroadcastWholeWindow(void);
/// Sends the progressbar to all clients of this window
void BroadcastInventoryProgress(short a_Progressbar, short a_Value);
/// Sends the progressbar to all clients of this window (same as SetProperty)
void BroadcastProgress(int a_Progressbar, int a_Value);
// tolua_begin
const AString & GetWindowTitle() const { return m_WindowTitle; }
void SetWindowTitle(const AString & a_WindowTitle ) { m_WindowTitle = a_WindowTitle; }
/// Sends the UpdateWindowProperty (0x69) packet to all clients of the window
void SetProperty(int a_Property, int a_Value);
/// Sends the UpdateWindowPropert(0x69) packet to the specified player
void SetProperty(int a_Property, int a_Value, cPlayer & a_Player);
// tolua_end
void OwnerDestroyed(void);