]> git.lizzy.rs Git - dragonfireclient.git/blob - clientmods/preview/init.lua
[CSM] Remove non-functional minetest.get_day_count()
[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] Time of day " .. core.get_timeofday())
147
148         print("[PREVIEW] Node level: " .. core.get_node_level({x=0, y=20, z=0}) ..
149                 " max level " .. core.get_node_max_level({x=0, y=20, z=0}))
150
151         print("[PREVIEW] Find node near: " .. dump(core.find_node_near({x=0, y=20, z=0}, 10,
152                 {"group:tree", "default:dirt", "default:stone"})))
153 end)
154
155 core.register_on_dignode(function(pos, node)
156         print("The local player dug a node!")
157         print("pos:" .. dump(pos))
158         print("node:" .. dump(node))
159         return false
160 end)
161
162 core.register_on_punchnode(function(pos, node)
163         print("The local player punched a node!")
164         local itemstack = core.get_wielded_item()
165         --[[
166         -- getters
167         print(dump(itemstack:is_empty()))
168         print(dump(itemstack:get_name()))
169         print(dump(itemstack:get_count()))
170         print(dump(itemstack:get_wear()))
171         print(dump(itemstack:get_meta()))
172         print(dump(itemstack:get_metadata()
173         print(dump(itemstack:is_known()))
174         --print(dump(itemstack:get_definition()))
175         print(dump(itemstack:get_tool_capabilities()))
176         print(dump(itemstack:to_string()))
177         print(dump(itemstack:to_table()))
178         -- setters
179         print(dump(itemstack:set_name("default:dirt")))
180         print(dump(itemstack:set_count("95")))
181         print(dump(itemstack:set_wear(934)))
182         print(dump(itemstack:get_meta()))
183         print(dump(itemstack:get_metadata()))
184         --]]
185         print(dump(itemstack:to_table()))
186         print("pos:" .. dump(pos))
187         print("node:" .. dump(node))
188         return false
189 end)
190
191 core.register_chatcommand("privs", {
192         func = function(param)
193                 return true, core.privs_to_string(minetest.get_privilege_list())
194         end,
195 })
196
197 core.register_chatcommand("text", {
198         func = function(param)
199                 return core.localplayer:hud_change(id, "text", param)
200         end,
201 })
202
203
204 core.register_on_mods_loaded(function()
205         core.log("Yeah preview mod is loaded with other CSM mods.")
206 end)