Hmm, I don't know how far you got with your attempt, but this is what I tried to do and what problems arised I couldn't solve:
While the building dissappearing issue has been fixed,
without changing the mining result for the breakable landfill, the problem is still to keep track of all the possible landfill you get, when you replace them with stonepath-like tiles, including the main inventory, cursor and on-ground-items, and in addition to that, the cargo inventory of robots. I couldn't figure out a way to delete the on-ground-items. And I think I didn't understand
If you remove the mining result of the breakable landfill, you have to give the player the landfill back, when the player mines that landfill. Prioritising the cursor stack first, if it's already landfill, then the main inventory if the cursor stack is full or not landfill, and if the player's inventory is full, then spawn the items on the ground. Still, I couldn't figure out how to spawn items on the ground.
In conclusion, with how many problems are arising when trying to fix the bug and the complicated solutions it would result, which wouldn't be UPS friendly, the only simple fix you could apply is to not be able to get any landfill back when mined (which conflicts with your mod concept) or implementing a tool (which is defined as water tile) only dedicated to break and get back landfill, which in this case, you don't need breakable landfill as tile anymore.
If you are interested, here is the control.lua I have, but be careful, it is not complete and still has problems with the inventory stuff, but it has the fix for the destroy-building-bug:
--We don't want players being able to mine tiles if they are underneath other buildings, so we make them unbreakable
script.on_event({defines.events.on_built_entity, defines.events.on_robot_built_entity}, function(event)
local entity = event.created_entity
if entity.has_flag("placeable-off-grid") or entity.type == "curved-rail" then return nil end
local position = entity.position
local surface = entity.surface
local tiles = {}
local selection_box = entity.selection_box
local top_left_x = math.ceil(selection_box.left_top.x * 2) / 2
local top_left_y = math.ceil(selection_box.left_top.y * 2) / 2
local right_bottom_x = math.ceil(selection_box.right_bottom.x * 2) / 2
local right_bottom_y = math.ceil(selection_box.right_bottom.y * 2) / 2
if top_left_x ~= right_bottom_x or right_bottom_x ~= right_bottom_y then
for _, tile in pairs(surface.find_tiles_filtered{area = {{top_left_x, top_left_y}, {right_bottom_x, right_bottom_y}}, name = "landfill"}) do
tiles[#tiles + 1] = {name = "unbreakable-landfill", position = tile.position}
end
surface.set_tiles(tiles)
end
end)
script.on_event({defines.events.on_player_mined_entity, defines.events.on_robot_mined_entity, defines.events.on_entity_died}, function(event)
local entity = event.entity
if entity.has_flag("placeable-off-grid") or entity.type == "curved-rail" then return nil end
local position = entity.position
local surface = entity.surface
local tiles = {}
local selection_box = entity.selection_box
local top_left_x = math.ceil(selection_box.left_top.x * 2) / 2
local top_left_y = math.ceil(selection_box.left_top.y * 2) / 2
local right_bottom_x = math.ceil(selection_box.right_bottom.x * 2) / 2
local right_bottom_y = math.ceil(selection_box.right_bottom.y * 2) / 2
if not (top_left_x == right_bottom_x and right_bottom_x == right_bottom_y) then
for _, tile in pairs(surface.find_tiles_filtered{area = {{top_left_x, top_left_y}, {right_bottom_x, right_bottom_y}}, name = "unbreakable-landfill"}) do
--tiles[#tiles + 1] = {name = "water", position = tile.position}
tiles[#tiles + 1] = {name = "landfill", position = tile.position}
end
surface.set_tiles(tiles)
end
end)
script.on_event({defines.events.on_player_built_tile, defines.events.on_robot_built_tile}, function(event)
--[[if event.tile.name == "landfill" then return nil end
local surface = game.surfaces[event.surface_index]
local tiles = {}
for _, tile in pairs(event.tiles) do
if tile.old_tile.name == "landfill" then
tiles[#tiles + 1] = {name = "unbreakable-landfill", position = tile.position}
tiles[#tiles + 1] = {name = event.tile.name, position = tile.position}
end
end
surface.set_tiles(tiles)]]
if event.tile.name ~= "landfill" then return nil end
local surface = game.surfaces[event.surface_index]
local tiles = {}
for _, tile in pairs(event.tiles) do
tiles[#tiles + 1] = {name = "unbreakable-landfill", position = tile.position}
tiles[#tiles + 1] = {name = "landfill", position = tile.position}
end
surface.set_tiles(tiles)
end)
script.on_event({defines.events.on_player_mined_tile, defines.events.on_robot_mined_tile}, function(event)
local entity = event.robot
if not entity then
entity = game.get_player(event.player_index)
end
local surface = game.surfaces[event.surface_index]
local tiles = {}
--local tilename
local building_on_tile = false
local inventory
--if event.robot then
-- inventory = event.robot.get_inventory(defines.inventory.robot_cargo)
--else
-- inventory = game.get_player(event.player_index).get_main_inventory()
--end
for _, tile in pairs(event.tiles) do
if tile.old_tile.name == "landfill" then
tiles[#tiles + 1] = {name = "water", position = tile.position}
if not entity then
entity = game.get_player(event.player_index)
inventory = entity.cursor_stack.get_inventory(defines.inventory.character_main)
else
inventory = entity.get_inventory(defines.inventory.robot_cargo)
end
inventory.insert({name = "landfill"})
elseif surface.get_tile(tile.position).name == "unbreakable-landfill" then
local top_left_x = tile.position.x
local top_left_y = tile.position.y
local right_bottom_x = top_left_x + 1
local right_bottom_y = top_left_y + 1
local entities = surface.find_entities_filtered{area = {{top_left_x, top_left_y}, {right_bottom_x, right_bottom_y}}}
if entities then
for _, entity in pairs(entities) do
if entity.health then
building_on_tile = true
break
end
end
if not building_on_tile then
--tiles[#tiles + 1] = {name = "water", position = tile.position}
tiles[#tiles + 1] = {name = "landfill", position = tile.position}
end
end
end
end
surface.set_tiles(tiles)
end)