items.lua 3.4 KB

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