]> git.lizzy.rs Git - minetest.git/blobdiff - clientmods/preview/init.lua
[CSM] Add callback on open inventory (#5793)
[minetest.git] / clientmods / preview / init.lua
index fb606b3f46b28e8b6ab2d6dd3657b8abf649744c..288b1b16c1d9ea67e2134fef3372ad5466d05d00 100644 (file)
@@ -1,6 +1,8 @@
 local modname = core.get_current_modname() or "??"
 local modstorage = core.get_mod_storage()
+local mod_channel
 
+dofile("preview:example.lua")
 -- This is an example function to ensure it's working properly, should be removed before merge
 core.register_on_shutdown(function()
        print("[PREVIEW] shutdown client")
@@ -13,6 +15,33 @@ core.register_on_connect(function()
        print("Server ip: " .. server_info.ip)
        print("Server address: " .. server_info.address)
        print("Server port: " .. server_info.port)
+
+       mod_channel = core.mod_channel_join("experimental_preview")
+
+       core.after(4, function()
+               if mod_channel:is_writeable() then
+                       mod_channel:send_all("preview talk to experimental")
+               end
+       end)
+end)
+
+core.register_on_modchannel_message(function(channel, sender, message)
+       print("[PREVIEW][modchannels] Received message `" .. message .. "` on channel `"
+                       .. channel .. "` from sender `" .. sender .. "`")
+       core.after(1, function()
+               mod_channel:send_all("CSM preview received " .. message)
+       end)
+end)
+
+core.register_on_modchannel_signal(function(channel, signal)
+       print("[PREVIEW][modchannels] Received signal id `" .. signal .. "` on channel `"
+                       .. channel)
+end)
+
+core.register_on_inventory_open(function(inventory)
+       print("INVENTORY OPEN")
+       print(dump(inventory))
+       return false
 end)
 
 core.register_on_placenode(function(pointed_thing, node)
@@ -22,14 +51,21 @@ core.register_on_placenode(function(pointed_thing, node)
        return false
 end)
 
+core.register_on_item_use(function(itemstack, pointed_thing)
+       print("The local player used an item!")
+       print("pointed_thing :" .. dump(pointed_thing))
+       print("item = " .. itemstack:get_name())
+       return false
+end)
+
 -- This is an example function to ensure it's working properly, should be removed before merge
-core.register_on_receiving_chat_messages(function(message)
+core.register_on_receiving_chat_message(function(message)
        print("[PREVIEW] Received message " .. message)
        return false
 end)
 
 -- This is an example function to ensure it's working properly, should be removed before merge
-core.register_on_sending_chat_messages(function(message)
+core.register_on_sending_chat_message(function(message)
        print("[PREVIEW] Sending message " .. message)
        return false
 end)
@@ -71,6 +107,10 @@ core.register_chatcommand("test_node", {
 
 local function preview_minimap()
        local minimap = core.ui.minimap
+       if not minimap then
+               print("[PREVIEW] Minimap is disabled. Skipping.")
+               return
+       end
        minimap:set_mode(4)
        minimap:show()
        minimap:set_pos({x=5, y=50, z=5})
@@ -89,7 +129,9 @@ core.after(2, function()
 end)
 
 core.after(5, function()
-       core.ui.minimap:show()
+       if core.ui.minimap then
+               core.ui.minimap:show()
+       end
 
        print("[PREVIEW] Day count: " .. core.get_day_count() ..
                " time of day " .. core.get_timeofday())
@@ -137,3 +179,8 @@ core.register_on_punchnode(function(pos, node)
        return false
 end)
 
+core.register_chatcommand("privs", {
+       func = function(param)
+               return true, core.privs_to_string(minetest.get_privilege_list())
+       end,
+})