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")
21 core.after(4, function()
22 if mod_channel:is_writeable() then
23 mod_channel:send_all("preview talk to experimental")
28 core.register_on_modchannel_message(function(channel, sender, message)
29 print("[PREVIEW][modchannels] Received message `" .. message .. "` on channel `"
30 .. channel .. "` from sender `" .. sender .. "`")
31 core.after(1, function()
32 mod_channel:send_all("CSM preview received " .. message)
36 core.register_on_modchannel_signal(function(channel, signal)
37 print("[PREVIEW][modchannels] Received signal id `" .. signal .. "` on channel `"
41 core.register_on_inventory_open(function(inventory)
42 print("INVENTORY OPEN")
43 print(dump(inventory))
47 core.register_on_placenode(function(pointed_thing, node)
48 print("The local player place a node!")
49 print("pointed_thing :" .. dump(pointed_thing))
50 print("node placed :" .. dump(node))
54 core.register_on_item_use(function(itemstack, pointed_thing)
55 print("The local player used an item!")
56 print("pointed_thing :" .. dump(pointed_thing))
57 print("item = " .. itemstack:get_name())
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)
67 -- This is an example function to ensure it's working properly, should be removed before merge
68 core.register_on_sending_chat_message(function(message)
69 print("[PREVIEW] Sending message " .. message)
73 -- This is an example function to ensure it's working properly, should be removed before merge
74 core.register_on_hp_modification(function(hp)
75 print("[PREVIEW] HP modified " .. hp)
78 -- This is an example function to ensure it's working properly, should be removed before merge
79 core.register_on_damage_taken(function(hp)
80 print("[PREVIEW] Damage taken " .. hp)
83 -- This is an example function to ensure it's working properly, should be removed before merge
84 core.register_globalstep(function(dtime)
85 -- print("[PREVIEW] globalstep " .. dtime)
88 -- This is an example function to ensure it's working properly, should be removed before merge
89 core.register_chatcommand("dump", {
90 func = function(param)
95 core.register_chatcommand("colorize_test", {
96 func = function(param)
97 return true, core.colorize("red", param)
101 core.register_chatcommand("test_node", {
102 func = function(param)
103 core.display_chat_message(dump(core.get_node({x=0, y=0, z=0})))
104 core.display_chat_message(dump(core.get_node_or_nil({x=0, y=0, z=0})))
108 local function preview_minimap()
109 local minimap = core.ui.minimap
111 print("[PREVIEW] Minimap is disabled. Skipping.")
116 minimap:set_pos({x=5, y=50, z=5})
117 minimap:set_shape(math.random(0, 1))
119 print("[PREVIEW] Minimap: mode => " .. dump(minimap:get_mode()) ..
120 " position => " .. dump(minimap:get_pos()) ..
121 " angle => " .. dump(minimap:get_angle()))
124 core.after(2, function()
125 print("[PREVIEW] loaded " .. modname .. " mod")
126 modstorage:set_string("current_mod", modname)
127 print(modstorage:get_string("current_mod"))
131 core.after(5, function()
132 if core.ui.minimap then
133 core.ui.minimap:show()
136 print("[PREVIEW] Day count: " .. core.get_day_count() ..
137 " time of day " .. core.get_timeofday())
139 print("[PREVIEW] Node level: " .. core.get_node_level({x=0, y=20, z=0}) ..
140 " max level " .. core.get_node_max_level({x=0, y=20, z=0}))
142 print("[PREVIEW] Find node near: " .. dump(core.find_node_near({x=0, y=20, z=0}, 10,
143 {"group:tree", "default:dirt", "default:stone"})))
146 core.register_on_dignode(function(pos, node)
147 print("The local player dug a node!")
148 print("pos:" .. dump(pos))
149 print("node:" .. dump(node))
153 core.register_on_punchnode(function(pos, node)
154 print("The local player punched a node!")
155 local itemstack = core.get_wielded_item()
158 print(dump(itemstack:is_empty()))
159 print(dump(itemstack:get_name()))
160 print(dump(itemstack:get_count()))
161 print(dump(itemstack:get_wear()))
162 print(dump(itemstack:get_meta()))
163 print(dump(itemstack:get_metadata()
164 print(dump(itemstack:is_known()))
165 --print(dump(itemstack:get_definition()))
166 print(dump(itemstack:get_tool_capabilities()))
167 print(dump(itemstack:to_string()))
168 print(dump(itemstack:to_table()))
170 print(dump(itemstack:set_name("default:dirt")))
171 print(dump(itemstack:set_count("95")))
172 print(dump(itemstack:set_wear(934)))
173 print(dump(itemstack:get_meta()))
174 print(dump(itemstack:get_metadata()))
176 print(dump(itemstack:to_table()))
177 print("pos:" .. dump(pos))
178 print("node:" .. dump(node))
182 core.register_chatcommand("privs", {
183 func = function(param)
184 return true, core.privs_to_string(minetest.get_privilege_list())