Bluebuild

by Mylon

Allows blueprints to be used much earlier. Once a blueprint is placed, nearby entities will be auto-placed at 5/second so long as you have the objects in inventory and are standing still. Once items are marked for deconstruction, they will be auto-removed and put into inventory so long as you are standing still. Press b to toggle building, press n to toggle demolishing.

Utilities
3 years ago
0.14 - 1.1
5.66K
Blueprints

b crash when placing "text plates" with "bluebuild"

7 years ago

nice mod, and i always enjoy watching items appear and disapear, eg when i have no personal roboport with me and want to collect loot, or at the start of a new game when i have lots of repetitive work to do ... BUT:

i don't know which of these two mods causes the problem, or maybe both of them together.
that's why i report this to both mods ...

when i tried to place a blueprint with some textplates (and no other items), using most current versions of both mods, factorio crashed on me with this Notice:
- Error while running event on_tick (ID 0)
- LuaEntity API call when LuaEntity was invalid.
- stack traceback:
- Bluebuild/control.lua:113: in function 'bluebuild'
- Bluebuild/control.lua:51: in function 'bluecheck'
- Bluebuild/control.lua:36: in function 'playerloop'
- Bluebuild/control.lua:198: in function <Bluebuild/control.lua:197>

7 years ago

for another bug report, Mylon wrote:
"Some of my other mods (like concreep) always check if entities are still valid before doing anything"

and for a copy of this bug report that i posted on the Text Plates forum, that author answered:
"Text plates uses a single item to build any end shape to avoid clogging your inventory, but to do this it swaps an entity with another entity. It looks like bluebuild keeps a reference to the entity but the reference becomes invalid. It should just be a case of adding a entity.valid check before the line that's causing the crash."

looks as if you did the check only on other mods, but not on this one. why?
many blueprint mods get similar problems often since lots of items and virtual items interact with each other ...

7 years ago
(updated 7 years ago)

Honestly I haven't looked at this mod in a while. This was my first. I'll put out a fix.

Edit: Looking at it, I called the events out of order. on_put_item should have been called first as it won't be modifying the entity involved. Usually.

7 years ago
(updated 7 years ago)

just tried again, and this time there was no crash,
but there is still something wrong.

a short test showed that letting robots place the textplates works correctly, but when they are placed by that autobuild ("10 items per second") in your mod, only the template/blank plate is placed and then not replaced by the correct letter.

edit: second test confirmed this: after disabling autobuild (with the hotkey), everything works correctly. after re-enabling it and removing my personal roboports, only the same textplate(#) is placed for all textplates.
(#) a bit strange: this is not the "base" textplate, but the last textplate that i used before when directly placing a textplate and using the textplate-gui.

7 years ago

I looked at the code for Textplates and that mod is reading the player cursor to determine what plate to place when on_player_built_entity is called. As bluebuild built entities are not built from the cursor, textplates will fail to update properly. I suggest you poke the Textplates author about this.

7 years ago

from https://forums.factorio.com/viewtopic.php?f=93&t=34935&p=235374#p234769

"When a robot or player places an entity an event is fired which allows a script to react to the placement. In this case the reaction is to replace a placeholder plate with a real plate. If a different script places an entity then no event is fired."

since i am no lua or factorio programmer, i don't know how that can be achieved, and whether it could be as simple as raising an event so that textplates handles it as if a robot would have placed the plate.

do you look at that thread too so that i don't have to relay things between this mod portal and that forum thread ?

7 years ago
(updated 7 years ago)

I have looked into the problem, and it is because textplates relies on on_player_built_entity being called when the player actually made the change via the UI. I have updated textplates with an updated version of an api that I've been working on for the AAI mods. This will enable textplates the respond to other mods reviving entities if they implement a custom on_entity_revived event. Please add the following code to the top of the bluebuild control.lua (other mods can also implement this interface to properly support bluebuild reviving entities).

EDIT: The formatting is a bit weird on the portal. I will add the modified control.lua to a post in the thread linked above to make it easier.

control.lua line 0:
-- require("serpent") --For debug only

--[[
CUSTOM EVENTS SENT

on_entity_revived
raise_event implementation: raise_event('on_entity_revived', {entity=LuaEntity, player_index=player.player_index})
on_event implementation: remote.add_interface("mymod", { on_entity_revived = function(data) return myfunction(data.entity, data.player_index) end})

]]--
local function raise_event(event_name, event_data)
local responses = {}
for interface_name, interface_functions in pairs(remote.interfaces) do
if interface_functions[event_name] then
responses[interface_name] = remote.call(interface_name, event_name, event_data)
end
end
return responses
end

-- Find ghosts to place. Then find buildings to destruct.

This code goes in control.lua near line 123:

<pre> -- game.print("Removing item from inventory.") raise_event('on_entity_revived', {entity=revive, player_index=builder.index}) if revive.valid then game.raise_event(defines.events.on_put_item, {position=revive.position, player_index=builder.index, name="on_put_item"}) game.raise_event(defines.events.on_built_entity, {created_entity=revive, player_index=builder.index, tick=game.tick, name="on_built_entity"}) end builder.remove_item({name=__}) </pre>
7 years ago

wow ... good service and fast updates just like from the developers and for the game itself

New response