z_mirror/CursorEnhancements
git clone https://git.raiguard.me/z_mirror/CursorEnhancements
902f690
smart-quickbar
1local bounding_box =require ( "__flib__/bounding-box" ) 2 3local util =require ( "__CursorEnhancements__/scripts/util" ) 4 5--- @param surface LuaSurface 6--- @param cursor_position MapPosition 7--- @return string? 8local function get_tile_item ( surface , cursor_position ) 9-- Get tile 10local tile_area =bounding_box . from_position ( cursor_position , true ) 11local tile =surface . find_tiles_filtered ( { area =tile_area } )[ 1 ] 12if not tile or not tile . valid then 13return 14end 15 16--- @type LuaEntityPrototype|LuaTilePrototype 17local prototype =tile . prototype 18if prototype . collision_mask [ "water-tile" ] then 19-- XXX: LuaCustomTable doesn't support next() 20for _ , entity in pairs ( game . get_filtered_entity_prototypes ( { { filter ="type" , type ="offshore-pump" } } )) do 21prototype =entity 22break 23end 24end 25 26local items_to_place_this =prototype . items_to_place_this 27if not items_to_place_this then 28return 29end 30local item_to_place =items_to_place_this [ 1 ] 31if item_to_place then 32return item_to_place . name 33end 34end 35 36--- @param e EventData.CustomInputEvent 37local function on_smart_pipette ( e ) 38local player =game . get_player ( e . player_index ) 39if not player then 40return 41end 42 43-- Don't override base game logic 44local cursor_stack =player . cursor_stack 45if not cursor_stack or cursor_stack . valid_for_read or player . cursor_ghost or player . selected then 46return 47end 48 49local item =util . get_selected_item ( e . selected_prototype ) or get_tile_item ( player . surface , e . cursor_position ) 50if not item then 51return 52end 53 54if not util . set_cursor ( player , item ) then 55return 56end 57 58player . play_sound ( { 59path ="utility/smart_pipette" , 60} ) 61end 62 63local smartpipette ={} 64 65smartpipette . events ={ 66[ "cen-linked-smart-pipette" ] =on_smart_pipette , 67} 68 69return smartpipette