init.lua 5.8 KB

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