mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
switch to inventory drop area
This commit is contained in:
parent
2a4b8b0297
commit
7c97966377
5 changed files with 75 additions and 41 deletions
|
|
@ -1,46 +1,10 @@
|
|||
local base_util = require "util"
|
||||
|
||||
local DROP_FORCE = 8
|
||||
local DROP_INIT_VEL = {0, 3, 0}
|
||||
|
||||
---@param mode integer 0 - whole stack, 1 - single item, 2 - dupe whole stack
|
||||
function drop_from_slot(invid, slot, mode)
|
||||
local pid = hud.get_player()
|
||||
if mode == 2 and !player.is_infinite_items(pid) then
|
||||
return
|
||||
end
|
||||
local itemid, itemcount = inventory.get(invid, slot)
|
||||
if itemid == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local drop_itemcount = 1
|
||||
if mode == 0 then
|
||||
drop_itemcount = itemcount
|
||||
end
|
||||
if mode == 2 then
|
||||
drop_itemcount = item.stack_size(itemid)
|
||||
else
|
||||
inventory.set(invid, slot, itemid, itemcount - drop_itemcount)
|
||||
end
|
||||
|
||||
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 drop = base_util.drop(ppos, itemid, drop_itemcount, data, 1.5)
|
||||
if not drop then
|
||||
return
|
||||
end
|
||||
local velocity = vec3.add(throw_force, vec3.add(pvel, DROP_INIT_VEL))
|
||||
drop.rigidbody:set_vel(velocity)
|
||||
end
|
||||
|
||||
function on_inventory_clicked_outside(exc_invid, exc_slot, mode)
|
||||
drop_from_slot(exc_invid, exc_slot, mode)
|
||||
end
|
||||
|
||||
function on_hud_open()
|
||||
events.on("core:drop_outside_inventory", function(mode)
|
||||
local invid = hud.get_exchange_inventory()
|
||||
base_util.drop_from_slot(invid, 0, mode)
|
||||
end)
|
||||
input.add_callback("player.drop", function()
|
||||
if hud.is_paused() or hud.is_inventory_open() then
|
||||
return
|
||||
|
|
@ -51,7 +15,7 @@ function on_hud_open()
|
|||
if input.is_pressed("key:left-ctrl") or input.is_pressed("key:right-ctrl") then
|
||||
mode = 0
|
||||
end
|
||||
drop_from_slot(invid, slot, mode)
|
||||
base_util.drop_from_slot(invid, slot, mode)
|
||||
end)
|
||||
rules.create("do-loot-non-player", true)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue