init.lua 4.1 KB

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