fix: 개선된 인벤토리 판독 로직으로 안정성 향상

- 인벤토리 판독 시 `inv.get_contents()`를 우선 사용하여 일부 환경에서 발생할 수 있는 오류를 줄임
- 이전 방식인 인덱스 접근 방식은 호환성 문제를 해결하기 위한 폴백으로 유지
- README.md에 변경 사항 반영
This commit is contained in:
21in7
2026-03-25 21:56:26 +09:00
parent 37127f7f4f
commit e98d08bb44
5 changed files with 21 additions and 8 deletions

View File

@@ -169,10 +169,16 @@ local ok, err = pcall(function()
local inv = p.get_main_inventory()
if not inv then rcon.print("{}") return end
local inv_summary = {}
for i = 1, #inv do
local stack = inv[i]
if stack.valid_for_read then
inv_summary[stack.name] = (inv_summary[stack.name] or 0) + stack.count
if inv.get_contents then
-- Factorio 2.0: get_contents()가 있으면 가장 안정적으로 읽음
inv_summary = inv.get_contents()
else
-- 호환 폴백
for i = 1, #inv do
local stack = inv[i]
if stack.valid_for_read then
inv_summary[stack.name] = (inv_summary[stack.name] or 0) + stack.count
end
end
end
rcon.print(game.table_to_json({