Skip to content

Commit f6cfe62

Browse files
committed
Add entity and surface valid checks everywhere
Update license copy right year
1 parent b7abbc1 commit f6cfe62

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 Jan Mischak
3+
Copyright (c) 2020-2022 Jan Mischak
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

changelog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
---------------------------------------------------------------------------------------------------
2+
Version: 1.1.1
3+
Date: 2022-09-12
4+
Bugfixes:
5+
- Fix error when pasting to entities with item request proxies while using Copy Paste Modules
6+
---------------------------------------------------------------------------------------------------
27
Version: 1.1.0
38
Date: 2020-11-24
49
Info:

control.lua

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,23 @@ script.on_event(defines.events.on_player_selected_area, function (event)
1111
if event.item == "AreaPaste-paste-planner" then
1212
local player_index = event.player_index
1313
local player = game.get_player(player_index)
14+
---@cast player -nil
1415
local copy_source = try_get_copy_source(player)
1516
if copy_source then
1617
local copy_source_name = copy_source.name
1718
local player_position = player.position
1819
local force = player.force
1920
local player_insert = player.insert
20-
local spill_item_stack = player.surface.spill_item_stack
21+
local surface = player.surface
22+
local spill_item_stack = surface.spill_item_stack
2123
local simple_item_stack = {}
2224
for _, entity in pairs(event.entities) do
23-
if entity.name == copy_source_name then
25+
if entity.valid and entity.name == copy_source_name then
26+
local entity_position = entity.position
27+
-- `copy_settings` raises an event, so every LuaObject could be invalidated by this call
2428
local returned_items = entity.copy_settings(copy_source, player)
25-
if next(returned_items) then
26-
if player.can_reach_entity(entity) then
29+
if next(returned_items) and surface.valid then
30+
if entity.valid and player.can_reach_entity(entity) then
2731
for name, count in pairs(returned_items) do
2832
simple_item_stack.name = name
2933
simple_item_stack.count = count
@@ -34,7 +38,6 @@ script.on_event(defines.events.on_player_selected_area, function (event)
3438
end
3539
end
3640
else
37-
local entity_position = entity.position
3841
for name, count in pairs(returned_items) do
3942
simple_item_stack.name = name
4043
simple_item_stack.count = count
@@ -43,6 +46,9 @@ script.on_event(defines.events.on_player_selected_area, function (event)
4346
end
4447
end
4548
end
49+
if not copy_source.valid then
50+
break
51+
end
4652
end
4753
end
4854
end

info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "AreaPaste",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"factorio_version": "1.1",
55
"title": "Area Paste",
66
"author": "JanSharp",

0 commit comments

Comments
 (0)