@@ -2440,7 +2441,7 @@ nb: use error(error_message) within your callback to trigger do not trigger dire
generated by LDoc
diff --git a/docs/core/Common.html b/docs/core/Common.html
index fed24023..9658dbfc 100644
--- a/docs/core/Common.html
+++ b/docs/core/Common.html
@@ -95,6 +95,7 @@
@@ -3403,7 +3404,7 @@ nb: this is one way, failing false after already gaining the role will not revok
generated by LDoc
diff --git a/docs/data/Alt-View.html b/docs/data/Alt-View.html
index 8bf070fd..f374bb9b 100644
--- a/docs/data/Alt-View.html
+++ b/docs/data/Alt-View.html
@@ -104,6 +104,7 @@
Explosive Gaming (often ExpGaming) is a server hosting community with a strong focus on Factorio and games that follow similar ideas. Our Factorio server are known for hosting large maps with the main goal of being a "mega base" which can produce as much as possible within our reset schedule. Although these servers tend to attract the more experienced players, our servers are open to everyone. You can find us through our [website], [discord], [wiki], or in the public games tab in Factorio (ExpGaming S1, ExpGaming S2, etc.).
+
Explosive Gaming (often ExpGaming) is a server hosting community with a strong focus on [Factorio](factorio) and games with similar themes. We are best known for our weekly reset Factorio server with a vanilla+ scenario. Although our servers tend to attract the more experienced players, our servers are open to everyone. You can find us through our [website], [discord], or the public server list with the name ExpGaming.
## Use and Installation
-
1) Download this [git repository](https://github.com/explosivegaming/scenario/archive/master.zip) for the stable release. The dev branch can be found [here](https://github.com/explosivegaming/scenario/archive/dev.zip) for those who want the latest features. See [releases](#releases) for other release branches.
-
2) Extract the downloaded zip file from the branch you downloaded into Factorio's scenario directory:
+
1) Download our [git repository](stable-dl) for the stable release. For the latest features you can download our [dev branch](experimental-dl). See [releases](#releases) for other major releases.
+
2) Extract the downloaded zip file into your Factorio scenario directory:
* Windows: `%appdata%\Factorio\scenarios`
* Linux: `~/.factorio/scenarios`
-
3) Within the scenario you can find `./config/_file_loader.lua` which contains a list of all the modules that will be loaded by the scenario; simply comment out (or remove) features you do not want but note that some modules may load other modules as dependencies even when removed from the list.
-
4) More advanced users may want to play with the other configs files within `./config` but please be aware that some of the config files will require a basic understanding of lua while others may just be a list of values.
-
5) Once you have made any config changes that you wish to make open Factorio, select play, then start scenario (or host scenario from within multiplayer tab), and select the scenario which will be called `scenario-master` if you have downloaded the latest stable release and have not changed the folder name.
-
6) The scenario will now load all the selected modules and start the map, any errors or exceptions raised in the scenario should not cause a game/server crash, so if any features do not work as expected then it may be returning an error in the log.
-Please report these errors to [the issues page](issues).
+
3) Within the scenario you can find `./config/_file_loader.lua` which contains a list of all the modules which will be loaded by the scenario. Comment out (or remove) features you do not want. Be aware modules may load other modules as dependencies even when removed from the list.
+
4) More advanced users can adjust other configs files within `./config` but please be aware some files will require a basic understanding of lua.
+
5) Once you have made your config changes: open Factorio, select either single or multiplayer, select (host) new game, and finally select our scenario which will be called `scenario-master` or `scenario-dev` under user scenarios.
+
6) You will now be asked to generate your map and the scenario will load all selected modules. If any module does not load as expected please check `factorio-current.log` in your Factorio directory for errors and report them to our [issues page](issues).
## Contributing
-
All are welcome to make pull requests and issues for this scenario, if you are in any doubt, please ask someone in our [discord]. If you do not know lua and don't feel like learning you can always make a [feature request]. To find out what we already have please read our [docs]. Please keep in mind while making code changes:
-
* New features should have the branch names: `feature/feature-name`
-* New features are merged into `dev` after it has been completed, this can be done through a pull request.
-* After a number of features have been added a release branch is made: `release/X.Y.0`
-* Bug fixes and localization can be made to the release branch with a pull request rather than into dev.
-* A release is merged into `master` on the following friday after it is considered stable.
-* Patches may be named `patch/X.Y.Z` and will be merged into `dev` and then `master` when appropriate.
+
All are welcome to make bug reports, feature requests, and pull requests for our scenario. We do not require you to have any lua or coding knowledge to make bug reports and feature requests. If you have any questions ask us in our [discord].
+
For developers wanting to add features please follow these guidelines:
+
* All code is documented using ldoc, the end result can be found [here](docs).
+* Changes should be made on your own fork and merged into `dev` through a pull request.
+* Pull requests are automatically linted and documentation checked.
+* Pull requests are manually reviewed to maintain code and language quality.
+* New features should have the branch names: `feature/feature-name`
+* Bug fixes should have the branch names: `fix/bug-name`
## Releases
-
| Scenario Version* | Version Name | Factorio Version** |
+
| Release* | Release Name | Factorio Version** |
|---|---|---|
-| [v6.1][s6.1] | External Data Overhaul | [v1.0.0][f1.0.0] |
-| [v6.0][s6.0] | Gui / 0.18 Overhaul | [v0.18.17][f0.18.17] |
-| [v5.10][s5.10] | Data Store Rewrite | [v0.17.71][f0.17.71] |
-| [v5.9][s5.9] | Control Modules and Documentation | [v0.17.63][f0.17.63] |
-| [v5.8][s5.8] | Home and Chat Bot | [v0.17.47][f0.17.49] |
-| [v5.7][s5.7] | Warp System | [v0.17.47][f0.17.47] |
-| [v5.6][s5.6] | Information Guis | [v0.17.44][f0.17.44] |
-| [v5.5][s5.5] | Gui System | [v0.17.43][f0.17.43] |
-| [v5.4][s5.4] | Admin Controls | [v0.17.32][f0.17.32] |
-| [v5.3][s5.3] | Custom Roles | [v0.17.28][f0.17.28] |
-| [v5.2][s5.2] | Quality of life | [v0.17.22][f0.17.22] |
-| [v5.1][s5.1] | Permission Groups | [v0.17.13][f0.17.13] |
-| [v5.0][s5.0] | 0.17 Overhaul| [v0.17][f0.17.9] |
-| [v4.0][s4.0] | Softmod Manager | [v0.16.51][f0.16.51] |
-| [v3.0][s3.0] | 0.16 Overhaul | [v0.16][f0.16] |
-| [v2.0][s2.0] | Localization and clean up | [v0.15][f0.15] |
-| [v1.0][s1.0] | Modulation | [v0.15][f0.15] |
-| [v0.1][s0.1] | First Tracked Version | [v0.14][f0.14] |
-
\* Scenario patch versions have been omitted.
-
\*\* Factorio versions show the version they were made for, often the minimum requirement.
-
[s6.1]: https://github.com/explosivegaming/scenario/releases/tag/6.1.0
+| [6.2][s6.2] | Mega Feature Bundle | [1.1.32][f1.1.32] |
+| [6.1][s6.1] | External Data Overhaul | [1.0.0][f1.0.0] |
+| [6.0][s6.0] | Gui / 0.18 Overhaul | [0.18.17][f0.18.17] |
+| [5.10][s5.10] | Data Store Rewrite | [0.17.71][f0.17.71] |
+| [5.9][s5.9] | Control Modules and Documentation | [0.17.63][f0.17.63] |
+| [5.8][s5.8] | Home and Chat Bot | [0.17.47][f0.17.49] |
+| [5.7][s5.7] | Warp System | [0.17.47][f0.17.47] |
+| [5.6][s5.6] | Information Guis | [0.17.44][f0.17.44] |
+| [5.5][s5.5] | Gui System | [0.17.43][f0.17.43] |
+| [5.4][s5.4] | Admin Controls | [0.17.32][f0.17.32] |
+| [5.3][s5.3] | Custom Roles | [0.17.28][f0.17.28] |
+| [5.2][s5.2] | Quality of life | [0.17.22][f0.17.22] |
+| [5.1][s5.1] | Permission Groups | [0.17.13][f0.17.13] |
+| [5.0][s5.0] | 0.17 Overhaul| [0.17][f0.17.9] |
+| [4.0][s4.0] | Softmod Manager | [0.16.51][f0.16.51] |
+| [3.0][s3.0] | 0.16 Overhaul | [0.16][f0.16] |
+| [2.0][s2.0] | Localization and clean up | [0.15][f0.15] |
+| [1.0][s1.0] | Modulation | [0.15][f0.15] |
+| [0.1][s0.1] | First Tracked Version | [0.14][f0.14] |
+
\* Scenario patch releases have been omitted and can be found [here](https://github.com/explosivegaming/scenario/releases).
+
\*\* Factorio versions show the version they were made for, often the minimum requirement to run the scenario.
+
From fd0d07d657c239f91f4b1591802d6ab979d947dd Mon Sep 17 00:00:00 2001
From: oof2win2
Date: Sat, 14 May 2022 11:13:43 +0200
Subject: [PATCH 2/7] fix(death): movement of items to chests Items would be
only copied and destroyed rather than transferred This would cause issues
with power armor, spidertrons etc.
---
expcore/common.lua | 58 +++++++++++++++++++++++++++++++++
modules/addons/death-logger.lua | 6 ++--
2 files changed, 61 insertions(+), 3 deletions(-)
diff --git a/expcore/common.lua b/expcore/common.lua
index 64886316..95011cb6 100644
--- a/expcore/common.lua
+++ b/expcore/common.lua
@@ -595,6 +595,64 @@ function Common.move_items(items, surface, position, radius, chest_type)
return last_chest
end
+--[[-- Moves items to the position and stores them in the closest entity of the type given
+@tparam table items items which are to be added to the chests, an array of LuaItemStack
+@tparam[opt=navies] LuaSurface surface the surface that the items will be moved to
+@tparam[opt={0, 0}] table position the position that the items will be moved to {x=100, y=100}
+@tparam[opt=32] number radius the radius in which the items are allowed to be placed
+@tparam[opt=iron-chest] string chest_type the chest type that the items should be moved into
+@treturn LuaEntity the last chest that had items inserted into it
+
+@usage-- Copy all the items in a players inventory and place them in chests at {0, 0}
+move_items(game.player.get_main_inventory())
+
+]]
+function Common.move_items_stack(items, surface, position, radius, chest_type)
+ chest_type = chest_type or 'iron-chest'
+ surface = surface or game.surfaces[1]
+ if position and type(position) ~= 'table' then return end
+ if type(items) ~= 'table' then return end
+ -- Finds all entities of the given type
+ local p = position or {x=0, y=0}
+ local r = radius or 32
+ local entities = surface.find_entities_filtered{area={{p.x-r, p.y-r}, {p.x+r, p.y+r}}, name=chest_type} or {}
+ local count = #entities
+ local current = 1
+ -- Makes a new empty chest when it is needed
+ local function make_new_chest()
+ local pos = surface.find_non_colliding_position(chest_type, position, 32, 1)
+ local chest = surface.create_entity{name=chest_type, position=pos, force='neutral'}
+ table.insert(entities, chest)
+ count = count + 1
+ return chest
+ end
+ -- Function used to round robin the items into all chests
+ local function next_chest(item)
+ local chest = entities[current]
+ if count == 0 then return make_new_chest() end
+ if chest.get_inventory(defines.inventory.chest).can_insert(item) then
+ -- If the item can be inserted then the chest is returned
+ current = current+1
+ if current > count then current = 1 end
+ return chest
+ else
+ -- Other wise it is removed from the list
+ table.remove(entities, current)
+ count = count - 1
+ end
+ end
+ -- Inserts the items into the chests
+ local last_chest
+ for i=1,#items do
+ local item = items[i]
+ local chest = next_chest(item)
+ if not chest or not chest.valid then return error(string.format('Cant move item %s to %s{%s, %s} no valid chest in radius', item_name, surface.name, p.x, p.y)) end
+ chest.insert(item)
+ last_chest = chest
+ end
+ return last_chest
+end
+
--[[-- Prints a colored value on a location, color is based on the value.
nb: src is below but the gradent has been edited
https://github.com/Refactorio/RedMew/blob/9184b2940f311d8c9c891e83429fc57ec7e0c4a2/map_gen/maps/diggy/debug.lua#L31
diff --git a/modules/addons/death-logger.lua b/modules/addons/death-logger.lua
index 97c057fe..092bcd4a 100644
--- a/modules/addons/death-logger.lua
+++ b/modules/addons/death-logger.lua
@@ -4,7 +4,7 @@
local Event = require 'utils.event' --- @dep utils.event
local Global = require 'utils.global' --- @dep utils.global
local config = require 'config.death_logger' --- @dep config.death_logger
-local format_time, move_items = _C.format_time, _C.move_items --- @dep expcore.common
+local format_time, move_items = _C.format_time, _C.move_items_stack --- @dep expcore.common
-- Max amount of ticks a corpse can be alive
local corpse_lifetime = 60*60*15
@@ -64,7 +64,7 @@ Event.add(defines.events.on_player_died, function(event)
local player = game.players[event.player_index]
local corpse = player.surface.find_entity('character-corpse', player.position)
if config.use_chests_as_bodies then
- local items = corpse.get_inventory(defines.inventory.character_corpse).get_contents()
+ local items = corpse.get_inventory(defines.inventory.character_corpse)
local chest = move_items(items, corpse.surface, corpse.position)
chest.destructible = false
corpse.destroy()
@@ -140,7 +140,7 @@ end
if config.auto_collect_bodies then
Event.add(defines.events.on_character_corpse_expired, function(event)
local corpse = event.corpse
- local items = corpse.get_inventory(defines.inventory.character_corpse).get_contents()
+ local items = corpse.get_inventory(defines.inventory.character_corpse)
move_items(items, corpse.surface, {x=0, y=0})
end)
end
From dc9f3b1198199d187391768bb5d70ef1939470c3 Mon Sep 17 00:00:00 2001
From: oof2win2
Date: Sat, 14 May 2022 15:38:03 +0200
Subject: [PATCH 3/7] fix: LuaItemStack could be invalid Fixed an issue with
clearing inventories of players where the command failed due to it attempting
to access LuaItemStacks that were invalid for read
---
expcore/common.lua | 10 ++++++----
modules/addons/inventory-clear.lua | 6 +++---
modules/commands/clear-inventory.lua | 16 ++++++++--------
3 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/expcore/common.lua b/expcore/common.lua
index 95011cb6..9b0078c2 100644
--- a/expcore/common.lua
+++ b/expcore/common.lua
@@ -645,10 +645,12 @@ function Common.move_items_stack(items, surface, position, radius, chest_type)
local last_chest
for i=1,#items do
local item = items[i]
- local chest = next_chest(item)
- if not chest or not chest.valid then return error(string.format('Cant move item %s to %s{%s, %s} no valid chest in radius', item_name, surface.name, p.x, p.y)) end
- chest.insert(item)
- last_chest = chest
+ if item.valid_for_read then
+ local chest = next_chest(item)
+ if not chest or not chest.valid then return error(string.format('Cant move item %s to %s{%s, %s} no valid chest in radius', item_name, surface.name, p.x, p.y)) end
+ chest.insert(item)
+ last_chest = chest
+ end
end
return last_chest
end
diff --git a/modules/addons/inventory-clear.lua b/modules/addons/inventory-clear.lua
index 57ae4958..51dc18e2 100644
--- a/modules/addons/inventory-clear.lua
+++ b/modules/addons/inventory-clear.lua
@@ -3,13 +3,13 @@
local Event = require 'utils.event' --- @dep utils.event
local events = require 'config.inventory_clear' --- @dep config.inventory_clear
-local move_items = _C.move_items --- @dep expcore.common
+local move_items_stack = _C.move_items_stack --- @dep expcore.common
local function clear_items(event)
local player = game.players[event.player_index]
local inv = player.get_main_inventory()
- move_items(inv.get_contents())
+ move_items_stack(inv)
inv.clear()
end
-for _, event_name in ipairs(events) do Event.add(event_name, clear_items) end
\ No newline at end of file
+for _, event_name in ipairs(events) do Event.add(event_name, clear_items) end
diff --git a/modules/commands/clear-inventory.lua b/modules/commands/clear-inventory.lua
index 04155978..ceb6b3e9 100644
--- a/modules/commands/clear-inventory.lua
+++ b/modules/commands/clear-inventory.lua
@@ -4,7 +4,7 @@
]]
local Commands = require 'expcore.commands' --- @dep expcore.commands
-local move_items = _C.move_items --- @dep expcore.common
+local move_items_stack = _C.move_items_stack --- @dep expcore.common
require 'config.expcore.command_role_parse'
--- Clears a players inventory
@@ -14,10 +14,10 @@ Commands.new_command('clear-inventory', 'Clears a players inventory')
:add_param('player', false, 'player-role')
:add_alias('clear-inv', 'move-inventory', 'move-inv')
:register(function(_, player)
- local inv = player.get_main_inventory()
- if not inv then
- return Commands.error{'expcore-commands.reject-player-alive'}
- end
- move_items(inv.get_contents())
- inv.clear()
-end)
\ No newline at end of file
+ local inv = player.get_main_inventory()
+ if not inv then
+ return Commands.error{'expcore-commands.reject-player-alive'}
+ end
+ move_items_stack(inv)
+ inv.clear()
+end)
From af19424ceabdb847d85dc4890c37744b474badb8 Mon Sep 17 00:00:00 2001
From: oof2win2
Date: Sat, 14 May 2022 15:52:47 +0200
Subject: [PATCH 4/7] fix: item_name to item.name and add docs
---
expcore/common.lua | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/expcore/common.lua b/expcore/common.lua
index 9b0078c2..38d58e52 100644
--- a/expcore/common.lua
+++ b/expcore/common.lua
@@ -539,6 +539,7 @@ end
-- @section factorio
--[[-- Moves items to the position and stores them in the closest entity of the type given
+-- Copies the items by prototype name, but keeps them in the original inventory
@tparam table items items which are to be added to the chests, ['name']=count
@tparam[opt=navies] LuaSurface surface the surface that the items will be moved to
@tparam[opt={0, 0}] table position the position that the items will be moved to {x=100, y=100}
@@ -596,6 +597,7 @@ function Common.move_items(items, surface, position, radius, chest_type)
end
--[[-- Moves items to the position and stores them in the closest entity of the type given
+-- Differs from move_items by accepting a table of LuaItemStack and transferring them into the inventory - not copying
@tparam table items items which are to be added to the chests, an array of LuaItemStack
@tparam[opt=navies] LuaSurface surface the surface that the items will be moved to
@tparam[opt={0, 0}] table position the position that the items will be moved to {x=100, y=100}
@@ -647,7 +649,7 @@ function Common.move_items_stack(items, surface, position, radius, chest_type)
local item = items[i]
if item.valid_for_read then
local chest = next_chest(item)
- if not chest or not chest.valid then return error(string.format('Cant move item %s to %s{%s, %s} no valid chest in radius', item_name, surface.name, p.x, p.y)) end
+ if not chest or not chest.valid then return error(string.format('Cant move item %s to %s{%s, %s} no valid chest in radius', item.name, surface.name, p.x, p.y)) end
chest.insert(item)
last_chest = chest
end
From 8caf3c0a8293e190f76b46307afde651dbe51652 Mon Sep 17 00:00:00 2001
From: oof2win2
Date: Sat, 14 May 2022 11:13:43 +0200
Subject: [PATCH 5/7] fix(death): movement of items to chests Items would be
only copied and destroyed rather than transferred This would cause issues
with power armor, spidertrons etc.
---
expcore/common.lua | 58 +++++++++++++++++++++++++++++++++
modules/addons/death-logger.lua | 6 ++--
2 files changed, 61 insertions(+), 3 deletions(-)
diff --git a/expcore/common.lua b/expcore/common.lua
index 64886316..95011cb6 100644
--- a/expcore/common.lua
+++ b/expcore/common.lua
@@ -595,6 +595,64 @@ function Common.move_items(items, surface, position, radius, chest_type)
return last_chest
end
+--[[-- Moves items to the position and stores them in the closest entity of the type given
+@tparam table items items which are to be added to the chests, an array of LuaItemStack
+@tparam[opt=navies] LuaSurface surface the surface that the items will be moved to
+@tparam[opt={0, 0}] table position the position that the items will be moved to {x=100, y=100}
+@tparam[opt=32] number radius the radius in which the items are allowed to be placed
+@tparam[opt=iron-chest] string chest_type the chest type that the items should be moved into
+@treturn LuaEntity the last chest that had items inserted into it
+
+@usage-- Copy all the items in a players inventory and place them in chests at {0, 0}
+move_items(game.player.get_main_inventory())
+
+]]
+function Common.move_items_stack(items, surface, position, radius, chest_type)
+ chest_type = chest_type or 'iron-chest'
+ surface = surface or game.surfaces[1]
+ if position and type(position) ~= 'table' then return end
+ if type(items) ~= 'table' then return end
+ -- Finds all entities of the given type
+ local p = position or {x=0, y=0}
+ local r = radius or 32
+ local entities = surface.find_entities_filtered{area={{p.x-r, p.y-r}, {p.x+r, p.y+r}}, name=chest_type} or {}
+ local count = #entities
+ local current = 1
+ -- Makes a new empty chest when it is needed
+ local function make_new_chest()
+ local pos = surface.find_non_colliding_position(chest_type, position, 32, 1)
+ local chest = surface.create_entity{name=chest_type, position=pos, force='neutral'}
+ table.insert(entities, chest)
+ count = count + 1
+ return chest
+ end
+ -- Function used to round robin the items into all chests
+ local function next_chest(item)
+ local chest = entities[current]
+ if count == 0 then return make_new_chest() end
+ if chest.get_inventory(defines.inventory.chest).can_insert(item) then
+ -- If the item can be inserted then the chest is returned
+ current = current+1
+ if current > count then current = 1 end
+ return chest
+ else
+ -- Other wise it is removed from the list
+ table.remove(entities, current)
+ count = count - 1
+ end
+ end
+ -- Inserts the items into the chests
+ local last_chest
+ for i=1,#items do
+ local item = items[i]
+ local chest = next_chest(item)
+ if not chest or not chest.valid then return error(string.format('Cant move item %s to %s{%s, %s} no valid chest in radius', item_name, surface.name, p.x, p.y)) end
+ chest.insert(item)
+ last_chest = chest
+ end
+ return last_chest
+end
+
--[[-- Prints a colored value on a location, color is based on the value.
nb: src is below but the gradent has been edited
https://github.com/Refactorio/RedMew/blob/9184b2940f311d8c9c891e83429fc57ec7e0c4a2/map_gen/maps/diggy/debug.lua#L31
diff --git a/modules/addons/death-logger.lua b/modules/addons/death-logger.lua
index 97c057fe..092bcd4a 100644
--- a/modules/addons/death-logger.lua
+++ b/modules/addons/death-logger.lua
@@ -4,7 +4,7 @@
local Event = require 'utils.event' --- @dep utils.event
local Global = require 'utils.global' --- @dep utils.global
local config = require 'config.death_logger' --- @dep config.death_logger
-local format_time, move_items = _C.format_time, _C.move_items --- @dep expcore.common
+local format_time, move_items = _C.format_time, _C.move_items_stack --- @dep expcore.common
-- Max amount of ticks a corpse can be alive
local corpse_lifetime = 60*60*15
@@ -64,7 +64,7 @@ Event.add(defines.events.on_player_died, function(event)
local player = game.players[event.player_index]
local corpse = player.surface.find_entity('character-corpse', player.position)
if config.use_chests_as_bodies then
- local items = corpse.get_inventory(defines.inventory.character_corpse).get_contents()
+ local items = corpse.get_inventory(defines.inventory.character_corpse)
local chest = move_items(items, corpse.surface, corpse.position)
chest.destructible = false
corpse.destroy()
@@ -140,7 +140,7 @@ end
if config.auto_collect_bodies then
Event.add(defines.events.on_character_corpse_expired, function(event)
local corpse = event.corpse
- local items = corpse.get_inventory(defines.inventory.character_corpse).get_contents()
+ local items = corpse.get_inventory(defines.inventory.character_corpse)
move_items(items, corpse.surface, {x=0, y=0})
end)
end
From 15a5d8d48a68d633c30dbc501f3b1f373a12a762 Mon Sep 17 00:00:00 2001
From: oof2win2
Date: Sat, 14 May 2022 15:38:03 +0200
Subject: [PATCH 6/7] fix: LuaItemStack could be invalid Fixed an issue with
clearing inventories of players where the command failed due to it attempting
to access LuaItemStacks that were invalid for read
---
expcore/common.lua | 10 ++++++----
modules/addons/inventory-clear.lua | 6 +++---
modules/commands/clear-inventory.lua | 16 ++++++++--------
3 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/expcore/common.lua b/expcore/common.lua
index 95011cb6..9b0078c2 100644
--- a/expcore/common.lua
+++ b/expcore/common.lua
@@ -645,10 +645,12 @@ function Common.move_items_stack(items, surface, position, radius, chest_type)
local last_chest
for i=1,#items do
local item = items[i]
- local chest = next_chest(item)
- if not chest or not chest.valid then return error(string.format('Cant move item %s to %s{%s, %s} no valid chest in radius', item_name, surface.name, p.x, p.y)) end
- chest.insert(item)
- last_chest = chest
+ if item.valid_for_read then
+ local chest = next_chest(item)
+ if not chest or not chest.valid then return error(string.format('Cant move item %s to %s{%s, %s} no valid chest in radius', item_name, surface.name, p.x, p.y)) end
+ chest.insert(item)
+ last_chest = chest
+ end
end
return last_chest
end
diff --git a/modules/addons/inventory-clear.lua b/modules/addons/inventory-clear.lua
index 57ae4958..51dc18e2 100644
--- a/modules/addons/inventory-clear.lua
+++ b/modules/addons/inventory-clear.lua
@@ -3,13 +3,13 @@
local Event = require 'utils.event' --- @dep utils.event
local events = require 'config.inventory_clear' --- @dep config.inventory_clear
-local move_items = _C.move_items --- @dep expcore.common
+local move_items_stack = _C.move_items_stack --- @dep expcore.common
local function clear_items(event)
local player = game.players[event.player_index]
local inv = player.get_main_inventory()
- move_items(inv.get_contents())
+ move_items_stack(inv)
inv.clear()
end
-for _, event_name in ipairs(events) do Event.add(event_name, clear_items) end
\ No newline at end of file
+for _, event_name in ipairs(events) do Event.add(event_name, clear_items) end
diff --git a/modules/commands/clear-inventory.lua b/modules/commands/clear-inventory.lua
index 04155978..ceb6b3e9 100644
--- a/modules/commands/clear-inventory.lua
+++ b/modules/commands/clear-inventory.lua
@@ -4,7 +4,7 @@
]]
local Commands = require 'expcore.commands' --- @dep expcore.commands
-local move_items = _C.move_items --- @dep expcore.common
+local move_items_stack = _C.move_items_stack --- @dep expcore.common
require 'config.expcore.command_role_parse'
--- Clears a players inventory
@@ -14,10 +14,10 @@ Commands.new_command('clear-inventory', 'Clears a players inventory')
:add_param('player', false, 'player-role')
:add_alias('clear-inv', 'move-inventory', 'move-inv')
:register(function(_, player)
- local inv = player.get_main_inventory()
- if not inv then
- return Commands.error{'expcore-commands.reject-player-alive'}
- end
- move_items(inv.get_contents())
- inv.clear()
-end)
\ No newline at end of file
+ local inv = player.get_main_inventory()
+ if not inv then
+ return Commands.error{'expcore-commands.reject-player-alive'}
+ end
+ move_items_stack(inv)
+ inv.clear()
+end)
From 89e2dd2afee6fb1a7eb5f39a650816324b0e4f1d Mon Sep 17 00:00:00 2001
From: oof2win2
Date: Sat, 14 May 2022 15:52:47 +0200
Subject: [PATCH 7/7] fix: item_name to item.name and add docs
---
expcore/common.lua | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/expcore/common.lua b/expcore/common.lua
index 9b0078c2..38d58e52 100644
--- a/expcore/common.lua
+++ b/expcore/common.lua
@@ -539,6 +539,7 @@ end
-- @section factorio
--[[-- Moves items to the position and stores them in the closest entity of the type given
+-- Copies the items by prototype name, but keeps them in the original inventory
@tparam table items items which are to be added to the chests, ['name']=count
@tparam[opt=navies] LuaSurface surface the surface that the items will be moved to
@tparam[opt={0, 0}] table position the position that the items will be moved to {x=100, y=100}
@@ -596,6 +597,7 @@ function Common.move_items(items, surface, position, radius, chest_type)
end
--[[-- Moves items to the position and stores them in the closest entity of the type given
+-- Differs from move_items by accepting a table of LuaItemStack and transferring them into the inventory - not copying
@tparam table items items which are to be added to the chests, an array of LuaItemStack
@tparam[opt=navies] LuaSurface surface the surface that the items will be moved to
@tparam[opt={0, 0}] table position the position that the items will be moved to {x=100, y=100}
@@ -647,7 +649,7 @@ function Common.move_items_stack(items, surface, position, radius, chest_type)
local item = items[i]
if item.valid_for_read then
local chest = next_chest(item)
- if not chest or not chest.valid then return error(string.format('Cant move item %s to %s{%s, %s} no valid chest in radius', item_name, surface.name, p.x, p.y)) end
+ if not chest or not chest.valid then return error(string.format('Cant move item %s to %s{%s, %s} no valid chest in radius', item.name, surface.name, p.x, p.y)) end
chest.insert(item)
last_chest = chest
end