Merge pull request #935 from Neveix/feat-inventory-enhancements-p8

Inventory enhancements #897: 8
This commit is contained in:
MihailRis 2026-08-17 20:47:30 +03:00 • committed by GitHub
commit 399bb5394a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,6 +2,30 @@ local util = {}
local DROP_FORCE = 8
local DROP_INIT_VEL = {0, 3, 0}
local DROP_MAX_ITEM_DIR_SHIFT_DEGREES = 65
local function calculate_item_drop_dir(pid)
local yaw, pitch = player.get_rot(pid)
local vp = gui.get_viewport()
local mpos = table.map(input.get_mouse_pos(), function(i, v)
return v / vp[i] - 0.5
end)
if not hud.is_inventory_open() and not hud.is_player_inventory_open() then
mpos = {0, 0}
end
local q_yaw = quat.from_euler({0, yaw, 0})
local q_pitch = quat.from_euler({pitch, 0, 0})
local q_rotation = quat.mul(q_yaw, q_pitch)
local q_shift = quat.from_euler({
-mpos[2]*DROP_MAX_ITEM_DIR_SHIFT_DEGREES*2,
-mpos[1]*DROP_MAX_ITEM_DIR_SHIFT_DEGREES*2,
0,
})
quat.mul(q_rotation, q_shift, q_rotation)
return quat.mul_vec3(q_rotation, {0, 0, -1})
end
---@param mode integer 0 - whole stack, 1 - single item, 2 - dupe whole stack
function util.drop_from_slot(invid, slot, mode)
@ -30,7 +54,8 @@ function util.drop_from_slot(invid, slot, mode)
local data = inventory.get_all_data(invid, slot)
local pvel = { player.get_vel(pid) }
local ppos = vec3.add({ player.get_pos(pid) }, { 0, 0.7, 0 })
local throw_force = vec3.mul(player.get_dir(pid), DROP_FORCE)
local dir = calculate_item_drop_dir(pid)
local throw_force = vec3.mul(dir, DROP_FORCE)
local drop = util.drop(ppos, itemid, drop_itemcount, data, 1.5)
if not drop then
return