Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 33 additions & 31 deletions scripts/reviver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,40 +44,42 @@ local function picker_revive_selected_ghosts(event)
local selected = player.selected
if player.controller_type ~= defines.controllers.ghost and selected then
local stack = player.cursor_stack
if stack.valid_for_read then
if selected.type == 'entity-ghost' and player.mod_settings['picker-revive-selected-ghosts-entity'].value then
if stack.type ~= 'rail-planner' and stack.prototype.place_result == game.entity_prototypes[selected.ghost_name] and pdata.next_revive_tick ~= event.tick then
local direction = selected.direction or defines.direction.north
local position = selected.position
-- API build_from_cursor to no do flip logic
if selected.ghost_type == 'underground-belt' then
if selected.belt_to_ground_type == 'output' then
direction = (direction + 4) % 8
end
local name = selected.ghost_name
local belt_type = selected.belt_to_ground_type
player.build_from_cursor {position = position, direction = direction}
local ent = player.surface.find_entity(name, position)
if ent then
if ent.belt_to_ground_type ~= belt_type then
ent.rotate()
if stack then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stack is a LuaItemStack it shouldn't ever be nil. Ill try to fire it up in the debugger and se whats happening

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if stack.valid_for_read then
if selected.type == 'entity-ghost' and player.mod_settings['picker-revive-selected-ghosts-entity'].value then
if stack.type ~= 'rail-planner' and stack.prototype.place_result == game.entity_prototypes[selected.ghost_name] and pdata.next_revive_tick ~= event.tick then
local direction = selected.direction or defines.direction.north
local position = selected.position
-- API build_from_cursor to no do flip logic
if selected.ghost_type == 'underground-belt' then
if selected.belt_to_ground_type == 'output' then
direction = (direction + 4) % 8
end
local name = selected.ghost_name
local belt_type = selected.belt_to_ground_type
player.build_from_cursor {position = position, direction = direction}
local ent = player.surface.find_entity(name, position)
if ent then
if ent.belt_to_ground_type ~= belt_type then
ent.rotate()
end
end
elseif selected.ghost_type == 'pipe-to-ground' then
local name = selected.ghost_name
player.build_from_cursor {position = position, direction = direction}
local ent = player.surface.find_entity(name, position)
if ent and ent.direction ~= direction then
ent.direction = direction
end
else
player.build_from_cursor {position = position, direction = direction}
end
elseif selected.ghost_type == 'pipe-to-ground' then
local name = selected.ghost_name
player.build_from_cursor {position = position, direction = direction}
local ent = player.surface.find_entity(name, position)
if ent and ent.direction ~= direction then
ent.direction = direction
end
else
player.build_from_cursor {position = position, direction = direction}
end
end
elseif selected.type == 'tile-ghost' and player.mod_settings['picker-revive-selected-ghosts-tile'].vaue then
local tile = stack.prototype.place_as_tile_result
if tile and tile.result == game.tile_prototypes[selected.ghost_name] and pdata.next_revive_tick ~= event.tick then
player.build_from_cursor {position = selected.position, direction = selected.direction, terrain_building_size = 1}
elseif selected.type == 'tile-ghost' and player.mod_settings['picker-revive-selected-ghosts-tile'].vaue then
local tile = stack.prototype.place_as_tile_result
if tile and tile.result == game.tile_prototypes[selected.ghost_name] and pdata.next_revive_tick ~= event.tick then
player.build_from_cursor {position = selected.position, direction = selected.direction, terrain_building_size = 1}
end
end
end
end
Expand Down