Linked belts reversing when placed or upgraded.

Place to get help with not working mods / modding interface.
Nihilistzsche
Burner Inserter
Burner Inserter
Posts: 7
Joined: Sun Jul 11, 2021 3:05 am
Contact:

Linked belts reversing when placed or upgraded.

Post by Nihilistzsche »

I'm using the mod Linked Belts with Krastorio 2/Space Exploration, along with a little mod I wrote myself to add the ability to upgrade the linked belts using the next_upgrade fields. There is an issue when placing the belts that they will appear flipped from the ghost, if the ghost is facing left, the placed belt will face right. In addition, when upgrading they will also be flipped if the original belt was facing right the new belt will be facing left. How can I prevent the belt from flipping like this?
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Linked belts reversing when placed or upgraded.

Post by darkfrei »

Don't forget to set the input and out type:

Code: Select all

inputEntity.linked_belt_type = "input"
outputEntity.linked_belt_type = "output"
Nihilistzsche
Burner Inserter
Burner Inserter
Posts: 7
Joined: Sun Jul 11, 2021 3:05 am
Contact:

Re: Linked belts reversing when placed or upgraded.

Post by Nihilistzsche »

That's weird because I don't change anything in the control.lua function from LinkedBelts.

Code: Select all

		
             if (handler.last_belt and handler.last_belt.valid) 
			and not (entity.linked_belt_neighbour) -- sometimes already linked 0_o
			then
			
			-- second linked belt
			handler.last_belt.linked_belt_type = "input"
			entity.linked_belt_type = "output"
			entity.connect_linked_belts(handler.last_belt)
			rendering.destroy(handler.rid)
			if entity.surface == handler.last_belt.surface then
				rendering.draw_line{
					color={1,1,1},
					width=1,
					from=handler.last_belt,
					to=entity,
					surface=entity.surface,
					time_to_live=600,
					forces={entity.force.name},
					only_in_alt_mode=true
				}
			end
			handler.last_belt=nil
			handler.rid=nil
		elseif not (entity.linked_belt_neighbour) then
			-- first linked belt
			entity.linked_belt_type = "input"
			handler.last_belt = entity
			handler.rid = rendering.draw_sprite{
				target=entity,
				sprite="utility/crafting_machine_recipe_not_unlocked",
				surface=entity.surface,
				forces={entity.force.name},
				only_in_alt_mode=true,
				x_scale=0.6, y_scale=0.6
			}
		else -- fast replace
			game.print ('fast replace')
		end
As far as I can tell thats exactly what this code is trying to do, but it isnt working correctly for some reason. There is a workaround with ghosts that if you simply face the ghost the opposite of what you want the belt will end up where you want it, and subsequent ghosts will also be reversed while placed in the correct position. The big issue is with upgrading, since upgrading the linked belts flips them all which breaks logistics all over the factory. As far as I can tell, this should be setting the first belt to "input", though if the ghost is "input" is will be placed "output", and if the ghost is "output" it will be placed "input".

Code: Select all

local belt_types = { "linked-belt", "fast-linked-belt", "express-linked-belt" };

for i=1,3 do
    data.raw["linked-belt"][belt_types[i]].fast_replaceable_group = "linked-belts"
    if i<3 then
        data.raw["linked-belt"][belt_types[i]].next_upgrade = belt_types[i+1]
    end
end

if mods["LinkedBelts-Extension"] then
    data.raw["linked-belt"][belt_types[3]].next_upgrade="advanced-linked-belt"
    data.raw["linked-belt"]["advanced-linked-belt"].fast_replaceable_group = "linked-belts"
    data.raw["linked-belt"]["advanced-linked-belt"].next_upgrade = "superior-linked-belt"
    data.raw["linked-belt"]["superior-linked-belt"].fast_replaceable_group = "linked-belts"
end
That is the entirity of the "LinkedBelts_FixUpgrades" mod I wrote.
The upgrade planner showing "Fast Linked Belt" to "Express Linked Belts"
Image

The Fast Linked Belts in the correct orientation.
Image

After upgrading, they are now facting the opposite direction and must be manually corrected.
Image
User avatar
jamiechi1
Filter Inserter
Filter Inserter
Posts: 272
Joined: Wed Jan 03, 2018 10:12 pm

Re: Linked belts reversing when placed or upgraded.

Post by jamiechi1 »

I had this issue with Krastorio2. I fixed it by commenting out the code in my copy of Krastorio2 that has to do with loaders. I don't use the loaders built into Krastorio2. I use the miniloaders mod instead. Some of the code that does this is in control.lua of Krastorio2.
Nihilistzsche
Burner Inserter
Burner Inserter
Posts: 7
Joined: Sun Jul 11, 2021 3:05 am
Contact:

Re: Linked belts reversing when placed or upgraded.

Post by Nihilistzsche »

Ah I thought it might be a Krastorio2 bug since the discussion on LinkedBelts also said Krastorio2 with the same issue. I am adept at editing so I will find loader code in control.lua and also disable it. I use deadlock loaders :) Ty for the tip!

That worked :) I checked to see if it was something that could be done externally, but doesnt appear so, so local changes it will have to be. Thank you again for the help and pointing me in the right direction.
Post Reply

Return to “Modding help”