]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - doc/lua_api.txt
Detached inventory callbacks and reworked node metadata callbacks
[dragonfireclient.git] / doc / lua_api.txt
index 176745a2d75207893c657e908ee6e6b7acf66d2c..5fb2c34e38144960fd230f381a8620da714c6d45 100644 (file)
@@ -677,6 +677,7 @@ size[<W>,<H>]
 ^ deprecated: invsize[<W>,<H>;]
 
 list[<inventory location>;<list name>;<X>,<Y>;<W>,<H>;]
+list[<inventory location>;<list name>;<X>,<Y>;<W>,<H>;<starting item index>]
 ^ Show an inventory list
 
 image[<X>,<Y>;<W>,<H>;<texture name>]
@@ -726,10 +727,12 @@ image_button_exit[<X>,<Y>;<W>,<H>;<texture name>;<name>;<label>]
 ^ When clicked, fields will be sent and the form will quit.
 
 Inventory location:
+
 - "context": Selected node metadata (deprecated: "current_name")
 - "current_player": Player to whom the menu is shown
 - "player:<name>": Any player
 - "nodemeta:<X>,<Y>,<Z>": Any node metadata
+- "detached:<name>": A detached inventory
 
 Helper functions
 -----------------
@@ -847,6 +850,10 @@ Inventory:
 minetest.get_inventory(location) -> InvRef
 ^ location = eg. {type="player", name="celeron55"}
                  {type="node", pos={x=, y=, z=}}
+                 {type="detached", name="creative"}
+minetest.create_detached_inventory(name, callbacks) -> InvRef
+^ callbacks: See "Detached inventory callbacks"
+^ Creates a detached inventory. If it already exists, it is cleared.
 
 Item handling:
 minetest.inventorycube(img1, img2, img3)
@@ -1355,35 +1362,25 @@ Node definition (register_node)
     ^ Called when an UI form (eg. sign text input) returns data
     ^ default: nil
 
-    on_metadata_inventory_move = func(pos, from_list, from_index,
-                                      to_list, to_index, count, player),
-    ^ Called when a player wants to move items inside the metadata
-    ^ Should move items, or some items, if permitted. If not, should do
-      nothing.
-    ^ The engine ensures the action is valid, i.e. the stack fits at the
-      given position
-    ^ default: minetest.node_metadata_inventory_move_allow_all
-
-    on_metadata_inventory_offer = func(pos, listname, index, stack, player),
-    ^ Called when a player wants to put something into the metadata
-      inventory
-    ^ Should check if the action is permitted (the engine ensures the
-      action is valid, i.e. the stack fits at the given position)
-      ^ If permitted, modify the metadata inventory and return the
-        "leftover" stack (normally nil).
-      ^ If not permitted, return itemstack.
-    ^ default: minetest.node_metadata_inventory_offer_allow_all
-
-    on_metadata_inventory_take = func(pos, listname, index, count, player),
-    ^ Called when a player wants to take something out of the metadata
-      inventory
-    ^ Should check if the action is permitted (the engine ensures the
-      action is valid, i.e. there's a stack of at least “count” items at
-      that position)
-      ^ If permitted, modify the metadata inventory and return the
-        stack of items
-      ^ If not permitted, return nil.
-    ^ default: minetest.node_metadata_inventory_take_allow_all
+       allow_metadata_inventory_move = func(pos, from_list, from_index,
+                       to_list, to_index, count, player),
+       ^ Called when a player wants to move items inside the inventory
+       ^ Return value: number of items allowed to move
+       
+       allow_metadata_inventory_put = func(pos, listname, index, stack, player),
+       ^ Called when a player wants to put something into the inventory
+       ^ Return value: number of items allowed to put
+  
+       allow_metadata_inventory_take = func(pos, listname, index, count, player),
+       ^ Called when a player wants to take something out of the inventory
+       ^ Return value: number of items allowed to take
+
+       on_metadata_inventory_move = func(pos, from_list, from_index,
+                       to_list, to_index, count, player),
+       on_metadata_inventory_put = func(pos, listname, index, stack, player),
+       on_metadata_inventory_take = func(pos, listname, index, count, player),
+       ^ Called after the actual action has happened, according to what was allowed.
+       ^ No return value
 }
 
 Recipe for register_craft: (shaped)
@@ -1440,3 +1437,24 @@ Chatcommand definition (register_chatcommand)
     func = function(name, param), -- called when command is run
 }
 
+Detached inventory callbacks
+{
+       allow_move = func(inv, from_list, from_index, to_list, to_index, count, player),
+    ^ Called when a player wants to move items inside the inventory
+       ^ Return value: number of items allowed to move
+       
+    allow_put = func(inv, listname, index, stack, player),
+    ^ Called when a player wants to put something into the inventory
+       ^ Return value: number of items allowed to put
+   
+    allow_take = func(inv, listname, index, count, player),
+    ^ Called when a player wants to take something out of the inventory
+       ^ Return value: number of items allowed to take
+       
+       on_move = func(inv, from_list, from_index, to_list, to_index, count, player),
+    on_put = func(inv, listname, index, stack, player),
+    on_take = func(inv, listname, index, count, player),
+       ^ Called after the actual action has happened, according to what was allowed.
+       ^ No return value
+}
+