Fix individual decor inventory identity (#128)

This commit is contained in:
Alexander Sellite 2026-09-02 09:51:33 -04:00
parent cab313d69d
commit 5aa723de54
6 changed files with 276 additions and 113 deletions

View file

@ -128,10 +128,21 @@ func place_local_decor(
not can_local_decorate()
or has_pending_local_decor_mutation()
or _bag == null
or _inventory_layout == null
or _hotbar == null
or _bag.get_quantity(decor_id) <= 0
or _world_service == null
):
return ""
var selected_entry_key: String = _hotbar.get_selected_item_entry_key()
var selected_entry: Dictionary = _inventory_layout.get_entry_by_key(
selected_entry_key
)
if (
selected_entry.is_empty()
or StringName(str(selected_entry.get("identity", ""))) != decor_id
):
return ""
var owner_fingerprint: String = (
_session.get_local_identity_fingerprint()
)
@ -162,7 +173,9 @@ func place_local_decor(
if instance_id.is_empty():
_suppress_local_submission = false
return ""
if not _bag.remove_item(decor_id, 1):
if not _inventory_layout.consume_individual_item_entry(
selected_entry_key
):
_local_home.remove_placement(instance_id)
_suppress_local_submission = false
return ""
@ -188,17 +201,9 @@ func remove_local_decor(instance_id: String) -> bool:
if transaction.is_empty():
return false
var decor_id := StringName(str(placement["decor_id"]))
var target_hotbar_slot: int = _hotbar.find_item_slot(decor_id)
if target_hotbar_slot < 0:
target_hotbar_slot = _hotbar.find_first_empty_slot()
var target_hotbar_slot: int = _hotbar.find_first_empty_slot()
var prepared_hotbar_placement: bool = false
if (
target_hotbar_slot >= 0
and _inventory_layout.get_container(
PlayerInventoryLayout.EntryKind.ITEM,
decor_id,
) < 0
):
if target_hotbar_slot >= 0:
prepared_hotbar_placement = (
_inventory_layout.prepare_new_item_placement(
decor_id,
@ -215,8 +220,7 @@ func remove_local_decor(instance_id: String) -> bool:
if prepared_hotbar_placement:
_inventory_layout.cancel_prepared_item_placement(decor_id)
return false
if target_hotbar_slot >= 0:
_hotbar.assign_item(target_hotbar_slot, decor_id)
if prepared_hotbar_placement:
_hotbar.select_slot(target_hotbar_slot)
_suppress_local_submission = true
if not _local_home.remove_placement(instance_id):
@ -980,15 +984,16 @@ func _restore_decor_item_to_bag(
if _bag == null:
return false
var prepared_slot: int = -1
if (
_inventory_layout != null
and _hotbar != null
and _inventory_layout.get_container(
PlayerInventoryLayout.EntryKind.ITEM, decor_id
) < 0
):
if _inventory_layout != null and _hotbar != null:
var candidate_slot: int = preferred_hotbar_slot
if candidate_slot < 0:
if (
candidate_slot < 0
or candidate_slot >= PlayerHotbar.SLOT_COUNT
or not _inventory_layout.get_key_at(
PlayerInventoryLayout.InventoryContainer.HOTBAR,
candidate_slot,
).is_empty()
):
candidate_slot = _hotbar.find_first_empty_slot()
if candidate_slot >= 0 and _inventory_layout.prepare_new_item_placement(
decor_id,
@ -1000,10 +1005,8 @@ func _restore_decor_item_to_bag(
if not restored:
if prepared_slot >= 0:
_inventory_layout.cancel_prepared_item_placement(decor_id)
if _bag.get_owned_item(decor_id) == null:
restored = _bag.add_item_to_storage(decor_id, 1)
restored = _bag.add_item_to_storage(decor_id, 1)
if restored and prepared_slot >= 0:
_hotbar.assign_item(prepared_slot, decor_id)
_hotbar.select_slot(prepared_slot)
return restored