init.lua 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. local modname = minetest.get_current_modname()
  2. local S = minetest.get_translator(modname)
  3. _G[modname] = {}
  4. local formspec =
  5. {
  6. "formspec_version[2]",
  7. "size[10,9]",
  8. "list[current_player;main;0.1,4.1;8,4]",
  9. "list[context;main;2.6,0.4;4,3]",
  10. "listring[]",
  11. "label[2.6,0.25;" .. S("Barrel") .. "]",
  12. "label[0.1,3.9;" .. S("Inventory") .. "]",
  13. }
  14. formspec = table.concat(formspec)
  15. local on_construct = function(pos)
  16. local meta = minetest.get_meta(pos)
  17. local inv = meta:get_inventory()
  18. inv:set_size("main", 12)
  19. meta:set_string("formspec", formspec)
  20. end
  21. local bounding_box =
  22. {
  23. type = "fixed",
  24. fixed = {-0.375, -0.5, -0.375, 0.375, 0.5, 0.375},
  25. }
  26. minetest.register_node(modname .. ":barrel",
  27. {
  28. drawtype = "mesh",
  29. mesh = "eg_storage_barrels_barrel.obj",
  30. tiles = {"eg_storage_barrels_wood.png", "eg_storage_barrels_rings.png", "eg_storage_barrels_top_bottom.png"},
  31. groups = {deconstructable = 3},
  32. selection_box = bounding_box,
  33. collision_box = bounding_box,
  34. on_construct = on_construct,
  35. sounds =
  36. {
  37. dig = "wood_high_dig",
  38. dug = "wood_low_dug",
  39. place = "wood_low_place",
  40. footstep = "wood_low_footstep",
  41. },
  42. can_dig = function(pos)
  43. local inv = minetest.get_inventory({type = "node", pos = pos})
  44. return inv:is_empty("main")
  45. end,
  46. })
  47. if minetest.get_modpath("eg_dungeons") and minetest.get_modpath("inventory_populator")
  48. then
  49. local dungeon_loot =
  50. {
  51. rolls = 3,
  52. rolls_max = 5,
  53. loots =
  54. {
  55. {
  56. weight = 5,
  57. loot = modname .. ":barrel",
  58. repetitions = 1,
  59. repetitions_max = 5,
  60. },
  61. accumulated_weight = 5,
  62. }
  63. }
  64. _G[modname].set_dungeon_loot_table = function(tab)
  65. dungeon_loot = tab
  66. end
  67. local get_inv_list = inventory_populator.get_inv_list
  68. local function populate_inv(pos, rand)
  69. local meta = minetest.get_meta(pos)
  70. local inv = meta:get_inventory()
  71. inv:set_list("main", get_inv_list(inv:get_size("main"), dungeon_loot, rand))
  72. end
  73. local on_construct = minetest.registered_nodes["eg_storage_barrels:barrel"].on_construct
  74. eg_dungeons.register_dungeon_populator(10, function(pos, rand)
  75. minetest.set_node(pos, {name = "eg_storage_barrels:barrel"})
  76. on_construct(pos)
  77. populate_inv(pos, rand)
  78. end)
  79. end