z_mirror/EditorExtensions
git clone https://git.raiguard.me/z_mirror/EditorExtensions
4cd1f18
1.14
1local util =require ( "__EditorExtensions__/scripts/util" ) 2 3local aggregate_chest_names ={ 4[ "ee-aggregate-chest" ] ="ee-aggregate-chest" , 5[ "ee-aggregate-chest-passive-provider" ] ="ee-aggregate-chest-passive-provider" , 6} 7 8--- Set the filters for the given aggregate chest and removes the bar if there is one 9--- @param entity LuaEntity 10local function set_filters ( entity ) 11entity . remove_unfiltered_items =true 12entity . infinity_container_filters =global . aggregate_filters 13entity . get_inventory ( defines . inventory . chest ). set_bar () 14end 15 16-- Update the filters of all existing aggregate chests 17local function update_all_filters () 18for _ , surface in pairs ( game . surfaces ) do 19for _ , entity in pairs ( surface . find_entities_filtered ( { name =aggregate_chest_names } )) do 20set_filters ( entity ) 21end 22end 23end 24 25-- Retrieve each item prototype and its stack size 26local function build_filter_cache () 27local include_hidden =settings . global [ "ee-aggregate-include-hidden" ]. value 28--- @type InfinityInventoryFilter[] 29local filters ={} 30local i =0 31for name , prototype in pairs ( game . item_prototypes ) do 32if prototype . type ~= "mining-tool" and include_hidden or not prototype . has_flag ( "hidden" ) then 33i =i + 1 34filters [ i ] ={ name =name , count =prototype . stack_size , mode ="exactly" , index =i } 35end 36end 37global . aggregate_filters =filters 38end 39 40--- @param e BuiltEvent 41local function on_built ( e ) 42local entity =e . created_entity or e . entity or e . destination 43if not entity or not entity . valid or not aggregate_chest_names [ entity . name ] then 44return 45end 46set_filters ( entity ) 47end 48 49--- @param e EventData.on_player_setup_blueprint 50local function on_setup_blueprint ( e ) 51local blueprint =util . get_blueprint ( e ) 52if not blueprint then 53return 54end 55 56local entities =blueprint . get_blueprint_entities () 57if not entities then 58return 59end 60local set =false 61for _ , entity in pairs ( entities ) do 62if aggregate_chest_names [ entity . name ] then 63set =true 64entity . infinity_settings . filters =nil --- @diagnostic disable-line 65end 66end 67if set then 68blueprint . set_blueprint_entities ( entities ) 69end 70end 71 72local aggregate_chest ={} 73 74aggregate_chest . on_init =build_filter_cache 75 76aggregate_chest . on_configuration_changed =function () 77build_filter_cache () 78update_all_filters () 79end 80 81aggregate_chest . events ={ 82[ defines . events . on_built_entity ] =on_built , 83[ defines . events . on_entity_cloned ] =on_built , 84[ defines . events . on_player_setup_blueprint ] =on_setup_blueprint , 85[ defines . events . on_robot_built_entity ] =on_built , 86[ defines . events . script_raised_built ] =on_built , 87[ defines . events . script_raised_revive ] =on_built , 88} 89 90return aggregate_chest