]> git.lizzy.rs Git - dragonfireclient.git/blob - clientmods/preview/init.lua
[CSM] Add callback on open inventory (#5793)
[dragonfireclient.git] / clientmods / preview / init.lua
1 local modname = core.get_current_modname() or "??"
2 local modstorage = core.get_mod_storage()
3 local mod_channel
4
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")
9 end)
10
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)
18
19         mod_channel = core.mod_channel_join("experimental_preview")
20
21         core.after(4, function()
22                 if mod_channel:is_writeable() then
23                         mod_channel:send_all("preview talk to experimental")
24                 end
25         end)
26 end)
27
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)
33         end)
34 end)
35
36 core.register_on_modchannel_signal(function(channel, signal)
37         print("[PREVIEW][modchannels] Received signal id `" .. signal .. "` on channel `"
38                         .. channel)
39 end)
40
41 core.register_on_inventory_open(function(inventory)
42         print("INVENTORY OPEN")
43         print(dump(inventory))
44         return false
45 end)
46
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))
51         return false
52 end)
53
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())
58         return false
59 end)
60
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)
64         return false
65 end)
66
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)
70         return false
71 end)
72
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)
76 end)
77
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)
81 end)
82
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)
86 end)
87
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)
91                 return true, dump(_G)
92         end,
93 })
94
95 core.register_chatcommand("colorize_test", {
96         func = function(param)
97                 return true, core.colorize("red", param)
98         end,
99 })
100
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})))
105         end,
106 })
107
108 local function preview_minimap()
109         local minimap = core.ui.minimap
110         if not minimap then
111                 print("[PREVIEW] Minimap is disabled. Skipping.")
112                 return
113         end
114         minimap:set_mode(4)
115         minimap:show()
116         minimap:set_pos({x=5, y=50, z=5})
117         minimap:set_shape(math.random(0, 1))
118
119         print("[PREVIEW] Minimap: mode => " .. dump(minimap:get_mode()) ..
120                         " position => " .. dump(minimap:get_pos()) ..
121                         " angle => " .. dump(minimap:get_angle()))
122 end
123
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"))
128         preview_minimap()
129 end)
130
131 core.after(5, function()
132         if core.ui.minimap then
133                 core.ui.minimap:show()
134         end
135
136         print("[PREVIEW] Day count: " .. core.get_day_count() ..
137                 " time of day " .. core.get_timeofday())
138
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}))
141
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"})))
144 end)
145
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))
150         return false
151 end)
152
153 core.register_on_punchnode(function(pos, node)
154         print("The local player punched a node!")
155         local itemstack = core.get_wielded_item()
156         --[[
157         -- getters
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()))
169         -- setters
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()))
175         --]]
176         print(dump(itemstack:to_table()))
177         print("pos:" .. dump(pos))
178         print("node:" .. dump(node))
179         return false
180 end)
181
182 core.register_chatcommand("privs", {
183         func = function(param)
184                 return true, core.privs_to_string(minetest.get_privilege_list())
185         end,
186 })