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