init.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. christmas = {}
  2. christmas.players = {}
  3. christmas.path = minetest.get_modpath("christmas")
  4. christmas.rewards = {}
  5. local mod_storage = minetest.get_mod_storage()
  6. dofile(christmas.path.."/functions.lua" )
  7. dofile(christmas.path.."/crafting.lua")
  8. local data = christmas.data
  9. ------------------------------------ Craft Items ------------------------------------
  10. minetest.register_craftitem("christmas:candy_cane", {
  11. description = "Candy Cane",
  12. inventory_image = "christmas_candy_cane.png",
  13. on_use = christmas.eat_candy(1)
  14. })
  15. minetest.register_craftitem("christmas:mince_pie", {
  16. description = "Mince Pie",
  17. inventory_image = "christmas_mincepie.png",
  18. on_use = minetest.item_eat(6)
  19. })
  20. minetest.register_craftitem("christmas:sugar", {
  21. description = "Sugar",
  22. inventory_image = "christmas_sugar.png",
  23. })
  24. minetest.register_craftitem("christmas:gingerbread_man", {
  25. description = "Gingerbread Man",
  26. inventory_image = "christmas_gingerbread_man.png",
  27. on_use = minetest.item_eat(4)
  28. })
  29. minetest.register_craftitem("christmas:bauble_red", {
  30. description = "Bauble (Red)",
  31. inventory_image = "christmas_bauble_red.png",
  32. groups = {tree_bauble=1},
  33. colour_code = 1,--Future support
  34. })
  35. minetest.register_craftitem("christmas:star", {
  36. description = "Star",
  37. inventory_image = "christmas_star_inv.png",
  38. groups = {tree_topper=1},
  39. })
  40. ------------------------------------ Nodes ------------------------------------
  41. minetest.register_node("christmas:eggnog", {
  42. description = "Eggnog",
  43. drawtype = "plantlike",
  44. tiles = {"christmas_eggnog.png"},
  45. inventory_image = "christmas_eggnog.png",
  46. on_use = minetest.item_eat(10),
  47. groups = {vessel = 1, dig_immediate = 3, attached_node = 1},
  48. })
  49. minetest.register_node("christmas:present", {
  50. description = "Christmas present",
  51. tiles = {"christmas_present.png"},
  52. drawtype = "mesh",
  53. paramtype = "light",
  54. mesh = "christmas_present.obj",
  55. groups = {oddly_breakable_by_hand = 3, attached_node = 1},
  56. selection_box = {
  57. type = "fixed",
  58. fixed = {
  59. {-0.3125, -0.5, -0.3125, 0.3125, 0.125, 0.3125},
  60. }
  61. },
  62. on_construct = function(pos, itemstack, placer, pointed_thing)
  63. local meta = minetest.get_meta(pos)
  64. meta:set_string("infotext", "Christmas Present")
  65. meta:set_string("owner", "")
  66. local inv = meta:get_inventory()
  67. inv:set_size("main", 1)
  68. end,
  69. can_dig = function(pos,player)
  70. local meta = minetest.get_meta(pos);
  71. local inv = meta:get_inventory()
  72. return inv:is_empty("main")
  73. end,
  74. after_place_node = function(pos, placer)
  75. local meta = minetest.get_meta(pos)
  76. meta:set_string("owner", placer:get_player_name() or "")
  77. meta:set_string("infotext", "Present from ".. meta:get_string("owner"))
  78. end,
  79. on_rightclick = function(pos, node, player, itemstack, pointed_thing)
  80. minetest.after(0.2,
  81. minetest.show_formspec,
  82. player:get_player_name(),
  83. "christmas:present",
  84. christmas.get_present_formspec(pos))
  85. end,
  86. })
  87. minetest.register_node("christmas:stocking", {
  88. description = "Christmas Stocking",
  89. drawtype = "signlike",
  90. tiles = {"christmas_stocking.png"},
  91. inventory_image = "christmas_stocking.png",
  92. paramtype = "light",
  93. paramtype2 = "wallmounted",
  94. sunlight_propagates = true,
  95. selection_box = {
  96. type = "wallmounted",
  97. },
  98. groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 3, attached_node = 1},
  99. walkable = false,
  100. on_construct = function(pos, itemstack, placer, pointed_thing)
  101. local meta = minetest.get_meta(pos)
  102. meta:set_string("infotext", "Stocking: No owner")
  103. meta:set_string("owner", "")
  104. local inv = meta:get_inventory()
  105. inv:set_size("main", 3)
  106. end,
  107. after_place_node = function(pos, player, itemstack, pointed_thing)
  108. local name = player:get_player_name()
  109. local meta = minetest.get_meta(pos)
  110. local stocking_pos = mod_storage:get_string(name.."_stocking_pos")
  111. local spos = minetest.string_to_pos(stocking_pos)
  112. if (spos and minetest.get_node(spos).name ~= "christmas:stocking") or stocking_pos == (nil or "") then
  113. mod_storage:set_string(name.."_stocking_pos", minetest.pos_to_string(pos))
  114. elseif spos and minetest.get_node(spos).name == "christmas:stocking" then
  115. minetest.set_node(pos, {name="air"})
  116. minetest.chat_send_player(name, "You already have a stocking at: ".. stocking_pos)
  117. return itemstack
  118. end
  119. meta:set_string("infotext", player:get_player_name().."'s Stocking")
  120. meta:set_string("owner", player:get_player_name())
  121. local timer = minetest.get_node_timer(pos)
  122. timer:start(5400)
  123. end,
  124. on_destruct = function(pos)
  125. local meta = minetest.get_meta(pos)
  126. local owner = meta:get_string("owner")
  127. local stocking_pos = mod_storage:get_string(owner.."_stocking_pos")
  128. local spos = minetest.string_to_pos(stocking_pos)
  129. if minetest.string_to_pos(stocking_pos) == pos then
  130. mod_storage:set_string(owner.."_stocking_pos", " ")
  131. end
  132. end,
  133. on_timer = function(pos)
  134. local meta = minetest.get_meta(pos)
  135. local owner = meta:get_string("owner")
  136. minetest.chat_send_player(owner, "Your stocking has refilled")--Hooray
  137. local inv = meta:get_inventory()
  138. inv:set_stack("main", 1, christmas.random_reward())
  139. inv:set_stack("main", 2, christmas.random_reward())
  140. inv:set_stack("main", 3, christmas.random_reward())
  141. end,
  142. on_rightclick = function(pos, node, player, itemstack, pointed_thing)
  143. local meta = minetest.get_meta(pos)
  144. local timer = minetest.get_node_timer(pos)
  145. local owner = meta:get_string("owner")
  146. local playerinv = player:get_inventory()
  147. if player:get_player_name() ~= owner then
  148. minetest.chat_send_player(player:get_player_name(), "This isn't your stocking")--Imposter!!
  149. return itemstack
  150. end
  151. local inv = meta:get_inventory()
  152. if inv:is_empty("main") then
  153. local time = christmas.to_time(math.floor(timer:get_timeout() - timer:get_elapsed()))
  154. minetest.chat_send_player(owner, "Your stocking is empty. (refill in: "..time..")")--Whyyyyyyy??? 😭
  155. elseif not inv:is_empty("main") then
  156. local item1 = inv:get_stack("main", 1)
  157. playerinv:add_item("main", item1)
  158. local item2 = inv:get_stack("main", 2)
  159. playerinv:add_item("main", item2)
  160. local item3 = inv:get_stack("main", 3)
  161. playerinv:add_item("main", item3)
  162. inv:set_stack("main", 1 ,'')
  163. inv:set_stack("main", 2 ,'')
  164. inv:set_stack("main", 3 ,'')
  165. timer:start(5400)
  166. end
  167. end,
  168. })
  169. minetest.register_node("christmas:lights", {
  170. description = "Christmas lights",
  171. drawtype = "signlike",
  172. tiles = {
  173. {
  174. name = "christmas_lights_animated.png",
  175. backface_culling = false,
  176. animation = {
  177. type = "vertical_frames",
  178. aspect_w = 16,
  179. aspect_h = 16,
  180. length = 2.0,
  181. },
  182. },
  183. },
  184. inventory_image = "christmas_lights.png",
  185. wield_image = "christmas_lights.png",
  186. paramtype = "light",
  187. paramtype2 = "wallmounted",
  188. light_source = 3,
  189. selection_box = {
  190. type = "wallmounted",
  191. },
  192. groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 3, attached_node = 1},
  193. walkable = false,
  194. })
  195. ------------------------------------ Christmas tree ------------------------------------
  196. minetest.register_node("christmas:tree", {
  197. description = "Christmas Tree",
  198. tiles = {
  199. "christmas_tree_leaves.png"
  200. },
  201. inventory_image = "christmas_tree_inv.png",
  202. drawtype = "mesh",
  203. paramtype = "light",
  204. mesh = "christmas_tree.obj",
  205. groups = {snappy = 2, attached_node = 1},
  206. collision_box = {
  207. type = "fixed",
  208. fixed = {-0.625, -0.5, -0.625, 0.625, 2, 0.625},
  209. },
  210. selection_box = {
  211. type = "fixed",
  212. fixed = {-0.75, -0.5, -0.75, 0.75, 2.3125, 0.75},
  213. },
  214. after_place_node = function(pos, placer, itemstack, pointed_thing)
  215. local pos1 = {x=pos.x, y=pos.y+1, z=pos.z}
  216. local pos2 = {x=pos.x, y=pos.y+2, z=pos.z}
  217. local node1 = minetest.get_node(pos1)
  218. local node2 = minetest.get_node(pos2)
  219. if node1.name ~= "air" or node2.name ~= "air" then
  220. minetest.set_node(pos, {name="air"})
  221. minetest.chat_send_player(placer:get_player_name(), "You need a 3 block tall space to place the tree")
  222. return itemstack
  223. end
  224. end,
  225. on_rightclick = function(pos, node, player, itemstack, pointed_thing)
  226. local item = minetest.registered_items[itemstack:get_name()]
  227. if item.groups.tree_bauble ~= nil then
  228. local pos2 = {x=pos.x, y=pos.y+1, z=pos.z}
  229. local name = minetest.get_node(pos2).name
  230. if minetest.registered_nodes[name].buildable_to then
  231. minetest.set_node(pos2, {name="christmas:ornament"})
  232. end
  233. itemstack:take_item()
  234. elseif item.groups.tree_topper ~= nil then
  235. local pos2 = {x=pos.x, y=pos.y+2, z=pos.z}
  236. local name = minetest.get_node(pos2).name
  237. if minetest.registered_nodes[name].buildable_to then
  238. minetest.set_node(pos2, {name="christmas:topper"})
  239. end
  240. itemstack:take_item()
  241. end
  242. end,
  243. on_destruct = function(pos)
  244. local pos1 = {x=pos.x, y=pos.y+1, z=pos.z}
  245. local pos2 = {x=pos.x, y=pos.y+2, z=pos.z}
  246. local name = minetest.get_node(pos1).name
  247. local name2 = minetest.get_node(pos2).name
  248. minetest.after(0.01, function()
  249. if name == "christmas:ornament" then
  250. minetest.set_node(pos1, {name="air"})
  251. minetest.add_item(pos1, "christmas:bauble_red")
  252. end
  253. if name2 == "christmas:topper" then
  254. minetest.set_node(pos2, {name="air"})
  255. minetest.add_item(pos2, "christmas:star")
  256. end
  257. end)
  258. end,
  259. })
  260. minetest.register_node("christmas:ornament", {
  261. description = "Bauble",
  262. tiles = {
  263. "christmas_bauble.png"
  264. },
  265. drawtype = "mesh",
  266. paramtype = "light",
  267. paramtype2 = "color",
  268. color = "red",
  269. mesh = "christmas_tree_balls.obj",
  270. groups = {not_in_creative_inventory = 1},
  271. walkable = false,
  272. pointable = false,
  273. on_construct = function(pos)
  274. local npos = {x=pos.x, y=pos.y-1, z=pos.z}
  275. local name = minetest.get_node(npos).name
  276. if name ~= "christmas:tree" then
  277. minetest.set_node(pos, {name="air"})
  278. end
  279. end,
  280. })
  281. minetest.register_node("christmas:topper", {
  282. description = "Topper",
  283. tiles = {
  284. "christmas_star.png"
  285. },
  286. drawtype = "mesh",
  287. paramtype = "light",
  288. light_source = 8,
  289. paramtype2 = "color",
  290. color = "yellow",
  291. mesh = "christmas_star.obj",
  292. groups = {not_in_creative_inventory = 1},
  293. walkable = false,
  294. pointable = false,
  295. on_construct = function(pos)
  296. local npos = {x=pos.x, y=pos.y-2, z=pos.z}
  297. local name = minetest.get_node(npos).name
  298. if name ~= "christmas:tree" then
  299. minetest.set_node(pos, {name="air"})
  300. end
  301. end,
  302. })
  303. christmas.register_reward("christmas:lights", {min=1, max=5}, 0.5)
  304. christmas.register_reward("christmas:candy_cane", {min=3, max=15}, 0.15)
  305. christmas.register_reward("christmas:eggnog", {min=1, max=3}, 0.15)
  306. christmas.register_reward("christmas:gingerbread_man", {min=1, max=9}, 0.5)
  307. christmas.register_reward("christmas:mince_pie", {min=6, max=12}, 0.3)
  308. christmas.register_reward("christmas:tree", {min=0, max=1}, 0.15)
  309. christmas.register_reward("christmas:bauble_red", {min=0, max=1}, 0.15)
  310. christmas.register_reward("christmas:star", {min=0, max=1}, 0.1)
  311. christmas.register_reward("christmas:sugar", {min=1, max=7}, 0.36)
  312. christmas.register_reward("christmas:present", {min=1, max=2}, 0.26)