items.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. if not mese_crystals.nodes_registered then
  2. local boxes = {
  3. {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2},
  4. {-0.2, -0.5, -0.2, 0.2, 0.10, 0.2},
  5. {-0.2, -0.5, -0.2, 0.2, 0.25, 0.2},
  6. {-0.2, -0.5, -0.2, 0.2, 0.35, 0.2},
  7. }
  8. local light = {1, 3, 5, 7}
  9. -- Register 4 levels of crystal.
  10. for i = 1, 4, 1 do
  11. minetest.register_node("mese_crystals:mese_crystal_ore" .. i, {
  12. description = "Zentamine Crystal Ore",
  13. mesh = "mese_crystal_ore" .. i .. ".obj",
  14. tiles = {"crystal.png"},
  15. paramtype = "light",
  16. paramtype2 = "facedir",
  17. drawtype = "mesh",
  18. groups = utility.dig_groups("crystal", {attached_node = 1, fall_damage_add_percent = 60}),
  19. drop = "default:mese_crystal_fragment " .. i,
  20. use_texture_alpha = true,
  21. sounds = default.node_sound_stone_defaults(),
  22. light_source = light[i],
  23. selection_box = {
  24. type = "fixed",
  25. fixed = boxes[i],
  26. },
  27. collision_box = {
  28. type = "fixed",
  29. fixed = boxes[i],
  30. },
  31. on_player_walk_over = function(pos, player)
  32. player:set_hp(player:get_hp() - 1)
  33. if player:get_hp() == 0 then
  34. minetest.chat_send_all("# Server: <" .. rename.gpn(player:get_player_name()) .. "> stepped on a zentamine spike.")
  35. end
  36. end,
  37. on_timer = function(...)
  38. return mese_crystals.on_timer(...)
  39. end,
  40. on_rotate = function(...)
  41. return screwdriver.rotate_simple(...)
  42. end,
  43. on_construct = function(pos)
  44. local node = minetest.get_node(pos)
  45. node.param2 = math.random(0, 3)
  46. minetest.swap_node(pos, node)
  47. end,
  48. })
  49. end
  50. minetest.register_craftitem("mese_crystals:zentamine", {
  51. description = "Zentamine Shard",
  52. inventory_image = "zentamine_fragment.png",
  53. })
  54. mese_crystals.nodes_registered = true
  55. end
  56. function mese_crystals.on_seed_place(itemstack, user, pt)
  57. if pt.type ~= "node" then
  58. return
  59. end
  60. local pos = pt.under
  61. local node = minetest.get_node(pos)
  62. -- Pass through interactions to nodes that define them (like chests).
  63. do
  64. local pdef = minetest.reg_ns_nodes[node.name]
  65. if pdef and pdef.on_rightclick and not user:get_player_control().sneak then
  66. return pdef.on_rightclick(pos, node, user, itemstack, pt)
  67. end
  68. end
  69. if node.name == "default:obsidian" then
  70. local pos1 = pt.above
  71. local node1 = minetest.get_node(pos1)
  72. if node1.name == "air" and not minetest.is_protected(pos1, user:get_player_name()) then
  73. itemstack:take_item()
  74. node.name = "mese_crystals:mese_crystal_ore1"
  75. minetest.add_node(pos1, {name=node.name, param2=math.random(0, 3)})
  76. minetest.get_node_timer(pos1):start(mese_crystals.get_grow_time())
  77. dirtspread.on_environment(pos1)
  78. droplift.notify(pos1)
  79. end
  80. end
  81. return itemstack
  82. end
  83. if not mese_crystals.seed_registered then
  84. minetest.register_craftitem("mese_crystals:mese_crystal_seed", {
  85. description = "Zentamine Crystal Seed\n\nGrows fastest in or below the cavern of the Brimstone Ocean!\nThe care and tending of zentamine crystals is difficult.",
  86. inventory_image = "mese_crystal_seed.png",
  87. on_place = function(...)
  88. return mese_crystals.on_seed_place(...)
  89. end,
  90. })
  91. mese_crystals.seed_registered = true
  92. end