api.txt 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. Lucky Block API
  2. ===============
  3. This guide will show you how to add schematic files and lucky blocks from
  4. within your own mods. Please make sure that lucky_block appears in the
  5. depends.txt file of your mod so everything work properly.
  6. Function Usage
  7. ==============
  8. Purge Block List
  9. ----------------
  10. lucky_block:purge_block_list()
  11. This command is used to clear all of the blocks in the lucky block list so that
  12. you can add your own.
  13. Add Lucky Blocks to list
  14. ------------------------
  15. lucky_block:add_blocks({ block definitions here })
  16. This command is used to add new blocks to the lucky block list.
  17. e.g.
  18. lucky_block:add_blocks({
  19. {"nod", "default:dirt", 0},
  20. {"dro", {"default:dirt"}, 5},
  21. })
  22. Purge Chest Items
  23. -----------------
  24. lucky_block:purge_chest_items()
  25. This command is used to purge all items in the default chest list so that you
  26. can add your own.
  27. Add Items to Default Chest
  28. --------------------------
  29. lucky_block:add_chest_items({ add new default chest items here })
  30. This command lets you add new items to the default chest when it appears
  31. inside a lucky block.
  32. e.g.
  33. lucky_block:add_chest_items({
  34. {name = "default:apple", max = 3},
  35. {name = "default:steel_ingot", max = 2},
  36. {name = "default:pick_diamond", max = 1, chance = 5},
  37. })
  38. Add Schematics to List
  39. ----------------------
  40. lucky_block:add_schematics({ add new schematic definitions here })
  41. This command lets you add schematic files and arrays to the list so they can
  42. be added to the lucky block list.
  43. e.g. check for Ethereal mod then get the path and add two of the tree's to the
  44. schematic list and finally to the lucky block list:
  45. if minetest.get_modpath("ethereal") then
  46. local path = minetest.get_modpath("ethereal") .. "/schematics/"
  47. lucky_block:add_schematics({
  48. -- name on list, schematic, offset placement
  49. {"appletree", ethereal.appletree, {x = 1, y = 0, z = 1}},
  50. {"bananatree", ethereal.bananatree, {x = 3, y = 0, z = 3}},
  51. }
  52. lucky_block:add_blocks({
  53. {"sch", "appletree", 0, false},
  54. {"sch", "bananatree", 0, false},
  55. })
  56. end
  57. Open Lucky Block
  58. ----------------
  59. lucky_block:open(pos, digger, blocks_list)
  60. This is the function called when the default lucky block has been dug, it will
  61. use the default blocks list or use a custom one when supplied so that modders
  62. can add their own lucky block sets.
  63. e.g.
  64. local my_blocks = {
  65. {"nod", "default:wood"},
  66. {"dro", {"default:tree", "default:jungletree"}, 5},
  67. {"exp"},
  68. }
  69. minetest.register_node('mymod:my_lucky_block', {
  70. description = "My Lucky Block",
  71. tiles = {"mymod_lucky_block.png"},
  72. paramtype = "light",
  73. groups = {oddly_breakable_by_hand = 3},
  74. drop = {},
  75. sounds = default.node_sound_wood_defaults(),
  76. on_dig = function(pos, node, digger)
  77. minetest.remove_node(pos) -- remove lucky block
  78. lucky_block:open(pos, digger, my_blocks) -- use custom blocks list
  79. end,
  80. })
  81. Lucky Block Commands
  82. ====================
  83. Using the lucky_block:add_blocks() command gives you access to many features
  84. from within this mod, these are listed below using this general format:
  85. lucky_block:add_blocks({
  86. {"command", command options},
  87. ..etc
  88. })
  89. Place Node
  90. ----------
  91. This command will place a node in place of the lucky block or at the players
  92. standing position.
  93. {"nod", "node name", position, chest items}
  94. e.g.
  95. Place a dirt block where lucky block was
  96. {"nod", "default:dirt", 0}
  97. Place a chest containing random items from default chest items list
  98. {"nod", "default:chest", 0}
  99. Place chest with a 1/5 chance of adding roses, up to 10x dirt and a worn shovel
  100. {"nod", "default:chest", 0, {
  101. {name = "default:dirt", max = 10},
  102. {name = "flowers:rose", max = 5, chance = 5},
  103. {name = "default:shovel_wood", max = 1, min_wear = 20000, max_wear = 65535},
  104. }}
  105. Place fire at player position
  106. {"nod", "fire:basic_flame", 1}
  107. Drop Item(s)
  108. ------------
  109. This command will throw a single or multiple items out of a lucky block,
  110. random colours can be used also.
  111. {"dro", {"item names"}, how many to drop, use random colours}
  112. e.g.
  113. Drop 5x torches as itemstack
  114. {"dro", {"default:torch"}, 5}
  115. Drop 10x randomly coloured wool (colour name added to end of item string)
  116. {"dro", {"wool:"}, 10, true}
  117. Drop 1x random tool from list
  118. {"dro", {"default:pick_mese", "default:shovel_steel", "default:axe_diamond"}, 1}
  119. Place Schematic
  120. ---------------
  121. This command lets you place a pre-added schematic file or definition in place
  122. of the lucky block or at the player position.
  123. {"sch", "schematic name", position, force placement, replacements}
  124. e.g.
  125. Place lucky platform at player position and force placement
  126. {"sch", "platform", 1, true}
  127. Place apple tree where lucky block use to be
  128. {"sch", "appletree", 0, false}
  129. Place apple tree where lucky block use to be and change wood into stone
  130. {"sch", "appletree", 0, false, {{"default:wood", "default:stone"}} }
  131. Spawn Entity or Mob
  132. -------------------
  133. This command allows you to place a monster, animal or other entity.
  134. {"spw", {"entity name"}, how many to spawn, tamed, owned, range, nametag}
  135. e.g.
  136. Spawn 2x Dirt or Stone Monsters over a radius of 10 blocks
  137. {"spw", {"mobs:dirt_monster", "mobs:stone_monster"}, 2, nil, nil, 10}
  138. Spawn 5x randomly coloured sheep (random colour only works with Mobs Redo sheep)
  139. {"spw", "mobs:sheep", 5}
  140. Spawn a single NPC who is tamed and owned by player and called "Bob"
  141. {"spw", "mobs:npc", 1, true, true, 1, "Bob"}
  142. Falling Blocks
  143. --------------
  144. This command allows for a tower of blocks or blocks falling within a set area.
  145. {"fal", {"node list"}, position, spread, range}
  146. e.g.
  147. Drop 2x sand and 1x gold block spread over a range of 5 blocks
  148. {"fal", {"default:sand", "default:sand", "default:goldblock"}, 0, true, 5}
  149. Drop 3x obsidian onto player as a tower
  150. {"fal", {"default:obsidian", "default:obsidian", "default:obsidian"}, 1}
  151. Troll Block
  152. -----------
  153. This command is similar to the place node command only it allows for a sound to
  154. be played on placement, then after two seconds the block will disappear or
  155. can explode causing damage to nearby players.
  156. {"tro", "node name", "sound", explode}
  157. e.g.
  158. Add diamond block then after 2 seconds remove with explosion
  159. {"tro", "default:diamondblock", nil, true}
  160. Add gold block with wood sound, then after 2 seconds remove with pop
  161. {"tro", "default:goldblock", "default_wood_footstep", nil}
  162. Random Teleport
  163. ---------------
  164. This command will teleport the player opening the lucky block a random number
  165. of blocks away using a preset range.
  166. {"tel", horizontal range, vertical range}
  167. e.g.
  168. Teleport player to random position 10 blocks left/right and 5 blocks up/under
  169. {"tel", 10, 5}
  170. Explosion
  171. ---------
  172. Now we start adding the bad lucky blocks that cause damage to the player by
  173. adding explosions.
  174. {"exp", radius}
  175. e.g.
  176. Cause explosion with damage radius of 4.
  177. {"exp", 4}
  178. Lightning Strike
  179. ----------------
  180. This is one of my favourite commands, lightning strikes the player and hurts
  181. everyone else nearby, can also place fire at strike position.
  182. {"lig", "fire node"}
  183. e.g.
  184. Strike player and place temporary fire
  185. {"lig", "fire:basic_flame"}
  186. Strike player and place permanent flame
  187. {"lig", "fire:permanent_flame"}
  188. Floor Placement
  189. ---------------
  190. This feature places random blocks from the list provided to make a floor under
  191. the lucky block with a pause after each block.
  192. {"flo", width, {node_list}, offset},
  193. e.g.
  194. Place a three wide obsidian and gold block floor with offset of 1 to centre on
  195. lucky block
  196. {"flo", 3, {"default:goldblock", "default:obsidian"}, 1}
  197. Have a woolen floor at 5 width with offset of 2 to keep it centred
  198. {"flo", 5, {"wool:red", "wool:blue", "wool:white", "wool:orange"}, 2}
  199. Custom Function
  200. ---------------
  201. This allows mod makers to use there own functions when opening lucky blocks and
  202. passes the block position, the player opening it and a def table with anything
  203. else the function needs.
  204. {"cus", myfunction, def}
  205. e.g.
  206. Punch player and deal 5 damage points (function first then line to add l.block)
  207. local function punchy(pos, player, def)
  208. player:punch(player, 1.0, {
  209. full_punch_interval = 1.0,
  210. damage_groups = {fleshy = def.damage}
  211. }, nil)
  212. end
  213. {"cus", punchy, {damage = 5} }
  214. Void Pick
  215. ---------
  216. This is a special item that can be dropped and allows the user to dig cracky grouped
  217. blocks as they are e.g. stone with copper is picked up as stone with copper, not copper
  218. ore. Adding {no_silktouch=1} group to a block prevents it from being dug in this way.
  219. Final Words
  220. ===========
  221. I hope this guide helps you add lucky blocks from within your own mods and for
  222. more examples please check out the blocks.lua and schems.lua files.