Cuberite Forum
Hook for detecting click in cWindow, currently only cLuaWindow - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Cuberite (https://forum.cuberite.org/forum-4.html)
+--- Forum: Development (https://forum.cuberite.org/forum-13.html)
+--- Thread: Hook for detecting click in cWindow, currently only cLuaWindow (/thread-2971.html)



Hook for detecting click in cWindow, currently only cLuaWindow - Seadragon91 - 06-06-2017

Created a branch on github that contains changes for a hook to detect and deny the click action in cLuaWindow.
Branch:
https://github.com/Seadragon91/cuberite/tree/window_click

The hook function has this params:
Code:
function MyOnWindowClicking(Player, LuaWindow, ClickedItem, ClickAction, SlotNum)

The ClickAction is already in available on lua side.
I created a example plugin that opens a lua window with command /openit. It contains a few items that runs a command / open a window on clicking it. The window is generated from the ini file in the plugin folder.

The biggest question is now do we want to detect a click in all windows? Brewing stand, furnace, crafting table, minecart with chest?
If yes then we need to add something with that we can get the owner of the window (block entity, minecart entity) and we would need to export all windows to lua.

In plugin SkyBlock I added a challenge window as test, works same like in a java skyblock plugin that I created years ago. Can be opened with "/challenges inv"
https://github.com/Seadragon91/SkyBlock/commits/window_test


RE: Hook for detecting click in cWindow, currently only cLuaWindow - xoft - 06-06-2017

The cWindow class is already exported exactly for this purpose: https://api.cuberite.org/cWindow.html ; there's no need to export any specific window types, and we don't need the window owner just yet.


RE: Hook for detecting click in cWindow, currently only cLuaWindow - Seadragon91 - 06-06-2017

Well how can I get the content of the window?


RE: Hook for detecting click in cWindow, currently only cLuaWindow - Seadragon91 - 06-06-2017

I think lua window is good enough for changing the content, the most plugins creates a custom window.
The current use I see to deny changing the content of non lua windows, would it to make then content only viewable and there it's still possible to have the clicked item.


RE: Hook for detecting click in cWindow, currently only cLuaWindow - xoft - 06-06-2017

No, the problem is that cLuaWindow is a specific one; if you want to call the hook for regular windows, there's no way to cast them to cLuaWindow.


RE: Hook for detecting click in cWindow, currently only cLuaWindow - Seadragon91 - 06-06-2017

I tested the hook for regular windows and it works.
But for this I have a idea:
  1. Get the block entity that the player wants to open
  2. Deny the opening of the block entity
  3. Create a lua window with the content of the block entity
  4. Call cPlayer:OpenWindow to open it
  5. Now the hook will be called and combining a list containing the player and the block entity - everything should be possible
  6. If the player closes the window, the callback SetOnClosing can be used to write the content back



RE: Hook for detecting click in cWindow, currently only cLuaWindow - Seadragon91 - 06-06-2017

Do we want the hook only for cLuaWindow or for regulars, too?


RE: Hook for detecting click in cWindow, currently only cLuaWindow - xoft - 06-07-2017

Why would we even need it for cLuaWindow, when the plugin already has the cLuaWindow object and does set all the handlers. We need a universal hook for all windows.