wooden_stuff.lua 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. function lottblocks.register_wooden_stuff(name, description, texture, wood_name)
  2. local wood_groups = minetest.registered_nodes[wood_name].groups
  3. local node_groups = {}
  4. for k,v in pairs(wood_groups) do
  5. if k ~= "wood" then
  6. node_groups[k] = v
  7. end
  8. end
  9. local groups_door = node_groups
  10. groups_door.door = 1
  11. if name ~= "wood" then
  12. doors:register_door("lottblocks:door_" .. name, {
  13. description = description .. " Door",
  14. inventory_image = "lottblocks_door_" .. name .. ".png",
  15. groups = groups_door,
  16. tiles_bottom = {"lottblocks_door_" .. name .."_b.png", "lottblocks_edge_" .. name ..".png"},
  17. tiles_top = {"lottblocks_door_" .. name .. "_a.png", "lottblocks_edge_" .. name ..".png"},
  18. sounds = default.node_sound_wood_defaults(),
  19. sound_open = "doors_door_open",
  20. sound_close = "doors_door_close"
  21. })
  22. minetest.register_craft({
  23. output = "lottblocks:door_" .. name,
  24. recipe = {
  25. {wood_name, wood_name},
  26. {wood_name, wood_name},
  27. {wood_name, wood_name}
  28. }
  29. })
  30. node_groups.not_in_creative_inventory = 0
  31. doors.register_trapdoor("lottblocks:hatch_" .. name, {
  32. description = description .. " Trapdoor",
  33. wield_image = "lottblocks_hatch_" .. name ..".png",
  34. tile_open = "lottblocks_hatch_" .. name .. "_open.png",
  35. tile_closed = "lottblocks_hatch_" .. name .. ".png",
  36. tile_side = "door_trapdoor_side.png",
  37. groups = node_groups,
  38. sounds = default.node_sound_wood_defaults(),
  39. sound_open = "doors_door_open",
  40. sound_close = "doors_door_close"
  41. })
  42. minetest.register_craft({
  43. output = "lottblocks:hatch_" .. name,
  44. recipe = {
  45. {wood_name, wood_name},
  46. {wood_name, wood_name},
  47. }
  48. })
  49. minetest.register_craft({
  50. output = "lottblocks:fence_" .. name .." 6",
  51. recipe = {
  52. {wood_name, wood_name, wood_name,},
  53. {wood_name, wood_name, wood_name,},
  54. }
  55. })
  56. end
  57. node_groups.fence = 1
  58. minetest.register_node("lottblocks:fence_" .. name, {
  59. description = description .. " Fence",
  60. drawtype = "nodebox",
  61. node_box = {
  62. type = "connected",
  63. fixed = {{-1/8, -1/2, -1/8, 1/8, 1/2, 1/8}},
  64. -- connect_top =
  65. -- connect_bottom =
  66. connect_front = {{-1/16,3/16,-1/2,1/16,5/16,-1/8},
  67. {-1/16,-5/16,-1/2,1/16,-3/16,-1/8}},
  68. connect_left = {{-1/2,3/16,-1/16,-1/8,5/16,1/16},
  69. {-1/2,-5/16,-1/16,-1/8,-3/16,1/16}},
  70. connect_back = {{-1/16,3/16,1/8,1/16,5/16,1/2},
  71. {-1/16,-5/16,1/8,1/16,-3/16,1/2}},
  72. connect_right = {{1/8,3/16,-1/16,1/2,5/16,1/16},
  73. {1/8,-5/16,-1/16,1/2,-3/16,1/16}},
  74. },
  75. connects_to = {"group:fence", "group:wood", "group:tree"},
  76. tiles = {texture},
  77. inventory_image = "lottblocks_" .. name .. "_fence.png",
  78. wield_image = "lottblocks_" .. name .. "_fence.png",
  79. paramtype = "light",
  80. is_ground_content = false,
  81. selection_box = {
  82. type = "fixed",
  83. fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7},
  84. },
  85. groups = node_groups
  86. })
  87. node_groups.fence = 0
  88. minetest.register_node("lottblocks:ladder_" .. name, {
  89. description = description .. " Ladder",
  90. drawtype = "nodebox",
  91. tiles = {texture},
  92. paramtype = "light",
  93. paramtype2 = "facedir",
  94. sunlight_propagates = true,
  95. walkable = true,
  96. climbable = true,
  97. is_ground_content = false,
  98. node_box = {
  99. type = "fixed",
  100. fixed = {
  101. {-0.375, -0.5, 0.4375, -0.25, 0.5, 0.5}, -- NodeBox1
  102. {0.25, -0.5, 0.4375, 0.375, 0.5, 0.5}, -- NodeBox2
  103. {-0.25, -0.4375, 0.4375, 0.25, -0.3125, 0.5}, -- NodeBox3
  104. {-0.25, -0.1875, 0.4375, 0.25, -0.0625, 0.5}, -- NodeBox5
  105. {-0.25, 0.0625, 0.4375, 0.25, 0.1875, 0.5}, -- NodeBox6
  106. {-0.25, 0.3125, 0.4375, 0.25, 0.4375, 0.5}, -- NodeBox7
  107. }
  108. },
  109. selection_box = {
  110. type = "fixed",
  111. fixed = {{-0.4375, -0.5, 0.4375, 0.4375, 0.5, 0.5}}
  112. },
  113. groups = {choppy=2,oddly_breakable_by_hand=3,flammable=2},
  114. legacy_wallmounted = true,
  115. sounds = default.node_sound_wood_defaults(),
  116. after_place_node = function(pos, placer, itemstack, pointed_thing)
  117. local dir = minetest.dir_to_facedir(placer:get_look_dir())
  118. local npos = pos
  119. if dir == 0 then
  120. npos = {x = pos.x, y = pos.y, z = pos.z + 1}
  121. elseif dir == 1 then
  122. npos = {x = pos.x + 1, y = pos.y, z = pos.z}
  123. elseif dir == 2 then
  124. npos = {x = pos.x, y = pos.y, z = pos.z - 1}
  125. elseif dir == 3 then
  126. npos = {x = pos.x - 1, y = pos.y, z = pos.z}
  127. end
  128. if minetest.registered_nodes[minetest.get_node(npos).name]["walkable"] == false then
  129. minetest.remove_node(pos)
  130. return true
  131. else
  132. minetest.set_node(pos, {name = "lottblocks:ladder_" .. name, param2 = dir})
  133. end
  134. end,
  135. })
  136. minetest.register_node("lottblocks:" .. name .. "_table", {
  137. description = description .. " Table",
  138. tiles = {texture},
  139. drawtype = "nodebox",
  140. sunlight_propagates = true,
  141. paramtype = 'light',
  142. paramtype2 = "facedir",
  143. node_box = {
  144. type = "fixed",
  145. fixed = {
  146. {-0.4,-0.5,-0.4, -0.3,0.4,-0.3},
  147. {0.3,-0.5,-0.4, 0.4,0.4,-0.3},
  148. {-0.4,-0.5,0.3, -0.3,0.4,0.4},
  149. {0.3,-0.5,0.3, 0.4,0.4,0.4},
  150. {-0.5,0.4,-0.5, 0.5,0.5,0.5},
  151. {-0.4,-0.2,-0.3, -0.3,-0.1,0.3},
  152. {0.3,-0.2,-0.4, 0.4,-0.1,0.3},
  153. {-0.3,-0.2,-0.4, 0.4,-0.1,-0.3},
  154. {-0.3,-0.2,0.3, 0.3,-0.1,0.4},
  155. },
  156. },
  157. groups = node_groups
  158. })
  159. minetest.register_node("lottblocks:" .. name .."_chair", {
  160. description = description .. " Chair",
  161. tiles = {texture},
  162. drawtype = "nodebox",
  163. sunlight_propagates = true,
  164. paramtype = "light",
  165. paramtype2 = "facedir",
  166. node_box = {
  167. type = "fixed",
  168. fixed = {
  169. {-0.3125, -0.5, 0.1875, -0.1875, 0.5, 0.3125},
  170. {0.1875, -0.5, 0.1875, 0.3125, 0.5, 0.3125},
  171. {0.1875, -0.5, -0.3125, 0.3125, -0.0625, -0.1875},
  172. {-0.3125, -0.5, -0.3125, -0.1875, -0.0625, -0.1875},
  173. {-0.3125, -0.125, -0.3125, 0.3125, 0, 0.3125},
  174. {-0.1875, 0.3125, 0.1875, 0.1875, 0.4375, 0.3125},
  175. {-0.3125, 0.125, 0.1875, 0.3125, 0.1875, 0.3125},
  176. {0.23, -0.4375, -0.3125, 0.29, -0.375, 0.3125},
  177. {-0.29, -0.4375, -0.3125, -0.23, -0.375, 0.3125},
  178. {-0.29, -0.4375, -0.0315, 0.29, -0.375, 0.031},
  179. },
  180. },
  181. selection_box = {
  182. type = "fixed",
  183. fixed = {-0.3125, -0.5, -0.3125, 0.3125, 0.5, 0.3125},
  184. },
  185. collision_box={
  186. type="fixed",
  187. fixed={
  188. {-0.3125, -0.5, -0.3125, 0.3125, -0.0625, 0.3125},
  189. {-0.3125, -0.5, 0.1875, -0.1875, 0.5, 0.3125},
  190. },
  191. },
  192. groups = node_groups,
  193. on_rightclick = function(pos, node, player, itemstack, pointed_thing)
  194. local v=player:get_player_velocity()
  195. if v.x~=0 or v.y~=0 or v.z~=0 then return end
  196. local name=player:get_player_name()
  197. local nname=minetest.get_node(pos).name
  198. if default.player_attached[name] then
  199. player:set_physics_override(1, 1, 1)
  200. minetest.after(0.3, function(player,name)
  201. player:set_eye_offset({x=0,y=0,z=0}, {x=0,y=0,z=0})
  202. default.player_attached[name]=false
  203. default.player_set_animation(player, "stand",30)
  204. if minetest.get_node({x = pos.x, y = pos.y + 2, z = pos.z}).name ~= "air" then
  205. local tab = minetest.find_nodes_in_area(
  206. {x = pos.x - 1, y = pos.y, z = pos.z - 1},
  207. {x = pos.x + 1, y = pos.y, z = pos.z + 1},
  208. "air")
  209. if tab then
  210. for i, v in pairs(tab) do
  211. if minetest.get_node({x = v.x, y = v.y + 1, z = v.z}).name == "air" then
  212. player:set_pos(v)
  213. break
  214. end
  215. end
  216. end
  217. end
  218. end,player,name)
  219. else
  220. player:set_physics_override(0, 0, 0)
  221. player:setpos({x=pos.x,y=pos.y,z=pos.z})
  222. minetest.after(0.3, function(player,name)
  223. player:set_eye_offset({x=0,y=-7,z=2}, {x=0,y=0,z=0})
  224. default.player_attached[name]=true
  225. default.player_set_animation(player, "sit",30)
  226. end,player,name)
  227. minetest.after(0.3, function(player,name)
  228. player:set_eye_offset({x=0,y=-7,z=2}, {x=0,y=0,z=0})
  229. default.player_attached[name]=true
  230. default.player_set_animation(player, "sit",30)
  231. end,player,name)
  232. end
  233. end,
  234. can_dig = function(pos, player)
  235. for _, ob in ipairs(minetest.get_objects_inside_radius(pos,1)) do
  236. return false
  237. end
  238. return true
  239. end,
  240. on_construct=function(pos)
  241. local meta=minetest.get_meta(pos)
  242. minetest.get_node_timer(pos):start(1)
  243. meta:set_int("n",20)
  244. meta:set_int("y",0)
  245. end,
  246. after_place_node = function(pos, placer)
  247. minetest.get_meta(pos):set_int("placed",1)
  248. end
  249. })
  250. minetest.register_craft({
  251. output = "lottblocks:" .. name .. "_table",
  252. recipe = {
  253. {wood_name, wood_name, wood_name},
  254. {'group:stick', 'group:stick', 'group:stick'},
  255. {'group:stick', '', 'group:stick'},
  256. }
  257. })
  258. minetest.register_craft({
  259. output = "lottblocks:" .. name .. "_chair",
  260. recipe = {
  261. {'group:stick', ''},
  262. {wood_name, wood_name},
  263. {'group:stick', 'group:stick'},
  264. }
  265. })
  266. end
  267. lottblocks.register_wooden_stuff("wood", "Wooden", "default_wood.png", "default:wood")
  268. lottblocks.register_wooden_stuff("junglewood", "Junglewood", "default_junglewood.png", "default:junglewood")
  269. lottblocks.register_wooden_stuff("alder", "Alder", "lottplants_alderwood.png", "lottplants:alderwood")
  270. lottblocks.register_wooden_stuff("birch", "Birch", "lottplants_birchwood.png", "lottplants:birchwood")
  271. lottblocks.register_wooden_stuff("pine", "Pine", "lottplants_pinewood.png", "lottplants:pinewood")
  272. lottblocks.register_wooden_stuff("lebethron", "Lebethron", "lottplants_lebethronwood.png", "lottplants:lebethronwood")
  273. lottblocks.register_wooden_stuff("mallorn", "Mallorn", "lottplants_mallornwood.png", "lottplants:mallornwood")