mirror of
https://github.com/minetest-mods/hopper.git
synced 2025-01-03 02:57:29 +01:00
use fake players for offline players like in Pipeworks
This commit is contained in:
parent
74c8cf887f
commit
3f5deef63a
20
utility.lua
20
utility.lua
@ -54,6 +54,22 @@ end
|
||||
-------------------------------------------------------------------------------------------
|
||||
-- Inventory transfer functions
|
||||
|
||||
local delay = function(x)
|
||||
return (function() return x end)
|
||||
end
|
||||
|
||||
local get_placer = function(player_name)
|
||||
if player_name ~= "" then
|
||||
return minetest.get_player_by_name(player_name) or {
|
||||
is_player = delay(true),
|
||||
get_player_name = delay(player_name),
|
||||
is_fake_player = ":hopper",
|
||||
get_wielded_item = delay(ItemStack(nil))
|
||||
}
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Used to remove items from the target block and put it into the hopper's inventory
|
||||
hopper.take_item_from = function(hopper_pos, target_pos, target_node, target_inventory_name)
|
||||
if target_inventory_name == nil then
|
||||
@ -63,7 +79,7 @@ hopper.take_item_from = function(hopper_pos, target_pos, target_node, target_inv
|
||||
--hopper inventory
|
||||
local hopper_meta = minetest.get_meta(hopper_pos);
|
||||
local hopper_inv = hopper_meta:get_inventory()
|
||||
local placer = minetest.get_player_by_name(hopper_meta:get_string("placer"))
|
||||
local placer = get_placer(hopper_meta:get_string("placer"))
|
||||
|
||||
--source inventory
|
||||
local target_inv = minetest.get_meta(target_pos):get_inventory()
|
||||
@ -110,7 +126,7 @@ hopper.send_item_to = function(hopper_pos, target_pos, target_node, target_inven
|
||||
return false
|
||||
end
|
||||
local hopper_inv_size = hopper_inv:get_size("main")
|
||||
local placer = minetest.get_player_by_name(hopper_meta:get_string("placer"))
|
||||
local placer = get_placer(hopper_meta:get_string("placer"))
|
||||
|
||||
--target inventory
|
||||
local target_inv = minetest.get_meta(target_pos):get_inventory()
|
||||
|
Loading…
Reference in New Issue
Block a user