init.lua 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. ts_furniture = {}
  2. -- If true, you can sit on chairs and benches, when right-click them.
  3. ts_furniture.enable_sitting = true
  4. -- The following code is from "Get Comfortable [cozy]" (by everamzah; published under WTFPL).
  5. -- Thomas S. modified it, so that it can be used in this mod
  6. minetest.register_globalstep(function(dtime)
  7. local players = minetest.get_connected_players()
  8. for i = 1, #players do
  9. local name = players[i]:get_player_name()
  10. if default.player_attached[name] and not players[i]:get_attach() and
  11. (players[i]:get_player_control().up == true or
  12. players[i]:get_player_control().down == true or
  13. players[i]:get_player_control().left == true or
  14. players[i]:get_player_control().right == true or
  15. players[i]:get_player_control().jump == true) then
  16. players[i]:set_eye_offset({ x = 0, y = 0, z = 0 }, { x = 0, y = 0, z = 0 })
  17. players[i]:set_physics_override(1, 1, 1)
  18. default.player_attached[name] = false
  19. default.player_set_animation(players[i], "stand", 30)
  20. end
  21. end
  22. end)
  23. ts_furniture.sit = function(name, pos)
  24. local player = minetest.get_player_by_name(name)
  25. if default.player_attached[name] then
  26. player:set_eye_offset({ x = 0, y = 0, z = 0 }, { x = 0, y = 0, z = 0 })
  27. player:set_physics_override(1, 1, 1)
  28. default.player_attached[name] = false
  29. default.player_set_animation(player, "stand", 30)
  30. else
  31. player:moveto(pos)
  32. player:set_eye_offset({ x = 0, y = -7, z = 2 }, { x = 0, y = 0, z = 0 })
  33. player:set_physics_override(0, 0, 0)
  34. default.player_attached[name] = true
  35. default.player_set_animation(player, "sit", 30)
  36. end
  37. end
  38. -- end of cozy-code
  39. local furnitures = {
  40. ["chair"] = {
  41. description = "Chair",
  42. sitting = true,
  43. nodebox = {
  44. { -0.3, -0.5, 0.2, -0.2, 0.5, 0.3 }, -- foot 1
  45. { 0.2, -0.5, 0.2, 0.3, 0.5, 0.3 }, -- foot 2
  46. { 0.2, -0.5, -0.3, 0.3, -0.1, -0.2 }, -- foot 3
  47. { -0.3, -0.5, -0.3, -0.2, -0.1, -0.2 }, -- foot 4
  48. { -0.3, -0.1, -0.3, 0.3, 0, 0.2 }, -- seating
  49. { -0.2, 0.1, 0.25, 0.2, 0.4, 0.26 } -- conector 1-2
  50. },
  51. craft = function(recipe)
  52. return {
  53. { "", "group:stick" },
  54. { recipe, recipe },
  55. { "group:stick", "group:stick" }
  56. }
  57. end
  58. },
  59. ["table"] = {
  60. description = "Table",
  61. nodebox = {
  62. { -0.4, -0.5, -0.4, -0.3, 0.4, -0.3 }, -- foot 1
  63. { 0.3, -0.5, -0.4, 0.4, 0.4, -0.3 }, -- foot 2
  64. { -0.4, -0.5, 0.3, -0.3, 0.4, 0.4 }, -- foot 3
  65. { 0.3, -0.5, 0.3, 0.4, 0.4, 0.4 }, -- foot 4
  66. { -0.5, 0.4, -0.5, 0.5, 0.5, 0.5 }, -- table top
  67. },
  68. craft = function(recipe)
  69. return {
  70. { recipe, recipe, recipe },
  71. { "group:stick", "", "group:stick" },
  72. { "group:stick", "", "group:stick" }
  73. }
  74. end
  75. },
  76. ["small_table"] = {
  77. description = "Small Table",
  78. nodebox = {
  79. { -0.4, -0.5, -0.4, -0.3, 0.1, -0.3 }, -- foot 1
  80. { 0.3, -0.5, -0.4, 0.4, 0.1, -0.3 }, -- foot 2
  81. { -0.4, -0.5, 0.3, -0.3, 0.1, 0.4 }, -- foot 3
  82. { 0.3, -0.5, 0.3, 0.4, 0.1, 0.4 }, -- foot 4
  83. { -0.5, 0.1, -0.5, 0.5, 0.2, 0.5 }, -- table top
  84. },
  85. craft = function(recipe)
  86. return {
  87. { recipe, recipe, recipe },
  88. { "group:stick", "", "group:stick" }
  89. }
  90. end
  91. },
  92. ["tiny_table"] = {
  93. description = "Tiny Table",
  94. nodebox = {
  95. { -0.5, -0.1, -0.5, 0.5, 0, 0.5 }, -- table top
  96. { -0.4, -0.5, -0.5, -0.3, -0.1, 0.5 }, -- foot 1
  97. { 0.3, -0.5, -0.5, 0.4, -0.1, 0.5 }, -- foot 2
  98. },
  99. craft = function(recipe)
  100. local bench_name = "ts_furniture:" .. recipe:gsub(":", "_") .. "_bench"
  101. return {
  102. { bench_name, bench_name }
  103. }
  104. end
  105. },
  106. ["bench"] = {
  107. description = "Bench",
  108. sitting = true,
  109. nodebox = {
  110. { -0.5, -0.1, 0, 0.5, 0, 0.5 }, -- seating
  111. { -0.4, -0.5, 0, -0.3, -0.1, 0.5 }, -- foot 1
  112. { 0.3, -0.5, 0, 0.4, -0.1, 0.5 }, -- foot 2
  113. },
  114. craft = function(recipe)
  115. return {
  116. { recipe, recipe },
  117. { "group:stick", "group:stick" }
  118. }
  119. end
  120. },
  121. }
  122. local ignore_groups = {
  123. ["wood"] = true,
  124. ["stone"] = true,
  125. }
  126. function ts_furniture.register_furniture(recipe, description, texture)
  127. local recipe_def = minetest.registered_items[recipe]
  128. if not recipe_def then
  129. return
  130. end
  131. local groups = {}
  132. for k, v in pairs(recipe_def.groups) do
  133. if not ignore_groups[k] then
  134. groups[k] = v
  135. end
  136. end
  137. for furniture, def in pairs(furnitures) do
  138. local node_name = "ts_furniture:" .. recipe:gsub(":", "_") .. "_" .. furniture
  139. def.on_rightclick = nil
  140. if def.sitting and ts_furniture.enable_sitting then
  141. def.on_rightclick = function(pos, node, player, itemstack, pointed_thing)
  142. ts_furniture.sit(player:get_player_name(), pos)
  143. end
  144. end
  145. minetest.register_node(":" .. node_name, {
  146. description = description .. " " .. def.description,
  147. drawtype = "nodebox",
  148. paramtype = "light",
  149. paramtype2 = "facedir",
  150. sunlight_propagates = true,
  151. tiles = { texture },
  152. groups = groups,
  153. node_box = {
  154. type = "fixed",
  155. fixed = def.nodebox
  156. },
  157. on_rightclick = def.on_rightclick
  158. })
  159. minetest.register_craft({
  160. output = node_name,
  161. recipe = def.craft(recipe)
  162. })
  163. end
  164. end
  165. ts_furniture.register_furniture("default:aspen_wood", "Aspen", "default_aspen_wood.png")
  166. ts_furniture.register_furniture("default:pine_wood", "Pine", "default_pine_wood.png")
  167. ts_furniture.register_furniture("default:acacia_wood", "Acacia", "default_acacia_wood.png")
  168. ts_furniture.register_furniture("default:wood", "Wooden", "default_wood.png")
  169. ts_furniture.register_furniture("default:junglewood", "Jungle Wood", "default_junglewood.png")
  170. if (minetest.get_modpath("moretrees")) then
  171. ts_furniture.register_furniture("moretrees:apple_tree_planks", "Apple Tree", "moretrees_apple_tree_wood.png")
  172. ts_furniture.register_furniture("moretrees:beech_planks", "Beech", "moretrees_beech_wood.png")
  173. ts_furniture.register_furniture("moretrees:birch_planks", "Birch", "moretrees_birch_wood.png")
  174. ts_furniture.register_furniture("moretrees:fir_planks", "Fir", "moretrees_fir_wood.png")
  175. ts_furniture.register_furniture("moretrees:oak_planks", "Oak", "moretrees_oak_wood.png")
  176. ts_furniture.register_furniture("moretrees:palm_planks", "Palm", "moretrees_palm_wood.png")
  177. ts_furniture.register_furniture("moretrees:rubber_tree_planks", "Rubber Tree", "moretrees_rubber_tree_wood.png")
  178. ts_furniture.register_furniture("moretrees:sequoia_planks", "Sequoia", "moretrees_sequoia_wood.png")
  179. ts_furniture.register_furniture("moretrees:spruce_planks", "Spruce", "moretrees_spruce_wood.png")
  180. ts_furniture.register_furniture("moretrees:willow_planks", "Willow", "moretrees_willow_wood.png")
  181. end