]> git.lizzy.rs Git - minetest.git/blob - clientmods/preview/init.lua
[CSM] add `on_item_use` (#5544)
[minetest.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_messages(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_messages(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         minimap:set_mode(4)
82         minimap:show()
83         minimap:set_pos({x=5, y=50, z=5})
84         minimap:set_shape(math.random(0, 1))
85
86         print("[PREVIEW] Minimap: mode => " .. dump(minimap:get_mode()) ..
87                         " position => " .. dump(minimap:get_pos()) ..
88                         " angle => " .. dump(minimap:get_angle()))
89 end
90
91 core.after(2, function()
92         print("[PREVIEW] loaded " .. modname .. " mod")
93         modstorage:set_string("current_mod", modname)
94         print(modstorage:get_string("current_mod"))
95         preview_minimap()
96 end)
97
98 core.after(5, function()
99         core.ui.minimap:show()
100
101         print("[PREVIEW] Day count: " .. core.get_day_count() ..
102                 " time of day " .. core.get_timeofday())
103
104         print("[PREVIEW] Node level: " .. core.get_node_level({x=0, y=20, z=0}) ..
105                 " max level " .. core.get_node_max_level({x=0, y=20, z=0}))
106
107         print("[PREVIEW] Find node near: " .. dump(core.find_node_near({x=0, y=20, z=0}, 10,
108                 {"group:tree", "default:dirt", "default:stone"})))
109 end)
110
111 core.register_on_dignode(function(pos, node)
112         print("The local player dug a node!")
113         print("pos:" .. dump(pos))
114         print("node:" .. dump(node))
115         return false
116 end)
117
118 core.register_on_punchnode(function(pos, node)
119         print("The local player punched a node!")
120         local itemstack = core.get_wielded_item()
121         --[[
122         -- getters
123         print(dump(itemstack:is_empty()))
124         print(dump(itemstack:get_name()))
125         print(dump(itemstack:get_count()))
126         print(dump(itemstack:get_wear()))
127         print(dump(itemstack:get_meta()))
128         print(dump(itemstack:get_metadata()
129         print(dump(itemstack:is_known()))
130         --print(dump(itemstack:get_definition()))
131         print(dump(itemstack:get_tool_capabilities()))
132         print(dump(itemstack:to_string()))
133         print(dump(itemstack:to_table()))
134         -- setters
135         print(dump(itemstack:set_name("default:dirt")))
136         print(dump(itemstack:set_count("95")))
137         print(dump(itemstack:set_wear(934)))
138         print(dump(itemstack:get_meta()))
139         print(dump(itemstack:get_metadata()))
140         --]]
141         print(dump(itemstack:to_table()))
142         print("pos:" .. dump(pos))
143         print("node:" .. dump(node))
144         return false
145 end)
146