z_mirror/MouseOverConstruction
git clone https://git.raiguard.me/z_mirror/MouseOverConstruction
7c145b8
insertion
1--- @param player_index PlayerIndex 2local function cancel ( player_index ) 3storage . deconstructing [ player_index ] =nil 4end 5 6--- @param player LuaPlayer 7--- @param entity LuaEntity 8--- @return boolean started 9local function start ( player , entity ) 10if not entity . valid then 11return false 12end 13 14if not player . mod_settings [ "moc-enable-deconstruction" ]. value then 15return false 16end 17 18if not entity . to_be_deconstructed () then 19return false 20end 21 22storage . deconstructing [ player . index ] =entity . position 23return true 24end 25 26local function on_tick () 27if not storage . deconstructing then 28return 29end 30 31for player_index , position in pairs ( storage . deconstructing ) do 32local player =game . get_player ( player_index ) 33if not player then 34cancel ( player_index ) 35goto continue 36end 37player . mining_state ={ mining =true , position =position } 38:: continue :: 39end 40end 41 42local function init () 43--- @type table<PlayerIndex, MapPosition> 44storage . deconstructing ={} 45end 46 47--- @class deconstruct_handler : event_handler 48local deconstruct_handler ={} 49 50deconstruct_handler . on_init =init 51deconstruct_handler . on_configuration_changed =init 52 53deconstruct_handler . events ={ 54[ defines . events . on_tick ] =on_tick , 55} 56 57deconstruct_handler . cancel =cancel 58deconstruct_handler . start =start 59 60return deconstruct_handler