Add new water type

Place to get help with not working mods / modding interface.
Post Reply
User avatar
Muppet9010
Filter Inserter
Filter Inserter
Posts: 278
Joined: Sat Dec 09, 2017 6:01 pm
Contact:

Add new water type

Post by Muppet9010 »

I am trying to add some new water types, but am having issues getting them recognised as water for the transitions to apply correctly.

In base\prototypes\tile\tiles.lua there is

Code: Select all

water_tile_type_names = { "water", "deepwater", "water-green", "deepwater-green" }
If I add my new water type to this list then transitions work nicely, however I am struggling on how to achieve this via a mod zip.

New Water code:

Code: Select all

data:extend(
{
  {
    name = "driedwater",
    type = "tile",
    collision_mask =
    {
      "water-tile",
      "resource-layer",
      "item-layer",
      "player-layer",
      "doodad-layer"
    },
    draw_in_water_layer = true,
    layer = 0,
    variants =
    {
      main =
      {
        {
          picture = "__MuppetWaterUsage__/graphics/driedwater/driedwater1.png",
          count = 8,
          size = 1,
          hr_version = {
            picture = "__MuppetWaterUsage__/graphics/driedwater/hr-driedwater1.png",
            count = 8,
            scale = 0.5,
            size = 1
          }
        },
        {
          picture = "__MuppetWaterUsage__/graphics/driedwater/driedwater2.png",
          count = 8,
          size = 2,
          hr_version = {
            picture = "__MuppetWaterUsage__/graphics/driedwater/hr-driedwater2.png",
            count = 8,
            scale = 0.5,
            size = 2
          }
        },
        {
          picture = "__MuppetWaterUsage__/graphics/driedwater/driedwater4.png",
          count = 6,
          size = 4,
          hr_version = {
            picture = "__MuppetWaterUsage__/graphics/driedwater/hr-driedwater4.png",
            count = 8,
            scale = 0.5,
            size = 4
          }
        }
      },
      inner_corner =
      {
        picture = "__MuppetWaterUsage__/graphics/driedwater/driedwater-inner-corner.png",
        count = 6,
        hr_version = {
          picture = "__MuppetWaterUsage__/graphics/driedwater/hr-driedwater-inner-corner.png",
          count = 6,
          scale = 0.5
        }
      },
      outer_corner =
      {
        picture = "__MuppetWaterUsage__/graphics/driedwater/driedwater-outer-corner.png",
        count = 6,
        hr_version = {
          picture = "__MuppetWaterUsage__/graphics/driedwater/hr-driedwater-outer-corner.png",
          count = 6,
          scale = 0.5
        }
      },
      side =
      {
        picture = "__MuppetWaterUsage__/graphics/driedwater/driedwater-side.png",
        count = 8,
        hr_version = {
          picture = "__MuppetWaterUsage__/graphics/driedwater/hr-driedwater-side.png",
          count = 8,
          scale = 0.5
        }
      }
    },
    map_color={r=38, g=64, b=73},
    ageing=0.0006
  }
}
)
I tried to add the below into my mod lua file to overwrite this transition function for a specific tile type as a test, but this causes an unhandled exception (raised separately as error message implies the dev's want notifying of unhandled exceptions).
Without adding my new water tile in to the water_tile_type_names list in tiles.lua my tile acts like a land tile for merging.

Code: Select all

water_tile_type_names = { "water", "deepwater", "water-green", "deepwater-green", "driedwater" }

function water_transition_template(to_tiles, normal_res_transition, high_res_transition, options)
  local function make_transition_variation(src_x, src_y, cnt_, line_len_, is_tall)
    return
    {
      picture = normal_res_transition,
      count = cnt_,
      line_length = line_len_,
      x = src_x,
      y = src_y,
      tall = is_tall,
      hr_version=
      {
        picture = high_res_transition,
        count = cnt_,
        line_length = line_len_,
        x = 2 * src_x,
        y = 2 * (src_y or 0),
        tall = is_tall,
        scale = 0.5,
      }
    }
  end

  local t = options.base or {}
  t.to_tiles = to_tiles
  local default_count = options.count or 16
  for k,y in pairs({inner_corner = 0, outer_corner = 288, side = 576, u_transition = 864, o_transition = 1152}) do
    local count = options[k .. "_count"] or default_count
    if count > 0 and type(y) == "number" then
      local line_length = options[k .. "_line_length"] or count
      local is_tall = true
      if (options[k .. "_tall"] == false) then
        is_tall = false
      end
      t[k] = make_transition_variation(0, y, count, line_length, is_tall)
      t[k .. "_background"] = make_transition_variation(544, y, count, line_length, is_tall)
      t[k .. "_mask"] = make_transition_variation(1088, y, count, line_length)
    end
  end

  return t
end

data.raw["tile"]["grass-1"].transitions.water_transition_template = water_transition_template
  (
      water_tile_type_names,
      "__base__/graphics/terrain/water-transitions/grass.png",
      "__base__/graphics/terrain/water-transitions/hr-grass.png",
      {
        o_transition_tall = false,
        u_transition_count = 4,
        o_transition_count = 8,
        base =
        {
          side_weights = { 1, 1, 1, 1,  0.25, 0.25, 1, 1,  1, 1, 0.125, 0.25,  1, 1, 1, 1 }
        }
      }
  )

User avatar
Muppet9010
Filter Inserter
Filter Inserter
Posts: 278
Joined: Sat Dec 09, 2017 6:01 pm
Contact:

Re: Add new water type

Post by Muppet9010 »

In case anyone else comes looking to add new water types, what I posted works above 0.16.15.
as covered in bug: viewtopic.php?f=11&t=56005

This approach wasn't dismissed by developers in the bug report as being a bad way to implement new water types using the stock land to water transitions. it is unfortunate that you have to overwrite parts of the stock tile types as this will limit automatic mod compatibility with other new tile mods.

posila
Factorio Staff
Factorio Staff
Posts: 5202
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: Add new water type

Post by posila »

In theory, it should work if you do just

Code: Select all

table.insert(water_tile_type_names, "driedwater")
table.insert(water_tile_type_names, "shallowwater")
in one of data-updates.lua or data-final-fixes.lua (but not in both of them).

EDIT: You also have to remove 'water_tile_type_names = { "water", "deepwater", "water-green", "deepwater-green", "driedwater", "shallowwater"}' from your code, because it will overwrite what table name 'water_tile_type_names' points to.

User avatar
Muppet9010
Filter Inserter
Filter Inserter
Posts: 278
Joined: Sat Dec 09, 2017 6:01 pm
Contact:

Re: Add new water type

Post by Muppet9010 »

thank you Posila that has worked under data-updates.lua

Post Reply

Return to “Modding help”