diff --git a/README.md b/README.md index 3cf20c2..9359850 100644 --- a/README.md +++ b/README.md @@ -118,3 +118,4 @@ planner.set_goal( - 또한 채굴 시작(`mining_state`) 좌표는 정수 타일이 아니라, Lua가 찾은 실제 자원 엔티티의 `e.position`(정확 실수 좌표)을 사용해 “플레이어가 타일 위에 있는데도 즉시 채굴 감지 실패”를 줄입니다. - `mine_resource`는 move 후 `p.position` 근처(반경 1.2)에서 실제로 해당 광물 엔티티가 있는지 재확인하고, 없으면 채굴을 시도하지 않고 다음 후보로 넘어갑니다. - `explore`는 `wanted_ores`가 있으면 해당 자원이 발견될 때까지 멈추지 않고 계속 이동해, `iron-ore`처럼 주변에 흔한 자원만 계속 발견되어 진행이 막히는 문제를 줄입니다. +- 인벤토리 판독은 `inv.get_contents()`를 우선 사용해, 일부 환경에서 `#inv` / 인덱스 접근이 비어있음으로 오인되는 문제를 줄입니다. diff --git a/__pycache__/context_compressor.cpython-311.pyc b/__pycache__/context_compressor.cpython-311.pyc index cd7cd46..4c40427 100644 Binary files a/__pycache__/context_compressor.cpython-311.pyc and b/__pycache__/context_compressor.cpython-311.pyc differ diff --git a/__pycache__/state_reader.cpython-311.pyc b/__pycache__/state_reader.cpython-311.pyc index ff188ba..ad8384d 100644 Binary files a/__pycache__/state_reader.cpython-311.pyc and b/__pycache__/state_reader.cpython-311.pyc differ diff --git a/context_compressor.py b/context_compressor.py index 7996440..b5a2518 100644 --- a/context_compressor.py +++ b/context_compressor.py @@ -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({ diff --git a/state_reader.py b/state_reader.py index 9b59f77..ca455a8 100644 --- a/state_reader.py +++ b/state_reader.py @@ -43,10 +43,16 @@ local ok, err = pcall(function() local inv = p.get_main_inventory() if not inv then rcon.print("{}") return end local result = {} - for i = 1, #inv do - local stack = inv[i] - if stack.valid_for_read then - result[stack.name] = (result[stack.name] or 0) + stack.count + if inv.get_contents then + -- Factorio 2.0: get_contents()가 있으면 가장 안정적으로 읽을 수 있음 + result = inv.get_contents() + else + -- 호환용 폴백 (일부 버전에서 #inv / 인덱스 접근이 불안정할 수 있음) + for i = 1, #inv do + local stack = inv[i] + if stack.valid_for_read then + result[stack.name] = (result[stack.name] or 0) + stack.count + end end end rcon.print(game.table_to_json(result))