portal_api.txt 12 KB

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