create_entity fast_replace isn't working

Place to get help with not working mods / modding interface.
User avatar
Sirenfal
Long Handed Inserter
Long Handed Inserter
Posts: 50
Joined: Tue Jan 10, 2017 1:42 am
Contact:

create_entity fast_replace isn't working

Post by Sirenfal »

I have two container types:

(https://paste.whitefire.in/view/uPUIWvbpgM)

Code: Select all

	{
		type = "container",
		name = "fre_connection-chest_input",
		icon = "__base__/graphics/icons/steel-chest.png",
		flags = {"not-blueprintable", "not-deconstructable"},
		minable = nil,
		max_health = 0,
		corpse = "small-remnants",
		open_sound = { filename = "__base__/sound/metallic-chest-open.ogg", volume=0.65 },
		close_sound = { filename = "__base__/sound/metallic-chest-close.ogg", volume = 0.7 },
		resistances =
		{
			{
				type = "fire",
				percent = 90
			}
		},
		collision_box = {{-0.35, -0.35}, {0.35, 0.35}},
		selection_box = {{-0.5, -0.5}, {0.5, 0.5}},
		fast_replaceable_group = "fre_connection-chest",
		inventory_size = 48,
		vehicle_impact_sound =	{ filename = "__base__/sound/car-metal-impact.ogg", volume = 0.65 },
		picture =
		{
			filename = "__base__/graphics/entity/steel-chest/steel-chest.png",
			priority = "extra-high",
			width = 48,
			height = 34,
			shift = {0.1875, 0}
		},
	},
	{
		type = "container",
		name = "fre_connection-chest_output",
		icon = "__base__/graphics/icons/steel-chest.png",
		flags = {"not-blueprintable", "not-deconstructable"},
		minable = nil,
		max_health = 0,
		corpse = "small-remnants",
		open_sound = { filename = "__base__/sound/metallic-chest-open.ogg", volume=0.65 },
		close_sound = { filename = "__base__/sound/metallic-chest-close.ogg", volume = 0.7 },
		resistances =
		{
			{
				type = "fire",
				percent = 90
			}
		},
		collision_box = {{-0.35, -0.35}, {0.35, 0.35}},
		selection_box = {{-0.5, -0.5}, {0.5, 0.5}},
		fast_replaceable_group = "fre_connection-chest",
		inventory_size = 48,
		vehicle_impact_sound =	{ filename = "__base__/sound/car-metal-impact.ogg", volume = 0.65 },
		picture =
		{
			filename = "__base__/graphics/entity/steel-chest/steel-chest.png",
			priority = "extra-high",
			width = 48,
			height = 34,
			shift = {0.1875, 0}
		},
	},

I want to replace an existing neutral entity with the opposite type. These are both identical besides entity name.

This is for reversing inputs and outputs, like so:

Code: Select all

	self.input, self.output = self.output, self.input

	self.input = self.input.surface.create_entity({
		name='fre_connection-chest_input',
		position=self.input.position,
		force='neutral',
		fast_replace=true,
	})

	self.output = self.output.surface.create_entity({
		name='fre_connection-chest_output',
		position=self.output.position,
		force='neutral',
		fast_replace=true,
	})
This just creates a second entity (of each type) on top of the existing entities instead of fast replacing. What am I doing wrong?
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: create_entity fast_replace isn't working

Post by Nexela »

I think fast_replaceable_group has to be an existing type "container"

edit I think my thinking is wrong though :)
Last edited by Nexela on Wed Feb 01, 2017 8:17 pm, edited 1 time in total.
User avatar
Sirenfal
Long Handed Inserter
Long Handed Inserter
Posts: 50
Joined: Tue Jan 10, 2017 1:42 am
Contact:

Re: create_entity fast_replace isn't working

Post by Sirenfal »

Nexela wrote:I think fast_replaceable_group has to be a type "container"
I thought so too at first, but I noticed long handed inserters have a non-type fast replacable group.

So I tried these two prototypes with items and they can be fast replaced properly by hand with each other, but not with other chests (which is what I want). It doesn't work with create_entity. Not sure why
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: create_entity fast_replace isn't working

Post by Nexela »

Does it work if you set the force to "player" when creating the entities?
User avatar
Sirenfal
Long Handed Inserter
Long Handed Inserter
Posts: 50
Joined: Tue Jan 10, 2017 1:42 am
Contact:

Re: create_entity fast_replace isn't working

Post by Sirenfal »

Nope. In the meantime I'll just spawn the dual entities, clone the items and delete the old entities. For anyone else trying to do this:

Code: Select all

	self.input, self.output = self.output, self.input

	for _, key in pairs({'input', 'output'}) do
		local old = self[key]
		self[key] = old.surface.create_entity({
			name='fre_connection-chest_' .. key,
			position=old.position,
			force='neutral',
		})

		local old_inven = old.get_inventory(defines.inventory.chest)
		local new_inven = self[key].get_inventory(defines.inventory.chest)

		for i=1,#old_inven do
			new_inven[i].set_stack(old_inven[i])
		end

		old.destroy()
	end
User avatar
Sirenfal
Long Handed Inserter
Long Handed Inserter
Posts: 50
Joined: Tue Jan 10, 2017 1:42 am
Contact:

Re: create_entity fast_replace isn't working

Post by Sirenfal »

For anyone's future reference: I believe this happened because I'm spawning the entities in places where the player can't ordinarily place them. create-entity doesn't care, but fast-replace=true does.
Post Reply

Return to “Modding help”