z_mirror/MouseOverConstruction
git clone https://git.raiguard.me/z_mirror/MouseOverConstruction
7c145b8
insertion
1local common =require ( "scripts.common" ) 2 3--- @param player LuaPlayer 4--- @param entity LuaEntity 5--- @return boolean succeeded 6return function ( player , entity ) 7if not entity . valid then 8return false 9end 10 11if not player . mod_settings [ "moc-enable-upgrading" ]. value then 12return false 13end 14 15if not entity . to_be_upgraded () then 16return false 17end 18 19local upgrade_prototype , upgrade_quality =entity . get_upgrade_target () 20if not upgrade_prototype then 21return false 22end 23--- @cast upgrade_quality -? 24 25if not common . check_can_place_entity ( player , entity , upgrade_prototype ) then 26return false 27end 28 29--- @type LuaEntity? 30local underground_neighbour =entity . type == "underground-belt" and entity . neighbours or nil 31 32local upgraded =common . build ( player , entity , upgrade_prototype , upgrade_quality ) 33if not upgraded then 34return false 35end 36 37if not underground_neighbour or not underground_neighbour . valid then 38-- Still return true because the selected entity was upgraded. 39return true 40end 41 42local neighbour_upgrade_prototype , neighbour_upgrade_quality =underground_neighbour . get_upgrade_target () 43if neighbour_upgrade_prototype then 44--- @cast neighbour_upgrade_quality -? 45-- Upgrading underground neighbours doesn't obey the usual build distance restrictions, so no need to check it here. 46common . build ( player , underground_neighbour , neighbour_upgrade_prototype , neighbour_upgrade_quality ) 47end 48 49return true 50end