You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

232 lines
6.6 KiB

  1. -- ===================================================================
  2. local modname = assert (core.get_current_modname())
  3. local modstorage = core.get_mod_storage()
  4. local mod_channel
  5. -- ===================================================================
  6. dofile (core.get_modpath (modname) .. "example.lua")
  7. -- ===================================================================
  8. core.register_on_shutdown (function()
  9. print ("[Preview] shutdown client")
  10. end)
  11. -- ===================================================================
  12. do
  13. local server_info = core.get_server_info()
  14. print ("Server version: " .. server_info.protocol_version)
  15. print ("Server ip: " .. server_info.ip)
  16. print ("Server address: " .. server_info.address)
  17. print ("Server port: " .. server_info.port)
  18. local l1, l2 = core.get_language()
  19. print ("Configured language: " .. l1 .. " / " .. l2)
  20. end
  21. -- ===================================================================
  22. if false then
  23. core.register_on_inventory_open (function (inventory)
  24. print ("Inventory open")
  25. print (dump (inventory))
  26. return false
  27. end)
  28. end
  29. -- ===================================================================
  30. core.register_on_placenode (function (pointed_thing, node)
  31. print ("The local player placed a node")
  32. print ("pointed_thing :" .. dump (pointed_thing ))
  33. print ("node placed :" .. dump (node ))
  34. return false
  35. end)
  36. -- ===================================================================
  37. core.register_on_item_use (function (itemstack, pointed_thing)
  38. print ("The local player used an item")
  39. print ("pointed_thing :" .. dump (pointed_thing))
  40. print ("item = " .. itemstack:get_name())
  41. return false
  42. end)
  43. -- ===================================================================
  44. -- This setting should usually be false as it enables debug code that
  45. -- is high-load and/or verbose.
  46. local high_debug = false
  47. if high_debug then
  48. core.register_on_receiving_chat_message (function (message)
  49. print ("[Preview] Received message " .. message)
  50. return false
  51. end)
  52. core.register_on_sending_chat_message (function (message)
  53. print ("[Preview] Sending message " .. message)
  54. return false
  55. end)
  56. core.register_on_hp_modification (function (hp)
  57. print ("[Preview] HP modified " .. hp)
  58. end)
  59. core.register_on_damage_taken (function (hp)
  60. print ("[Preview] Damage taken " .. hp)
  61. end)
  62. core.register_globalstep (function (dtime)
  63. -- print ("[Preview] globalstep " .. dtime)
  64. end)
  65. core.register_chatcommand ("dump", {
  66. func = function (param)
  67. return true, dump(_G)
  68. end,
  69. })
  70. end
  71. -- ===================================================================
  72. core.register_chatcommand ("colorize_test", {
  73. func = function (param)
  74. return true, core.colorize ("red", param)
  75. end,
  76. })
  77. -- ===================================================================
  78. core.register_chatcommand ("test_node", {
  79. func = function (param)
  80. core.display_chat_message (dump (core.get_node ({
  81. x=0, y=0, z=0 })))
  82. core.display_chat_message (dump (core.get_node_or_nil ({
  83. x=0, y=0, z=0 })))
  84. end,
  85. })
  86. -- ===================================================================
  87. local function preview_minimap()
  88. local minimap = core.ui.minimap
  89. if not minimap then
  90. print ("[Preview] Minimap is disabled. Skipping.")
  91. return
  92. end
  93. minimap:set_mode(4)
  94. minimap:show()
  95. minimap:set_pos({x=5, y=50, z=5})
  96. minimap:set_shape(math.random(0, 1))
  97. print ("[Preview] Minimap: mode => " .. dump(minimap:get_mode()) ..
  98. " position => " .. dump(minimap:get_pos()) ..
  99. " angle => " .. dump(minimap:get_angle()))
  100. end
  101. -- ===================================================================
  102. core.after(2, function()
  103. print ("[Preview] loaded " .. modname .. " mod")
  104. modstorage:set_string ("current_mod", modname)
  105. print (modstorage:get_string ("current_mod"))
  106. preview_minimap()
  107. end)
  108. -- ===================================================================
  109. core.after(5, function()
  110. if core.ui.minimap then
  111. core.ui.minimap:show()
  112. end
  113. print ("[Preview] Day count: " ..
  114. core.get_day_count() ..
  115. " time of day " .. core.get_timeofday())
  116. print ("[Preview] Node level: " ..
  117. core.get_node_level({x=0, y=20, z=0}) ..
  118. " max level " .. core.get_node_max_level ({x=0, y=20, z=0}))
  119. print ("[Preview] Find node near: " ..
  120. dump (core.find_node_near ({x=0, y=20, z=0}, 10,
  121. {"group:tree", "default:dirt", "default:stone"})))
  122. end)
  123. -- ===================================================================
  124. core.register_on_dignode (function (pos, node)
  125. print ("The local player dug a node")
  126. print ("pos:" .. dump (pos ))
  127. print ("node:" .. dump (node ))
  128. return false
  129. end)
  130. -- ===================================================================
  131. core.register_on_punchnode (function (pos, node)
  132. print ("The local player punched a node")
  133. local itemstack = core.get_wielded_item()
  134. --[[
  135. -- getters
  136. print (dump(itemstack:is_empty()))
  137. print (dump(itemstack:get_name()))
  138. print (dump(itemstack:get_count()))
  139. print (dump(itemstack:get_wear()))
  140. print (dump(itemstack:get_meta()))
  141. print (dump(itemstack:get_metadata()
  142. print (dump(itemstack:is_known()))
  143. --print (dump(itemstack:get_definition()))
  144. print (dump(itemstack:get_tool_capabilities()))
  145. print (dump(itemstack:to_string()))
  146. print (dump(itemstack:to_table()))
  147. -- setters
  148. print (dump(itemstack:set_name("default:dirt")))
  149. print (dump(itemstack:set_count("95")))
  150. print (dump(itemstack:set_wear(934)))
  151. print (dump(itemstack:get_meta()))
  152. print (dump(itemstack:get_metadata()))
  153. --]]
  154. print (dump (itemstack:to_table()))
  155. print ("pos:" .. dump (pos ))
  156. print ("node:" .. dump (node ))
  157. return false
  158. end)
  159. -- ===================================================================
  160. core.register_chatcommand ("privs", {
  161. func = function (param)
  162. return true, core.privs_to_string (minetest.get_privilege_list())
  163. end,
  164. })
  165. -- ===================================================================
  166. local id = nil
  167. core.register_chatcommand ("text", {
  168. func = function (param)
  169. return core.localplayer:hud_change (id, "text", param)
  170. end,
  171. })
  172. -- ===================================================================
  173. core.register_on_mods_loaded (function()
  174. core.log ("CSM preview mod is loaded")
  175. end)
  176. -- ===================================================================
  177. -- End of file.