Run on_item_use CSM callback even if item is not marked usable
authorsfan5 <sfan5@live.de>
Fri, 8 Nov 2019 23:41:33 +0000 (00:41 +0100)
committersfan5 <sfan5@live.de>
Mon, 11 Nov 2019 13:06:48 +0000 (14:06 +0100)
Mods may want to to handle item interaction even if the item
is not marked usable (= server-side callback exists).

clientmods/preview/init.lua
src/client/game.cpp

index 96deae0749a79a01a2049748a94f615f74fca29f..dd856217f7eff9a82e5c7e93edc48904884033b2 100644 (file)
@@ -66,6 +66,10 @@ core.register_on_item_use(function(itemstack, pointed_thing)
        print("pointed_thing :" .. dump(pointed_thing))
        print("item = " .. itemstack:get_name())
 
+       if not itemstack:is_empty() then
+               return false
+       end
+
        local pos = vector.add(core.localplayer:get_pos(), core.camera:get_offset())
        local pos2 = vector.add(pos, vector.multiply(core.camera:get_look_dir(), 100))
 
index 450eb4e32d34c40658bf19d5133124f9b8d92fe3..59654e892ddf084b7e127163d2959d4f593afa32 100644 (file)
@@ -3061,6 +3061,9 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug)
        } else if (input->getLeftState()) {
                // When button is held down in air, show continuous animation
                runData.left_punch = true;
+               // Run callback even though item is not usable
+               if (input->getLeftClicked() && client->modsLoaded())
+                       client->getScript()->on_item_use(selected_item, pointed);
        } else if (input->getRightClicked()) {
                handlePointingAtNothing(selected_item);
        }