init.lua 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. void_chest = {
  2. show_particles = (minetest.settings:get("void_chest.show_particles") ~= "false")
  3. }
  4. -- Register the void chest.
  5. minetest.register_node("void_chest:void_chest", {
  6. description = "" ..core.colorize("#660099","Void Chest\n") ..core.colorize("#FFFFFF", "Use the power of the void to store your items."),
  7. tiles = {"void_chest_top.png", "void_chest_top.png", "void_chest_side.png",
  8. "void_chest_side.png", "void_chest_side.png", "void_chest_front.png"},
  9. paramtype2 = "facedir",
  10. groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2,},
  11. legacy_facedir_simple = true,
  12. sounds = default.node_sound_wood_defaults(),
  13. on_construct = function(pos)
  14. if void_chest.show_particles then
  15. local timer = minetest.get_node_timer(pos)
  16. timer:start(.1) -- in seconds
  17. end
  18. local meta = minetest.get_meta(pos)
  19. meta:set_string("formspec",
  20. "size[8,9]"..
  21. default.gui_bg ..
  22. default.gui_bg_img ..
  23. default.gui_slots ..
  24. "list[current_player;void_chest:void_chest;0,0.0;16,8;]"..
  25. "list[current_player;main;0,9.0;16,2;]" ..
  26. "list[current_player;main;0,9.0;0,16;1]" ..
  27. "listring[current_player;void_chest:void_chest]" ..
  28. "listring[current_player;main]" ..
  29. default.get_hotbar_bg(0,9.0))
  30. meta:set_string("infotext", "Void Chest")
  31. end,
  32. on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  33. minetest.log("action", player:get_player_name()..
  34. " moves stuff in void chest at "..minetest.pos_to_string(pos))
  35. end,
  36. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  37. minetest.log("action", player:get_player_name()..
  38. " moves stuff to void chest at "..minetest.pos_to_string(pos))
  39. end,
  40. on_metadata_inventory_take = function(pos, listname, index, stack, player)
  41. minetest.log("action", player:get_player_name()..
  42. " takes stuff from void chest at "..minetest.pos_to_string(pos))
  43. end,
  44. on_timer = function(pos)
  45. if void_chest.show_particles then
  46. -- Particles for the void effect, implemented by MisterE, thanks!
  47. for i=1,2 do -- number of particles spawned every on_timer
  48. local spin_speed = math.random(80,175)/1000 --controls how fast a particular particle spins
  49. local vel_scalar = math.random(0,5)/10 -- multiplied by the particle's velocity vector of 1
  50. local accel_scalar = math.random(1,5)/10 -- multiplied by the particle's accel vector of 1
  51. local expir = math.random(1,5) -- number of sec particle will last, if it doesn't hit a node
  52. local particle_pos = {x=pos.x + ((math.random(-15,15)/10)*(math.random(6,15)/10)), y=pos.y + ((math.random(-15,15)/10)*(math.random(6,15)/10)), z=pos.z+ ((math.random(-15,15)/10)*(math.random(6,15)/10))}
  53. local part_vel = vector.direction(particle_pos, pos)
  54. part_vel = {x= vel_scalar*part_vel.x, y= vel_scalar*part_vel.y, z= vel_scalar*part_vel.z}
  55. local part_accel = vector.direction(particle_pos, pos)
  56. part_accel = {x= accel_scalar*part_accel.x, y= accel_scalar*part_accel.y, z= accel_scalar*part_accel.z}
  57. minetest.add_particle({
  58. pos = particle_pos,
  59. velocity = part_vel,
  60. acceleration = part_accel,
  61. expirationtime = expir,
  62. size = math.random(5,15)/10,
  63. collisiondetection = true,
  64. collision_removal = true,
  65. vertical = false,
  66. texture = "void_chest_void_particle.png",
  67. animation = {
  68. type = "vertical_frames",
  69. aspect_w = 16,
  70. aspect_h = 16,
  71. length = spin_speed,
  72. },
  73. glow = 5,
  74. })
  75. end
  76. end
  77. return true
  78. end,
  79. })
  80. -- Register crafting recipes.
  81. -- If the "magic_materials" mod is present we use a more accurate recipe.
  82. if minetest.get_modpath("magic_materials") then
  83. minetest.register_craft({
  84. output = 'void_chest:void_chest',
  85. recipe = {
  86. {'default:steelblock','magic_materials:void_rune','default:steelblock'},
  87. {'magic_materials:void_rune','default:chest_locked','magic_materials:void_rune'},
  88. {'default:steelblock','magic_materials:void_rune','default:steelblock'}
  89. }
  90. })
  91. else -- Else we use a recipe using "default" to avoid a hard dependency.
  92. minetest.register_craft({
  93. output = 'void_chest:void_chest',
  94. recipe = {
  95. {'default:stone','default:coalblock','default:stone'},
  96. {'default:coalblock','default:furnace','default:coalblock'},
  97. {'default:stone','default:coalblock','default:stone'}
  98. }
  99. })
  100. end
  101. -- Create a detached void chest inventory when players connect.
  102. minetest.register_on_joinplayer(function(player)
  103. local inv = player:get_inventory()
  104. inv:set_size("void_chest:void_chest", 16*11)
  105. end)