1 local modname = core.get_current_modname() or "??"
2 local modstorage = core.get_mod_storage()
5 dofile("preview:example.lua")
6 -- This is an example function to ensure it's working properly, should be removed before merge
7 core.register_on_shutdown(function()
8 print("[PREVIEW] shutdown client")
11 core.register_on_connect(function()
12 print("[PREVIEW] Player connection completed")
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)
19 mod_channel = core.mod_channel_join("experimental_preview")
22 core.register_on_modchannel_message(function(channel, sender, message)
23 print("[PREVIEW][modchannels] Received message `" .. message .. "` on channel `"
24 .. channel .. "` from sender `" .. sender .. "`")
25 core.after(1, function()
26 mod_channel:send_all("CSM preview received " .. message)
30 core.register_on_modchannel_signal(function(channel, signal)
31 print("[PREVIEW][modchannels] Received signal id `" .. signal .. "` on channel `"
35 core.register_on_placenode(function(pointed_thing, node)
36 print("The local player place a node!")
37 print("pointed_thing :" .. dump(pointed_thing))
38 print("node placed :" .. dump(node))
42 core.register_on_item_use(function(itemstack, pointed_thing)
43 print("The local player used an item!")
44 print("pointed_thing :" .. dump(pointed_thing))
45 print("item = " .. itemstack:get_name())
49 -- This is an example function to ensure it's working properly, should be removed before merge
50 core.register_on_receiving_chat_message(function(message)
51 print("[PREVIEW] Received message " .. message)
55 -- This is an example function to ensure it's working properly, should be removed before merge
56 core.register_on_sending_chat_message(function(message)
57 print("[PREVIEW] Sending message " .. message)
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)
66 -- This is an example function to ensure it's working properly, should be removed before merge
67 core.register_on_damage_taken(function(hp)
68 print("[PREVIEW] Damage taken " .. hp)
71 -- This is an example function to ensure it's working properly, should be removed before merge
72 core.register_globalstep(function(dtime)
73 -- print("[PREVIEW] globalstep " .. dtime)
76 -- This is an example function to ensure it's working properly, should be removed before merge
77 core.register_chatcommand("dump", {
78 func = function(param)
83 core.register_chatcommand("colorize_test", {
84 func = function(param)
85 return true, core.colorize("red", param)
89 core.register_chatcommand("test_node", {
90 func = function(param)
91 core.display_chat_message(dump(core.get_node({x=0, y=0, z=0})))
92 core.display_chat_message(dump(core.get_node_or_nil({x=0, y=0, z=0})))
96 local function preview_minimap()
97 local minimap = core.ui.minimap
99 print("[PREVIEW] Minimap is disabled. Skipping.")
104 minimap:set_pos({x=5, y=50, z=5})
105 minimap:set_shape(math.random(0, 1))
107 print("[PREVIEW] Minimap: mode => " .. dump(minimap:get_mode()) ..
108 " position => " .. dump(minimap:get_pos()) ..
109 " angle => " .. dump(minimap:get_angle()))
112 core.after(2, function()
113 print("[PREVIEW] loaded " .. modname .. " mod")
114 modstorage:set_string("current_mod", modname)
115 print(modstorage:get_string("current_mod"))
119 core.after(4, function()
120 if mod_channel:is_writeable() then
121 mod_channel:send_all("preview talk to experimental")
125 core.after(5, function()
126 if core.ui.minimap then
127 core.ui.minimap:show()
130 print("[PREVIEW] Day count: " .. core.get_day_count() ..
131 " time of day " .. core.get_timeofday())
133 print("[PREVIEW] Node level: " .. core.get_node_level({x=0, y=20, z=0}) ..
134 " max level " .. core.get_node_max_level({x=0, y=20, z=0}))
136 print("[PREVIEW] Find node near: " .. dump(core.find_node_near({x=0, y=20, z=0}, 10,
137 {"group:tree", "default:dirt", "default:stone"})))
140 core.register_on_dignode(function(pos, node)
141 print("The local player dug a node!")
142 print("pos:" .. dump(pos))
143 print("node:" .. dump(node))
147 core.register_on_punchnode(function(pos, node)
148 print("The local player punched a node!")
149 local itemstack = core.get_wielded_item()
152 print(dump(itemstack:is_empty()))
153 print(dump(itemstack:get_name()))
154 print(dump(itemstack:get_count()))
155 print(dump(itemstack:get_wear()))
156 print(dump(itemstack:get_meta()))
157 print(dump(itemstack:get_metadata()
158 print(dump(itemstack:is_known()))
159 --print(dump(itemstack:get_definition()))
160 print(dump(itemstack:get_tool_capabilities()))
161 print(dump(itemstack:to_string()))
162 print(dump(itemstack:to_table()))
164 print(dump(itemstack:set_name("default:dirt")))
165 print(dump(itemstack:set_count("95")))
166 print(dump(itemstack:set_wear(934)))
167 print(dump(itemstack:get_meta()))
168 print(dump(itemstack:get_metadata()))
170 print(dump(itemstack:to_table()))
171 print("pos:" .. dump(pos))
172 print("node:" .. dump(node))
176 core.register_chatcommand("privs", {
177 func = function(param)
178 return true, core.privs_to_string(minetest.get_privilege_list())