Nether mod for Minetest
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

250 lines
11KB

  1. Portal API Reference
  2. ====================
  3. The portal system used to get to the Nether can be used to create portals
  4. to other realms.
  5. Pick a node type to have your portals built from, a shape in which the
  6. portals must be built, and provide 3 functions for portals to find their
  7. destination with:
  8. * `find_realm_anchorPos(surface_anchorPos)`
  9. * `find_surface_anchorPos(realm_anchorPos)`
  10. * `is_within_realm(pos)`
  11. Optionally decorate by choosing portal colors, particles, media etc.
  12. See `init.lua` and `portal_examples.lua` for examples of 3 different portals.
  13. Portal code is more efficient when each type of portal uses a different type
  14. of node to build its frame out of - consider creating your own node for
  15. players to build portals from. However it is possible to register more than
  16. one kind of portal with the same frame material — such as obsidian — provided
  17. the size of the PortalShape is distinct from any other type of portal that is
  18. using the same node for its frame, and portal sizes remain small.
  19. Realms
  20. ------
  21. This API uses the concept of a realm for each type of portal. If a portal is
  22. outside its realm then it links to a portal inside the realm, if a portal is
  23. inside its realm then it links to the outside.
  24. You get to decide what constitutes your realm by implementing the function
  25. `is_within_realm(position)`.
  26. For example, the Nether realm is defined as existing at a certain depth and
  27. anything above that depth is considered outside the Realm.
  28. In contrast, the "Surface portal" - an example in portal_examples.lua, only
  29. uses one realm. Its `is_within_realm()` function always returns true so that
  30. any time a portal is opened it will use `find_surface_anchorPos()`.
  31. Note that the name "find_surface_anchorPos" is a Nether-centric misnomer, as
  32. different types of portals are free to use different definitions of a realm
  33. such that leaving the realm might not be synonymous with travelling to the
  34. surface.
  35. Helper functions
  36. ----------------
  37. * `nether.volume_is_natural(minp, maxp)`: returns a boolean
  38. * use this when determining where to spawn a portal, to avoid overwriting
  39. player builds. It checks the area for any nodes that aren't ground or
  40. trees.
  41. Water will fail this test, unless it is unemerged.
  42. * `nether.find_surface_target_y(target_x, target_z, portal_name)`: returns a
  43. suitable anchorPos
  44. * Can be used when implementing custom find_surface_anchorPos() functions
  45. * portal_name is optional, providing it allows existing portals on the
  46. surface to be reused.
  47. * `nether.find_nearest_working_portal(portal_name, anchorPos, distance_limit, y_factor)`: returns
  48. (anchorPos, orientation), or nil if no portal was found within the
  49. distance_limit.
  50. * A y_factor of 0 means y does not affect the distance_limit, a y_factor
  51. of 1 means y is included (the default if y_factor is nil), and a y_factor
  52. of 2 would squash the search-sphere by a factor of 2 on the y-axis, etc.
  53. * Only portals in the same realm as the anchorPos will be returned, even if
  54. y_factor is 0.
  55. * Pass a nil (or negative) distance_limit to indicate no distance limit
  56. API functions
  57. -------------
  58. Call these functions only at load time:
  59. * `nether.register_portal(name, portal_definition)`
  60. * Returns true on success. Can return false if the portal definition
  61. clashes with a portal already registered by another mod, e.g. if the size
  62. and frame node is not unique.
  63. A false return value should be handled, you could:
  64. * Fall back to using a secondary material for portals to be built with.
  65. * Use error() to exit lua with a message explaining how two mods are
  66. clashing and how it can be resolved.
  67. * Continue without a portal (the reason will be logged for the user).
  68. * `nether.register_portal_ignition_item(name, ignition_failure_sound)`
  69. * ignition_failure_sound is optional, it plays any time an attempt to use
  70. the item occurs if a portal is not ignited.
  71. * `nether.register_wormhole_node(name, nodedef_overrides)`
  72. * Can be used to register wormhole nodes with a different post_effect_color
  73. from the "nether:portal" node. "Post effect color" is the tint the world
  74. takes on when you are standing inside a portal. `post_effect_color` is the
  75. only key/value that is needed in the nodedef_overrides table to achieve that,
  76. but the function allows any nodedef key/value to be specified/overridden.
  77. * After `register_wormhole_node()`, invoke `register_portal()` and include
  78. `wormhole_node_name` in the portal_definition, assigning it the name of the
  79. new wormhole node.
  80. * `nether.unregister_portal(name)`
  81. * Unregisters the portal from the engine, and deletes the entry with key
  82. `name` from `nether.registered_portals` and associated internal tables.
  83. * Returns true on success
  84. * You will probably never need to call this, it exists only for completeness.
  85. Portal definition
  86. -----------------
  87. Used by `nether.register_portal`.
  88. {
  89. frame_node_name = "default:obsidian",
  90. -- Required. For best results, have your portal constructed of a
  91. -- material nobody else is using.
  92. frame_node_color = 0,
  93. -- Optional.
  94. -- A value from 0 to 7. Only used if the frame node's paramtype2 is
  95. -- "colorfacedir", in which case this color will be used when a remote
  96. -- portal is created.
  97. shape = nether.PortalShape_Traditional,
  98. -- Optional.
  99. -- Shapes available are:
  100. -- nether.PortalShape_Traditional (default)
  101. -- nether.PortalShape_Circular
  102. -- nether.PortalShape_Platform
  103. -- New shapes can be created, but are beyond the scope of this guide.
  104. wormhole_node_name = "nether:portal",
  105. -- Optional. Allows a custom wormhole node to be specified.
  106. -- Useful if you want the portals to have a different post_effect_color
  107. -- or texture.
  108. -- The Nether mod provides:
  109. -- "nether:portal" (default)
  110. -- "nether:portal_alt"
  111. wormhole_node_color = 0,
  112. -- Optional. Defaults to 0/magenta.
  113. -- A value from 0 to 7 corresponding to the color of pixels in
  114. -- nether_portals_palette.png:
  115. -- 0 traditional/magenta
  116. -- 1 black
  117. -- 2 blue
  118. -- 3 green
  119. -- 4 cyan
  120. -- 5 red
  121. -- 6 yellow
  122. -- 7 white
  123. particle_color = "#808",
  124. -- Optional. Will default to a colour matching the wormhole_node_color
  125. -- if not specified.
  126. particle_texture = "image.png",
  127. -- Optional. Hardware colouring (i.e. particle_color) is applied to
  128. -- this texture, use particle_texture_colored instead if you want to
  129. -- use the colors of the image.
  130. -- Animation and particle scale may also be specified, e.g:
  131. -- particle_texture = {
  132. -- name = "nether_particle_anim1.png",
  133. -- animation = {
  134. -- type = "vertical_frames",
  135. -- aspect_w = 7,
  136. -- aspect_h = 7,
  137. -- length = 1,
  138. -- },
  139. -- scale = 1.5
  140. -- },
  141. -- See lua_api.txt for Tile Animation definition
  142. -- Some animated and non-animated textures are provided by this mod:
  143. -- nether_particle.png (original)
  144. -- nether_particle_anim1.png (stars)
  145. -- nether_particle_anim2.png (bubbles)
  146. -- nether_particle_anim3.png (sparks)
  147. -- nether_particle_anim4.png (particles)
  148. title = "Gateway to Moria",
  149. -- Optional. Provides a title for the portal.
  150. -- Used in the Book of Portals or Help modpack.
  151. book_of_portals_pagetext = "Everything I need the player to know",
  152. -- Optional. Provides the text for the portal in the Book of Portals
  153. -- and Help modpack.
  154. -- The Book of Portals is a book that can be found in chests, and
  155. -- provides players with instructions on how to build and use the
  156. -- portal, so be sure to mention the node type the frame must be built
  157. -- from.
  158. -- This can also provide flavortext or details about where the portal
  159. -- will take the player.
  160. sounds = {
  161. ambient = <SimpleSoundSpec>,
  162. -- if the ambient SimpleSoundSpec is a table it can also contain a
  163. -- "length" int, which is the number of seconds to wait before
  164. -- repeating the ambient sound. Default is 3.
  165. ignite = <SimpleSoundSpec>,
  166. extinguish = <SimpleSoundSpec>,
  167. teleport = <SimpleSoundSpec>,
  168. }
  169. -- sounds is optional
  170. within_realm = function(pos),
  171. -- Required. Return true if a portal at pos is in the realm, rather
  172. -- than the surface world.
  173. -- Ideally implementations are fast, as this function can be used to
  174. -- sift through a list of portals.
  175. find_realm_anchorPos = function(surface_anchorPos),
  176. -- Required. Return a position in the realm that a portal created at
  177. -- surface_anchorPos will link to.
  178. -- Return an anchorPos or (anchorPos, orientation)
  179. -- If orientation is not specified then the orientation of the surface
  180. -- portal will be used.
  181. -- If the location of an existing portal is returned then include the
  182. -- orientation, otherwise the existing portal could be overwritten by
  183. -- a new one with the orientation of the surface portal.
  184. -- Return nil to prevent the portal from igniting.
  185. find_surface_anchorPos = function(realm_anchorPos),
  186. -- Optional. If you don't implement this then a position near the
  187. -- surface will be picked.
  188. -- Return an anchorPos or (anchorPos, orientation)
  189. -- The name of this function is a Nether-centric misnomer. It should
  190. -- return a position outside the realm, and different types of portals
  191. -- are free to use different definitions of a realm such that leaving
  192. -- the realm might not be synonymous with travelling to the surface.
  193. -- If orientation is not specified then the orientation of the realm
  194. -- portal will be used.
  195. -- If the location of an existing portal is returned then include the
  196. -- orientation, otherwise the existing portal could be overwritten by
  197. -- a new one with the orientation of the realm portal.
  198. -- Return nil to prevent the portal from igniting.
  199. on_run_wormhole = function(portalDef, anochorPos, orientation),
  200. -- invoked once per second per portal
  201. on_extinguish = function(portalDef, anochorPos, orientation),
  202. -- invoked when a portal is extinguished, including when the portal
  203. -- it connected to was extinguished.
  204. on_player_teleported = function(portalDef, player, oldPos, newPos),
  205. -- invoked immediately after a player is teleported
  206. on_ignite = function(portalDef, anochorPos, orientation)
  207. -- invoked when a player or mesecon ignites a portal
  208. on_created = function(portalDef, anochorPos, orientation)
  209. -- invoked when a portal creates a remote twin, this is usually when
  210. -- a player travels through a portal for the first time.
  211. }