Transfer authority over requested-to-be-spawned items to whoever requested them.

This commit is contained in:
IQuant 2024-09-16 15:23:58 +03:00
parent faff4c67a7
commit 6f6abd6550
3 changed files with 6 additions and 4 deletions

View file

@ -42,7 +42,7 @@ local function run_spawn_fn(fn_name, x, y, ...)
-- Function returns item's entity id.
if fn_info.kind == "item" then
local eid = ret
ctx.cap.item_sync.globalize(eid, true)
ctx.cap.item_sync.globalize(eid, true, ctx.rpc_peer_id)
end
end

View file

@ -110,7 +110,7 @@ function item_sync.host_localize_item(gid, peer_id)
rpc.item_localize(peer_id, gid)
end
function item_sync.make_item_global(item, instant)
function item_sync.make_item_global(item, instant, give_authority_to)
EntityAddTag(item, "ew_global_item")
async(function()
if not instant then
@ -126,6 +126,9 @@ function item_sync.make_item_global(item, instant)
local gid
if gid_component == nil then
gid = allocate_global_id()
if give_authority_to ~= nil then
gid = give_authority_to..":"..gid
end
EntityAddComponent2(item, "VariableStorageComponent", {
_tags = "enabled_in_world,enabled_in_hand,enabled_in_inventory,ew_global_item_id",
value_string = gid,
@ -317,7 +320,6 @@ end
rpc.opts_reliable()
function rpc.item_globalize(item_data)
if is_safe_to_remove() then
print("remove in globalize")
item_sync.remove_item_with_id_now(item_data.gid)
end
local item = inventory_helper.deserialize_single_item(item_data)