tunnel.lua 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. local function make_tunnel(pos, radius, length, dir)
  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 wlow = math.ceil(width / 2)
  6. local whigh = math.floor(width / 2)
  7. local exp = 2
  8. -- local off = math.sin(math.pi/(exp*exp)) * height
  9. for l = 0,length do
  10. -- local y = -off + math.sin(math.pi/(exp*exp) + ((l / length) * math.pi / exp) ) * height
  11. local p = {x = pos.x+l*ndir.x, y=pos.y+l*ndir.y, z=pos.z+l*ndir.z}
  12. -- local param2 = 0
  13. -- if math.floor(y + .5) ~= math.floor(y) then
  14. -- p.y = p.y - 1
  15. -- param2 = 20
  16. -- end
  17. print(dump(p))
  18. minetest.set_node(p, {name="air"})
  19. for h = -radius,radius do
  20. for w = -radius,radius do
  21. if math.sqrt(h*h + w*w) <= radius then
  22. local p2 = vector.add(p, vector.multiply(cross, w))
  23. p2.y = p2.y + h
  24. minetest.set_node(
  25. p2,
  26. {name="air"})
  27. end
  28. end
  29. end
  30. end
  31. end
  32. minetest.register_craftitem("potions:tunnel_seed", {
  33. description = "Tunnel Seed",
  34. inventory_image = "default_sandstone_brick.png",
  35. groups = {cracky=3,},
  36. liquids_pointable=true,
  37. on_use = function(itemstack, player, pointed_thing)
  38. local pos = player:get_pos()
  39. if not pos then
  40. return
  41. end
  42. pos.y = pos.y + 1
  43. -- local below = {x=pos.x, y=pos.y-1, z=pos.z}
  44. -- local n = minetest.get_node(below)
  45. -- if n.name == "air" or n.name == "ignore" then
  46. -- return
  47. -- end
  48. -- local newname = get_temp_node(n.name)
  49. local th = player:get_look_horizontal()
  50. local thv = player:get_look_vertical()
  51. local dir = vector.normalize({
  52. x = -math.sin(th),
  53. y = math.sin(thv),
  54. z = math.cos(th),
  55. })
  56. local pos2 = vector.add(pos, vector.multiply(dir, potions.get_manna(player)))
  57. -- local b, pos3 = minetest.line_of_sight(pos, pos2)
  58. -- if b == false then
  59. -- pos2 = pos3
  60. -- end
  61. local dist = 20 -- vector.distance(pos, pos2)
  62. dist = potions.use_manna(player, dist)
  63. if dist < 2 then
  64. return
  65. end
  66. print(dump(dir))
  67. -- minetest.set_node(pos, {name="air"})
  68. make_tunnel(pos, 4, 5, 30, dir)
  69. -- get player yaw, calc direction
  70. -- itemstack:take_item()
  71. return itemstack
  72. end,
  73. })