Guest User

pipe.lua

a guest
Nov 22nd, 2024
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.07 KB | None | 0 0
  1. local entity = table.deepcopy(data.raw["pipe-to-ground"]["pipe-to-ground"])
  2. local dist = entity.fluid_box.pipe_connections[2].max_underground_distance
  3. local underground_collision_mask = {layers={lava_tile=true, empty_space=true}}
  4. -- local simulations = require("__base__.prototypes.factoriopedia-simulations")
  5.  
  6. if mods["ConfigUnderLengths"] then
  7.   dist = tonumber(settings.startup["config-under-lengths-pipes-1"].value) + 1
  8. end
  9.  
  10. local category = tostring(settings.startup["connection-categories"].value) ---@type string
  11.  
  12. function get_categories(inputstr) --underground pipes cant have more than one connection atm
  13.   sep = ","
  14.   local t = {}
  15.   for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  16.     str = string.gsub(str, "%s+", "")
  17.     table.insert(t, str)
  18.   end
  19.   return t
  20. end
  21.  
  22.  
  23. local name = {"pipe-to-ground", "pipe-to-ground-2", "pipe-to-ground-3"}
  24. local icon = {
  25.   "__base__/graphics/icons/pipe-to-ground.png",
  26.   "__pipe_plus__/graphics/icon-2.png",
  27.   "__pipe_plus__/graphics/icon-3.png",
  28. }
  29.  
  30. local pictures = {
  31.   north =
  32.   {
  33.     entity.pictures.north.filename,
  34.     "__pipe_plus__/graphics/pipe/hr-up-2.png",
  35.     "__pipe_plus__/graphics/pipe/hr-up-3.png",
  36.   },
  37.   south =
  38.   {
  39.     entity.pictures.south.filename,
  40.     "__pipe_plus__/graphics/pipe/hr-down-2.png",
  41.     "__pipe_plus__/graphics/pipe/hr-down-3.png",
  42.   },
  43.   west =
  44.   {
  45.     entity.pictures.west.filename,
  46.     "__pipe_plus__/graphics/pipe/hr-left-2.png",
  47.     "__pipe_plus__/graphics/pipe/hr-left-3.png",
  48.   },
  49.   east =
  50.   {
  51.     entity.pictures.east.filename,
  52.     "__pipe_plus__/graphics/pipe/hr-right-2.png",
  53.     "__pipe_plus__/graphics/pipe/hr-right-3.png",
  54.   }
  55. }
  56. -- log(serpent.block(pictures.north[1]))
  57. local pipe_connections = {
  58.   {
  59.     { connection_type = "underground", direction = defines.direction.south, position = {0, 0}, max_underground_distance = dist},
  60.     { direction = defines.direction.north, position = {0, 0} },
  61.   },
  62.   {
  63.     { direction = defines.direction.east, position = {0, 0} },
  64.     { underground_collision_mask = underground_collision_mask, connection_type = "underground", direction = defines.direction.south, position = {0, 0}, max_underground_distance = dist, },
  65.     { direction = defines.direction.west, position = {0, 0} },
  66.   },
  67.   {
  68.     {  direction = defines.direction.north, position = {0, 0} },
  69.     { underground_collision_mask = underground_collision_mask, connection_type = "underground", direction = defines.direction.south, position = {0, 0}, max_underground_distance = dist},
  70.     {  direction = defines.direction.east, position = {0, 0} },
  71.     {  direction = defines.direction.west, position = {0, 0} },
  72.   },
  73. }
  74. local vis_data = {
  75.   { -- skip, lol
  76.     filename = "__base__/graphics/entity/pipe-to-ground/visualization.png",
  77.     x = {64, 128, 192, 256},
  78.   },
  79.   {
  80.     filename = "__pipe_plus__/graphics/pipe/visualization_2.png",
  81.     x = {0, 64, 0, 64},
  82.   },
  83.   {
  84.     filename = "__pipe_plus__/graphics/pipe/visualization_3.png",
  85.     x = {64, 128, 0, 192},
  86.   }
  87. }
  88. local visualization_2 = {
  89.   north =
  90.   {
  91.     filename = vis_data[2].filename,
  92.     priority = "extra-high",
  93.     x = vis_data[2].x[1],
  94.     size = 64,
  95.     scale = 0.5,
  96.     flags = {"icon"}
  97.   },
  98.   east =
  99.   {
  100.     filename = vis_data[2].filename,
  101.     priority = "extra-high",
  102.     x = vis_data[2].x[2],
  103.     size = 64,
  104.     scale = 0.5,
  105.     flags = {"icon"}
  106.   },
  107.   south =
  108.   {
  109.     filename = vis_data[2].filename,
  110.     priority = "extra-high",
  111.     x = vis_data[2].x[3],
  112.     size = 64,
  113.     scale = 0.5,
  114.     flags = {"icon"}
  115.   },
  116.   west =
  117.   {
  118.     filename = vis_data[2].filename,
  119.     priority = "extra-high",
  120.     x = vis_data[2].x[4],
  121.     size = 64,
  122.     scale = 0.5,
  123.     flags = {"icon"}
  124.   },
  125. }
  126. local visualization_3 = {
  127.   north =
  128.   {
  129.     filename = vis_data[3].filename,
  130.     priority = "extra-high",
  131.     x = vis_data[3].x[1],
  132.     size = 64,
  133.     scale = 0.5,
  134.     flags = {"icon"}
  135.   },
  136.   east =
  137.   {
  138.     filename = vis_data[3].filename,
  139.     priority = "extra-high",
  140.     x = vis_data[3].x[2],
  141.     size = 64,
  142.     scale = 0.5,
  143.     flags = {"icon"}
  144.   },
  145.   south =
  146.   {
  147.     filename = vis_data[3].filename,
  148.     priority = "extra-high",
  149.     x = vis_data[3].x[3],
  150.     size = 64,
  151.     scale = 0.5,
  152.     flags = {"icon"}
  153.   },
  154.   west =
  155.   {
  156.     filename = vis_data[3].filename,
  157.     priority = "extra-high",
  158.     x = vis_data[3].x[4],
  159.     size = 64,
  160.     scale = 0.5,
  161.     flags = {"icon"}
  162.   },
  163. }
  164.  
  165. for i = 2, 3 do
  166.  
  167.   entity = table.deepcopy(data.raw["pipe-to-ground"]["pipe-to-ground"])
  168.   local item = table.deepcopy(data.raw.item["pipe-to-ground"])
  169.   local recipe = table.deepcopy(data.raw.recipe["pipe-to-ground"])
  170.  
  171.   item.name = name[i]
  172.   item.localised_name = i >1 and {"", {"entity-name.pipe-to-ground"}, " ", tostring(i)} or nil
  173.   item.icon = icon[i]
  174.   item.place_result = name[i]
  175.  
  176.   recipe.name = name[i]
  177.   recipe.localised_name = i >1 and {"", {"entity-name.pipe-to-ground"}, " ", tostring(i)} or nil
  178.   recipe.icon = icon[i]
  179.   recipe.results = {{type = "item", name = name[i], amount = 2}}
  180.  
  181.   entity.name = name[i]
  182.   entity.localised_name = i >1 and {"", {"entity-name.pipe-to-ground"}, " ", tostring(i)} or nil
  183.   entity.icon = icon[i]
  184.   entity.minable = {mining_time = 0.1, result = name[i]}
  185.   -- entity.corpse = "pipe-to-ground-remnants" -- TODO
  186.   -- entity.factoriopedia_simulation = simulations.factoriopedia_pipe_to_ground
  187.   entity.fluid_box = {
  188.     volume = 100,
  189.     pipe_covers = pipecoverspictures(),
  190.     pipe_connections = pipe_connections[i],
  191.     hide_connection_info = true
  192.   }
  193.  
  194.   entity.fluid_box.pipe_connections[2].connection_category = get_categories(category)
  195.  
  196.   if i == 2 then
  197.     entity.visualization = visualization_2
  198.   end
  199.   if i == 3 then
  200.     entity.visualization = visualization_3
  201.   end
  202.  
  203.   for _, dir in pairs({"north","south","west","east"}) do
  204.     entity.pictures[dir].filename = pictures[dir][i]
  205.   end
  206.  
  207.   if i > 1 and data.raw.technology["steam-power"] then
  208.     recipe.enabled = false
  209.     table.insert(data.raw.technology["steam-power"].effects, {type = "unlock-recipe", recipe = name[i]})
  210.   end
  211.  
  212.   data:extend({entity, item, recipe})
  213. end
Advertisement
Add Comment
Please, Sign In to add comment