api.txt 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. Key API
  2. -------
  3. The key API allows mods to add key functionality to nodes that have
  4. ownership or specific permissions. Using the API will make it so
  5. that a node owner can use skeleton keys on their nodes to create keys
  6. for that node in that location, and give that key to other players,
  7. allowing them some sort of access that they otherwise would not have
  8. due to node protection.
  9. To make your new nodes work with the key API, you need to register
  10. two callback functions in each nodedef:
  11. `on_key_use(pos, player)`
  12. * Is called when a player right-clicks (uses) a normal key on your
  13. * node.
  14. * `pos` - position of the node
  15. * `player` - PlayerRef
  16. * return value: none, ignored
  17. The `on_key_use` callback should validate that the player is wielding
  18. a key item with the right key meta secret. If needed the code should
  19. deny access to the node functionality.
  20. If formspecs are used, the formspec callbacks should duplicate these
  21. checks in the metadata callback functions.
  22. `on_skeleton_key_use(pos, player, newsecret)`
  23. * Is called when a player right-clicks (uses) a skeleton key on your
  24. * node.
  25. * `pos` - position of the node
  26. * `player` - PlayerRef
  27. * `newsecret` - a secret value(string)
  28. * return values:
  29. * `secret` - `nil` or the secret value that unlocks the door
  30. * `name` - a string description of the node ("a locked chest")
  31. * `owner` - name of the node owner
  32. The `on_skeleton_key_use` function should validate that the player has
  33. the right permissions to make a new key for the item. The newsecret
  34. value is useful if the node has no secret value. The function should
  35. store this secret value somewhere so that in the future it may compare
  36. key secrets and match them to allow access. If a node already has a
  37. secret value, the function should return that secret value instead
  38. of the newsecret value. The secret value stored for the node should
  39. not be overwritten, as this would invalidate existing keys.
  40. Aside from the secret value, the function should retun a descriptive
  41. name for the node and the owner name. The return values are all
  42. encoded in the key that will be given to the player in replacement
  43. for the wielded skeleton key.
  44. if `nil` is returned, it is assumed that the wielder did not have
  45. permissions to create a key for this node, and no key is created.