1
0

Drop only 1 item if sneak is pressed

This commit is contained in:
Maksym H 2023-09-18 17:17:57 +03:00 committed by Maksym H.
parent 52228db808
commit 3d80a69b47

View File

@ -6,6 +6,7 @@ local abs, atan2, cos, floor, max, sin, random =
math.abs, math.atan2, math.cos, math.floor, math.max, math.sin, math.random math.abs, math.atan2, math.cos, math.floor, math.max, math.sin, math.random
local vadd, vnew, vmultiply, vnormalize, vsubtract = local vadd, vnew, vmultiply, vnormalize, vsubtract =
vector.add, vector.new, vector.multiply, vector.normalize, vector.subtract vector.add, vector.new, vector.multiply, vector.normalize, vector.subtract
local tcopy = table.copy
local creative_mode = core.settings:get_bool("creative_mode") local creative_mode = core.settings:get_bool("creative_mode")
local node_drop = core.settings:get_bool("node_drop") local node_drop = core.settings:get_bool("node_drop")
@ -529,14 +530,15 @@ end
function core.item_drop(itemstack, dropper, pos) function core.item_drop(itemstack, dropper, pos)
local dropper_is_player = dropper and dropper:is_player() local dropper_is_player = dropper and dropper:is_player()
local p = table.copy(pos) local p = tcopy(pos)
local cnt = itemstack:get_count()
if not core.is_valid_pos(p) then if not core.is_valid_pos(p) then
return return
end end
if dropper_is_player then if dropper_is_player then
p.y = p.y + 1.2 p.y = p.y + 1.2
end end
local sneak = dropper_is_player and dropper:get_player_control().sneak
local cnt = sneak and 1 or itemstack:get_count()
local item = itemstack:take_item(cnt) local item = itemstack:take_item(cnt)
local obj = core.add_item(p, item) local obj = core.add_item(p, item)
if obj then if obj then