]> git.lizzy.rs Git - dragonfireclient.git/blob - clientmods/preview/init.lua
test
[dragonfireclient.git] / clientmods / preview / init.lua
1 local modname = assert(core.get_current_modname())
2 local modstorage = core.get_mod_storage()
3 local mod_channel
4
5 dofile(core.get_modpath(modname) .. "example.lua")
6
7 core.register_on_shutdown(function()
8         print("[PREVIEW] shutdown client")
9 end)
10 local id = nil
11
12 do
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         print("CSM restrictions: " .. dump(core.get_csm_restrictions()))
20
21         local l1, l2 = core.get_language()
22         print("Configured language: " .. l1 .. " / " .. l2)
23 end
24
25 mod_channel = core.mod_channel_join("experimental_preview")
26
27 core.after(4, function()
28         if mod_channel:is_writeable() then
29                 mod_channel:send_all("preview talk to experimental")
30         end
31 end)
32
33 core.after(1, function()
34         id = core.localplayer:hud_add({
35                         hud_elem_type = "text",
36                         name = "example",
37                         number = 0xff0000,
38                         position = {x=0, y=1},
39                         offset = {x=8, y=-8},
40                         text = "You are using the preview mod",
41                         scale = {x=200, y=60},
42                         alignment = {x=1, y=-1},
43         })
44 end)
45
46 core.register_on_modchannel_message(function(channel, sender, message)
47         print("[PREVIEW][modchannels] Received message `" .. message .. "` on channel `"
48                         .. channel .. "` from sender `" .. sender .. "`")
49         core.after(1, function()
50                 mod_channel:send_all("CSM preview received " .. message)
51         end)
52 end)
53
54 core.register_on_modchannel_signal(function(channel, signal)
55         print("[PREVIEW][modchannels] Received signal id `" .. signal .. "` on channel `"
56                         .. channel)
57 end)
58
59 core.register_on_inventory_open(function(inventory)
60         print("INVENTORY OPEN")
61         print(dump(inventory))
62         return false
63 end)
64
65 core.register_on_placenode(function(pointed_thing, node)
66         print("The local player place a node!")
67         print("pointed_thing :" .. dump(pointed_thing))
68         print("node placed :" .. dump(node))
69         return false
70 end)
71
72 core.register_on_item_use(function(itemstack, pointed_thing)
73         print("The local player used an item!")
74         print("pointed_thing :" .. dump(pointed_thing))
75         print("item = " .. itemstack:get_name())
76
77         if not itemstack:is_empty() then
78                 return false
79         end
80
81         local pos = vector.add(core.localplayer:get_pos(), core.camera:get_offset())
82         local pos2 = vector.add(pos, vector.multiply(core.camera:get_look_dir(), 100))
83
84         local rc = core.raycast(pos, pos2)
85         local i = rc:next()
86         print("[PREVIEW] raycast next: " .. dump(i))
87         if i then
88                 print("[PREVIEW] line of sight: " .. (core.line_of_sight(pos, i.above) and "yes" or "no"))
89
90                 local n1 = core.find_nodes_in_area(pos, i.under, {"default:stone"})
91                 local n2 = core.find_nodes_in_area_under_air(pos, i.under, {"default:stone"})
92                 print(("[PREVIEW] found %s nodes, %s nodes under air"):format(
93                                 n1 and #n1 or "?", n2 and #n2 or "?"))
94         end
95
96         return false
97 end)
98
99 -- This is an example function to ensure it's working properly, should be removed before merge
100 core.register_on_receiving_chat_message(function(message)
101         print("[PREVIEW] Received message " .. message)
102         return false
103 end)
104
105 -- This is an example function to ensure it's working properly, should be removed before merge
106 core.register_on_sending_chat_message(function(message)
107         print("[PREVIEW] Sending message " .. message)
108         return false
109 end)
110
111 -- This is an example function to ensure it's working properly, should be removed before merge
112 core.register_on_hp_modification(function(hp)
113         print("[PREVIEW] HP modified " .. hp)
114 end)
115
116 -- This is an example function to ensure it's working properly, should be removed before merge
117 core.register_on_damage_taken(function(hp)
118         print("[PREVIEW] Damage taken " .. hp)
119 end)
120
121 -- This is an example function to ensure it's working properly, should be removed before merge
122 core.register_chatcommand("dump", {
123         func = function(param)
124                 return true, dump(_G)
125         end,
126 })
127
128 core.register_chatcommand("colorize_test", {
129         func = function(param)
130                 return true, core.colorize("red", param)
131         end,
132 })
133
134 core.register_chatcommand("test_node", {
135         func = function(param)
136                 core.display_chat_message(dump(core.get_node({x=0, y=0, z=0})))
137                 core.display_chat_message(dump(core.get_node_or_nil({x=0, y=0, z=0})))
138         end,
139 })
140
141 local function preview_minimap()
142         local minimap = core.ui.minimap
143         if not minimap then
144                 print("[PREVIEW] Minimap is disabled. Skipping.")
145                 return
146         end
147         minimap:set_mode(4)
148         minimap:show()
149         minimap:set_pos({x=5, y=50, z=5})
150         minimap:set_shape(math.random(0, 1))
151
152         print("[PREVIEW] Minimap: mode => " .. dump(minimap:get_mode()) ..
153                         " position => " .. dump(minimap:get_pos()) ..
154                         " angle => " .. dump(minimap:get_angle()))
155 end
156
157 core.after(2, function()
158         print("[PREVIEW] loaded " .. modname .. " mod")
159         modstorage:set_string("current_mod", modname)
160         print(modstorage:get_string("current_mod"))
161         preview_minimap()
162 end)
163
164 core.after(5, function()
165         if core.ui.minimap then
166                 core.ui.minimap:show()
167         end
168
169         print("[PREVIEW] Time of day " .. core.get_timeofday())
170
171         print("[PREVIEW] Node level: " .. core.get_node_level({x=0, y=20, z=0}) ..
172                 " max level " .. core.get_node_max_level({x=0, y=20, z=0}))
173
174         print("[PREVIEW] Find node near: " .. dump(core.find_node_near({x=0, y=20, z=0}, 10,
175                 {"group:tree", "default:dirt", "default:stone"})))
176 end)
177
178 core.register_on_dignode(function(pos, node)
179         print("The local player dug a node!")
180         print("pos:" .. dump(pos))
181         print("node:" .. dump(node))
182         return false
183 end)
184
185 core.register_on_punchnode(function(pos, node)
186         print("The local player punched a node!")
187         local itemstack = core.get_wielded_item()
188         --[[
189         -- getters
190         print(dump(itemstack:is_empty()))
191         print(dump(itemstack:get_name()))
192         print(dump(itemstack:get_count()))
193         print(dump(itemstack:get_wear()))
194         print(dump(itemstack:get_meta()))
195         print(dump(itemstack:get_metadata()
196         print(dump(itemstack:is_known()))
197         --print(dump(itemstack:get_definition()))
198         print(dump(itemstack:get_tool_capabilities()))
199         print(dump(itemstack:to_string()))
200         print(dump(itemstack:to_table()))
201         -- setters
202         print(dump(itemstack:set_name("default:dirt")))
203         print(dump(itemstack:set_count("95")))
204         print(dump(itemstack:set_wear(934)))
205         print(dump(itemstack:get_meta()))
206         print(dump(itemstack:get_metadata()))
207         --]]
208         print(dump(itemstack:to_table()))
209         print("pos:" .. dump(pos))
210         print("node:" .. dump(node))
211         return false
212 end)
213
214 core.register_chatcommand("privs", {
215         func = function(param)
216                 return true, core.privs_to_string(minetest.get_privilege_list())
217         end,
218 })
219
220 core.register_chatcommand("text", {
221         func = function(param)
222                 return core.localplayer:hud_change(id, "text", param)
223         end,
224 })
225
226
227 core.register_on_mods_loaded(function()
228         core.log("Yeah preview mod is loaded with other CSM mods.")
229 end)