SOLVED! Make spaceship wreck deconstructable!

Place to get help with not working mods / modding interface.
PrestonLeeC
Burner Inserter
Burner Inserter
Posts: 14
Joined: Mon Aug 24, 2020 1:02 pm
Contact:

SOLVED! Make spaceship wreck deconstructable!

Post by PrestonLeeC »

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!
Image

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
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...

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
And you need to change the entity.force to "player" in control.lua

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)
Last edited by PrestonLeeC on Tue Aug 25, 2020 1:59 am, edited 4 times in total.
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3716
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Solved?: Make spaceship wreck deconstructable

Post by DaveMcW »

Code: Select all

data.raw.container["crash-site-spaceship"].allow_copy_paste = true
But I still can't deconstruct it after doing that.
PrestonLeeC
Burner Inserter
Burner Inserter
Posts: 14
Joined: Mon Aug 24, 2020 1:02 pm
Contact:

Re: SOLVED! Make spaceship wreck deconstructable!

Post by PrestonLeeC »

This has been a long and difficult process for me, and I've posted some misinformation in the original post a couple times. I believe at this point it's actually accurate. Sorry if anyone saw the version where I didn't realize the wreckage needed to be on the player force.

Good luck, modders!
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: SOLVED! Make spaceship wreck deconstructable!

Post by darkfrei »

PrestonLeeC wrote: Tue Aug 25, 2020 1:58 am Sorry if anyone saw the version where I didn't realize the wreckage needed to be on the player force.
You can add autodrop inventory on destroying.
https://mods.factorio.com/mod/SpilledItems

Or so: https://mods.factorio.com/mod/LootingRemnants
Post Reply

Return to “Modding help”