]> git.lizzy.rs Git - dragonfireclient.git/blob - clientmods/preview/init.lua
CSM: Fix documentation error for register_on_*_chat_messages (#5917)
[dragonfireclient.git] / clientmods / preview / init.lua
1 local modname = core.get_current_modname() or "??"
2 local modstorage = core.get_mod_storage()
3
4 -- This is an example function to ensure it's working properly, should be removed before merge
5 core.register_on_shutdown(function()
6         print("[PREVIEW] shutdown client")
7 end)
8
9 core.register_on_connect(function()
10         print("[PREVIEW] Player connection completed")
11         local server_info = core.get_server_info()
12         print("Server version: " .. server_info.protocol_version)
13         print("Server ip: " .. server_info.ip)
14         print("Server address: " .. server_info.address)
15         print("Server port: " .. server_info.port)
16 end)
17
18 core.register_on_placenode(function(pointed_thing, node)
19         print("The local player place a node!")
20         print("pointed_thing :" .. dump(pointed_thing))
21         print("node placed :" .. dump(node))
22         return false
23 end)
24
25 core.register_on_item_use(function(itemstack, pointed_thing)
26         print("The local player used an item!")
27         print("pointed_thing :" .. dump(pointed_thing))
28         print("item = " .. itemstack:get_name())
29         return false
30 end)
31
32 -- This is an example function to ensure it's working properly, should be removed before merge
33 core.register_on_receiving_chat_message(function(message)
34         print("[PREVIEW] Received message " .. message)
35         return false
36 end)
37
38 -- This is an example function to ensure it's working properly, should be removed before merge
39 core.register_on_sending_chat_message(function(message)
40         print("[PREVIEW] Sending message " .. message)
41         return false
42 end)
43
44 -- This is an example function to ensure it's working properly, should be removed before merge
45 core.register_on_hp_modification(function(hp)
46         print("[PREVIEW] HP modified " .. hp)
47 end)
48
49 -- This is an example function to ensure it's working properly, should be removed before merge
50 core.register_on_damage_taken(function(hp)
51         print("[PREVIEW] Damage taken " .. hp)
52 end)
53
54 -- This is an example function to ensure it's working properly, should be removed before merge
55 core.register_globalstep(function(dtime)
56         -- print("[PREVIEW] globalstep " .. dtime)
57 end)
58
59 -- This is an example function to ensure it's working properly, should be removed before merge
60 core.register_chatcommand("dump", {
61         func = function(param)
62                 return true, dump(_G)
63         end,
64 })
65
66 core.register_chatcommand("colorize_test", {
67         func = function(param)
68                 return true, core.colorize("red", param)
69         end,
70 })
71
72 core.register_chatcommand("test_node", {
73         func = function(param)
74                 core.display_chat_message(dump(core.get_node({x=0, y=0, z=0})))
75                 core.display_chat_message(dump(core.get_node_or_nil({x=0, y=0, z=0})))
76         end,
77 })
78
79 local function preview_minimap()
80         local minimap = core.ui.minimap
81         if not minimap then
82                 print("[PREVIEW] Minimap is disabled. Skipping.")
83                 return
84         end
85         minimap:set_mode(4)
86         minimap:show()
87         minimap:set_pos({x=5, y=50, z=5})
88         minimap:set_shape(math.random(0, 1))
89
90         print("[PREVIEW] Minimap: mode => " .. dump(minimap:get_mode()) ..
91                         " position => " .. dump(minimap:get_pos()) ..
92                         " angle => " .. dump(minimap:get_angle()))
93 end
94
95 core.after(2, function()
96         print("[PREVIEW] loaded " .. modname .. " mod")
97         modstorage:set_string("current_mod", modname)
98         print(modstorage:get_string("current_mod"))
99         preview_minimap()
100 end)
101
102 core.after(5, function()
103         if core.ui.minimap then
104                 core.ui.minimap:show()
105         end
106
107         print("[PREVIEW] Day count: " .. core.get_day_count() ..
108                 " time of day " .. core.get_timeofday())
109
110         print("[PREVIEW] Node level: " .. core.get_node_level({x=0, y=20, z=0}) ..
111                 " max level " .. core.get_node_max_level({x=0, y=20, z=0}))
112
113         print("[PREVIEW] Find node near: " .. dump(core.find_node_near({x=0, y=20, z=0}, 10,
114                 {"group:tree", "default:dirt", "default:stone"})))
115 end)
116
117 core.register_on_dignode(function(pos, node)
118         print("The local player dug a node!")
119         print("pos:" .. dump(pos))
120         print("node:" .. dump(node))
121         return false
122 end)
123
124 core.register_on_punchnode(function(pos, node)
125         print("The local player punched a node!")
126         local itemstack = core.get_wielded_item()
127         --[[
128         -- getters
129         print(dump(itemstack:is_empty()))
130         print(dump(itemstack:get_name()))
131         print(dump(itemstack:get_count()))
132         print(dump(itemstack:get_wear()))
133         print(dump(itemstack:get_meta()))
134         print(dump(itemstack:get_metadata()
135         print(dump(itemstack:is_known()))
136         --print(dump(itemstack:get_definition()))
137         print(dump(itemstack:get_tool_capabilities()))
138         print(dump(itemstack:to_string()))
139         print(dump(itemstack:to_table()))
140         -- setters
141         print(dump(itemstack:set_name("default:dirt")))
142         print(dump(itemstack:set_count("95")))
143         print(dump(itemstack:set_wear(934)))
144         print(dump(itemstack:get_meta()))
145         print(dump(itemstack:get_metadata()))
146         --]]
147         print(dump(itemstack:to_table()))
148         print("pos:" .. dump(pos))
149         print("node:" .. dump(node))
150         return false
151 end)
152
153 core.register_chatcommand("privs", {
154         func = function(param)
155                 return true, core.privs_to_string(minetest.get_privilege_list())
156         end,
157 })