init.lua 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. local modname = core.get_current_modname() or "??"
  2. local modstorage = core.get_mod_storage()
  3. dofile("preview:example.lua")
  4. -- This is an example function to ensure it's working properly, should be removed before merge
  5. core.register_on_shutdown(function()
  6. print("[PREVIEW] shutdown client")
  7. end)
  8. core.register_on_connect(function()
  9. print("[PREVIEW] Player connection completed")
  10. local server_info = core.get_server_info()
  11. print("Server version: " .. server_info.protocol_version)
  12. print("Server ip: " .. server_info.ip)
  13. print("Server address: " .. server_info.address)
  14. print("Server port: " .. server_info.port)
  15. end)
  16. core.register_on_placenode(function(pointed_thing, node)
  17. print("The local player place a node!")
  18. print("pointed_thing :" .. dump(pointed_thing))
  19. print("node placed :" .. dump(node))
  20. return false
  21. end)
  22. core.register_on_item_use(function(itemstack, pointed_thing)
  23. print("The local player used an item!")
  24. print("pointed_thing :" .. dump(pointed_thing))
  25. print("item = " .. itemstack:get_name())
  26. return false
  27. end)
  28. -- This is an example function to ensure it's working properly, should be removed before merge
  29. core.register_on_receiving_chat_message(function(message)
  30. print("[PREVIEW] Received message " .. message)
  31. return false
  32. end)
  33. -- This is an example function to ensure it's working properly, should be removed before merge
  34. core.register_on_sending_chat_message(function(message)
  35. print("[PREVIEW] Sending message " .. message)
  36. return false
  37. end)
  38. -- This is an example function to ensure it's working properly, should be removed before merge
  39. core.register_on_hp_modification(function(hp)
  40. print("[PREVIEW] HP modified " .. hp)
  41. end)
  42. -- This is an example function to ensure it's working properly, should be removed before merge
  43. core.register_on_damage_taken(function(hp)
  44. print("[PREVIEW] Damage taken " .. hp)
  45. end)
  46. -- This is an example function to ensure it's working properly, should be removed before merge
  47. core.register_globalstep(function(dtime)
  48. -- print("[PREVIEW] globalstep " .. dtime)
  49. end)
  50. -- This is an example function to ensure it's working properly, should be removed before merge
  51. core.register_chatcommand("dump", {
  52. func = function(param)
  53. return true, dump(_G)
  54. end,
  55. })
  56. core.register_chatcommand("colorize_test", {
  57. func = function(param)
  58. return true, core.colorize("red", param)
  59. end,
  60. })
  61. core.register_chatcommand("test_node", {
  62. func = function(param)
  63. core.display_chat_message(dump(core.get_node({x=0, y=0, z=0})))
  64. core.display_chat_message(dump(core.get_node_or_nil({x=0, y=0, z=0})))
  65. end,
  66. })
  67. local function preview_minimap()
  68. local minimap = core.ui.minimap
  69. if not minimap then
  70. print("[PREVIEW] Minimap is disabled. Skipping.")
  71. return
  72. end
  73. minimap:set_mode(4)
  74. minimap:show()
  75. minimap:set_pos({x=5, y=50, z=5})
  76. minimap:set_shape(math.random(0, 1))
  77. print("[PREVIEW] Minimap: mode => " .. dump(minimap:get_mode()) ..
  78. " position => " .. dump(minimap:get_pos()) ..
  79. " angle => " .. dump(minimap:get_angle()))
  80. end
  81. core.after(2, function()
  82. print("[PREVIEW] loaded " .. modname .. " mod")
  83. modstorage:set_string("current_mod", modname)
  84. print(modstorage:get_string("current_mod"))
  85. preview_minimap()
  86. end)
  87. core.after(5, function()
  88. if core.ui.minimap then
  89. core.ui.minimap:show()
  90. end
  91. print("[PREVIEW] Day count: " .. core.get_day_count() ..
  92. " time of day " .. core.get_timeofday())
  93. print("[PREVIEW] Node level: " .. core.get_node_level({x=0, y=20, z=0}) ..
  94. " max level " .. core.get_node_max_level({x=0, y=20, z=0}))
  95. print("[PREVIEW] Find node near: " .. dump(core.find_node_near({x=0, y=20, z=0}, 10,
  96. {"group:tree", "default:dirt", "default:stone"})))
  97. end)
  98. core.register_on_dignode(function(pos, node)
  99. print("The local player dug a node!")
  100. print("pos:" .. dump(pos))
  101. print("node:" .. dump(node))
  102. return false
  103. end)
  104. core.register_on_punchnode(function(pos, node)
  105. print("The local player punched a node!")
  106. local itemstack = core.get_wielded_item()
  107. --[[
  108. -- getters
  109. print(dump(itemstack:is_empty()))
  110. print(dump(itemstack:get_name()))
  111. print(dump(itemstack:get_count()))
  112. print(dump(itemstack:get_wear()))
  113. print(dump(itemstack:get_meta()))
  114. print(dump(itemstack:get_metadata()
  115. print(dump(itemstack:is_known()))
  116. --print(dump(itemstack:get_definition()))
  117. print(dump(itemstack:get_tool_capabilities()))
  118. print(dump(itemstack:to_string()))
  119. print(dump(itemstack:to_table()))
  120. -- setters
  121. print(dump(itemstack:set_name("default:dirt")))
  122. print(dump(itemstack:set_count("95")))
  123. print(dump(itemstack:set_wear(934)))
  124. print(dump(itemstack:get_meta()))
  125. print(dump(itemstack:get_metadata()))
  126. --]]
  127. print(dump(itemstack:to_table()))
  128. print("pos:" .. dump(pos))
  129. print("node:" .. dump(node))
  130. return false
  131. end)
  132. core.register_chatcommand("privs", {
  133. func = function(param)
  134. return true, core.privs_to_string(minetest.get_privilege_list())
  135. end,
  136. })