1 local modname = assert(core.get_current_modname())
2 local modstorage = core.get_mod_storage()
5 dofile(core.get_modpath(modname) .. "example.lua")
7 core.register_on_shutdown(function()
8 print("[PREVIEW] shutdown client")
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 print("CSM restrictions: " .. dump(core.get_csm_restrictions()))
21 local l1, l2 = core.get_language()
22 print("Configured language: " .. l1 .. " / " .. l2)
25 mod_channel = core.mod_channel_join("experimental_preview")
27 core.after(4, function()
28 if mod_channel:is_writeable() then
29 mod_channel:send_all("preview talk to experimental")
33 core.after(1, function()
34 print("armor: " .. dump(core.localplayer:get_armor_groups()))
35 id = core.localplayer:hud_add({
36 hud_elem_type = "text",
39 position = {x=0, y=1},
41 text = "You are using the preview mod",
42 scale = {x=200, y=60},
43 alignment = {x=1, y=-1},
47 core.register_on_modchannel_message(function(channel, sender, message)
48 print("[PREVIEW][modchannels] Received message `" .. message .. "` on channel `"
49 .. channel .. "` from sender `" .. sender .. "`")
50 core.after(1, function()
51 mod_channel:send_all("CSM preview received " .. message)
55 core.register_on_modchannel_signal(function(channel, signal)
56 print("[PREVIEW][modchannels] Received signal id `" .. signal .. "` on channel `"
60 core.register_on_inventory_open(function(inventory)
61 print("INVENTORY OPEN")
62 print(dump(inventory))
66 core.register_on_placenode(function(pointed_thing, node)
67 print("The local player place a node!")
68 print("pointed_thing :" .. dump(pointed_thing))
69 print("node placed :" .. dump(node))
73 core.register_on_item_use(function(itemstack, pointed_thing)
74 print("The local player used an item!")
75 print("pointed_thing :" .. dump(pointed_thing))
76 print("item = " .. itemstack:get_name())
78 if not itemstack:is_empty() then
82 local pos = core.camera:get_pos()
83 local pos2 = vector.add(pos, vector.multiply(core.camera:get_look_dir(), 100))
85 local rc = core.raycast(pos, pos2)
87 print("[PREVIEW] raycast next: " .. dump(i))
89 print("[PREVIEW] line of sight: " .. (core.line_of_sight(pos, i.above) and "yes" or "no"))
91 local n1 = core.find_nodes_in_area(pos, i.under, {"default:stone"})
92 local n2 = core.find_nodes_in_area_under_air(pos, i.under, {"default:stone"})
93 print(("[PREVIEW] found %s nodes, %s nodes under air"):format(
94 n1 and #n1 or "?", n2 and #n2 or "?"))
100 -- This is an example function to ensure it's working properly, should be removed before merge
101 core.register_on_receiving_chat_message(function(message)
102 print("[PREVIEW] Received message " .. message)
106 -- This is an example function to ensure it's working properly, should be removed before merge
107 core.register_on_sending_chat_message(function(message)
108 print("[PREVIEW] Sending message " .. message)
112 core.register_on_chatcommand(function(command, params)
113 print("[PREVIEW] caught command '"..command.."'. Parameters: '"..params.."'")
116 -- This is an example function to ensure it's working properly, should be removed before merge
117 core.register_on_hp_modification(function(hp)
118 print("[PREVIEW] HP modified " .. hp)
121 -- This is an example function to ensure it's working properly, should be removed before merge
122 core.register_on_damage_taken(function(hp)
123 print("[PREVIEW] Damage taken " .. hp)
126 -- This is an example function to ensure it's working properly, should be removed before merge
127 core.register_chatcommand("dump", {
128 func = function(param)
129 return true, dump(_G)
133 local function preview_minimap()
134 local minimap = core.ui.minimap
136 print("[PREVIEW] Minimap is disabled. Skipping.")
141 minimap:set_pos({x=5, y=50, z=5})
142 minimap:set_shape(math.random(0, 1))
144 print("[PREVIEW] Minimap: mode => " .. dump(minimap:get_mode()) ..
145 " position => " .. dump(minimap:get_pos()) ..
146 " angle => " .. dump(minimap:get_angle()))
149 core.after(2, function()
150 print("[PREVIEW] loaded " .. modname .. " mod")
151 modstorage:set_string("current_mod", modname)
152 assert(modstorage:get_string("current_mod") == modname)
156 core.after(5, function()
157 if core.ui.minimap then
158 core.ui.minimap:show()
161 print("[PREVIEW] Time of day " .. core.get_timeofday())
163 print("[PREVIEW] Node level: " .. core.get_node_level({x=0, y=20, z=0}) ..
164 " max level " .. core.get_node_max_level({x=0, y=20, z=0}))
166 print("[PREVIEW] Find node near: " .. dump(core.find_node_near({x=0, y=20, z=0}, 10,
167 {"group:tree", "default:dirt", "default:stone"})))
170 core.register_on_dignode(function(pos, node)
171 print("The local player dug a node!")
172 print("pos:" .. dump(pos))
173 print("node:" .. dump(node))
177 core.register_on_punchnode(function(pos, node)
178 print("The local player punched a node!")
179 local itemstack = core.localplayer:get_wielded_item()
180 print(dump(itemstack:to_table()))
181 print("pos:" .. dump(pos))
182 print("node:" .. dump(node))
183 local meta = core.get_meta(pos)
184 print("punched meta: " .. (meta and dump(meta:to_table()) or "(missing)"))
188 core.register_chatcommand("privs", {
189 func = function(param)
190 return true, core.privs_to_string(minetest.get_privilege_list())
194 core.register_chatcommand("text", {
195 func = function(param)
196 return core.localplayer:hud_change(id, "text", param)
201 core.register_on_mods_loaded(function()
202 core.log("Yeah preview mod is loaded with other CSM mods.")