move 'player.pick' binding handler to Lua

This commit is contained in:
MihailRis
2024-12-23 12:37:26 +03:00
parent 22d207ba28
commit 9164edf971
6 changed files with 34 additions and 31 deletions
+26
View File
@@ -23,4 +23,30 @@ function on_hud_open()
local velocity = vec3.add(throw_force, vec3.add(pvel, DROP_INIT_VEL))
drop.rigidbody:set_vel(velocity)
end)
input.add_callback("player.pick", function ()
if hud.is_paused() or hud.is_inventory_open() then
return
end
local pid = hud.get_player()
local x, y, z = player.get_selected_block(pid)
if x == nil then
return
end
local id = block.get_picking_item(block.get(x, y, z))
local inv, cur_slot = player.get_inventory(pid)
local slot = inventory.find_by_item(inv, id, 0, 9)
if slot then
player.set_selected_slot(pid, slot)
return
end
if not rules.get("allow-content-access") then
return
end
slot = inventory.find_by_item(inv, 0, 0, 9)
if slot then
cur_slot = slot
end
player.set_selected_slot(pid, cur_slot)
inventory.set(inv, cur_slot, id, 1)
end)
end
-1
View File
@@ -320,7 +320,6 @@ function __vc_on_hud_open()
_rules.create("allow-content-access", hud._is_content_access(), function(value)
hud._set_content_access(value)
input.set_enabled("player.pick", value)
end)
_rules.create("allow-flight", true, function(value)
input.set_enabled("player.flight", value)