items.lua 3.1 KB

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