shanemadden wrote: Fri Nov 01, 2019 11:27 pm
mrvn wrote: Tue Oct 29, 2019 5:30 pm
Despite multiple reports according to Deadlock this bug does not exist and it's you doing something wrong or having broken mods do something wrong.
If you want your blueprints to place loaders right you have to disable the snapping in the mod options. It's the snapping code that turns those loaders around the wrong way. The drawback is that manually palcing loaders won't automatically switch between loading and unloading for you. You have to often place and rotate (50% of the time basically).
As I think I've asked before, give me a blueprint string and combination of mods and settings that reproduces this and I'll fix it; every test I've done builds properly in situations like this, and every time I've found an issue it's another mod's snapping stuff that's screwing up.
Lets boil this down to the very minimum:
1) Modlist: deadlock-beltboxes-loaders_2.2.2.zip, Bluebuild_1.2.0.zip
Both inventory and belt snapping set to true.
Note: Bluebuild calls ghost.revive() and then triggers on_built_entity. There is no rotation going on in the mod.
2) Start scenario/sandbox
Bluebuild needs a character to work so:
/c game.player.create_character()
3) Build this by hand:
- Build by hand
- beltbox1.png (39.67 KiB) Viewed 5657 times
4) cut & paste the loader
- press ctrl-x to activate cut mode
- select just the loader
- place ghost of loader right back
- Ghost build loader
- beltbox2.png (22.12 KiB) Viewed 5657 times
I've added some log() lines to both mods to show what's going on. Mostly just turned the comments in the source into log().
Now here is what happens when you place the loader manually:
Code: Select all
2692.136 Script @__deadlock-beltboxes-loaders__/control.lua:78: on_built_entity({
created_entity = {
__self = "userdata"
},
item = {
__self = "userdata"
},
name = 6,
player_index = 1,
stack = {
__self = "userdata"
},
tick = 25439
})
2692.136 Script @__deadlock-beltboxes-loaders__/control.lua:80: entity type = loader
2692.137 Script @__deadlock-beltboxes-loaders__/control.lua:81: entity direction = 4
2692.137 Script @__deadlock-beltboxes-loaders__/control.lua:87: entity loader_type = output
2692.137 Script @__deadlock-beltboxes-loaders__/control.lua:99: there's a belt facing toward the belt-side of the loader, so we want to be in input mode
And what happens when you place the ghost:
Code: Select all
2703.452 Script @__deadlock-beltboxes-loaders__/control.lua:78: on_built_entity({
created_entity = {
__self = "userdata"
},
name = 6,
player_index = 1,
stack = {
__self = "userdata"
},
tick = 26118
})
2703.453 Script @__deadlock-beltboxes-loaders__/control.lua:80: entity type = entity-ghost
2703.453 Script @__deadlock-beltboxes-loaders__/control.lua:81: entity direction = 0
2703.453 Script @__deadlock-beltboxes-loaders__/control.lua:84: invalid
2703.485 Script @__Bluebuild__/control.lua:124: calling ghost.revive()
2703.486 Script @__Bluebuild__/control.lua:138: rasing on_put_item
2703.486 Script @__Bluebuild__/control.lua:140: raising on_built_entity
2703.487 Script @__deadlock-beltboxes-loaders__/control.lua:78: on_built_entity({
created_entity = {
__self = "userdata"
},
mod_name = "Bluebuild",
name = 6,
player_index = 1,
revive = true,
tick = 26120
})
2703.487 Script @__deadlock-beltboxes-loaders__/control.lua:80: entity type = loader
2703.487 Script @__deadlock-beltboxes-loaders__/control.lua:81: entity direction = 0
2703.487 Script @__deadlock-beltboxes-loaders__/control.lua:87: entity loader_type = input
2703.487 Script @__deadlock-beltboxes-loaders__/control.lua:112: there's a loadable entity on the belt end but not on the loader end, flip around and go into input mode to load it up
2703.487 Script @__deadlock-beltboxes-loaders__/control.lua:117: not facing belt
Note: Bluebuild sets event.revive and not event.revived like some other mods so the "I better do nothing" test fails. Bluebuild (and every other mod) probabyl shouldn't call on_built_entity but script_raised_revive now that that exists. Luckily it doesn't so I can demonstrate the bug in Deadlocks loaders and beltboxes with it.
Now to explain why this is going wrong: The loader entity has both a direction (N,S,W,E) and a loader_type (input/output). A manually placed loader is always in output mode (so far, hopefully that may change in the future) as can be seen in the log:
Code: Select all
2692.137 Script @__deadlock-beltboxes-loaders__/control.lua:81: entity direction = 4
2692.137 Script @__deadlock-beltboxes-loaders__/control.lua:87: entity loader_type = output
The loader is facing the wooden-chest and the belt is going into the loader. So the control.lua correctly switches it to input mode.
Next when the ghost is placed this looks differently:
Code: Select all
2703.487 Script @__deadlock-beltboxes-loaders__/control.lua:81: entity direction = 0
2703.487 Script @__deadlock-beltboxes-loaders__/control.lua:87: entity loader_type = input
Both the direction and the loader type are reversed. Because, well, it seems that for "input" ty0pe loaders the direction of the entity is reversed in the game.
The control.lua then sees that the loader is facing away from the wooden-chest (which is wrong as it's an input type facing the chest) and turns it around. It also switches the mode to what it things is "input" mode. But the entity already is in "input" mode so gets switched to "output" mode. In the end the loaders is both facing the wrong way and going the wrong direction.
I have no idea why the direction of loaders is reversed when they have "input" type but that's how it is. So the control.lua should not ignore the loader_type of the entity. Once that is taken in consideration the snapping code can do the right thing.
In conclusion:
Any mod that revives loader ghosts and calls on_built_entity without even.revived=true will trigger this bug with "input" type loaders. Event.revived is a custom flag invented by some other mod and not part of the API. Not every mod adds that unofficial flag and as seen
in bluebuild there seems to be a competing event.revive=true flag. I believe both of them are obsolete since the official API has:
script_raised_built A static event mods can use to tell other mods they built something with a script.
script_raised_destroy A static event mods can use to tell other mods they destroyed something with a script.
script_raised_revive A static event mods can use to tell other mods they revived something with a script.
The bug should still be fixed because in the future it might be possible to place "input" type loaders directly and enough mods do call on_built_entity to matter.