Breakable Landfill deprecated


Allows you to break landfill after you place it. An alternative to my platforms mod.

Content
4 years ago
0.17 - 0.18
10
Logistics

b Duplicate Landfill & Disappearing Buildings

4 years ago
(updated 4 years ago)

Hello,
I don't know if you are still active, but I will give it a try anyway.

I have found two bugs in this mod.
1.)
If you place other tiles, like stone path, on the placed landfill, you get landfill back. That means you are able to remove entire water pools with just one landfill and a bunch of tiles. Given, that landfill is usually more expensive than any tile, it is a cheap method to fill up water pools, so I don't think, it is intended that way. (Although you get the same amount of materials back which you used, when you mine the tiles).
Seems like your new defined landfill counts as a stone-path-like tile, unlike the vanilla landfill.
2.)
Use landfill on a water pool and put some tiles on that. Put a building on those tiles. Now mine those tiles under that building. The building will be lost forever. So you can accidently destroy building with that.

It seems like your platforms mod has the same problems as well. I tried to fix it by myself, but I am stuck at how to deal with the landfill, that you get back, when you build tiles on them. So I hope you might be able to deal with the problems better than me and find a better solution to them.

4 years ago

I also tried but I failed

4 years ago
(updated 4 years ago)

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)
4 years ago

I have fixed the issue
I ended up not using your solution but it was still helpful so I added you to contributors
I also fixed other bugs

4 years ago

Hmm, it seems like you deprecated this mod in favor of the your platforms mod, am I right ?
That means the fixes are also implemented in platforms mod ?
If it's the case, then thank you for taking your time and fixing the bugs.
I would like to try it, but the update with the fixes is for Factorio 0.18 only.
Are the fixes not 0.17 compatible ?

4 years ago

honestly, I have no idea if they are or not
I am just focusing on updating everything to .18

New response