Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Run on_item_use CSM callback even if item is not marked usable
Mods may want to to handle item interaction even if the item
is not marked usable (= server-side callback exists).
  • Loading branch information
sfan5 committed Nov 11, 2019
1 parent 682b9de commit 3f27156
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clientmods/preview/init.lua
Expand Up @@ -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))

Expand Down
3 changes: 3 additions & 0 deletions src/client/game.cpp
Expand Up @@ -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);
}
Expand Down

0 comments on commit 3f27156

Please sign in to comment.