bridge.lua 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. local function make_bridge(pos, width, length, height, dir, node)
  2. dir.y = 0
  3. local ndir = vector.normalize(dir)
  4. local cross = vector.normalize({x=-dir.z, y=0, z=dir.x})
  5. local w2 = width / 2
  6. local exp = 2
  7. local off = math.sin(math.pi/(exp*exp)) * height
  8. for l = 0,length do
  9. local y = -off + math.sin(math.pi/(exp*exp) + ((l / length) * math.pi / exp) ) * height
  10. local p = {x = pos.x+l*ndir.x, y=pos.y+y, z=pos.z+l*ndir.z}
  11. local param2 = 0
  12. if math.floor(y + .5) ~= math.floor(y) then
  13. p.y = p.y - 1
  14. param2 = 20
  15. end
  16. for w = -w2,w2 do
  17. minetest.set_node(
  18. vector.add(p, vector.multiply(cross, w)),
  19. {name=node, param2 = param2})
  20. end
  21. end
  22. end
  23. function make_temp_node(oname)
  24. local t = string.split(oname, ":")
  25. local mn = t[1]
  26. local nn = t[2]
  27. local newname = "potions:temp_slab_"..mn.."_"..nn
  28. -- see if it's already registered
  29. if minetest.registered_nodes[newname] ~= nil then
  30. return newname
  31. end
  32. local odef = minetest.registered_nodes[oname]
  33. minetest.register_node(newname, {
  34. description = odef.name,
  35. tiles = odef.tiles,
  36. special_tiles = odef.special_tiles,
  37. groups = {cracky=3, crumbly=3, snappy=3, choppy=3, not_in_creative_inventory=1},
  38. drawtype = "nodebox",
  39. paramtype = "light",
  40. paramtype2 = "facedir",
  41. alpha = odef.alpha,
  42. sounds = odef.sounds,
  43. drop = "",
  44. node_box = {
  45. type = "fixed",
  46. fixed = {
  47. {-0.5, -0.5, -0.5, 0.5, 0.0, 0.5},
  48. },
  49. },
  50. on_construct = function(pos)
  51. minetest.get_node_timer(pos):start(10 * 3 + math.random(10))
  52. end,
  53. on_timer = function(pos)
  54. minetest.set_node(pos, {name="air"})
  55. end,
  56. })
  57. return newname
  58. end
  59. function get_temp_node(oname)
  60. local t = string.split(oname, ":")
  61. local mn = t[1]
  62. local nn = t[2]
  63. local newname = "potions:temp_slab_"..mn.."_"..nn
  64. -- see if it's already registered
  65. if minetest.registered_nodes[newname] ~= nil then
  66. return newname
  67. end
  68. -- TODO: check groups to return the closest analog
  69. return "potions:temp_slab_default_dirt"
  70. end
  71. make_temp_node("default:dirt")
  72. -- the special tiles are messed up
  73. -- make_temp_node("default:dirt_with_grass")
  74. -- make_temp_node("default:dirt_with_rainforest_litter")
  75. -- make_temp_node("default:dirt_with_coniferous_litter")
  76. -- make_temp_node("default:dirt_with_dry_grass")
  77. -- make_temp_node("default:dirt_with_snow")
  78. make_temp_node("default:sand")
  79. make_temp_node("default:desert_sand")
  80. make_temp_node("default:silver_sand")
  81. make_temp_node("default:cobble")
  82. make_temp_node("default:stone")
  83. make_temp_node("default:desert_stone")
  84. make_temp_node("default:desert_cobble")
  85. make_temp_node("default:mossycobble")
  86. make_temp_node("default:sandstone")
  87. make_temp_node("default:desert_sandstone")
  88. make_temp_node("default:silver_sandstone")
  89. make_temp_node("default:obsidian")
  90. make_temp_node("default:permafrost")
  91. make_temp_node("default:permafrost_with_stones")
  92. make_temp_node("default:permafrost_with_moss")
  93. make_temp_node("default:gravel")
  94. make_temp_node("default:clay")
  95. make_temp_node("default:snow")
  96. make_temp_node("default:snowblock")
  97. make_temp_node("default:cave_ice")
  98. make_temp_node("default:ice")
  99. make_temp_node("default:tree")
  100. make_temp_node("default:wood")
  101. make_temp_node("default:leaves")
  102. make_temp_node("default:acacia_tree")
  103. make_temp_node("default:acacia_wood")
  104. make_temp_node("default:acacia_leaves")
  105. make_temp_node("default:aspen_tree")
  106. make_temp_node("default:aspen_wood")
  107. make_temp_node("default:aspen_leaves")
  108. make_temp_node("default:pine_tree")
  109. make_temp_node("default:pine_wood")
  110. make_temp_node("default:pine_needles")
  111. make_temp_node("default:jungletree")
  112. make_temp_node("default:junglewood")
  113. make_temp_node("default:jungleleaves")
  114. make_temp_node("default:water_source")
  115. make_temp_node("default:water_flowing")
  116. make_temp_node("default:river_water_source")
  117. make_temp_node("default:river_water_flowing")
  118. make_temp_node("default:lava_source")
  119. make_temp_node("default:lava_flowing")
  120. make_temp_node("default:glass")
  121. make_temp_node("default:brick")
  122. make_temp_node("default:obsidian_glass")
  123. minetest.register_craftitem("potions:bridge_seed", {
  124. description = "Bridge Seed",
  125. inventory_image = "default_stone_brick.png",
  126. groups = {cracky=3,},
  127. liquids_pointable=true,
  128. on_use = function(itemstack, player, pointed_thing)
  129. local pos = pointed_thing.above
  130. if not pos then
  131. return
  132. end
  133. local below = {x=pos.x, y=pos.y-1, z=pos.z}
  134. local n = minetest.get_node(below)
  135. if n.name == "air" or n.name == "ignore" then
  136. return
  137. end
  138. local newname = get_temp_node(n.name)
  139. local th = player:get_look_horizontal()
  140. local dir = {
  141. x = -math.sin(th),
  142. y = 0,
  143. z = math.cos(th),
  144. }
  145. local pos2 = vector.add(pos, vector.multiply(dir, potions.get_manna(player)))
  146. local b, pos3 = minetest.line_of_sight(pos, pos2)
  147. if b == false then
  148. pos2 = pos3
  149. end
  150. local dist = vector.distance(pos, pos2)
  151. dist = potions.use_manna(player, dist)
  152. if dist < 2 then
  153. return
  154. end
  155. minetest.set_node(pos, {name="air"})
  156. make_bridge(pos, 3, dist, dist / 3, dir, newname)
  157. -- get player yaw, calc direction
  158. -- itemstack:take_item()
  159. return itemstack
  160. end,
  161. })