Skip to content

Commit 3f27156

Browse files
committedNov 11, 2019
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).
1 parent 682b9de commit 3f27156

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed
 

Diff for: ‎clientmods/preview/init.lua

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ core.register_on_item_use(function(itemstack, pointed_thing)
6666
print("pointed_thing :" .. dump(pointed_thing))
6767
print("item = " .. itemstack:get_name())
6868

69+
if not itemstack:is_empty() then
70+
return false
71+
end
72+
6973
local pos = vector.add(core.localplayer:get_pos(), core.camera:get_offset())
7074
local pos2 = vector.add(pos, vector.multiply(core.camera:get_look_dir(), 100))
7175

Diff for: ‎src/client/game.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -3061,6 +3061,9 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug)
30613061
} else if (input->getLeftState()) {
30623062
// When button is held down in air, show continuous animation
30633063
runData.left_punch = true;
3064+
// Run callback even though item is not usable
3065+
if (input->getLeftClicked() && client->modsLoaded())
3066+
client->getScript()->on_item_use(selected_item, pointed);
30643067
} else if (input->getRightClicked()) {
30653068
handlePointingAtNothing(selected_item);
30663069
}

0 commit comments

Comments
 (0)
Please sign in to comment.