]> git.lizzy.rs Git - dragonfireclient.git/blob - clientmods/preview/init.lua
DevTest: Fix broken PNG textures
[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         print("armor: " .. dump(core.localplayer:get_armor_groups()))
35         id = core.localplayer:hud_add({
36                         hud_elem_type = "text",
37                         name = "example",
38                         number = 0xff0000,
39                         position = {x=0, y=1},
40                         offset = {x=8, y=-8},
41                         text = "You are using the preview mod",
42                         scale = {x=200, y=60},
43                         alignment = {x=1, y=-1},
44         })
45 end)
46
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)
52         end)
53 end)
54
55 core.register_on_modchannel_signal(function(channel, signal)
56         print("[PREVIEW][modchannels] Received signal id `" .. signal .. "` on channel `"
57                         .. channel)
58 end)
59
60 core.register_on_inventory_open(function(inventory)
61         print("INVENTORY OPEN")
62         print(dump(inventory))
63         return false
64 end)
65
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))
70         return false
71 end)
72
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())
77
78         if not itemstack:is_empty() then
79                 return false
80         end
81
82         local pos = core.camera:get_pos()
83         local pos2 = vector.add(pos, vector.multiply(core.camera:get_look_dir(), 100))
84
85         local rc = core.raycast(pos, pos2)
86         local i = rc:next()
87         print("[PREVIEW] raycast next: " .. dump(i))
88         if i then
89                 print("[PREVIEW] line of sight: " .. (core.line_of_sight(pos, i.above) and "yes" or "no"))
90
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 "?"))
95         end
96
97         return false
98 end)
99
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)
103         return false
104 end)
105
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)
109         return false
110 end)
111
112 core.register_on_chatcommand(function(command, params)
113         print("[PREVIEW] caught command '"..command.."'. Parameters: '"..params.."'")
114 end)
115
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)
119 end)
120
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)
124 end)
125
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)
130         end,
131 })
132
133 local function preview_minimap()
134         local minimap = core.ui.minimap
135         if not minimap then
136                 print("[PREVIEW] Minimap is disabled. Skipping.")
137                 return
138         end
139         minimap:set_mode(4)
140         minimap:show()
141         minimap:set_pos({x=5, y=50, z=5})
142         minimap:set_shape(math.random(0, 1))
143
144         print("[PREVIEW] Minimap: mode => " .. dump(minimap:get_mode()) ..
145                         " position => " .. dump(minimap:get_pos()) ..
146                         " angle => " .. dump(minimap:get_angle()))
147 end
148
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)
153         preview_minimap()
154 end)
155
156 core.after(5, function()
157         if core.ui.minimap then
158                 core.ui.minimap:show()
159         end
160
161         print("[PREVIEW] Time of day " .. core.get_timeofday())
162
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}))
165
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"})))
168 end)
169
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))
174         return false
175 end)
176
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)"))
185         return false
186 end)
187
188 core.register_chatcommand("privs", {
189         func = function(param)
190                 return true, core.privs_to_string(minetest.get_privilege_list())
191         end,
192 })
193
194 core.register_chatcommand("text", {
195         func = function(param)
196                 return core.localplayer:hud_change(id, "text", param)
197         end,
198 })
199
200
201 core.register_on_mods_loaded(function()
202         core.log("Yeah preview mod is loaded with other CSM mods.")
203 end)