init.lua 7.6 KB

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