z_mirror/CursorEnhancements
git clone https://git.raiguard.me/z_mirror/CursorEnhancements
b4ff864
smart-quickbar
1local util =require ( "__CursorEnhancements__/scripts/util" ) 2 3--- @class BuiltItemData 4--- @field item string 5--- @field tick uint 6 7--- @param e EventData.on_built_entity 8local function on_built_entity ( e ) 9local player =game . get_player ( e . player_index ) 10if not player then 11return 12end 13 14if not player . mod_settings [ "cen-auto-ghost-cursor" ]. value then 15return 16end 17 18local built_item =global . built_item [ e . player_index ] 19if not built_item then 20return 21end 22global . built_item [ e . player_index ] =nil 23if built_item . tick ~= game . tick then 24return 25end 26 27-- Don't do anything if the cursor stack is not empty 28local cursor_stack =player . cursor_stack 29if not cursor_stack or cursor_stack . valid_for_read then 30return 31end 32 33util . set_cursor ( player , built_item . item ) 34end 35 36--- @param e EventData.on_pre_build 37local function on_pre_build ( e ) 38local player =game . get_player ( e . player_index ) 39if not player then 40return 41end 42 43if not player . mod_settings [ "cen-auto-ghost-cursor" ]. value then 44return 45end 46 47local cursor_stack =player . cursor_stack 48if not cursor_stack or not cursor_stack . valid_for_read then 49return 50end 51 52global . built_item [ e . player_index ] ={ item =cursor_stack . name , tick =game . tick } 53end 54 55--- @param e EventData.on_player_main_inventory_changed 56local function on_player_main_inventory_changed ( e ) 57local player =game . get_player ( e . player_index ) 58if not player then 59return 60end 61 62if not player . mod_settings [ "cen-auto-ghost-cursor" ]. value then 63return 64end 65 66local cursor_ghost =player . cursor_ghost 67if not cursor_ghost then 68return 69end 70 71local main_inventory =player . get_main_inventory () 72if not main_inventory then 73return 74end 75 76local count =main_inventory . get_item_count ( cursor_ghost . name ) 77if count == 0 then 78return 79end 80util . set_cursor ( player , cursor_ghost . name ) 81end 82 83local auto_ghost_cursor ={} 84 85auto_ghost_cursor . on_init =function () 86--- @type table<uint, BuiltItemData?> 87global . built_item ={} 88end 89 90auto_ghost_cursor . on_configuration_changed =function () 91global . built_item ={} 92end 93 94auto_ghost_cursor . events ={ 95[ defines . events . on_built_entity ] =on_built_entity , 96[ defines . events . on_player_main_inventory_changed ] =on_player_main_inventory_changed , 97[ defines . events . on_pre_build ] =on_pre_build , 98} 99 100return auto_ghost_cursor