mirror of
https://github.com/minetest-mods/drawers.git
synced 2024-11-25 16:13:45 +01:00
Insert all from inv on rightclick with bare hand
This commit is contained in:
parent
14f21a434e
commit
e36c8721b1
@ -157,15 +157,55 @@ core.register_entity("drawers:visual", {
|
||||
core.record_protection_violation(self.drawer_pos, clicker:get_player_name())
|
||||
return
|
||||
end
|
||||
local leftover = self.try_insert_stack(self, clicker:get_wielded_item(),
|
||||
not clicker:get_player_control().sneak)
|
||||
|
||||
-- if smth. was added play the interact sound
|
||||
-- used to check if we need to play a sound in the end
|
||||
local inventoryChanged = false
|
||||
|
||||
-- When the player uses the drawer with their bare hand all
|
||||
-- stacks from the inventory will be added to the drawer.
|
||||
if self.itemName ~= "" and
|
||||
clicker:get_wielded_item():get_name() == "" and
|
||||
not clicker:get_player_control().sneak then
|
||||
-- try to insert all items from inventory
|
||||
local i = 0
|
||||
local inv = clicker:get_inventory()
|
||||
|
||||
while i < inv:get_size("main") do
|
||||
-- set current stack to leftover of insertion
|
||||
local leftover = self.try_insert_stack(
|
||||
self,
|
||||
inv:get_stack("main", i),
|
||||
true
|
||||
)
|
||||
|
||||
-- check if something was added
|
||||
if leftover:get_count() < inv:get_stack("main", i):get_count() then
|
||||
inventoryChanged = true
|
||||
end
|
||||
|
||||
-- set new stack
|
||||
inv:set_stack("main", i, leftover)
|
||||
i = i + 1
|
||||
end
|
||||
else
|
||||
-- try to insert wielded item only
|
||||
local leftover = self.try_insert_stack(
|
||||
self,
|
||||
clicker:get_wielded_item(),
|
||||
not clicker:get_player_control().sneak
|
||||
)
|
||||
|
||||
-- check if something was added
|
||||
if clicker:get_wielded_item():get_count() > leftover:get_count() then
|
||||
self:play_interact_sound()
|
||||
inventoryChanged = true
|
||||
end
|
||||
-- set the leftover as new wielded item for the player
|
||||
clicker:set_wielded_item(leftover)
|
||||
end
|
||||
|
||||
if inventoryChanged then
|
||||
self:play_interact_sound()
|
||||
end
|
||||
end,
|
||||
|
||||
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
|
||||
|
Loading…
Reference in New Issue
Block a user