init.lua 5.5 KB

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