init.lua 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. local S = minetest.get_translator("homedecor_cobweb")
  2. homedecor_cobweb = {}
  3. minetest.register_node(":homedecor:cobweb_corner", {
  4. description = S("Cobweb"),
  5. drawtype = "torchlike",
  6. tiles = { "homedecor_cobweb_torchlike.png" },
  7. inventory_image = "homedecor_cobweb.png",
  8. wield_image = "homedecor_cobweb.png",
  9. paramtype = "light",
  10. paramtype2 = "wallmounted",
  11. sunlight_propagates = true,
  12. liquid_viscosity = 8,
  13. liquidtype = "source",
  14. liquid_alternative_flowing = "homedecor:cobweb_corner",
  15. liquid_alternative_source = "homedecor:cobweb_corner",
  16. liquid_renewable = false,
  17. liquid_range = 0,
  18. walkable = false,
  19. selection_box = { type = "regular" },
  20. visual_scale = 1.4,
  21. groups = { snappy = 3, liquid=3 },
  22. after_place_node = function(pos, placer, itemstack, pointed_thing)
  23. homedecor_cobweb.rotate(pos)
  24. end
  25. })
  26. minetest.register_node(":homedecor:cobweb_centered", {
  27. description = S("Cobweb"),
  28. drawtype = "nodebox",
  29. tiles = { "homedecor_cobweb.png" },
  30. inventory_image = "homedecor_cobweb.png",
  31. paramtype = "light",
  32. paramtype2 = "facedir",
  33. sunlight_propagates = true,
  34. liquid_viscosity = 8,
  35. liquidtype = "source",
  36. liquid_alternative_flowing = "homedecor:cobweb_centered",
  37. liquid_alternative_source = "homedecor:cobweb_centered",
  38. liquid_renewable = false,
  39. liquid_range = 0,
  40. walkable = false,
  41. selection_box = {
  42. type = "fixed",
  43. fixed = { -0.5, -0.5, -0.1, 0.5, 0.5, 0.1 }
  44. },
  45. node_box = {
  46. type = "fixed",
  47. fixed = { -0.5, -0.5, 0, 0.5, 0.5, 0 }
  48. },
  49. groups = { snappy = 3, liquid=3, not_in_creative_inventory = 1 },
  50. drop = "homedecor:cobweb_corner"
  51. })
  52. minetest.register_node(":homedecor:cobweb_flat", {
  53. description = S("Cobweb"),
  54. drawtype = "nodebox",
  55. tiles = { "homedecor_cobweb.png" },
  56. inventory_image = "homedecor_cobweb.png",
  57. paramtype = "light",
  58. paramtype2 = "facedir",
  59. sunlight_propagates = true,
  60. liquid_viscosity = 8,
  61. liquidtype = "source",
  62. liquid_alternative_flowing = "homedecor:cobweb_flat",
  63. liquid_alternative_source = "homedecor:cobweb_flat",
  64. liquid_renewable = false,
  65. liquid_range = 0,
  66. walkable = false,
  67. selection_box = {
  68. type = "fixed",
  69. fixed = { -0.5, -0.5, 0.4, 0.5, 0.5, 0.5 }
  70. },
  71. node_box = {
  72. type = "fixed",
  73. fixed = { -0.5, -0.5, 0.495, 0.5, 0.5, 0.495 }
  74. },
  75. groups = { snappy = 3, liquid=3, not_in_creative_inventory = 1 },
  76. drop = "homedecor:cobweb_corner"
  77. })
  78. minetest.register_node(":homedecor:cobweb_plantlike", {
  79. description = S("Cobweb"),
  80. drawtype = "plantlike",
  81. tiles = { "homedecor_cobweb_plantlike.png" },
  82. inventory_image = "homedecor_cobweb.png",
  83. paramtype = "light",
  84. paramtype2 = "facedir",
  85. sunlight_propagates = true,
  86. liquid_viscosity = 8,
  87. liquidtype = "source",
  88. liquid_alternative_flowing = "homedecor:cobweb_plantlike",
  89. liquid_alternative_source = "homedecor:cobweb_plantlike",
  90. liquid_renewable = false,
  91. liquid_range = 0,
  92. walkable = false,
  93. selection_box = { type = "regular" },
  94. visual_scale = 1.189,
  95. groups = { snappy = 3, liquid=3, not_in_creative_inventory = 1 },
  96. drop = "homedecor:cobweb_corner"
  97. })
  98. -- helper function to rotate the cobweb after it's placed
  99. function homedecor_cobweb.rotate(pos)
  100. local wall_xm = minetest.get_node({ x=pos.x-1, y=pos.y, z=pos.z }).name
  101. local wall_xp = minetest.get_node({ x=pos.x+1, y=pos.y, z=pos.z }).name
  102. local wall_zm = minetest.get_node({ x=pos.x, y=pos.y, z=pos.z-1}).name
  103. local wall_zp = minetest.get_node({ x=pos.x, y=pos.y, z=pos.z+1}).name
  104. local iswall_xm = (wall_xm ~= "air" and not string.find(wall_xm, "homedecor:cobweb"))
  105. local iswall_xp = (wall_xp ~= "air" and not string.find(wall_xp, "homedecor:cobweb"))
  106. local iswall_zm = (wall_zm ~= "air" and not string.find(wall_zm, "homedecor:cobweb"))
  107. local iswall_zp = (wall_zp ~= "air" and not string.find(wall_zp, "homedecor:cobweb"))
  108. -- only xm+zp, or only xp+zm means on-floor torchlike
  109. if (iswall_xm and iswall_zp and not iswall_xp and not iswall_zm)
  110. or (iswall_xp and iswall_zm and not iswall_xm and not iswall_zp) then
  111. minetest.set_node(pos, {name = "homedecor:cobweb_corner", param2 = 1})
  112. -- only xm+zm, or only xp+zp means on-ceiling torchlike
  113. elseif (iswall_xm and iswall_zm and not iswall_xp and not iswall_zp)
  114. or (iswall_xp and iswall_zp and not iswall_xm and not iswall_zm) then
  115. minetest.set_node(pos, {name = "homedecor:cobweb_corner", param2 = 0})
  116. -- only xm+xp means nodebox (not rotated, 0 degrees)
  117. elseif iswall_xm and iswall_xp and not iswall_zm and not iswall_zp then
  118. minetest.set_node(pos, {name = "homedecor:cobweb_centered", param2 = 0})
  119. -- only zm+zp means nodebox rotated to 90 degrees
  120. elseif iswall_zm and iswall_zp and not iswall_xm and not iswall_xp then
  121. minetest.set_node(pos, {name = "homedecor:cobweb_centered", param2 = 1})
  122. -- ok, there aren't any simple two-wall corners or opposing walls.
  123. -- Are there any standalone walls?
  124. elseif iswall_xm and not iswall_xp and not iswall_zm and not iswall_zp then
  125. minetest.set_node(pos, {name = "homedecor:cobweb_flat", param2 = 3})
  126. elseif iswall_xp and not iswall_xm and not iswall_zm and not iswall_zp then
  127. minetest.set_node(pos, {name = "homedecor:cobweb_flat", param2 = 1})
  128. elseif iswall_zm and not iswall_xm and not iswall_xp and not iswall_zp then
  129. minetest.set_node(pos, {name = "homedecor:cobweb_flat", param2 = 2})
  130. elseif iswall_zp and not iswall_xm and not iswall_xp and not iswall_zm then
  131. minetest.set_node(pos, {name = "homedecor:cobweb_flat", param2 = 0})
  132. -- if all else fails, place the plantlike version as a fallback.
  133. else
  134. minetest.set_node(pos, {name = "homedecor:cobweb_plantlike", param2 = 0})
  135. end
  136. end
  137. -- crafting
  138. minetest.register_craft( {
  139. output = "homedecor:cobweb_corner 5",
  140. recipe = {
  141. { "farming:string", "", "farming:string" },
  142. { "", "farming:string", "" },
  143. { "farming:string", "", "farming:string" }
  144. },
  145. })