Skip to content

Commit

Permalink
Fix item insertion via proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Tubbles committed Oct 30, 2024
1 parent 8bf1a9c commit bd608c0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Version: 2.0.2
Date: TBD
Bugfixes:
- Fixed the collision, they should now correctly squeeze through belts, rail tracks, etc.
- Fixed a crash when ordering drones to insert items into entities
---------------------------------------------------------------------------------------------------
Version: 2.0.1
Date: 2024-10-28T14:19:53+01:00
Expand Down
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Updated_Construction_Drones",
"version": "2.0.1",
"version": "2.0.2",
"title": "Updated Construction Drones",
"author": "Tubbles",
"contact": "",
Expand Down
21 changes: 11 additions & 10 deletions script/construction_drone.lua
Original file line number Diff line number Diff line change
Expand Up @@ -671,12 +671,12 @@ local check_proxy = function(entity, player)
local items = entity.item_requests

local position = entity.position
for name, count in pairs(items) do
if player.get_item_count(name) > 0 or player.cheat_mode then
for _, item in pairs(items) do
if player.get_item_count(item.name) > 0 or player.cheat_mode then
local drone_data = {
player = player,
order = drone_orders.request_proxy,
pickup = { stack = { name = name, count = count } },
pickup = { stack = { name = item.name, count = item.count } },
target = entity,
}
make_path_request(drone_data, player, entity)
Expand Down Expand Up @@ -1757,8 +1757,10 @@ local process_request_proxy_command = function(drone_data)
local requests = target.item_requests

local stack
for name, count in pairs(requests) do
stack = find_item_stack(name)
local requests_index
for k, item in pairs(requests) do
stack = find_item_stack(item.name)
requests_index = k
if stack then
break
end
Expand Down Expand Up @@ -1794,15 +1796,14 @@ local process_request_proxy_command = function(drone_data)
return cancel_drone_order(drone_data)
end
drone_inventory.remove({ name = stack_name, count = inserted })
requests[stack_name] = requests[stack_name] - inserted
if requests[stack_name] <= 0 then
requests[stack_name] = nil
requests[requests_index].count = requests[requests_index].count - inserted
if requests[requests_index].count <= 0 then
requests[requests_index] = nil
end

-- If we fulfilled all the requests, we can safely destroy the proxy chest
if not next(requests) then
target.destroy()
else
target.item_requests = requests
end

local build_time = get_build_time(drone_data)
Expand Down

0 comments on commit bd608c0

Please sign in to comment.