Pipeworks
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

154 lines
5.4 KiB

  1. -- Pipeworks mod by Vanessa Ezekowitz - 2013-07-13
  2. --
  3. -- This mod supplies various steel pipes and plastic pneumatic tubes
  4. -- and devices that they can connect to.
  5. --
  6. pipeworks = {}
  7. local DEBUG = false
  8. pipeworks.worldpath = minetest.get_worldpath()
  9. pipeworks.modpath = minetest.get_modpath("pipeworks")
  10. local S = minetest.get_translator("pipeworks")
  11. dofile(pipeworks.modpath.."/default_settings.lua")
  12. -- Read the external config file if it exists.
  13. local worldsettingspath = pipeworks.worldpath.."/pipeworks_settings.txt"
  14. local worldsettingsfile = io.open(worldsettingspath, "r")
  15. if worldsettingsfile then
  16. worldsettingsfile:close()
  17. dofile(worldsettingspath)
  18. end
  19. if pipeworks.toggles.pipe_mode == "pressure" then
  20. minetest.log("warning", "pipeworks pressure logic mode comes with caveats and differences in behaviour, you have been warned!")
  21. end
  22. -- Random variables
  23. pipeworks.expect_infinite_stacks = true
  24. if minetest.get_modpath("unified_inventory") or not minetest.settings:get_bool("creative_mode") then
  25. pipeworks.expect_infinite_stacks = false
  26. end
  27. pipeworks.meseadjlist={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=0,y=1,z=0},{x=0,y=-1,z=0},{x=1,y=0,z=0},{x=-1,y=0,z=0}}
  28. pipeworks.rules_all = {{x=0, y=0, z=1},{x=0, y=0, z=-1},{x=1, y=0, z=0},{x=-1, y=0, z=0},
  29. {x=0, y=1, z=1},{x=0, y=1, z=-1},{x=1, y=1, z=0},{x=-1, y=1, z=0},
  30. {x=0, y=-1, z=1},{x=0, y=-1, z=-1},{x=1, y=-1, z=0},{x=-1, y=-1, z=0},
  31. {x=0, y=1, z=0}, {x=0, y=-1, z=0}}
  32. pipeworks.mesecons_rules={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=1,y=0,z=0},{x=-1,y=0,z=0},{x=0,y=1,z=0},{x=0,y=-1,z=0}}
  33. pipeworks.digilines_rules={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=1,y=0,z=0},{x=-1,y=0,z=0},{x=0,y=1,z=0},{x=0,y=-1,z=0}}
  34. pipeworks.liquid_texture = "default_water.png"
  35. pipeworks.button_off = {text="", texture="pipeworks_button_off.png", addopts="false;false;pipeworks_button_interm.png"}
  36. pipeworks.button_on = {text="", texture="pipeworks_button_on.png", addopts="false;false;pipeworks_button_interm.png"}
  37. pipeworks.button_base = "image_button[0,4.3;1,0.6"
  38. pipeworks.button_label = "label[0.9,4.31;"..S("Allow splitting incoming stacks from tubes").."]"
  39. -- Helper functions
  40. function pipeworks.fix_image_names(table, replacement)
  41. local outtable={}
  42. for i in ipairs(table) do
  43. outtable[i]=string.gsub(table[i], "_XXXXX", replacement)
  44. end
  45. return outtable
  46. end
  47. function pipeworks.add_node_box(t, b)
  48. if not t or not b then return end
  49. for i in ipairs(b)
  50. do table.insert(t, b[i])
  51. end
  52. end
  53. function pipeworks.may_configure(pos, player)
  54. local name = player:get_player_name()
  55. local meta = minetest.get_meta(pos)
  56. local owner = meta:get_string("owner")
  57. if owner ~= "" then -- wielders and filters
  58. return owner == name
  59. end
  60. return not minetest.is_protected(pos, name)
  61. end
  62. function pipeworks.replace_name(tbl,tr,name)
  63. local ntbl={}
  64. for key,i in pairs(tbl) do
  65. if type(i)=="string" then
  66. ntbl[key]=string.gsub(i,tr,name)
  67. elseif type(i)=="table" then
  68. ntbl[key]=pipeworks.replace_name(i,tr,name)
  69. else
  70. ntbl[key]=i
  71. end
  72. end
  73. return ntbl
  74. end
  75. pipeworks.logger = function(msg)
  76. print("[pipeworks] "..msg)
  77. end
  78. -------------------------------------------
  79. -- Load the various other parts of the mod
  80. -- early auto-detection for finite water mode if not explicitly disabled
  81. if pipeworks.toggles.finite_water == nil then
  82. dofile(pipeworks.modpath.."/autodetect-finite-water.lua")
  83. end
  84. if minetest.get_modpath("signs_lib") then
  85. dofile(pipeworks.modpath.."/signs_compat.lua")
  86. end
  87. dofile(pipeworks.modpath.."/common.lua")
  88. dofile(pipeworks.modpath.."/models.lua")
  89. dofile(pipeworks.modpath.."/autoplace_pipes.lua")
  90. dofile(pipeworks.modpath.."/autoplace_tubes.lua")
  91. dofile(pipeworks.modpath.."/luaentity.lua")
  92. dofile(pipeworks.modpath.."/item_transport.lua")
  93. dofile(pipeworks.modpath.."/flowing_logic.lua")
  94. dofile(pipeworks.modpath.."/crafts.lua")
  95. dofile(pipeworks.modpath.."/tube_registration.lua")
  96. dofile(pipeworks.modpath.."/routing_tubes.lua")
  97. dofile(pipeworks.modpath.."/sorting_tubes.lua")
  98. dofile(pipeworks.modpath.."/vacuum_tubes.lua")
  99. dofile(pipeworks.modpath.."/signal_tubes.lua")
  100. dofile(pipeworks.modpath.."/decorative_tubes.lua")
  101. dofile(pipeworks.modpath.."/filter-injector.lua")
  102. dofile(pipeworks.modpath.."/trashcan.lua")
  103. dofile(pipeworks.modpath.."/wielder.lua")
  104. local logicdir = "/pressure_logic/"
  105. -- note that even with these files the new flow logic is not yet default.
  106. -- registration will take place but no actual ABMs/node logic will be installed,
  107. -- unless the toggle flag is specifically enabled in the per-world settings flag.
  108. dofile(pipeworks.modpath..logicdir.."flowable_node_registry.lua")
  109. dofile(pipeworks.modpath..logicdir.."abms.lua")
  110. dofile(pipeworks.modpath..logicdir.."abm_register.lua")
  111. dofile(pipeworks.modpath..logicdir.."flowable_node_registry_install.lua")
  112. if pipeworks.enable_pipes then dofile(pipeworks.modpath.."/pipes.lua") end
  113. if pipeworks.enable_teleport_tube then dofile(pipeworks.modpath.."/teleport_tube.lua") end
  114. if pipeworks.enable_pipe_devices then dofile(pipeworks.modpath.."/devices.lua") end
  115. if pipeworks.enable_redefines then
  116. dofile(pipeworks.modpath.."/compat-chests.lua")
  117. dofile(pipeworks.modpath.."/compat-furnaces.lua")
  118. end
  119. if pipeworks.enable_autocrafter then dofile(pipeworks.modpath.."/autocrafter.lua") end
  120. if pipeworks.enable_lua_tube and
  121. (minetest.get_modpath("mesecons") or minetest.get_modpath("digilines")) then
  122. dofile(pipeworks.modpath.."/lua_tube.lua")
  123. end
  124. minetest.register_alias("pipeworks:pipe", "pipeworks:pipe_110000_empty")
  125. print("Pipeworks loaded!")