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")
12 local server_info = core.get_server_info()
13 print("Server version: " .. server_info.protocol_version)
14 print("Server ip: " .. server_info.ip)
15 print("Server address: " .. server_info.address)
16 print("Server port: " .. server_info.port)
17 mod_channel = core.mod_channel_join("experimental_preview")
19 core.after(4, function()
20 if mod_channel:is_writeable() then
21 mod_channel:send_all("preview talk to experimental")
25 core.after(1, function()
26 id = core.localplayer:hud_add({
27 hud_elem_type = "text",
30 position = {x=0, y=1},
32 text = "You are using the preview mod",
33 scale = {x=200, y=60},
34 alignment = {x=1, y=-1},
38 core.register_on_modchannel_message(function(channel, sender, message)
39 print("[PREVIEW][modchannels] Received message `" .. message .. "` on channel `"
40 .. channel .. "` from sender `" .. sender .. "`")
41 core.after(1, function()
42 mod_channel:send_all("CSM preview received " .. message)
46 core.register_on_modchannel_signal(function(channel, signal)
47 print("[PREVIEW][modchannels] Received signal id `" .. signal .. "` on channel `"
51 core.register_on_inventory_open(function(inventory)
52 print("INVENTORY OPEN")
53 print(dump(inventory))
57 core.register_on_placenode(function(pointed_thing, node)
58 print("The local player place a node!")
59 print("pointed_thing :" .. dump(pointed_thing))
60 print("node placed :" .. dump(node))
64 core.register_on_item_use(function(itemstack, pointed_thing)
65 print("The local player used an item!")
66 print("pointed_thing :" .. dump(pointed_thing))
67 print("item = " .. itemstack:get_name())
71 -- This is an example function to ensure it's working properly, should be removed before merge
72 core.register_on_receiving_chat_message(function(message)
73 print("[PREVIEW] Received message " .. message)
77 -- This is an example function to ensure it's working properly, should be removed before merge
78 core.register_on_sending_chat_message(function(message)
79 print("[PREVIEW] Sending message " .. message)
83 -- This is an example function to ensure it's working properly, should be removed before merge
84 core.register_on_hp_modification(function(hp)
85 print("[PREVIEW] HP modified " .. hp)
88 -- This is an example function to ensure it's working properly, should be removed before merge
89 core.register_on_damage_taken(function(hp)
90 print("[PREVIEW] Damage taken " .. hp)
93 -- This is an example function to ensure it's working properly, should be removed before merge
94 core.register_globalstep(function(dtime)
95 -- print("[PREVIEW] globalstep " .. dtime)
98 -- This is an example function to ensure it's working properly, should be removed before merge
99 core.register_chatcommand("dump", {
100 func = function(param)
101 return true, dump(_G)
105 core.register_chatcommand("colorize_test", {
106 func = function(param)
107 return true, core.colorize("red", param)
111 core.register_chatcommand("test_node", {
112 func = function(param)
113 core.display_chat_message(dump(core.get_node({x=0, y=0, z=0})))
114 core.display_chat_message(dump(core.get_node_or_nil({x=0, y=0, z=0})))
118 local function preview_minimap()
119 local minimap = core.ui.minimap
121 print("[PREVIEW] Minimap is disabled. Skipping.")
126 minimap:set_pos({x=5, y=50, z=5})
127 minimap:set_shape(math.random(0, 1))
129 print("[PREVIEW] Minimap: mode => " .. dump(minimap:get_mode()) ..
130 " position => " .. dump(minimap:get_pos()) ..
131 " angle => " .. dump(minimap:get_angle()))
134 core.after(2, function()
135 print("[PREVIEW] loaded " .. modname .. " mod")
136 modstorage:set_string("current_mod", modname)
137 print(modstorage:get_string("current_mod"))
141 core.after(5, function()
142 if core.ui.minimap then
143 core.ui.minimap:show()
146 print("[PREVIEW] Day count: " .. core.get_day_count() ..
147 " time of day " .. core.get_timeofday())
149 print("[PREVIEW] Node level: " .. core.get_node_level({x=0, y=20, z=0}) ..
150 " max level " .. core.get_node_max_level({x=0, y=20, z=0}))
152 print("[PREVIEW] Find node near: " .. dump(core.find_node_near({x=0, y=20, z=0}, 10,
153 {"group:tree", "default:dirt", "default:stone"})))
156 core.register_on_dignode(function(pos, node)
157 print("The local player dug a node!")
158 print("pos:" .. dump(pos))
159 print("node:" .. dump(node))
163 core.register_on_punchnode(function(pos, node)
164 print("The local player punched a node!")
165 local itemstack = core.get_wielded_item()
168 print(dump(itemstack:is_empty()))
169 print(dump(itemstack:get_name()))
170 print(dump(itemstack:get_count()))
171 print(dump(itemstack:get_wear()))
172 print(dump(itemstack:get_meta()))
173 print(dump(itemstack:get_metadata()
174 print(dump(itemstack:is_known()))
175 --print(dump(itemstack:get_definition()))
176 print(dump(itemstack:get_tool_capabilities()))
177 print(dump(itemstack:to_string()))
178 print(dump(itemstack:to_table()))
180 print(dump(itemstack:set_name("default:dirt")))
181 print(dump(itemstack:set_count("95")))
182 print(dump(itemstack:set_wear(934)))
183 print(dump(itemstack:get_meta()))
184 print(dump(itemstack:get_metadata()))
186 print(dump(itemstack:to_table()))
187 print("pos:" .. dump(pos))
188 print("node:" .. dump(node))
192 core.register_chatcommand("privs", {
193 func = function(param)
194 return true, core.privs_to_string(minetest.get_privilege_list())
198 core.register_chatcommand("text", {
199 func = function(param)
200 return core.localplayer:hud_change(id, "text", param)