Advertisement
Guest User

Picker Extended underground belt fix, whole file

a guest
Jul 15th, 2021
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. -------------------------------------------------------------------------------
  2. --[Reviver] -- Revives the selected entity
  3. -------------------------------------------------------------------------------
  4.  
  5. local Event = require('__stdlib__/stdlib/event/event')
  6. local Area = require('__stdlib__/stdlib/area/area')
  7. local Player = require('__stdlib__/stdlib/event/player')
  8. local lib = require('__PickerAtheneum__/utils/lib')
  9.  
  10. --as of 08/30 this is mostly incorporated into base.
  11. --Modules are still not revived,
  12. --items on ground are not picked up
  13. --tile proxys are not selected Should be added to pippette to put in hand
  14.  
  15. local function revive_it(event)
  16. local placed = event.created_entity
  17. if not lib.ghosts[placed.name] and Area(placed.selection_box):size() > 0 then
  18. local player = game.get_player(event.player_index)
  19. lib.satisfy_requests(player, placed)
  20. else
  21. -- Auto reviver hack, stops autobuilding when placing a ghost item from an item (alt mode)
  22. local _, pdata = Player.get(event.player_index)
  23. pdata.next_revive_tick = event.tick + 1
  24. end
  25. end
  26. Event.register(defines.events.on_built_entity, revive_it)
  27.  
  28. local function picker_revive_selected(event)
  29. local player = game.players[event.player_index]
  30. if player.selected and player.controller_type ~= defines.controllers.ghost then
  31. if player.selected.name == 'item-on-ground' then
  32. return player.mine_entity(player.selected)
  33. elseif player.selected.name == 'item-request-proxy' and not player.cursor_stack.valid_for_read then
  34. lib.satisfy_requests(player, player.selected)
  35. end
  36. end
  37. end
  38. Event.register('picker-select', picker_revive_selected)
  39.  
  40. --- Automatically revive ghosts when hovering over them with the item in hand.
  41. local function picker_revive_selected_ghosts(event)
  42. local player, pdata = Player.get(event.player_index)
  43. local selected = player.selected
  44. if player.controller_type ~= defines.controllers.ghost and selected then
  45. local stack = player.cursor_stack
  46. if stack.valid_for_read then
  47. if selected.type == 'entity-ghost' and player.mod_settings['picker-revive-selected-ghosts-entity'].value then
  48. if stack.type ~= 'rail-planner' and stack.prototype.place_result == game.entity_prototypes[selected.ghost_name] and pdata.next_revive_tick ~= event.tick then
  49. local direction = selected.direction or defines.direction.north
  50. local position = selected.position
  51. -- API build_from_cursor to no do flip logic
  52. if selected.ghost_type == 'underground-belt' then
  53. if selected.belt_to_ground_type == 'output' then
  54. direction = (direction + 4) % 8
  55. end
  56. local name = selected.ghost_name
  57. local belt_type = selected.belt_to_ground_type
  58.  
  59. player.build_from_cursor {position = position, direction = direction}
  60. local ent = player.surface.find_entity(name, position)
  61. if ent then
  62. if ent.belt_to_ground_type ~= belt_type then
  63. ent.rotate()
  64. end
  65. end
  66. elseif selected.ghost_type == 'pipe-to-ground' then
  67. local name = selected.ghost_name
  68. player.build_from_cursor {position = position, direction = direction}
  69. local ent = player.surface.find_entity(name, position)
  70. if ent and ent.direction ~= direction then
  71. ent.direction = direction
  72. end
  73. else
  74. player.build_from_cursor {position = position, direction = direction}
  75. end
  76. end
  77. elseif selected.type == 'tile-ghost' and player.mod_settings['picker-revive-selected-ghosts-tile'].vaue then
  78. local tile = stack.prototype.place_as_tile_result
  79. if tile and tile.result == game.tile_prototypes[selected.ghost_name] and pdata.next_revive_tick ~= event.tick then
  80. player.build_from_cursor {position = selected.position, direction = selected.direction, terrain_building_size = 1}
  81. end
  82. end
  83. end
  84. end
  85. end
  86. Event.register(defines.events.on_selected_entity_changed, picker_revive_selected_ghosts)
  87.  
  88. return picker_revive_selected
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement