init.lua 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. -- check for available hunger mods
  2. local hmod = minetest.get_modpath("hunger")
  3. local hbmod = minetest.get_modpath("hbhunger")
  4. local stmod = minetest.global_exists("stamina")
  5. local defmod = minetest.get_modpath("default")
  6. local mclhunger = minetest.get_modpath("mcl_hunger")
  7. local screwdriver_exists = minetest.get_modpath("screwdriver")
  8. -- sound support
  9. local cake_sound = defmod and default.node_sound_dirt_defaults()
  10. if minetest.get_modpath("mcl_sounds") then
  11. cake_sound = mcl_sounds.node_sound_dirt_defaults()
  12. end
  13. -- eat pie slice function
  14. local function replace_pie(node, puncher, pos)
  15. -- is this my pie?
  16. if minetest.is_protected(pos, puncher:get_player_name()) then
  17. return
  18. end
  19. -- which size of pie did we hit?
  20. local pie = node.name:split("_")[1]
  21. local num = tonumber(node.name:split("_")[2])
  22. -- are we using crystal shovel to pick up full pie using soft touch?
  23. local tool = puncher:get_wielded_item():get_name()
  24. if num == 0 and tool == "ethereal:shovel_crystal" then
  25. local inv = puncher:get_inventory()
  26. minetest.remove_node(pos)
  27. if inv:room_for_item("main", {name = pie .. "_0"}) then
  28. inv:add_item("main", pie .. "_0")
  29. else
  30. pos.y = pos.y + 0.5
  31. minetest.add_item(pos, {name = pie .. "_0"})
  32. end
  33. return
  34. end
  35. -- eat slice or remove whole pie
  36. if num == 3 then
  37. node.name = "air"
  38. elseif num < 3 then
  39. node.name = pie .. "_" .. (num + 1)
  40. end
  41. minetest.swap_node(pos, node)
  42. if num == 3 then
  43. minetest.check_for_falling(pos)
  44. end
  45. -- default eat sound
  46. local sound = "default_dig_crumbly"
  47. -- Blockmen's hud_hunger mod
  48. if hmod then
  49. local h = hunger.read(puncher)
  50. h = math.min(h + 4, 30)
  51. local ok = hunger.update_hunger(puncher, h)
  52. sound = "hunger_eat"
  53. -- Wuzzy's hbhunger mod
  54. elseif hbmod then
  55. local h = tonumber(hbhunger.hunger[puncher:get_player_name()])
  56. h = math.min(h + 4, 30)
  57. hbhunger.hunger[puncher:get_player_name()] = h
  58. sound = "hbhunger_eat_generic"
  59. -- Sofar's stamina mod
  60. elseif stmod then
  61. stamina.change(puncher, 4)
  62. sound = "stamina_eat"
  63. -- mineclone2 mcl_hunger mod
  64. elseif mclhunger then
  65. local h = mcl_hunger.get_hunger(puncher)
  66. h = math.min(h + 4, 20)
  67. mcl_hunger.set_hunger(puncher, h)
  68. sound = "mcl_hunger_bite"
  69. -- none of the above found? add to health instead
  70. else
  71. local h = puncher:get_hp()
  72. h = math.min(h + 4, 20)
  73. puncher:set_hp(h)
  74. end
  75. minetest.sound_play(sound, {pos = pos, gain = 0.7, max_hear_distance = 5}, true)
  76. end
  77. -- register pie bits
  78. local function register_pie(pie, desc)
  79. -- full pie
  80. minetest.register_node("pie:" .. pie .. "_0", {
  81. description = desc,
  82. paramtype = "light",
  83. paramtype2 = "facedir",
  84. use_texture_alpha = "clip",
  85. sunlight_propagates = false,
  86. tiles = {
  87. pie .. "_top.png", pie .. "_bottom.png", pie .. "_side.png",
  88. pie .. "_side.png", pie .. "_side.png", pie .. "_side.png"
  89. },
  90. inventory_image = pie .. "_inv.png",
  91. wield_image = pie .. "_inv.png",
  92. drawtype = "nodebox",
  93. node_box = {
  94. type = "fixed",
  95. fixed = {-0.45, -0.5, -0.45, 0.45, 0, 0.45}
  96. },
  97. sounds = cake_sound,
  98. on_rotate = screwdriver_exists and screwdriver.rotate_simple,
  99. on_punch = function(pos, node, puncher, pointed_thing)
  100. replace_pie(node, puncher, pos)
  101. end
  102. })
  103. -- 3/4 pie
  104. minetest.register_node("pie:" .. pie .. "_1", {
  105. description = "3/4 " .. desc,
  106. paramtype = "light",
  107. paramtype2 = "facedir",
  108. use_texture_alpha = "clip",
  109. sunlight_propagates = true,
  110. tiles = {
  111. pie .. "_top.png", pie .. "_bottom.png", pie .. "_side.png",
  112. pie .. "_side.png", pie .. "_side.png", pie .. "_inside.png"
  113. },
  114. groups = {not_in_creative_inventory = 1},
  115. drop = {},
  116. drawtype = "nodebox",
  117. node_box = {
  118. type = "fixed",
  119. fixed = {-0.45, -0.5, -0.25, 0.45, 0, 0.45}
  120. },
  121. sounds = cake_sound,
  122. on_rotate = screwdriver_exists and screwdriver.rotate_simple,
  123. on_punch = function(pos, node, puncher, pointed_thing)
  124. replace_pie(node, puncher, pos)
  125. end
  126. })
  127. -- 1/2 pie
  128. minetest.register_node("pie:" .. pie .. "_2", {
  129. description = "Half " .. desc,
  130. paramtype = "light",
  131. paramtype2 = "facedir",
  132. use_texture_alpha = "clip",
  133. sunlight_propagates = true,
  134. tiles = {
  135. pie .. "_top.png", pie .. "_bottom.png", pie .. "_side.png",
  136. pie .. "_side.png", pie .. "_side.png", pie .. "_inside.png"
  137. },
  138. groups = {not_in_creative_inventory = 1},
  139. drop = {},
  140. drawtype = "nodebox",
  141. node_box = {
  142. type = "fixed",
  143. fixed = {-0.45, -0.5, 0.0, 0.45, 0, 0.45}
  144. },
  145. sounds = cake_sound,
  146. on_rotate = screwdriver_exists and screwdriver.rotate_simple,
  147. on_punch = function(pos, node, puncher, pointed_thing)
  148. replace_pie(node, puncher, pos)
  149. end
  150. })
  151. -- 1/4 pie
  152. minetest.register_node("pie:" .. pie .. "_3", {
  153. description = "Piece of " .. desc,
  154. paramtype = "light",
  155. paramtype2 = "facedir",
  156. use_texture_alpha = "clip",
  157. sunlight_propagates = true,
  158. tiles = {
  159. pie .. "_top.png", pie .. "_bottom.png", pie .. "_side.png",
  160. pie .. "_side.png", pie .. "_side.png", pie .. "_inside.png"
  161. },
  162. groups = {not_in_creative_inventory = 1},
  163. drop = {},
  164. drawtype = "nodebox",
  165. node_box = {
  166. type = "fixed",
  167. fixed = {-0.45, -0.5, 0.25, 0.45, 0, 0.45}
  168. },
  169. sounds = cake_sound,
  170. on_rotate = screwdriver_exists and screwdriver.rotate_simple,
  171. on_punch = function(pos, node, puncher, pointed_thing)
  172. replace_pie(node, puncher, pos)
  173. end
  174. })
  175. end
  176. -- register cakes
  177. register_pie("pie", "Cake")
  178. register_pie("choc", "Chocolate Cake")
  179. register_pie("scsk", "Strawberry Cheesecake")
  180. register_pie("coff", "Coffee Cake")
  181. register_pie("rvel", "Red Velvet Cake")
  182. register_pie("meat", "Meat Cake")
  183. register_pie("bana", "Banana Cake")
  184. register_pie("brpd", "Bread Pudding")
  185. register_pie("orange", "Orange Pie")
  186. -- replacement items
  187. local replace_these = {
  188. {"mobs:bucket_milk", "bucket:bucket_empty"},
  189. {"mobs:wooden_bucket_milk", "wooden_bucket:bucket_wood_empty"},
  190. {"mcl_mobitems:milk_bucket", "mcl_buckets:bucket_empty"}
  191. }
  192. -- ingredient variables
  193. local mcl = minetest.get_modpath("mcl_dye")
  194. local i_sugar = mcl and "mcl_core:sugar" or "group:food_sugar"
  195. local i_wheat = mcl and "mcl_farming:wheat_item" or "group:food_wheat"
  196. local i_flour = mcl and "mcl_farming:bread" or "group:food_flour"
  197. local i_egg = mcl and "mcl_throwing:egg" or "group:food_egg"
  198. local i_milk = mcl and "mcl_mobitems:milk_bucket" or "group:food_milk"
  199. local i_cocoa = mcl and "mcl_dye:brown" or "group:food_cocoa"
  200. local i_strawberry = mcl and "mcl_dye:red" or "group:food_strawberry"
  201. local i_coffee = mcl and "mcl_dye:black" or "group:food_coffee"
  202. local i_cheese = mcl and "mcl_dye:yellow" or "group:food_cheese"
  203. local i_red = mcl and "mcl_dye:red" or "dye:red"
  204. local i_meat = mcl and "mcl_mobitems:beef" or "group:food_meat_raw"
  205. local i_banana = mcl and "mcl_dye:yellow" or "group:food_banana"
  206. local i_bread = mcl and "mcl_farming:bread" or "group:food_bread"
  207. local i_orange = mcl and "mcl_dye:orange" or "group:food_orange"
  208. -- normal cake recipe
  209. minetest.register_craft({
  210. output = "pie:pie_0",
  211. recipe = {
  212. {i_sugar, i_milk, i_sugar},
  213. {i_sugar, i_egg, i_sugar},
  214. {i_wheat, i_flour, i_wheat}
  215. },
  216. replacements = replace_these
  217. })
  218. -- chocolate cake recipe
  219. minetest.register_craft({
  220. output = "pie:choc_0",
  221. recipe = {
  222. {i_cocoa, i_milk, i_cocoa},
  223. {i_sugar, i_egg, i_sugar},
  224. {i_wheat, i_flour, i_wheat}
  225. },
  226. replacements = replace_these
  227. })
  228. -- strawberry cheesecake recipe
  229. minetest.register_craft({
  230. output = "pie:scsk_0",
  231. recipe = {
  232. {i_strawberry, i_milk, i_strawberry},
  233. {i_sugar, i_egg, i_sugar},
  234. {i_wheat, i_flour, i_wheat}
  235. },
  236. replacements = replace_these
  237. })
  238. -- coffee cake recipe
  239. minetest.register_craft({
  240. output = "pie:coff_0",
  241. recipe = {
  242. {i_coffee, i_milk, i_coffee},
  243. {i_sugar, i_egg, i_sugar},
  244. {i_wheat, i_flour, i_wheat}
  245. },
  246. replacements = replace_these
  247. })
  248. -- red velvet cake recipe
  249. minetest.register_craft({
  250. output = "pie:rvel_0",
  251. recipe = {
  252. {i_cocoa, i_milk, i_red},
  253. {i_sugar, i_egg, i_sugar},
  254. {i_flour, i_cheese, i_flour}
  255. },
  256. replacements = replace_these
  257. })
  258. -- meat cake recipe
  259. minetest.register_craft({
  260. output = "pie:meat_0",
  261. recipe = {
  262. {i_meat, i_egg, i_meat},
  263. {i_wheat, i_wheat, i_wheat}
  264. }
  265. })
  266. -- banana cake recipe
  267. minetest.register_craft({
  268. output = "pie:bana_0",
  269. recipe = {
  270. {i_banana, i_milk, i_banana},
  271. {i_sugar, i_egg, i_sugar},
  272. {i_wheat, i_flour, i_wheat}
  273. },
  274. replacements = replace_these
  275. })
  276. -- bread pudding recipe
  277. minetest.register_craft({
  278. output = "pie:brpd_0",
  279. recipe = {
  280. {i_bread, i_milk, i_bread},
  281. {i_sugar, i_egg, i_sugar},
  282. {i_wheat, i_flour, i_wheat}
  283. },
  284. replacements = replace_these
  285. })
  286. -- orange pie
  287. minetest.register_craft({
  288. output = "pie:orange_0",
  289. recipe = {
  290. {i_orange, i_milk, i_orange},
  291. {i_sugar, i_egg, i_sugar},
  292. {i_wheat, i_flour, i_wheat}
  293. },
  294. replacements = replace_these
  295. })
  296. -- add lucky blocks
  297. if minetest.get_modpath("lucky_block") then
  298. lucky_block:add_blocks({
  299. {"nod", "pie:pie_0", 0},
  300. {"nod", "pie:choc_0", 0},
  301. {"nod", "pie:coff_0", 0},
  302. {"tro", "pie:pie_0"},
  303. {"nod", "pie:rvel_0", 0},
  304. {"nod", "pie:scsk_0", 0},
  305. {"nod", "pie:bana_0", 0},
  306. {"nod", "pie:orange_0", 0},
  307. {"tro", "pie:orange_0", "default_place_node_hard", true},
  308. {"nod", "pie:brpd_0", 0},
  309. {"nod", "pie:meat_0", 0},
  310. {"lig"}
  311. })
  312. end
  313. -- some aliases for older pie mod by Mitroman
  314. minetest.register_alias("pie:apie_0", "pie:pie_0")
  315. minetest.register_alias("pie:apie_1", "pie:pie_1")
  316. minetest.register_alias("pie:apie_2", "pie:pie_2")
  317. minetest.register_alias("pie:apie_3", "pie:pie_3")
  318. minetest.register_alias("pie:piebatter", "pie:pie_0")
  319. minetest.register_alias("pie:apiebatter", "pie:pie_0")
  320. minetest.register_alias("pie:amuffinbatter", "pie:pie_0")
  321. minetest.register_alias("pie:applemuffin", "pie:pie_0")
  322. minetest.register_alias("pie:sugar", "farming:sugar")
  323. minetest.register_alias("pie:knife", "default:sword_steel")
  324. print("[MOD] Pie loaded")