init.lua 8.6 KB

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