SOLVED! Make spaceship wreck deconstructable!
Posted: Mon Aug 24, 2020 5:48 pm
TLDR: There is a bug in Factorio: The developers wrote code to create items associated with crash wreckage, but the functions to create these items are never run. Therefore, the entities cannot be marked for deconstruction. To mark wreckage for deconstruction, 1.) add items that can place the wreckage entities, 2.) remove the "non-destructable" flag, and 3.) change the entity force to "player".
CREDIT: viewtopic.php?f=25&t=47980&p=278536&hil ... le#p278536 Bob mentions that there must exist an item with the property place_result = [the entity you want to deconstruct]
Factorio has most of the code necessary to create these items for spaceship wreckage. There even exists icon graphics for all the debris!

The functions to create these items are in
Because these functions are local, you'll need to copy-paste them into your own code to actually run them in data:extend{}.
The TWO other things you need to do to make these items deconstructible, is remove the "not-deconstructable" flag...
And you need to change the entity.force to "player" in control.lua
CREDIT: viewtopic.php?f=25&t=47980&p=278536&hil ... le#p278536 Bob mentions that there must exist an item with the property place_result = [the entity you want to deconstruct]
Factorio has most of the code necessary to create these items for spaceship wreckage. There even exists icon graphics for all the debris!

The functions to create these items are in
Code: Select all
prototypes/item/demo-crash-site-item.lua
Code: Select all
local big_wreck_item = function(n)
return
{
type = "item",
name = "crash-site-spaceship-wreck-big-"..n,
icon = "__base__/graphics/icons/crash-site-spaceship-wreck-big-"..n..".png",
icon_size = 64, icon_mipmaps = 4,
subgroup = "crash-site",
order = "z[crash-site-spaceship]-b",
place_result = "crash-site-spaceship-wreck-big-"..n,
stack_size = 1,
flags = {"hidden"}
}
end
The TWO other things you need to do to make these items deconstructible, is remove the "not-deconstructable" flag...
Code: Select all
local deconstructable = {
['container'] = {
"crash-site-chest-1",
"crash-site-chest-2",
"crash-site-spaceship-wreck-big-1",
"crash-site-spaceship-wreck-big-2",
"crash-site-spaceship-wreck-medium-1",
"crash-site-spaceship-wreck-medium-2",
"crash-site-spaceship-wreck-medium-3"
},
['simple-entity-with-owner'] = {
"crash-site-spaceship-wreck-small-1",
"crash-site-spaceship-wreck-small-2",
"crash-site-spaceship-wreck-small-3",
"crash-site-spaceship-wreck-small-4",
"crash-site-spaceship-wreck-small-5",
"crash-site-spaceship-wreck-small-6"
}
}
Code: Select all
for type_, array in pairs(deconstructable) do
for _, name in pairs(array) do
for i, flag in pairs(data.raw[type_][name].flags) do
if flag == "not-deconstructable" then
table.remove(data.raw[type_][name].flags, i)
end
end
end
end
Code: Select all
local wreckage = {
"crash-site-spaceship-wreck-big-1",
"crash-site-spaceship-wreck-big-2",
"crash-site-spaceship-wreck-medium-1",
"crash-site-spaceship-wreck-medium-2",
"crash-site-spaceship-wreck-medium-3",
"crash-site-spaceship-wreck-small-1",
"crash-site-spaceship-wreck-small-2",
"crash-site-spaceship-wreck-small-3",
"crash-site-spaceship-wreck-small-4",
"crash-site-spaceship-wreck-small-5",
"crash-site-spaceship-wreck-small-6"
}
script.on_event(defines.events.on_player_created, function(event)
for i, entity in pairs(game.surfaces[1].find_entities_filtered{position = {0, 0}, radius = 50, name = wreckage}) do
entity.force = "player"
end
end)