mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 15:13:16 +00:00
Fixed item duplication. Again
This commit is contained in:
parent
6d5dd0a039
commit
3295b0eff0
3 changed files with 19 additions and 6 deletions
|
@ -208,9 +208,8 @@ function inventory_helper.set_item_data(item_data, player_data)
|
|||
return
|
||||
end
|
||||
|
||||
EntityRemoveTag(item, "ew_global_item")
|
||||
|
||||
if(itemInfo.is_wand)then
|
||||
EntityAddTag(item.entity_id, "ew_client_item")
|
||||
item:PickUp(player)
|
||||
local itemComp = EntityGetFirstComponentIncludingDisabled(item.entity_id, "ItemComponent")
|
||||
if (itemComp ~= nil) then
|
||||
|
@ -221,6 +220,7 @@ function inventory_helper.set_item_data(item_data, player_data)
|
|||
active_item_entity = item.entity_id
|
||||
end
|
||||
else
|
||||
EntityAddTag(item, "ew_client_item")
|
||||
pickup_item(player, item)
|
||||
local itemComp = EntityGetFirstComponentIncludingDisabled(item, "ItemComponent")
|
||||
if (itemComp ~= nil) then
|
||||
|
@ -268,7 +268,7 @@ function inventory_helper.has_inventory_changed(player_data)
|
|||
for _, item in ipairs(GameGetAllInventoryItems(player_data.entity)) do
|
||||
local item_comp = EntityGetFirstComponentIncludingDisabled(item, "ItemComponent")
|
||||
local slot_x, slot_y = ComponentGetValue2(item_comp, "inventory_slot")
|
||||
inventory_hash = (inventory_hash + (item % 1024 + slot_x + slot_y)) % (math.pow(2, 20) - 1)
|
||||
inventory_hash = (inventory_hash*19 + (item % 65000 + slot_x + slot_y)) % (math.pow(2, 20) - 1)
|
||||
end
|
||||
player_data.prev_inventory_hash = inventory_hash
|
||||
return inventory_hash ~= prev_inventory
|
||||
|
|
|
@ -88,6 +88,17 @@ local function get_global_ent(key)
|
|||
end
|
||||
end
|
||||
|
||||
local function remove_client_items_from_world()
|
||||
if GameGetFrameNum() % 5 ~= 3 then
|
||||
return
|
||||
end
|
||||
for _, item in ipairs(EntityGetWithTag("ew_client_item")) do
|
||||
if is_item_on_ground(item) then
|
||||
EntityKill(item)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function item_sync.host_upload_items(my_player)
|
||||
if GameGetFrameNum() % 5 == 4 then
|
||||
mark_in_inventory(my_player)
|
||||
|
@ -102,6 +113,7 @@ function item_sync.host_upload_items(my_player)
|
|||
local g_id = item_sync.get_global_item_id(picked_item)
|
||||
item_sync.host_localize_item(g_id, ctx.my_id)
|
||||
end
|
||||
remove_client_items_from_world()
|
||||
end
|
||||
|
||||
function item_sync.client_tick(my_player)
|
||||
|
@ -109,7 +121,7 @@ function item_sync.client_tick(my_player)
|
|||
mark_in_inventory(my_player)
|
||||
end
|
||||
local thrown_item = get_global_ent("ew_thrown")
|
||||
if thrown_item ~= nil then
|
||||
if thrown_item ~= nil and not EntityHasTag(thrown_item, "ew_client_item") then
|
||||
ctx.lib.net.send_item_upload(inventory_helper.serialize_single_item(thrown_item))
|
||||
EntityKill(thrown_item)
|
||||
end
|
||||
|
@ -119,6 +131,7 @@ function item_sync.client_tick(my_player)
|
|||
local gid = item_sync.get_global_item_id(picked_item)
|
||||
ctx.lib.net.send_localize_request(gid)
|
||||
end
|
||||
remove_client_items_from_world()
|
||||
end
|
||||
|
||||
function item_sync.upload(item_data)
|
||||
|
|
4
init.lua
4
init.lua
|
@ -232,11 +232,11 @@ local function on_world_pre_update_inner()
|
|||
net.send_host_player_info(player_info)
|
||||
end
|
||||
|
||||
if ctx.events.new_player_just_connected or ctx.events.inventory_maybe_just_changed or GameGetFrameNum() % 20 == 0 then
|
||||
if ctx.events.new_player_just_connected or ctx.events.inventory_maybe_just_changed or GameGetFrameNum() % 5 == 0 then
|
||||
if ctx.events.new_player_just_connected or inventory_helper.has_inventory_changed(my_player) then
|
||||
local inventory_state = player_fns.serialize_items(my_player)
|
||||
if inventory_state ~= nil then
|
||||
GamePrint("Sending updated inventory")
|
||||
-- GamePrint("Sending updated inventory")
|
||||
net.send_player_inventory(inventory_state)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue