lb_well.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. -- well block (player stands near and it triggers drops)
  2. minetest.register_node("lucky_block:well_block", {
  3. description = "Well Block",
  4. tiles = {"default_glass.png"},
  5. light_source = 5,
  6. groups = {not_in_creative_inventory = 1, unbreakable = 1},
  7. on_blast = function() end,
  8. drop = {}
  9. })
  10. -- wishing well schematic layout
  11. local stb = {name = "default:steelblock", param1 = 255}
  12. local sbr = {name = "default:stonebrick", param1 = 255}
  13. local fwd = {name = "default:fence_wood", param1 = 255}
  14. local slb = {name = "stairs:slab_stonebrick", param1 = 255}
  15. local wbl = {name = "lucky_block:well_block", param1 = 255}
  16. local gla = {name = "default:glass", param1 = 255}
  17. local wat = {name = "default:water_source", param1 = 255}
  18. local air = {name = "air"}
  19. local wishing_well = {
  20. size = {x = 3, y = 5, z = 3},
  21. data = {
  22. stb,sbr,stb,
  23. sbr,sbr,sbr,
  24. fwd,air,fwd,
  25. fwd,air,fwd,
  26. slb,slb,slb,
  27. sbr,wbl,sbr,
  28. sbr,wat,sbr,
  29. air,air,air,
  30. air,air,air,
  31. slb,gla,slb,
  32. stb,sbr,stb,
  33. sbr,sbr,sbr,
  34. fwd,air,fwd,
  35. fwd,air,fwd,
  36. slb,slb,slb
  37. }
  38. }
  39. -- add schematic to list
  40. lucky_block:add_schematics({
  41. {"wishingwell", wishing_well, {x = 1, y = 1, z = 1}}
  42. })
  43. -- Global list containing well blocks that can be dropped
  44. lucky_block.wellblocks = {}
  45. -- helper function
  46. local add_wblock = function(list)
  47. for s = 1, #list do
  48. table.insert(lucky_block.wellblocks, list[s])
  49. end
  50. end
  51. if lucky_block.mod_def then
  52. add_wblock({
  53. {"default:ice", 5},
  54. {"default:bronzeblock", 2},
  55. {"default:lava_source", 7},
  56. {"default:coalblock", 4},
  57. {"default:sand", 7},
  58. {"default:goldblock", 2},
  59. {"default:cactus", 5},
  60. {"default:cobble", 5},
  61. {"default:brick", 5},
  62. {"fire:permanent_flame", 7},
  63. {"default:desert_sand", 7},
  64. {"default:grass_5", 7},
  65. {"default:obsidian", 4},
  66. {"default:diamondblock", 2},
  67. {"default:dirt", 7},
  68. {"default:clay", 5},
  69. {"default:copperblock", 2},
  70. {"default:mese", 2},
  71. {"default:silver_sand", 7},
  72. {"default:snowblock", 7},
  73. {"default:mossycobble", 5},
  74. {"default:lava_source", 5},
  75. {"default:blueberry_bush_leaves_with_berries", 4},
  76. {"default:coral_skeleton", 4},
  77. {"default:coral_orange", 4},
  78. {"default:coral_brown", 4},
  79. {"default:gravel", 5},
  80. {"default:permafrost_with_moss", 4},
  81. {"default:stone_with_diamond", 4},
  82. {"default:stone_with_gold", 4},
  83. {"default:stone_with_copper", 4},
  84. {"default:lava_source", 4},
  85. {"default:stone_with_mese", 4},
  86. {"default:stone_with_coal", 4},
  87. {"default:stone_with_tin", 4},
  88. {"default:stone_with_iron", 4},
  89. {"fire:permanent_flame", 7}
  90. })
  91. end
  92. if minetest.get_modpath("tnt") then
  93. add_wblock({
  94. {"tnt:tnt_burning", 8},
  95. {"tnt:tnt_burning", 4},
  96. {"tnt:tnt_burning", 8}
  97. })
  98. end
  99. if minetest.get_modpath("ethereal") then
  100. add_wblock({
  101. {"ethereal:crystal_block", 2}
  102. })
  103. end
  104. if minetest.get_modpath("bones") then
  105. add_wblock({
  106. {"bones:bones", 4}
  107. })
  108. end
  109. if lucky_block.mod_mcl then
  110. add_wblock({
  111. {"mcl_core:diamondblock", 4},
  112. {"mcl_core:goldblock", 4},
  113. {"mcl_core:lava_source", 4},
  114. {"mcl_core:water_source", 4},
  115. {"mcl_core:sand", 7},
  116. {"mcl_core:gravel", 7},
  117. {"mcl_core:obsidian", 4},
  118. {"mcl_core:ironblock", 4},
  119. {"mcl_core:sandstone", 7},
  120. {"mcl_core:snow", 7}
  121. })
  122. end
  123. -- abm function to detect player and trigger drops
  124. minetest.register_abm({
  125. label = "Lucky Block Wishing Well Block",
  126. nodenames = {"lucky_block:well_block"},
  127. interval = 2,
  128. chance = 1,
  129. catch_up = false,
  130. action = function(pos, node, active_object_count, active_object_count_wider)
  131. for _,object in pairs(minetest.get_objects_inside_radius(pos, 1.2)) do
  132. if object and object:is_player() then
  133. minetest.swap_node(pos, {name = lucky_block.def_glass})
  134. minetest.sound_play("default_tool_breaks", {
  135. pos = pos, gain = 1.0, max_hear_distance = 5}, true)
  136. local b_no = math.random(#lucky_block.wellblocks)
  137. local item = lucky_block.wellblocks[b_no][1]
  138. for n = 1, lucky_block.wellblocks[b_no][2] do
  139. local nod = table.copy(minetest.registered_nodes[item])
  140. if nod then
  141. local obj = minetest.add_entity({
  142. x = pos.x + math.random(-7, 7),
  143. y = pos.y + 7,
  144. z = pos.z + math.random(-7, 7)
  145. }, "__builtin:falling_node")
  146. if obj then
  147. local ent = obj:get_luaentity()
  148. if ent then
  149. nod.param2 = 1 -- set default rotation
  150. ent:set_node(nod)
  151. end
  152. end
  153. end
  154. end
  155. break
  156. end
  157. end
  158. end
  159. })