wagons.lua 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758
  1. local S = dlxtrains_industrial_wagons.S
  2. local use_attachment_patch = advtrains_attachment_offset_patch and advtrains_attachment_offset_patch.setup_advtrains_wagon
  3. local mod_name = "dlxtrains_industrial_wagons"
  4. local crate_texture_count = dlxtrains_industrial_wagons.crate_texture_count
  5. local shipping_container_livery_count = dlxtrains_industrial_wagons.shipping_container_livery_count
  6. local tank_container_livery_count = dlxtrains_industrial_wagons.tank_container_livery_count
  7. dlxtrains.register_mod(mod_name)
  8. -- ////////////////////////////////////////////////////////////////////////////////////
  9. local livery_scheme_industrial_wagon_container_type1 = {
  10. filename_prefix = "dlxtrains_industrial_wagons_container_type1",
  11. [0]={code="dlx"},
  12. [1]={code="dz"},
  13. [2]={code="wf"},
  14. [3]={code="t"},
  15. [4]={code="zr"},
  16. count = 5,
  17. }
  18. local livery_scheme_industrial_wagon_container_type2 = {
  19. filename_prefix = "dlxtrains_industrial_wagons_container_type2",
  20. [0]={code="dlx"},
  21. [1]={code="dz"},
  22. [2]={code="wf"},
  23. [3]={code="t"},
  24. [4]={code="zr"},
  25. count = 5,
  26. }
  27. local livery_scheme_industrial_wagon_covered_goods_type1 = {
  28. filename_prefix = "dlxtrains_industrial_wagons_covered_goods_type1",
  29. [0]={code="nr"},
  30. [1]={code="tt"},
  31. [2]={code="dlx"},
  32. [3]={code="t"},
  33. count = 4,
  34. }
  35. local livery_scheme_industrial_wagon_covered_goods_type2 = {
  36. filename_prefix = "dlxtrains_industrial_wagons_covered_goods_type2",
  37. [0]={code="vr"},
  38. [1]={code="ar"},
  39. [2]={code="at"},
  40. [3]={code="t"},
  41. count = 4,
  42. }
  43. local livery_scheme_industrial_wagon_covered_goods_type3 = {
  44. filename_prefix = "dlxtrains_industrial_wagons_covered_goods_type3",
  45. [0]={code="dz"},
  46. [1]={code="t"},
  47. [2]={code="wf"},
  48. [3]={code="zr"},
  49. count = 4,
  50. }
  51. local livery_scheme_industrial_wagon_flat_type1 = {
  52. filename_prefix = "dlxtrains_industrial_wagons_flat_type1",
  53. [0]={code="zr"},
  54. [1]={code="t"},
  55. [2]={code="dz"},
  56. [3]={code="wf"},
  57. count = 4,
  58. }
  59. local livery_scheme_industrial_wagon_flat_type2 = {
  60. filename_prefix = "dlxtrains_industrial_wagons_flat_type2",
  61. [0]={code="ar"},
  62. [1]={code="at"},
  63. [2]={code="t"},
  64. [3]={code="vr"},
  65. count = 4,
  66. }
  67. local livery_scheme_industrial_wagon_hopper_type1 = {
  68. filename_prefix = "dlxtrains_industrial_wagons_hopper_type1",
  69. [0]={code="dlx"},
  70. [1]={code="t"},
  71. [2]={code="tt"},
  72. [3]={code="nr"},
  73. count = 4,
  74. }
  75. local livery_scheme_industrial_wagon_hopper_type2 = {
  76. filename_prefix = "dlxtrains_industrial_wagons_hopper_type2",
  77. [0]={code="dlx"},
  78. [1]={code="t"},
  79. [2]={code="tt"},
  80. [3]={code="nr"},
  81. count = 4,
  82. }
  83. local livery_scheme_industrial_wagon_livestock_type1 = {
  84. filename_prefix = "dlxtrains_industrial_wagons_livestock_type1",
  85. [0]={code="ar"},
  86. [1]={code="at"},
  87. [2]={code="t"},
  88. [3]={code="vr"},
  89. count = 4,
  90. }
  91. local livery_scheme_industrial_wagon_open_type1 = {
  92. filename_prefix = "dlxtrains_industrial_wagons_open_type1",
  93. [0]={code="ar"},
  94. [1]={code="at"},
  95. [2]={code="t"},
  96. [3]={code="vr"},
  97. count = 4,
  98. }
  99. local livery_scheme_industrial_wagon_stake_type1 = {
  100. filename_prefix = "dlxtrains_industrial_wagons_stake_type1",
  101. [0]={code="t"},
  102. [1]={code="dz"},
  103. [2]={code="wf"},
  104. [3]={code="zr"},
  105. count = 4,
  106. }
  107. local livery_scheme_industrial_wagon_tank_type1 = {
  108. filename_prefix = "dlxtrains_industrial_wagons_tank_type1",
  109. [0]={code="dz"},
  110. [1]={code="t"},
  111. [2]={code="wf"},
  112. [3]={code="zr"},
  113. count = 4,
  114. }
  115. local livery_scheme_industrial_wagon_tank_type2 = {
  116. filename_prefix = "dlxtrains_industrial_wagons_tank_type2",
  117. [0]={code="dz"},
  118. [1]={code="t"},
  119. [2]={code="wf"},
  120. [3]={code="zr"},
  121. count = 4,
  122. }
  123. local livery_scheme_industrial_wagon_transition_type1 = {
  124. filename_prefix = "dlxtrains_industrial_wagons_transition_type1",
  125. [0]={code="dlx"},
  126. [1]={code="t"},
  127. count = 2,
  128. }
  129. -- ////////////////////////////////////////////////////////////////////////////////////
  130. local livery_templates = {
  131. ["dlxtrains_industrial_wagons:container_type1"] = {
  132. dlxtrains.init_livery_template(mod_name, 0, dlxtrains.livery_type.standard, "DL&X", "container_type1_dlx"),
  133. dlxtrains.init_livery_template(mod_name, 1, dlxtrains.livery_type.standard, "DZ", "container_type1_dz"),
  134. dlxtrains.init_livery_template(mod_name, 2, dlxtrains.livery_type.standard, "WF", "container_type1_wf"),
  135. dlxtrains.init_livery_template(mod_name, 3, dlxtrains.livery_type.standard, "T", "container_type1_t"),
  136. dlxtrains.init_livery_template(mod_name, 4, dlxtrains.livery_type.standard, "ZR", "container_type1_zr"),
  137. },
  138. ["dlxtrains_industrial_wagons:container_type2"] = {
  139. dlxtrains.init_livery_template(mod_name, 0, dlxtrains.livery_type.standard, "DL&X", "container_type2_dlx"),
  140. dlxtrains.init_livery_template(mod_name, 1, dlxtrains.livery_type.standard, "DZ", "container_type2_dz"),
  141. dlxtrains.init_livery_template(mod_name, 2, dlxtrains.livery_type.standard, "WF", "container_type2_wf"),
  142. dlxtrains.init_livery_template(mod_name, 3, dlxtrains.livery_type.standard, "T", "container_type2_t"),
  143. dlxtrains.init_livery_template(mod_name, 4, dlxtrains.livery_type.standard, "ZR", "container_type2_zr"),
  144. },
  145. ["dlxtrains_industrial_wagons:covered_goods_type1"] = {
  146. dlxtrains.init_livery_template(mod_name, 0, dlxtrains.livery_type.early_era, "NR", "covered_goods_type1_nr"),
  147. dlxtrains.init_livery_template(mod_name, 1, dlxtrains.livery_type.early_era, "TT", "covered_goods_type1_tt"),
  148. dlxtrains.init_livery_template(mod_name, 2, dlxtrains.livery_type.early_era, "DL&X", "covered_goods_type1_dlx"),
  149. dlxtrains.init_livery_template(mod_name, 3, dlxtrains.livery_type.early_era, "T", "covered_goods_type1_t"),
  150. },
  151. ["dlxtrains_industrial_wagons:covered_goods_type2"] = {
  152. dlxtrains.init_livery_template(mod_name, 0, dlxtrains.livery_type.middle_era, "VR", "covered_goods_type2_vr"),
  153. dlxtrains.init_livery_template(mod_name, 1, dlxtrains.livery_type.middle_era, "AR", "covered_goods_type2_ar"),
  154. dlxtrains.init_livery_template(mod_name, 2, dlxtrains.livery_type.middle_era, "AT", "covered_goods_type2_at"),
  155. dlxtrains.init_livery_template(mod_name, 3, dlxtrains.livery_type.standard, "T", "covered_goods_type2_t"),
  156. },
  157. ["dlxtrains_industrial_wagons:covered_goods_type3"] = {
  158. dlxtrains.init_livery_template(mod_name, 0, dlxtrains.livery_type.middle_era, "DZ", "covered_goods_type3_dz"),
  159. dlxtrains.init_livery_template(mod_name, 1, dlxtrains.livery_type.middle_era, "T", "covered_goods_type3_t"),
  160. dlxtrains.init_livery_template(mod_name, 2, dlxtrains.livery_type.early_era, "WF", "covered_goods_type3_wf"),
  161. dlxtrains.init_livery_template(mod_name, 3, dlxtrains.livery_type.middle_era, "ZR", "covered_goods_type3_zr"),
  162. },
  163. ["dlxtrains_industrial_wagons:flat_type1"] = {
  164. dlxtrains.init_livery_template(mod_name, 0, dlxtrains.livery_type.standard, "ZR", "flat_type1_zr"),
  165. dlxtrains.init_livery_template(mod_name, 1, dlxtrains.livery_type.standard, "T", "flat_type1_t"),
  166. dlxtrains.init_livery_template(mod_name, 2, dlxtrains.livery_type.standard, "DZ", "flat_type1_dz"),
  167. dlxtrains.init_livery_template(mod_name, 3, dlxtrains.livery_type.standard, "WF", "flat_type1_wf"),
  168. },
  169. ["dlxtrains_industrial_wagons:flat_type2"] = {
  170. dlxtrains.init_livery_template(mod_name, 0, dlxtrains.livery_type.middle_era, "AR", "flat_type2_ar"),
  171. dlxtrains.init_livery_template(mod_name, 1, dlxtrains.livery_type.middle_era, "AT", "flat_type2_at"),
  172. dlxtrains.init_livery_template(mod_name, 2, dlxtrains.livery_type.standard, "T", "flat_type2_t"),
  173. dlxtrains.init_livery_template(mod_name, 3, dlxtrains.livery_type.middle_era, "VR", "flat_type2_vr"),
  174. },
  175. ["dlxtrains_industrial_wagons:hopper_type1"] = {
  176. dlxtrains.init_livery_template(mod_name, 0, dlxtrains.livery_type.standard, "DL&X", "hopper_type1_dlx"),
  177. dlxtrains.init_livery_template(mod_name, 1, dlxtrains.livery_type.standard, "T", "hopper_type1_t"),
  178. dlxtrains.init_livery_template(mod_name, 2, dlxtrains.livery_type.middle_era, "TT", "hopper_type1_tt"),
  179. dlxtrains.init_livery_template(mod_name, 3, dlxtrains.livery_type.middle_era, "NR", "hopper_type1_nr"),
  180. },
  181. ["dlxtrains_industrial_wagons:hopper_type2"] = {
  182. dlxtrains.init_livery_template(mod_name, 0, dlxtrains.livery_type.standard, "DL&X", "hopper_type2_dlx"),
  183. dlxtrains.init_livery_template(mod_name, 1, dlxtrains.livery_type.standard, "T", "hopper_type2_t"),
  184. dlxtrains.init_livery_template(mod_name, 2, dlxtrains.livery_type.standard, "TT", "hopper_type2_tt"),
  185. dlxtrains.init_livery_template(mod_name, 3, dlxtrains.livery_type.middle_era, "NR", "hopper_type2_nr"),
  186. },
  187. ["dlxtrains_industrial_wagons:livestock_type1"] = {
  188. dlxtrains.init_livery_template(mod_name, 0, dlxtrains.livery_type.middle_era, "AR", "livestock_type1_ar"),
  189. dlxtrains.init_livery_template(mod_name, 1, dlxtrains.livery_type.middle_era, "AT", "livestock_type1_at"),
  190. dlxtrains.init_livery_template(mod_name, 2, dlxtrains.livery_type.standard, "T", "livestock_type1_t"),
  191. dlxtrains.init_livery_template(mod_name, 3, dlxtrains.livery_type.middle_era, "VR", "livestock_type1_vr"),
  192. },
  193. ["dlxtrains_industrial_wagons:open_type1"] = {
  194. dlxtrains.init_livery_template(mod_name, 0, dlxtrains.livery_type.middle_era, "AR", "open_type1_ar"),
  195. dlxtrains.init_livery_template(mod_name, 1, dlxtrains.livery_type.middle_era, "AT", "open_type1_at"),
  196. dlxtrains.init_livery_template(mod_name, 2, dlxtrains.livery_type.standard, "T", "open_type1_t"),
  197. dlxtrains.init_livery_template(mod_name, 3, dlxtrains.livery_type.middle_era, "VR", "open_type1_vr"),
  198. },
  199. ["dlxtrains_industrial_wagons:stake_type1"] = {
  200. dlxtrains.init_livery_template(mod_name, 0, dlxtrains.livery_type.standard, "T", "stake_type1_t"),
  201. dlxtrains.init_livery_template(mod_name, 1, dlxtrains.livery_type.standard, "DZ", "stake_type1_dz"),
  202. dlxtrains.init_livery_template(mod_name, 2, dlxtrains.livery_type.standard, "WF", "stake_type1_wf"),
  203. dlxtrains.init_livery_template(mod_name, 3, dlxtrains.livery_type.standard, "ZR", "stake_type1_zr"),
  204. },
  205. ["dlxtrains_industrial_wagons:tank_type1"] = {
  206. dlxtrains.init_livery_template(mod_name, 0, dlxtrains.livery_type.early_era, "DZ", "tank_type1_dz"),
  207. dlxtrains.init_livery_template(mod_name, 1, dlxtrains.livery_type.early_era, "T", "tank_type1_t"),
  208. dlxtrains.init_livery_template(mod_name, 2, dlxtrains.livery_type.early_era, "WF", "tank_type1_wf"),
  209. dlxtrains.init_livery_template(mod_name, 3, dlxtrains.livery_type.early_era, "ZR", "tank_type1_zr"),
  210. },
  211. ["dlxtrains_industrial_wagons:tank_type2"] = {
  212. dlxtrains.init_livery_template(mod_name, 0, dlxtrains.livery_type.early_era, "DZ", "tank_type2_dz"),
  213. dlxtrains.init_livery_template(mod_name, 1, dlxtrains.livery_type.early_era, "T", "tank_type2_t"),
  214. dlxtrains.init_livery_template(mod_name, 2, dlxtrains.livery_type.early_era, "WF", "tank_type2_wf"),
  215. dlxtrains.init_livery_template(mod_name, 3, dlxtrains.livery_type.early_era, "ZR", "tank_type2_zr"),
  216. },
  217. ["dlxtrains_industrial_wagons:transition_type1"] = {
  218. dlxtrains.init_livery_template(mod_name, 0, dlxtrains.livery_type.standard, "DL&X", "transition_type1_dlx"),
  219. dlxtrains.init_livery_template(mod_name, 1, dlxtrains.livery_type.standard, "T", "transition_type1_t"),
  220. },
  221. }
  222. -- ////////////////////////////////////////////////////////////////////////////////////
  223. local function is_filled_bucket(stack)
  224. local stack_name = stack:get_name()
  225. if minetest.get_modpath("default") then
  226. -- Any liquid registered with the bucket mod will be considered a valid liquid
  227. for bucket, def in pairs(bucket.liquids) do
  228. if def.itemname == stack_name then
  229. return true
  230. end
  231. end
  232. end
  233. if minetest.get_modpath("mcl_buckets") then
  234. -- Any liquid registered with the mcl_bucket mod will be considered a valid liquid
  235. for bucket, def in pairs(mcl_buckets.liquids) do
  236. if def.bucketname == stack_name then
  237. return true
  238. end
  239. end
  240. if stack_name == "mcl_mobitems:milk_bucket" then
  241. return true
  242. end
  243. end
  244. return false
  245. end
  246. local stackable_liquid_proxies = {}
  247. local function register_stackable_liquid_proxy(src_mod_name, item_name)
  248. if src_mod_name ~= nil and item_name ~= nil then
  249. if minetest.get_modpath(src_mod_name) then
  250. table.insert(stackable_liquid_proxies, item_name)
  251. end
  252. end
  253. end
  254. local technic_cans = {}
  255. if minetest.get_modpath("technic") then
  256. if technic.cans ~= nil then
  257. -- This version of the technic mod has a table of can definitions.
  258. -- Use it to build the local list of technic can names so that any
  259. -- changes to the list of cans will be supported automatically.
  260. for _, def in pairs(technic.cans) do
  261. technic_cans[def.can_name] = true
  262. end
  263. else
  264. -- This version of the technic mod lacks a table of can definitions.
  265. -- Define a hard-coded local list. Any changes to the list of cans
  266. -- will need to be manually updated here.
  267. technic_cans["technic:water_can"] = true
  268. technic_cans["technic:lava_can"] = true
  269. technic_cans["technic:river_water_can"] = true
  270. end
  271. end
  272. -- Register items defined in other mods that are stackable and that can be
  273. -- considered to be a liquid for the purpose of determining whether it
  274. -- should be shown as being transported in a shipping container or a tank
  275. -- container. These proxies are typically non-empty liquid containers.
  276. --
  277. -- While liquids in containers are not actually placed in tank containers
  278. -- in the real world, this was done here to make it easier for players to
  279. -- have wagons with tank containers in game when playing in survival mode.
  280. -- Please note, however, that these non-empty liquid containers
  281. -- might not be considered be liquids in a future release of this mod.
  282. --
  283. register_stackable_liquid_proxy("basic_materials", "basic_materials:oil_extract")
  284. register_stackable_liquid_proxy("biofuel", "biofuel:phial_fuel")
  285. register_stackable_liquid_proxy("biofuel", "biofuel:bottle_fuel")
  286. register_stackable_liquid_proxy("biofuel", "biofuel:fuel_can")
  287. register_stackable_liquid_proxy("farming", "farming:bottle_ethanol")
  288. register_stackable_liquid_proxy("farming", "farming:hemp_oil")
  289. register_stackable_liquid_proxy("pipeworks", "homedecor:oil_extract")
  290. register_stackable_liquid_proxy("technic", "technic:cottonseed_oil")
  291. register_stackable_liquid_proxy("technic", "technic:lox")
  292. if minetest.get_modpath("techage") then
  293. -- Note:
  294. -- The Techage mod limits the stack size of all of the following items
  295. -- to one. Thus, these items cannot be used for specifying the livery
  296. -- of a container. However, thay can still be used for triggering the
  297. -- appearance of ISO tank containers on a container wagon.
  298. -- Techage liquids:
  299. register_stackable_liquid_proxy("techage", "techage:bitumen")
  300. register_stackable_liquid_proxy("techage", "techage:epoxy")
  301. register_stackable_liquid_proxy("techage", "techage:fueloil")
  302. register_stackable_liquid_proxy("techage", "techage:gasoline")
  303. register_stackable_liquid_proxy("techage", "techage:lye")
  304. register_stackable_liquid_proxy("techage", "techage:naphtha")
  305. register_stackable_liquid_proxy("techage", "techage:redmud")
  306. -- Techage gases:
  307. register_stackable_liquid_proxy("techage", "techage:hydrogen")
  308. register_stackable_liquid_proxy("techage", "techage:isobutane")
  309. register_stackable_liquid_proxy("techage", "techage:gas")
  310. -- Filled Techage Barrels
  311. register_stackable_liquid_proxy("techage", "techage:ta3_barrel_bitumen") -- Bitumen
  312. register_stackable_liquid_proxy("techage", "techage:barrel_epoxy") -- Epoxide Resin
  313. register_stackable_liquid_proxy("techage", "techage:ta3_barrel_fueloil") -- Fuel Oil
  314. register_stackable_liquid_proxy("techage", "techage:ta3_barrel_gasoline") -- Gasoline
  315. register_stackable_liquid_proxy("techage", "techage:barrel_lye") -- Lye
  316. register_stackable_liquid_proxy("techage", "techage:ta3_barrel_naphtha") -- Naphtha
  317. register_stackable_liquid_proxy("techage", "techage:ta3_barrel_oil") -- Oil
  318. register_stackable_liquid_proxy("techage", "techage:barrel_redmud") -- Red Mud
  319. register_stackable_liquid_proxy("techage", "techage:barrel_river_water") -- River Water
  320. register_stackable_liquid_proxy("techage", "techage:barrel_water") -- Water
  321. -- Filled Techage Canisters
  322. register_stackable_liquid_proxy("techage", "techage:ta3_canister_bitumen") -- Bitumen
  323. register_stackable_liquid_proxy("techage", "techage:canister_epoxy") -- Epoxide Resin
  324. register_stackable_liquid_proxy("techage", "techage:ta3_canister_fueloil") -- Fuel Oil
  325. register_stackable_liquid_proxy("techage", "techage:ta3_canister_gasoline") -- Gasoline
  326. register_stackable_liquid_proxy("techage", "techage:canister_lye") -- Lye
  327. register_stackable_liquid_proxy("techage", "techage:ta3_canister_naphtha") -- Naphtha
  328. register_stackable_liquid_proxy("techage", "techage:ta3_canister_oil") -- Oil
  329. register_stackable_liquid_proxy("techage", "techage:canister_redmud") -- Red Mud
  330. -- Filled Techage Large Cylinders
  331. register_stackable_liquid_proxy("techage", "techage:cylinder_large_hydrogen") -- Hydrogen
  332. register_stackable_liquid_proxy("techage", "techage:ta4_cylinder_large_isobutane") -- Isobutane
  333. register_stackable_liquid_proxy("techage", "techage:ta3_cylinder_large_gas") -- Propane
  334. -- Filled Techage Small Cylinders
  335. register_stackable_liquid_proxy("techage", "techage:cylinder_small_hydrogen") -- Hydrogen
  336. register_stackable_liquid_proxy("techage", "techage:ta4_cylinder_small_isobutane") -- Isobutane
  337. register_stackable_liquid_proxy("techage", "techage:ta3_cylinder_small_gas") -- Propane
  338. end
  339. local function is_stackable_liquid_proxy(item_name)
  340. for _, proxy_name in ipairs(stackable_liquid_proxies) do
  341. if item_name == proxy_name then
  342. return true
  343. end
  344. end
  345. return false
  346. end
  347. local function get_liquid_count(stack)
  348. -- The liquid count is either the count of liquid nodes in the given stack or the
  349. -- amount of liquid in a liquid container since such containers do not stack.
  350. local liquid_count = 0
  351. if is_filled_bucket(stack) then
  352. -- Filled buckets neither stack nor contain more than one unit of liquid.
  353. liquid_count = 1
  354. elseif technic_cans[stack:get_name()] then
  355. -- Technic cans do not stack so use the quantity of liquid in the container.
  356. liquid_count = tonumber(stack:get_metadata()) or 0
  357. else
  358. local item_def = minetest.registered_items[stack:get_name()]
  359. if item_def then
  360. if item_def.groups.liquid or is_stackable_liquid_proxy(stack:get_name()) then
  361. -- This is a stackable liquid node so use the stack size to get the
  362. -- liquid count.
  363. liquid_count = stack:get_count()
  364. end
  365. end
  366. end
  367. return liquid_count
  368. end
  369. local function is_loose_material(node_def)
  370. if node_def and node_def.name ~= "" then
  371. if node_def.groups.soil
  372. or node_def.groups.sand
  373. or node_def.name == dlxtrains.materials.gravel
  374. or node_def.name == dlxtrains.materials.coalblock
  375. or node_def.name == dlxtrains.materials.permafrost
  376. or node_def.name == dlxtrains.materials.permafrost_with_stones
  377. or node_def.name == dlxtrains.materials.cobble then
  378. return true
  379. end
  380. end
  381. return false
  382. end
  383. local function get_crate_texture_index(wagon_id, quantity)
  384. return (wagon_id + quantity) % crate_texture_count
  385. end
  386. -- ////////////////////////////////////////////////////////////////////////////////////
  387. local animal_types = {
  388. ["mobs_animal:cow"] = "cow",
  389. ["mobs_animal:cow_set"] = "cow",
  390. ["animalia:spawn_cow"] = "cow",
  391. ["animalia:cow"] = "cow",
  392. ["mob_horse:horse"] = "horse",
  393. ["mob_horse:horse_set"] = "horse",
  394. ["animalia:spawn_horse"] = "horse",
  395. ["animalia:horse"] = "horse",
  396. ["animalia:spawn_pig"] = "pig",
  397. ["mobs_animal:sheep"] = "sheep",
  398. ["animalia:spawn_sheep"] = "sheep",
  399. ["animalia:sheep"] = "sheep",
  400. ["mobs_animal:pumba"] = "warthog",
  401. ["mobs_animal:pumba_set"] = "warthog",
  402. }
  403. local function get_animal_type(stack)
  404. local stack_item = stack:get_name()
  405. if string.sub(stack_item, 1, 17) == "mobs_animal:sheep" then
  406. -- Remove the color string that the mobs_animal mod appends to sheep.
  407. stack_item = "mobs_animal:sheep"
  408. elseif stack_item == "animalia:net" or stack_item == "animalia:crate" then
  409. local meta = stack:get_meta()
  410. if meta then
  411. stack_item = meta:get_string("mob") or stack:get_name()
  412. end
  413. end
  414. return animal_types[stack_item]
  415. end
  416. local animal_info = {
  417. ["cow"] = {texture_count = 3, },
  418. ["horse"] = {texture_count = 5, },
  419. ["pig"] = {texture_count = 3, },
  420. ["sheep"] = {texture_count = 4, },
  421. ["warthog"] = {texture_count = 4, },
  422. }
  423. local function get_animal_texture(animal_type, rnd_number, quantity)
  424. local info = animal_info[animal_type]
  425. if info then
  426. local index = 1 + ((rnd_number + quantity) % info.texture_count)
  427. return dlxtrains.add_modifier_escaping("dlxtrains_industrial_wagons_animals_"..animal_type.."-"..index..".png")
  428. end
  429. return ""
  430. end
  431. local function play_animal_sound(wagon, wagon_id, cargo_stack)
  432. local animal_count = cargo_stack:get_count()
  433. if dlxtrains.wagon_sounds and animal_count > 0 then
  434. local count = animal_count
  435. if count > 99 then
  436. count = 99
  437. end
  438. -- Vary the frequency of the animals making a sound based on the number of
  439. -- animals. More animals should result in more frequent sounds.
  440. -- The following formula is an arbitrary curve with a range of 1500 to 210
  441. -- for the domain of 1 to 99. This should result in a count of 1
  442. -- triggering a sound once every few minutes and a count of 99 triggering
  443. -- a sound once every few seconds.
  444. local odds = math.floor(24000 * math.pow(count + 15, -1))
  445. if math.random(1, odds) == 1 then
  446. local animal_sounds = dlxtrains_animal_sounds.get_sounds(get_animal_type(cargo_stack))
  447. if animal_sounds and #animal_sounds > 0 then
  448. -- Play a random sound if more than one is available for the animal_type.
  449. local sound_idx = math.random(1, #animal_sounds)
  450. local animal_sound = animal_sounds[sound_idx]
  451. local sound_name = animal_sound.name
  452. local gain = math.random(animal_sound.gain - 10, animal_sound.gain + 10) / 100
  453. local pitch = math.random(90, 110) / 100
  454. minetest.sound_play(sound_name, {
  455. object = wagon,
  456. gain = gain,
  457. pitch = pitch,
  458. })
  459. end
  460. end
  461. end
  462. end
  463. -- ////////////////////////////////////////////////////////////////////////////////////
  464. local function get_valid_flat_wagon_load_texture(node_def, crate_texture_index)
  465. -- Return a texture that is appropriate for a flat wagon load. The default is for the load to
  466. -- appear as "in a shipping crate". For instance, sand would not appear as a block since it
  467. -- would collapse into a pile. Of course, it would be more appropriate for sand to be placed
  468. -- in a hopper or open wagon anyway...
  469. -- Note: Some nodes that would seem valid to appear as themselves on a flat wagon will still
  470. -- be shown as "in a crate". This is because only one texture is used for all sides of the
  471. -- node when rendered as a load on the wagon. Thus, any node that has more than 2 unique
  472. -- faces would likely appear obviously incorrect and so will be shown as "in a crate" instead.
  473. -- Even though two unique faces for a node can result in some loads appearing incorrect, it's
  474. -- not likely to be very obvious and so it is not shown as "in a crate".
  475. local texture = "dlxtrains_industrial_wagons_wooden_crate.png"
  476. if crate_texture_index > 0 and dlxtrains_industrial_wagons.get_crate_texture ~= nil then
  477. texture = dlxtrains_industrial_wagons.get_crate_texture(crate_texture_index)
  478. end
  479. if node_def.drawtype == "normal" and not is_loose_material(node_def) and node_def.tiles then
  480. if type(node_def.tiles) == "table" and node_def.tiles[1] and not node_def.tiles[3] then
  481. texture = node_def.tiles[1]
  482. end
  483. end
  484. return dlxtrains.add_modifier_escaping(texture)
  485. end
  486. local function get_shipping_container_livery_id(wagon_id, quantity)
  487. return (wagon_id + quantity) % shipping_container_livery_count
  488. end
  489. local function get_shipping_container_texture(livery_id)
  490. if dlxtrains_industrial_wagons.get_shipping_container_texture ~= nil then
  491. return dlxtrains_industrial_wagons.get_shipping_container_texture(livery_id)
  492. end
  493. return "invalid.png"
  494. end
  495. local function get_shipping_container_overlay(livery_id, y)
  496. local overlay_texture = ""
  497. if livery_id > 0 then -- livery_id 0 is reserved for the container livery defined by the current livery of the wagon.
  498. overlay_texture = ":0,"..y.."="..get_shipping_container_texture(livery_id).."\\^\\[resize\\:216x32"
  499. end
  500. return overlay_texture
  501. end
  502. local function get_tank_container_livery_id(wagon_id, quantity)
  503. return (wagon_id + quantity) % tank_container_livery_count
  504. end
  505. local function get_tank_container_texture(livery_id)
  506. if dlxtrains_industrial_wagons.get_tank_container_texture ~= nil then
  507. return dlxtrains_industrial_wagons.get_tank_container_texture(livery_id)
  508. end
  509. return "invalid.png"
  510. end
  511. local function get_default_tank_container_texture(livery_code)
  512. return "dlxtrains_industrial_wagons_default_tank_container_"..livery_code..".png"
  513. end
  514. local function get_tank_container_overlay(livery_id, livery_code, y)
  515. local overlay_texture = ":0,"..y.."="
  516. if livery_id > 0 then
  517. -- Use a tank container livery from the set of extra liveries.
  518. overlay_texture = overlay_texture..get_tank_container_texture(livery_id)
  519. else
  520. -- Use the container livery corresponding to the current livery of the wagon.
  521. overlay_texture = overlay_texture..get_default_tank_container_texture(livery_code)
  522. end
  523. overlay_texture = overlay_texture.."\\^\\[resize\\:232x32"
  524. return overlay_texture
  525. end
  526. -- ////////////////////////////////////////////////////////////////////////////////////
  527. local function update_model_industrial_wagon_container(wagon, data, texture_file, meshes, livery_code)
  528. local updated_texture = texture_file
  529. -- Assume the wagon is not loaded
  530. wagon.object:set_properties({
  531. mesh = meshes.default
  532. })
  533. local inv = minetest.get_inventory({type="detached", name="advtrains_wgn_"..data.id})
  534. if inv and not inv:is_empty("box") then
  535. local occupied_slots = 1
  536. local stack1 = inv:get_stack("box", 1)
  537. local stack17 = inv:get_stack("box", 17)
  538. if stack1:get_count() > 0 and stack17:get_count() > 0 then
  539. occupied_slots = 2
  540. end
  541. local liquid_count1 = get_liquid_count(stack1)
  542. local liquid_count17 = get_liquid_count(stack17)
  543. -- Update texture to include appropriate shipping and/or tank container overlays
  544. local overlay_y_offset = {[1]=64, [2]=96}
  545. updated_texture = "[combine:256x256:0,0=("..texture_file..")"
  546. if liquid_count1 > 0 or (occupied_slots == 1 and liquid_count17 > 0) then
  547. -- The first or only container is a tank container
  548. local livery_id = get_tank_container_livery_id(data.id, liquid_count1)
  549. if occupied_slots == 1 and stack17:get_count() > 0 then
  550. -- stack1 is empty but stack17 is not so use it to determine the livery_id
  551. livery_id = get_tank_container_livery_id(data.id, liquid_count17)
  552. end
  553. updated_texture = updated_texture..get_tank_container_overlay(livery_id, livery_code, overlay_y_offset[1])
  554. else
  555. -- The first or only container is a shipping container
  556. local livery_id = get_shipping_container_livery_id(data.id, stack1:get_count())
  557. if stack1:get_count() == 0 and stack17:get_count() > 0 then
  558. -- stack1 is empty but stack17 is not so use it to determine the livery_id
  559. livery_id = get_shipping_container_livery_id(data.id, stack17:get_count())
  560. end
  561. updated_texture = updated_texture..get_shipping_container_overlay(livery_id, overlay_y_offset[1])
  562. end
  563. if occupied_slots > 1 then
  564. if liquid_count17 > 0 then
  565. -- The second container is a tank container
  566. local livery_id = get_tank_container_livery_id(data.id, liquid_count17)
  567. updated_texture = updated_texture..get_tank_container_overlay(livery_id, livery_code, overlay_y_offset[2])
  568. else
  569. -- The second container is a shipping container
  570. local livery_id = get_shipping_container_livery_id(data.id, stack17:get_count())
  571. updated_texture = updated_texture..get_shipping_container_overlay(livery_id, overlay_y_offset[2])
  572. end
  573. end
  574. -- Use a mesh that corresponds to the number of shipping containers/tank containers to be shown.
  575. -- Since the wagon's inventory is not empty, one of the following cases will apply:
  576. --
  577. -- Case Mesh to use
  578. -- ---------------------------------- -----------
  579. -- 1 shipping container load_a
  580. -- 1 shipping container and 1 tank container load_ab
  581. -- 2 shipping containers load_aa
  582. -- 1 tank container load_b
  583. -- 1 tank container and 1 shipping container load_ba
  584. -- 2 tank containers load_bb
  585. local mesh_with_load = meshes.load_a
  586. if liquid_count1 > 0 or liquid_count17 > 0 then
  587. mesh_with_load = meshes.load_b
  588. end
  589. if occupied_slots > 1 then
  590. mesh_with_load = meshes.load_aa
  591. if liquid_count1 > 0 and liquid_count17 > 0 then
  592. mesh_with_load = meshes.load_bb
  593. elseif liquid_count1 > 0 then
  594. mesh_with_load = meshes.load_ba
  595. elseif liquid_count17 > 0 then
  596. mesh_with_load = meshes.load_ab
  597. end
  598. end
  599. wagon.object:set_properties({
  600. mesh = mesh_with_load
  601. })
  602. end
  603. return updated_texture
  604. end
  605. local function update_model_industrial_wagon_flat(wagon, data, texture_file, meshes)
  606. local updated_texture = texture_file
  607. -- Assume the wagon is not loaded
  608. wagon.object:set_properties({
  609. mesh = meshes.default
  610. })
  611. local inv = minetest.get_inventory({type="detached", name="advtrains_wgn_"..data.id})
  612. if inv and not inv:is_empty("box") then
  613. -- Show at least one crate as a load on the wagon since the inventory is not empty.
  614. -- Show additional crates depending on how many selected "target" slots are occupied.
  615. -- These target slots are currently 1, 9 and 17. They were chosen because they should
  616. -- provide a sense of how full the wagon's inventory might be when automatic loading
  617. -- is used. Thus, one crate represents the wagon being < 1/3 filled, three crates
  618. -- represent the wagon being less than 2/3 filled and five crates represent the wagon
  619. -- being mostly filled. Alternatively, a player may choose to fill the target slots
  620. -- manually in order to achieve a specific appearance for the wagon regardless of how
  621. -- full the wagon may be. That is an intended feature of this approach.
  622. local stack1 = inv:get_stack("box", 1)
  623. local stack2 = inv:get_stack("box", 9)
  624. local stack3 = inv:get_stack("box", 17)
  625. local node_def1 = minetest.registered_nodes[stack1:get_name()]
  626. local node_def2 = minetest.registered_nodes[stack2:get_name()]
  627. local node_def3 = minetest.registered_nodes[stack3:get_name()]
  628. local occupied_slots = 0 -- This is only the count of occupied target slots, not the count of all occupied slots
  629. if not stack1:is_empty() then occupied_slots = occupied_slots + 1 end
  630. if not stack2:is_empty() then occupied_slots = occupied_slots + 1 end
  631. if not stack3:is_empty() then occupied_slots = occupied_slots + 1 end
  632. if occupied_slots > 0 then
  633. updated_texture = "[combine:256x256:0,0=("..texture_file..")"
  634. if node_def1 then
  635. updated_texture = updated_texture..":0,112="..get_valid_flat_wagon_load_texture(node_def1,get_crate_texture_index(data.id,stack1:get_count())).."\\^\\[resize\\:16x16"
  636. end
  637. if node_def2 then
  638. local x = 16
  639. if stack1:is_empty() then x = 0 end
  640. updated_texture = updated_texture..":"..x..",112="..get_valid_flat_wagon_load_texture(node_def2,get_crate_texture_index(data.id,stack2:get_count())).."\\^\\[resize\\:16x16"
  641. end
  642. if node_def3 then
  643. local x = 32
  644. if stack1:is_empty() and stack2:is_empty() then
  645. x = 0
  646. elseif stack2:is_empty() then
  647. x = 16
  648. end
  649. updated_texture = updated_texture..":"..x..",112="..get_valid_flat_wagon_load_texture(node_def3,get_crate_texture_index(data.id,stack3:get_count())).."\\^\\[resize\\:16x16"
  650. end
  651. end
  652. -- Use a mesh that corresponds to the number of nodes/crates to be shown.
  653. local mesh_with_load = meshes.loaded1
  654. if occupied_slots == 2 then
  655. mesh_with_load = meshes.loaded3
  656. elseif occupied_slots == 3 then
  657. mesh_with_load = meshes.loaded5
  658. end
  659. wagon.object:set_properties({
  660. mesh = mesh_with_load
  661. })
  662. end
  663. return updated_texture
  664. end
  665. local function update_model_industrial_wagon_hopper(wagon, data, texture_file, meshes)
  666. -- Assume the wagon is not loaded
  667. wagon.object:set_properties({
  668. mesh = meshes.default
  669. })
  670. local inv = minetest.get_inventory({type="detached", name="advtrains_wgn_"..data.id})
  671. if inv and not inv:is_empty("box") then
  672. local stack = inv:get_stack("box", 1)
  673. local node_def = minetest.registered_nodes[stack:get_name()]
  674. local item_def = minetest.registered_items[stack:get_name()]
  675. if node_def or item_def then
  676. -- Use the "loaded" version of the wagon model even if the inventory isn't appropriate for a hopper wagon.
  677. -- In such cases, a default texture will be used which will represent a generic load.
  678. wagon.object:set_properties({
  679. mesh = meshes.loaded
  680. })
  681. -- Use an applicable texture for the load. Note that in some cases the texture may differ
  682. -- from the actual item's texture so that it appears reasonable as cargo in the wagon.
  683. local load_node_name = nil
  684. if is_loose_material(node_def) then
  685. load_node_name = node_def.name
  686. elseif item_def then
  687. if item_def.name == dlxtrains.materials.coal_lump or item_def.name == "technic:coal_dust" then
  688. load_node_name = dlxtrains.materials.coalblock
  689. end
  690. end
  691. if load_node_name then
  692. local load_node_def = minetest.registered_nodes[load_node_name]
  693. if load_node_def then
  694. if load_node_def.drawtype == "normal" then
  695. local texture = load_node_def.tiles or "dlxtrains_mixed_material.png"
  696. if type(texture) == "table" then
  697. texture = texture[1] or "dlxtrains_mixed_material.png"
  698. end
  699. local texture_clause = dlxtrains.add_modifier_escaping(texture).."\\^\\[resize\\:16x16"
  700. return "[combine:256x256:0,0=("..texture_file..
  701. "):128,32="..texture_clause..
  702. ":144,32="..texture_clause..
  703. ":160,32="..texture_clause..
  704. ":176,32="..texture_clause..
  705. ":192,32="..texture_clause..
  706. ":208,32="..texture_clause..
  707. ":128,48="..texture_clause..
  708. ":144,48="..texture_clause..
  709. ":160,48="..texture_clause..
  710. ":176,48="..texture_clause..
  711. ":192,48="..texture_clause..
  712. ":208,48="..texture_clause
  713. end
  714. end
  715. end
  716. end
  717. end
  718. return texture_file
  719. end
  720. local function update_model_industrial_wagon_livestock(wagon, data, texture_file, meshes)
  721. local updated_texture = texture_file
  722. -- Assume the wagon is not loaded
  723. wagon.object:set_properties({
  724. mesh = meshes.default
  725. })
  726. local inv = minetest.get_inventory({type="detached", name="advtrains_wgn_"..data.id})
  727. if inv and not inv:is_empty("box") then
  728. local stack = inv:get_stack("box", 1)
  729. updated_texture = "[combine:256x256:0,0=("..texture_file..")"
  730. -- Use the texture and mesh that corresponds to the detected load. Note that the
  731. -- default texture includes the crate texture for the loaded model. The applicable
  732. -- animal texture will overlay the crate textures since they won't be needed when
  733. -- animals are loaded.
  734. local mesh_with_load = meshes.loaded
  735. local animal_type = get_animal_type(stack)
  736. if animal_type then
  737. local pseudo_rnd_1 = data.id -- A pseudo random number based on the wagon's id.
  738. local pseudo_rnd_2 = math.floor(data.id/10) -- A pseudo random number based on the wagon's id.
  739. local stack_count = stack:get_count()
  740. updated_texture = updated_texture..":0,96="..get_animal_texture(animal_type, pseudo_rnd_1, stack_count).."\\^\\[resize\\:32x32"
  741. updated_texture = updated_texture..":32,96="..get_animal_texture(animal_type, pseudo_rnd_2, stack_count).."\\^\\[resize\\:32x32"
  742. mesh_with_load = meshes.animal_load[animal_type]
  743. else
  744. local node_def = minetest.registered_nodes[stack:get_name()]
  745. if node_def ~= nil then
  746. local x = 16 -- Overlay the middle crate texture to indicate the load type.
  747. updated_texture = updated_texture..":"..x..",112="..get_valid_flat_wagon_load_texture(node_def, get_crate_texture_index(data.id, stack:get_count())).."\\^\\[resize\\:16x16"
  748. end
  749. end
  750. wagon.object:set_properties({
  751. mesh = mesh_with_load
  752. })
  753. end
  754. return updated_texture
  755. end
  756. local function update_model_industrial_wagon_open(wagon, data, texture_file, meshes)
  757. -- Assume the wagon is not loaded
  758. wagon.object:set_properties({
  759. mesh = meshes.default
  760. })
  761. local inv = minetest.get_inventory({type="detached", name="advtrains_wgn_"..data.id})
  762. if inv and not inv:is_empty("box") then
  763. local stack = inv:get_stack("box", 1)
  764. local node_def = minetest.registered_nodes[stack:get_name()]
  765. local item_def = minetest.registered_items[stack:get_name()]
  766. if node_def or item_def then
  767. wagon.object:set_properties({
  768. mesh = meshes.loaded
  769. })
  770. -- Use an applicable texture for the load. Note that in some cases the texture may differ
  771. -- from the actual item's texture so that it appears reasonable as cargo in the wagon.
  772. local load_node_name = nil
  773. if is_loose_material(node_def) then
  774. load_node_name = node_def.name
  775. elseif item_def then
  776. if item_def.name == dlxtrains.materials.coal_lump or item_def.name == "technic:coal_dust" then
  777. load_node_name = dlxtrains.materials.coalblock
  778. end
  779. end
  780. if load_node_name then
  781. -- Note: Only the material in slot 1 can trigger this load representation.
  782. local load_node_def = minetest.registered_nodes[load_node_name]
  783. if load_node_def then
  784. if load_node_def.drawtype == "normal" then
  785. local texture = load_node_def.tiles or "dlxtrains_mixed_material.png"
  786. if type(texture) == "table" then
  787. texture = texture[1] or "dlxtrains_mixed_material.png"
  788. end
  789. local texture_clause = dlxtrains.add_modifier_escaping(texture).."\\^\\[resize\\:16x16"
  790. return "[combine:256x256:0,0=("..texture_file..
  791. "):80,112="..texture_clause..
  792. ":96,112="..texture_clause..
  793. ":112,112="..texture_clause..
  794. ":128,112="..texture_clause..
  795. ":144,112="..texture_clause..
  796. ":160,112="..texture_clause..
  797. ":80,128="..texture_clause..
  798. ":96,128="..texture_clause..
  799. ":112,128="..texture_clause..
  800. ":128,128="..texture_clause..
  801. ":144,128="..texture_clause..
  802. ":160,128="..texture_clause
  803. end
  804. end
  805. else
  806. -- The load isn't appropriate for an open wagon (i.e. it's not a loose
  807. -- material such as coal, dirt or sand), so use another representation.
  808. -- If inventory slot 1 contains a craft item then use the canvas/tarpaulin covered open wagon.
  809. if item_def and item_def.type == "craft" and meshes.covered then
  810. wagon.object:set_properties({
  811. mesh = meshes.covered
  812. })
  813. return texture_file
  814. end
  815. -- If inventory slot 1 contains a tree node then show the wagon without doors and loaded with logs.
  816. if node_def and node_def.groups.tree and meshes.log_load then
  817. wagon.object:set_properties({
  818. mesh = meshes.log_load
  819. })
  820. local tree_side = "default_tree_top.png"
  821. local tree_end = "default_tree.png"
  822. if type(node_def.tiles) == "table" and node_def.tiles[1] and node_def.tiles[3] then
  823. tree_end = node_def.tiles[1]
  824. tree_side = node_def.tiles[3]
  825. end
  826. local tree_end_texture = dlxtrains.add_modifier_escaping(tree_end).."\\^\\[resize\\:16x16"
  827. local tree_side_texture = dlxtrains.add_modifier_escaping(tree_side).."\\^\\[resize\\:16x16"
  828. return "[combine:256x256:0,0=("..texture_file.."):48,112="..tree_end_texture..":64,112="..tree_side_texture
  829. end
  830. -- If none of the above is true then handle the load as a flat wagon.
  831. return update_model_industrial_wagon_flat(wagon, data, texture_file, meshes)
  832. end
  833. end
  834. end
  835. return texture_file
  836. end
  837. local function update_model_industrial_wagon_stake(wagon, data, texture_file, meshes)
  838. local updated_texture = texture_file
  839. -- Assume the wagon is not loaded
  840. wagon.object:set_properties({
  841. mesh = meshes.default
  842. })
  843. local inv = minetest.get_inventory({type="detached", name="advtrains_wgn_"..data.id})
  844. if inv and not inv:is_empty("box") then
  845. local stack = inv:get_stack("box", 1)
  846. local node_def = minetest.registered_nodes[stack:get_name()]
  847. -- If inventory slot 1 is not a tree node then handle the load as a flat wagon.
  848. if not node_def or not node_def.groups.tree then
  849. return update_model_industrial_wagon_flat(wagon, data, texture_file, meshes)
  850. end
  851. if meshes.log_load then
  852. wagon.object:set_properties({
  853. mesh = meshes.log_load
  854. })
  855. local tree_side = "default_tree_top.png"
  856. local tree_end = "default_tree.png"
  857. if type(node_def.tiles) == "table" and node_def.tiles[1] and node_def.tiles[3] then
  858. tree_end = node_def.tiles[1]
  859. tree_side = node_def.tiles[3]
  860. end
  861. local tree_end_texture = dlxtrains.add_modifier_escaping(tree_end).."\\^\\[resize\\:16x16"
  862. local tree_side_texture = dlxtrains.add_modifier_escaping(tree_side).."\\^\\[resize\\:16x16"
  863. return "[combine:256x256:0,0=("..texture_file.."):48,112="..tree_end_texture..":64,112="..tree_side_texture
  864. end
  865. end
  866. return updated_texture
  867. end
  868. local function get_wagon_proprties_button_spec(wagon_id, pname, x, y)
  869. local button_spec = ""
  870. if advtrains.wagons[wagon_id].owner == pname then
  871. button_spec = "button_exit["..x..","..y..";4,1;prop;"..S("Wagon properties").."]"
  872. end
  873. return button_spec
  874. end
  875. -- ////////////////////////////////////////////////////////////////////////////////////
  876. local meshes_industrial_wagon_container_type1 = {
  877. default = "dlxtrains_industrial_wagons_container_type1.b3d",
  878. load_a = "dlxtrains_industrial_wagons_container_type1_a.b3d",
  879. load_aa = "dlxtrains_industrial_wagons_container_type1_aa.b3d",
  880. load_ab = "dlxtrains_industrial_wagons_container_type1_ab.b3d",
  881. load_b = "dlxtrains_industrial_wagons_container_type1_b.b3d",
  882. load_ba = "dlxtrains_industrial_wagons_container_type1_ba.b3d",
  883. load_bb = "dlxtrains_industrial_wagons_container_type1_bb.b3d",
  884. update_model = function(wagon, data, texture_file, meshes)
  885. return update_model_industrial_wagon_container(wagon, data, texture_file, meshes, livery_scheme_industrial_wagon_container_type1[data.scheme_id or 0].code)
  886. end,
  887. }
  888. local meshes_industrial_wagon_container_type2 = {
  889. default = "dlxtrains_industrial_wagons_container_type2.b3d",
  890. load_a = "dlxtrains_industrial_wagons_container_type2_a.b3d",
  891. load_b = "dlxtrains_industrial_wagons_container_type2_b.b3d",
  892. update_model = function(wagon, data, texture_file, meshes)
  893. return update_model_industrial_wagon_container(wagon, data, texture_file, meshes, livery_scheme_industrial_wagon_container_type2[data.scheme_id or 0].code)
  894. end,
  895. }
  896. local meshes_industrial_wagon_covered_goods_type1 = {
  897. default = "dlxtrains_industrial_wagons_covered_goods_type1.obj",
  898. }
  899. local meshes_industrial_wagon_covered_goods_type2 = {
  900. default = "dlxtrains_industrial_wagons_covered_goods_type2.obj",
  901. }
  902. local meshes_industrial_wagon_covered_goods_type3 = {
  903. default = "dlxtrains_industrial_wagons_covered_goods_type3.obj",
  904. }
  905. local meshes_industrial_wagon_flat_type1 = {
  906. default = "dlxtrains_industrial_wagons_flat_type1.obj",
  907. loaded1 = "dlxtrains_industrial_wagons_flat_type1_loaded1.obj",
  908. loaded3 = "dlxtrains_industrial_wagons_flat_type1_loaded3.obj",
  909. loaded5 = "dlxtrains_industrial_wagons_flat_type1_loaded5.obj",
  910. update_model = function(wagon, data, texture_file, meshes)
  911. return update_model_industrial_wagon_flat(wagon, data, texture_file, meshes)
  912. end,
  913. }
  914. local meshes_industrial_wagon_flat_type2 = {
  915. default = "dlxtrains_industrial_wagons_flat_type2.b3d",
  916. loaded1 = "dlxtrains_industrial_wagons_flat_type2_loaded1.b3d",
  917. loaded3 = "dlxtrains_industrial_wagons_flat_type2_loaded3.b3d",
  918. loaded5 = "dlxtrains_industrial_wagons_flat_type2_loaded5.b3d",
  919. update_model = function(wagon, data, texture_file, meshes)
  920. return update_model_industrial_wagon_flat(wagon, data, texture_file, meshes)
  921. end,
  922. }
  923. local meshes_industrial_wagon_hopper_type1 = {
  924. default = "dlxtrains_industrial_wagons_hopper_type1.obj",
  925. loaded = "dlxtrains_industrial_wagons_hopper_type1_loaded.obj",
  926. update_model = function(wagon, data, texture_file, meshes)
  927. return update_model_industrial_wagon_hopper(wagon, data, texture_file, meshes)
  928. end,
  929. }
  930. local meshes_industrial_wagon_hopper_type2 = {
  931. default = "dlxtrains_industrial_wagons_hopper_type2.obj",
  932. }
  933. local meshes_industrial_wagon_livestock_type1 = {
  934. default = "dlxtrains_industrial_wagons_livestock_type1.b3d",
  935. loaded = "dlxtrains_industrial_wagons_livestock_type1_loaded.b3d",
  936. animal_load = {
  937. ["cow"] = "dlxtrains_industrial_wagons_livestock_type1_cows.b3d",
  938. ["horse"] = "dlxtrains_industrial_wagons_livestock_type1_horses.b3d",
  939. ["pig"] = "dlxtrains_industrial_wagons_livestock_type1_pigs.b3d",
  940. ["sheep"] = "dlxtrains_industrial_wagons_livestock_type1_sheep.b3d",
  941. ["warthog"] = "dlxtrains_industrial_wagons_livestock_type1_warthogs.b3d",
  942. },
  943. update_model = function(wagon, data, texture_file, meshes)
  944. return update_model_industrial_wagon_livestock(wagon, data, texture_file, meshes)
  945. end,
  946. }
  947. local meshes_industrial_wagon_open_type1 = {
  948. default = "dlxtrains_industrial_wagons_open_type1.b3d",
  949. loaded = "dlxtrains_industrial_wagons_open_type1_loaded.b3d",
  950. loaded1 = "dlxtrains_industrial_wagons_open_type1_loaded1.b3d",
  951. loaded3 = "dlxtrains_industrial_wagons_open_type1_loaded3.b3d",
  952. loaded5 = "dlxtrains_industrial_wagons_open_type1_loaded5.b3d",
  953. covered = "dlxtrains_industrial_wagons_open_type1_covered.b3d",
  954. log_load = "dlxtrains_industrial_wagons_open_type1_logs.b3d",
  955. update_model = function(wagon, data, texture_file, meshes)
  956. return update_model_industrial_wagon_open(wagon, data, texture_file, meshes)
  957. end,
  958. }
  959. local meshes_industrial_wagon_stake_type1 = {
  960. default = "dlxtrains_industrial_wagons_stake_type1.obj",
  961. loaded1 = "dlxtrains_industrial_wagons_stake_type1_loaded1.obj",
  962. loaded3 = "dlxtrains_industrial_wagons_stake_type1_loaded3.obj",
  963. loaded5 = "dlxtrains_industrial_wagons_stake_type1_loaded5.obj",
  964. log_load = "dlxtrains_industrial_wagons_stake_type1_logs.obj",
  965. update_model = function(wagon, data, texture_file, meshes)
  966. return update_model_industrial_wagon_stake(wagon, data, texture_file, meshes)
  967. end,
  968. }
  969. local meshes_industrial_wagon_tank_type1 = {
  970. default = "dlxtrains_industrial_wagons_tank_type1.b3d",
  971. }
  972. local meshes_industrial_wagon_tank_type2 = {
  973. default = "dlxtrains_industrial_wagons_tank_type2.b3d",
  974. }
  975. local meshes_industrial_wagon_transition_type1 = {
  976. default = "dlxtrains_industrial_wagons_transition_type1.obj",
  977. loaded1 = "dlxtrains_industrial_wagons_transition_type1_loaded1.obj",
  978. loaded3 = "dlxtrains_industrial_wagons_transition_type1_loaded3.obj",
  979. loaded5 = "dlxtrains_industrial_wagons_transition_type1_loaded5.obj",
  980. update_model = function(wagon, data, texture_file, meshes)
  981. return update_model_industrial_wagon_flat(wagon, data, texture_file, meshes)
  982. end,
  983. }
  984. -- ////////////////////////////////////////////////////////////////////////////////////
  985. if dlxtrains_industrial_wagons.max_wagon_length >= 8.5 then
  986. local wagon_type = "dlxtrains_industrial_wagons:container_type1"
  987. dlxtrains.register_livery_templates(wagon_type, mod_name, livery_templates)
  988. advtrains.register_wagon(wagon_type, {
  989. mesh = meshes_industrial_wagon_container_type1.default,
  990. textures = {dlxtrains.get_init_texture()},
  991. set_textures = function(wagon, data)
  992. dlxtrains.set_textures_for_livery_scheme(wagon, data, livery_scheme_industrial_wagon_container_type1, meshes_industrial_wagon_container_type1)
  993. end,
  994. custom_may_destroy = function(wagon, puncher, time_from_last_punch, tool_capabilities, direction)
  995. return not dlxtrains.update_livery(wagon, puncher, livery_scheme_industrial_wagon_container_type1)
  996. end,
  997. seats = {},
  998. drives_on={default=true},
  999. max_speed=20,
  1000. visual_size = {x=1, y=1},
  1001. wagon_span=4.25,
  1002. wheel_positions = {2.6875, -2.6875},
  1003. collisionbox = {-1.0,-0.5,-1.0,1.0,2.5,1.0},
  1004. coupler_types_front = {chain=true},
  1005. coupler_types_back = {chain=true},
  1006. drops={dlxtrains.materials.steelblock},
  1007. has_inventory = true,
  1008. get_inventory_formspec = function(wagon, pname, invname)
  1009. return "size[8,9]"..
  1010. "box[0,0;.8,.88;#077]".. -- Highlight slots that impact visible loads
  1011. "box[0,2;.8,.88;#077]"..
  1012. "list["..invname..";box;0,0;8,4;]"..
  1013. "list[current_player;main;0,5;8,4;]"..
  1014. "listring[]"..
  1015. get_wagon_proprties_button_spec(wagon.id, pname, 2, 4)
  1016. end,
  1017. inventory_list_sizes = {
  1018. box=8*4,
  1019. },
  1020. }, S("European Container Wagon"), "dlxtrains_industrial_wagons_container_type1_inv.png")
  1021. end
  1022. if dlxtrains_industrial_wagons.max_wagon_length >= 4.875 then
  1023. local wagon_type = "dlxtrains_industrial_wagons:container_type2"
  1024. dlxtrains.register_livery_templates(wagon_type, mod_name, livery_templates)
  1025. advtrains.register_wagon(wagon_type, {
  1026. mesh = meshes_industrial_wagon_container_type2.default,
  1027. textures = {dlxtrains.get_init_texture()},
  1028. set_textures = function(wagon, data)
  1029. dlxtrains.set_textures_for_livery_scheme(wagon, data, livery_scheme_industrial_wagon_container_type2, meshes_industrial_wagon_container_type2)
  1030. end,
  1031. custom_may_destroy = function(wagon, puncher, time_from_last_punch, tool_capabilities, direction)
  1032. return not dlxtrains.update_livery(wagon, puncher, livery_scheme_industrial_wagon_container_type2)
  1033. end,
  1034. seats = {},
  1035. drives_on={default=true},
  1036. max_speed=20,
  1037. visual_size = {x=1, y=1},
  1038. wagon_span=2.4375,
  1039. wheel_positions = {1.5, -1.5},
  1040. collisionbox = {-1.0,-0.5,-1.0,1.0,2.5,1.0},
  1041. coupler_types_front = {chain=true},
  1042. coupler_types_back = {chain=true},
  1043. drops={dlxtrains.materials.steelblock},
  1044. has_inventory = true,
  1045. get_inventory_formspec = function(wagon, pname, invname)
  1046. return "size[8,7]"..
  1047. "box[0,0;.8,.88;#077]".. -- Highlight slot that impacts visible loads
  1048. "list["..invname..";box;0,0;8,2;]"..
  1049. "list[current_player;main;0,3;8,4;]"..
  1050. "listring[]"..
  1051. get_wagon_proprties_button_spec(wagon.id, pname, 2, 2)
  1052. end,
  1053. inventory_list_sizes = {
  1054. box=8*2,
  1055. },
  1056. }, S("European Single Container Wagon"), "dlxtrains_industrial_wagons_container_type2_inv.png")
  1057. end
  1058. if dlxtrains_industrial_wagons.max_wagon_length >= 8 then
  1059. local wagon_type = "dlxtrains_industrial_wagons:covered_goods_type1"
  1060. dlxtrains.register_livery_templates(wagon_type, mod_name, livery_templates)
  1061. advtrains.register_wagon(wagon_type, {
  1062. mesh = meshes_industrial_wagon_covered_goods_type1.default,
  1063. textures = {dlxtrains.get_init_texture()},
  1064. set_textures = function(wagon, data)
  1065. dlxtrains.set_textures_for_livery_scheme(wagon, data, livery_scheme_industrial_wagon_covered_goods_type1, meshes_industrial_wagon_covered_goods_type1)
  1066. end,
  1067. custom_may_destroy = function(wagon, puncher, time_from_last_punch, tool_capabilities, direction)
  1068. return not dlxtrains.update_livery(wagon, puncher, livery_scheme_industrial_wagon_covered_goods_type1)
  1069. end,
  1070. seats = {},
  1071. drives_on={default=true},
  1072. max_speed=25,
  1073. visual_size = {x=1, y=1},
  1074. wagon_span=4,
  1075. wheel_positions = {3.0, -3.0},
  1076. collisionbox = {-1.0,-0.5,-1.0,1.0,2.5,1.0},
  1077. coupler_types_front = {knuckle=true},
  1078. coupler_types_back = {knuckle=true},
  1079. drops={dlxtrains.materials.steelblock},
  1080. has_inventory = true,
  1081. get_inventory_formspec = function(wagon, pname, invname)
  1082. return "size[8,10]"..
  1083. "list["..invname..";box;0,0;8,5;]"..
  1084. "list[current_player;main;0,6;8,4;]"..
  1085. "listring[]"..
  1086. get_wagon_proprties_button_spec(wagon.id, pname, 2, 5)
  1087. end,
  1088. inventory_list_sizes = {
  1089. box=8*5,
  1090. },
  1091. }, S("North American Wooden Boxcar"), "dlxtrains_industrial_wagons_covered_goods_type1_inv.png")
  1092. end
  1093. if dlxtrains_industrial_wagons.max_wagon_length >= 8 then
  1094. local wagon_type = "dlxtrains_industrial_wagons:covered_goods_type2"
  1095. dlxtrains.register_livery_templates(wagon_type, mod_name, livery_templates)
  1096. advtrains.register_wagon(wagon_type, {
  1097. mesh = meshes_industrial_wagon_covered_goods_type2.default,
  1098. textures = {dlxtrains.get_init_texture()},
  1099. set_textures = function(wagon, data)
  1100. dlxtrains.set_textures_for_livery_scheme(wagon, data, livery_scheme_industrial_wagon_covered_goods_type2, meshes_industrial_wagon_covered_goods_type2)
  1101. end,
  1102. custom_may_destroy = function(wagon, puncher, time_from_last_punch, tool_capabilities, direction)
  1103. return not dlxtrains.update_livery(wagon, puncher, livery_scheme_industrial_wagon_covered_goods_type2)
  1104. end,
  1105. seats = {},
  1106. drives_on={default=true},
  1107. max_speed=25,
  1108. visual_size = {x=1, y=1},
  1109. wagon_span=4,
  1110. wheel_positions = {2.8, -2.8},
  1111. collisionbox = {-1.0,-0.5,-1.0,1.0,2.5,1.0},
  1112. coupler_types_front = {knuckle=true},
  1113. coupler_types_back = {knuckle=true},
  1114. drops={dlxtrains.materials.steelblock},
  1115. has_inventory = true,
  1116. get_inventory_formspec = function(wagon, pname, invname)
  1117. return "size[8,10]"..
  1118. "list["..invname..";box;0,0;8,5;]"..
  1119. "list[current_player;main;0,6;8,4;]"..
  1120. "listring[]"..
  1121. get_wagon_proprties_button_spec(wagon.id, pname, 2, 5)
  1122. end,
  1123. inventory_list_sizes = {
  1124. box=8*5,
  1125. },
  1126. }, S("Australian Louver Van"), "dlxtrains_industrial_wagons_covered_goods_type2_inv.png")
  1127. end
  1128. if dlxtrains_industrial_wagons.max_wagon_length >= 7 then
  1129. local wagon_type = "dlxtrains_industrial_wagons:covered_goods_type3"
  1130. dlxtrains.register_livery_templates(wagon_type, mod_name, livery_templates)
  1131. advtrains.register_wagon(wagon_type, {
  1132. mesh = meshes_industrial_wagon_covered_goods_type3.default,
  1133. textures = {dlxtrains.get_init_texture()},
  1134. set_textures = function(wagon, data)
  1135. dlxtrains.set_textures_for_livery_scheme(wagon, data, livery_scheme_industrial_wagon_covered_goods_type3, meshes_industrial_wagon_covered_goods_type3)
  1136. end,
  1137. custom_may_destroy = function(wagon, puncher, time_from_last_punch, tool_capabilities, direction)
  1138. return not dlxtrains.update_livery(wagon, puncher, livery_scheme_industrial_wagon_covered_goods_type3)
  1139. end,
  1140. seats = {},
  1141. drives_on={default=true},
  1142. max_speed=20,
  1143. visual_size = {x=1, y=1},
  1144. wagon_span=3.5,
  1145. wheel_positions = {2.0, -2.0},
  1146. collisionbox = {-1.0,-0.5,-1.0,1.0,2.5,1.0},
  1147. coupler_types_front = {chain=true},
  1148. coupler_types_back = {chain=true},
  1149. drops={dlxtrains.materials.steelblock},
  1150. has_inventory = true,
  1151. get_inventory_formspec = function(wagon, pname, invname)
  1152. return "size[8,9]"..
  1153. "list["..invname..";box;0,0;8,4;]"..
  1154. "list[current_player;main;0,5;8,4;]"..
  1155. "listring[]"..
  1156. get_wagon_proprties_button_spec(wagon.id, pname, 2, 4)
  1157. end,
  1158. inventory_list_sizes = {
  1159. box=8*4,
  1160. },
  1161. }, S("European Wooden Covered Goods Wagon"), "dlxtrains_industrial_wagons_covered_goods_type3_inv.png")
  1162. end
  1163. -- ////////////////////////////////////////////////////////////////////////////////////
  1164. if dlxtrains_industrial_wagons.max_wagon_length >= 6 then
  1165. local wagon_type = "dlxtrains_industrial_wagons:flat_type1"
  1166. dlxtrains.register_livery_templates(wagon_type, mod_name, livery_templates)
  1167. advtrains.register_wagon(wagon_type, {
  1168. mesh = meshes_industrial_wagon_flat_type1.default,
  1169. textures = {dlxtrains.get_init_texture()},
  1170. set_textures = function(wagon, data)
  1171. dlxtrains.set_textures_for_livery_scheme(wagon, data, livery_scheme_industrial_wagon_flat_type1, meshes_industrial_wagon_flat_type1)
  1172. end,
  1173. custom_may_destroy = function(wagon, puncher, time_from_last_punch, tool_capabilities, direction)
  1174. return not dlxtrains.update_livery(wagon, puncher, livery_scheme_industrial_wagon_flat_type1)
  1175. end,
  1176. seats = {},
  1177. drives_on={default=true},
  1178. max_speed=20,
  1179. visual_size = {x=1, y=1},
  1180. wagon_span=3,
  1181. wheel_positions = {2.0, -2.0},
  1182. collisionbox = {-1.0,-0.5,-1.0,1.0,2.5,1.0},
  1183. coupler_types_front = {chain=true},
  1184. coupler_types_back = {chain=true},
  1185. drops={dlxtrains.materials.steelblock},
  1186. has_inventory = true,
  1187. get_inventory_formspec = function(wagon, pname, invname)
  1188. return "size[8,8]"..
  1189. "box[0,0;.8,.88;#077]".. -- Highlight slots that impact visible loads
  1190. "box[0,1;.8,.88;#077]"..
  1191. "box[0,2;.8,.88;#077]"..
  1192. "list["..invname..";box;0,0;8,3;]"..
  1193. "list[current_player;main;0,4;8,4;]"..
  1194. "listring[]"..
  1195. get_wagon_proprties_button_spec(wagon.id, pname, 2, 3)
  1196. end,
  1197. inventory_list_sizes = {
  1198. box=8*3,
  1199. },
  1200. }, S("European Flat Wagon"), "dlxtrains_industrial_wagons_flat_type1_inv.png")
  1201. end
  1202. -- ////////////////////////////////////////////////////////////////////////////////////
  1203. if dlxtrains_industrial_wagons.max_wagon_length >= 6 then
  1204. local wagon_type = "dlxtrains_industrial_wagons:flat_type2"
  1205. dlxtrains.register_livery_templates(wagon_type, mod_name, livery_templates)
  1206. advtrains.register_wagon(wagon_type, {
  1207. mesh = meshes_industrial_wagon_flat_type2.default,
  1208. textures = {dlxtrains.get_init_texture()},
  1209. set_textures = function(wagon, data)
  1210. dlxtrains.set_textures_for_livery_scheme(wagon, data, livery_scheme_industrial_wagon_flat_type2, meshes_industrial_wagon_flat_type2)
  1211. end,
  1212. custom_may_destroy = function(wagon, puncher, time_from_last_punch, tool_capabilities, direction)
  1213. return not dlxtrains.update_livery(wagon, puncher, livery_scheme_industrial_wagon_flat_type2)
  1214. end,
  1215. seats = {},
  1216. drives_on={default=true},
  1217. max_speed=20,
  1218. visual_size = {x=1, y=1},
  1219. wagon_span=3,
  1220. wheel_positions = {2.0, -2.0},
  1221. collisionbox = {-1.0,-0.5,-1.0,1.0,2.5,1.0},
  1222. coupler_types_front = {knuckle=true},
  1223. coupler_types_back = {knuckle=true},
  1224. drops={dlxtrains.materials.steelblock},
  1225. has_inventory = true,
  1226. get_inventory_formspec = function(wagon, pname, invname)
  1227. return "size[8,8]"..
  1228. "box[0,0;.8,.88;#077]".. -- Highlight slots that impact visible loads
  1229. "box[0,1;.8,.88;#077]"..
  1230. "box[0,2;.8,.88;#077]"..
  1231. "list["..invname..";box;0,0;8,3;]"..
  1232. "list[current_player;main;0,4;8,4;]"..
  1233. "listring[]"..
  1234. get_wagon_proprties_button_spec(wagon.id, pname, 2, 3)
  1235. end,
  1236. inventory_list_sizes = {
  1237. box=8*3,
  1238. },
  1239. }, S("Australian Flat Wagon"), "dlxtrains_industrial_wagons_flat_type2_inv.png")
  1240. end
  1241. -- ////////////////////////////////////////////////////////////////////////////////////
  1242. if dlxtrains_industrial_wagons.max_wagon_length >= 6 then
  1243. local wagon_type = "dlxtrains_industrial_wagons:hopper_type1"
  1244. dlxtrains.register_livery_templates(wagon_type, mod_name, livery_templates)
  1245. advtrains.register_wagon(wagon_type, {
  1246. mesh = meshes_industrial_wagon_hopper_type1.default,
  1247. textures = {dlxtrains.get_init_texture()},
  1248. set_textures = function(wagon, data)
  1249. dlxtrains.set_textures_for_livery_scheme(wagon, data, livery_scheme_industrial_wagon_hopper_type1, meshes_industrial_wagon_hopper_type1)
  1250. end,
  1251. custom_may_destroy = function(wagon, puncher, time_from_last_punch, tool_capabilities, direction)
  1252. return not dlxtrains.update_livery(wagon, puncher, livery_scheme_industrial_wagon_hopper_type1)
  1253. end,
  1254. seats = {},
  1255. drives_on={default=true},
  1256. max_speed=25,
  1257. visual_size = {x=1, y=1},
  1258. wagon_span=3,
  1259. wheel_positions = {2.0, -2.0},
  1260. collisionbox = {-1.0,-0.5,-1.0,1.0,2.5,1.0},
  1261. coupler_types_front = {knuckle=true},
  1262. coupler_types_back = {knuckle=true},
  1263. drops={dlxtrains.materials.steelblock},
  1264. has_inventory = true,
  1265. get_inventory_formspec = function(wagon, pname, invname)
  1266. return "size[8,8]"..
  1267. "box[0,0;.8,.88;#077]".. -- Highlight slot that impacts visible loads
  1268. "list["..invname..";box;0,0;8,3;]"..
  1269. "list[current_player;main;0,4;8,4;]"..
  1270. "listring[]"..
  1271. get_wagon_proprties_button_spec(wagon.id, pname, 2, 3)
  1272. end,
  1273. inventory_list_sizes = {
  1274. box=8*3,
  1275. },
  1276. }, S("North American Hopper Wagon"), "dlxtrains_industrial_wagons_hopper_type1_inv.png")
  1277. end
  1278. -- ////////////////////////////////////////////////////////////////////////////////////
  1279. if dlxtrains_industrial_wagons.max_wagon_length >= 6 then
  1280. local wagon_type = "dlxtrains_industrial_wagons:hopper_type2"
  1281. dlxtrains.register_livery_templates(wagon_type, mod_name, livery_templates)
  1282. advtrains.register_wagon(wagon_type, {
  1283. mesh = meshes_industrial_wagon_hopper_type2.default,
  1284. textures = {dlxtrains.get_init_texture()},
  1285. set_textures = function(wagon, data)
  1286. dlxtrains.set_textures_for_livery_scheme(wagon, data, livery_scheme_industrial_wagon_hopper_type2, meshes_industrial_wagon_hopper_type2)
  1287. end,
  1288. custom_may_destroy = function(wagon, puncher, time_from_last_punch, tool_capabilities, direction)
  1289. return not dlxtrains.update_livery(wagon, puncher, livery_scheme_industrial_wagon_hopper_type2)
  1290. end,
  1291. seats = {},
  1292. drives_on={default=true},
  1293. max_speed=25,
  1294. visual_size = {x=1, y=1},
  1295. wagon_span=3,
  1296. wheel_positions = {2.0, -2.0},
  1297. collisionbox = {-1.0,-0.5,-1.0,1.0,2.5,1.0},
  1298. coupler_types_front = {knuckle=true},
  1299. coupler_types_back = {knuckle=true},
  1300. drops={dlxtrains.materials.steelblock},
  1301. has_inventory = true,
  1302. get_inventory_formspec = function(wagon, pname, invname)
  1303. return "size[8,8]"..
  1304. "list["..invname..";box;0,0;8,3;]"..
  1305. "list[current_player;main;0,4;8,4;]"..
  1306. "listring[]"..
  1307. get_wagon_proprties_button_spec(wagon.id, pname, 2, 3)
  1308. end,
  1309. inventory_list_sizes = {
  1310. box=8*3,
  1311. },
  1312. }, S("North American Covered Hopper Wagon"), "dlxtrains_industrial_wagons_hopper_type2_inv.png")
  1313. end
  1314. -- ////////////////////////////////////////////////////////////////////////////////////
  1315. if dlxtrains_industrial_wagons.max_wagon_length >= 6 then
  1316. local wagon_type = "dlxtrains_industrial_wagons:livestock_type1"
  1317. dlxtrains.register_livery_templates(wagon_type, mod_name, livery_templates)
  1318. advtrains.register_wagon(wagon_type, {
  1319. mesh = meshes_industrial_wagon_livestock_type1.default,
  1320. textures = {dlxtrains.get_init_texture()},
  1321. set_textures = function(wagon, data)
  1322. dlxtrains.set_textures_for_livery_scheme(wagon, data, livery_scheme_industrial_wagon_livestock_type1, meshes_industrial_wagon_livestock_type1)
  1323. end,
  1324. custom_may_destroy = function(wagon, puncher, time_from_last_punch, tool_capabilities, direction)
  1325. return not dlxtrains.update_livery(wagon, puncher, livery_scheme_industrial_wagon_livestock_type1)
  1326. end,
  1327. custom_on_step = function(self, dtime, data, train)
  1328. if dlxtrains.wagon_sounds then
  1329. local inv = minetest.get_inventory({type="detached", name="advtrains_wgn_"..data.id})
  1330. if inv and not inv:is_empty("box") then
  1331. local stack = inv:get_stack("box", 1)
  1332. if not stack:is_empty() then
  1333. play_animal_sound(self.object, data.id, stack)
  1334. end
  1335. end
  1336. end
  1337. end,
  1338. seats = {},
  1339. drives_on={default=true},
  1340. max_speed=20,
  1341. visual_size = {x=1, y=1},
  1342. wagon_span=3,
  1343. wheel_positions = {2.0, -2.0},
  1344. collisionbox = {-1.0,-0.5,-1.0,1.0,2.5,1.0},
  1345. coupler_types_front = {knuckle=true},
  1346. coupler_types_back = {knuckle=true},
  1347. drops={"default:steelblock"},
  1348. has_inventory = true,
  1349. get_inventory_formspec = function(wagon, pname, invname)
  1350. return "size[8,7]"..
  1351. "box[0,0;.8,.88;#077]".. -- Highlight slot that impacts visible loads
  1352. "list["..invname..";box;0,0;8,2;]"..
  1353. "list[current_player;main;0,3;8,4;]"..
  1354. "listring[]"..
  1355. get_wagon_proprties_button_spec(wagon.id, pname, 2, 2)
  1356. end,
  1357. inventory_list_sizes = {
  1358. box=8*3,
  1359. },
  1360. }, S("Australian Cattle Van"), "dlxtrains_industrial_wagons_livestock_type1_inv.png")
  1361. end
  1362. -- ////////////////////////////////////////////////////////////////////////////////////
  1363. if dlxtrains_industrial_wagons.max_wagon_length >= 6 then
  1364. local wagon_type = "dlxtrains_industrial_wagons:open_type1"
  1365. dlxtrains.register_livery_templates(wagon_type, mod_name, livery_templates)
  1366. advtrains.register_wagon(wagon_type, {
  1367. mesh = meshes_industrial_wagon_open_type1.default,
  1368. textures = {dlxtrains.get_init_texture()},
  1369. set_textures = function(wagon, data)
  1370. dlxtrains.set_textures_for_livery_scheme(wagon, data, livery_scheme_industrial_wagon_open_type1, meshes_industrial_wagon_open_type1)
  1371. end,
  1372. custom_may_destroy = function(wagon, puncher, time_from_last_punch, tool_capabilities, direction)
  1373. return not dlxtrains.update_livery(wagon, puncher, livery_scheme_industrial_wagon_open_type1)
  1374. end,
  1375. seats = {},
  1376. drives_on={default=true},
  1377. max_speed=20,
  1378. visual_size = {x=1, y=1},
  1379. wagon_span=3,
  1380. wheel_positions = {2.0, -2.0},
  1381. collisionbox = {-1.0,-0.5,-1.0,1.0,2.5,1.0},
  1382. coupler_types_front = {knuckle=true},
  1383. coupler_types_back = {knuckle=true},
  1384. drops={dlxtrains.materials.steelblock},
  1385. has_inventory = true,
  1386. get_inventory_formspec = function(wagon, pname, invname)
  1387. return "size[8,8]"..
  1388. "box[0,0;.8,.88;#077]".. -- Highlight slots that impact visible loads
  1389. "box[0,1;.8,.88;#077]"..
  1390. "box[0,2;.8,.88;#077]"..
  1391. "list["..invname..";box;0,0;8,3;]"..
  1392. "list[current_player;main;0,4;8,4;]"..
  1393. "listring[]"..
  1394. get_wagon_proprties_button_spec(wagon.id, pname, 2, 3)
  1395. end,
  1396. inventory_list_sizes = {
  1397. box=8*3,
  1398. },
  1399. }, S("Australian Open Wagon"), "dlxtrains_industrial_wagons_open_type1_inv.png")
  1400. end
  1401. -- ////////////////////////////////////////////////////////////////////////////////////
  1402. if dlxtrains_industrial_wagons.max_wagon_length >= 6 then
  1403. local wagon_type = "dlxtrains_industrial_wagons:stake_type1"
  1404. dlxtrains.register_livery_templates(wagon_type, mod_name, livery_templates)
  1405. advtrains.register_wagon(wagon_type, {
  1406. mesh = meshes_industrial_wagon_stake_type1.default,
  1407. textures = {dlxtrains.get_init_texture()},
  1408. set_textures = function(wagon, data)
  1409. dlxtrains.set_textures_for_livery_scheme(wagon, data, livery_scheme_industrial_wagon_stake_type1, meshes_industrial_wagon_stake_type1)
  1410. end,
  1411. custom_may_destroy = function(wagon, puncher, time_from_last_punch, tool_capabilities, direction)
  1412. return not dlxtrains.update_livery(wagon, puncher, livery_scheme_industrial_wagon_stake_type1)
  1413. end,
  1414. seats = {},
  1415. drives_on={default=true},
  1416. max_speed=20,
  1417. visual_size = {x=1, y=1},
  1418. wagon_span=3,
  1419. wheel_positions = {2.0, -2.0},
  1420. collisionbox = {-1.0,-0.5,-1.0,1.0,2.5,1.0},
  1421. coupler_types_front = {chain=true},
  1422. coupler_types_back = {chain=true},
  1423. drops={dlxtrains.materials.steelblock},
  1424. has_inventory = true,
  1425. get_inventory_formspec = function(wagon, pname, invname)
  1426. return "size[8,8]"..
  1427. "box[0,0;.8,.88;#077]".. -- Highlight slots that impact visible loads
  1428. "box[0,1;.8,.88;#077]"..
  1429. "box[0,2;.8,.88;#077]"..
  1430. "list["..invname..";box;0,0;8,3;]"..
  1431. "list[current_player;main;0,4;8,4;]"..
  1432. "listring[]"..
  1433. get_wagon_proprties_button_spec(wagon.id, pname, 2, 3)
  1434. end,
  1435. inventory_list_sizes = {
  1436. box=8*3,
  1437. },
  1438. }, S("European Stake Wagon"), "dlxtrains_industrial_wagons_stake_type1_inv.png")
  1439. end
  1440. -- ////////////////////////////////////////////////////////////////////////////////////
  1441. if dlxtrains_industrial_wagons.max_wagon_length >= 4.875 then
  1442. local wagon_type = "dlxtrains_industrial_wagons:tank_type1"
  1443. dlxtrains.register_livery_templates(wagon_type, mod_name, livery_templates)
  1444. local wagon_def = {
  1445. mesh = meshes_industrial_wagon_tank_type1.default,
  1446. textures = {dlxtrains.get_init_texture()},
  1447. set_textures = function(wagon, data)
  1448. dlxtrains.set_textures_for_livery_scheme(wagon, data, livery_scheme_industrial_wagon_tank_type1, meshes_industrial_wagon_tank_type1)
  1449. end,
  1450. custom_may_destroy = function(wagon, puncher, time_from_last_punch, tool_capabilities, direction)
  1451. return not dlxtrains.update_livery(wagon, puncher, livery_scheme_industrial_wagon_tank_type1)
  1452. end,
  1453. seats = {
  1454. {
  1455. name = "Seat in Brakeman's Cabin",
  1456. attach_offset = use_attachment_patch and {x=0, y=1, z=-18.0} or {x=0, y=1, z=-18.0},
  1457. view_offset = use_attachment_patch and {x=0, y=0, z=0} or {x=0, y=6.5, z=0},
  1458. advtrains_attachment_offset_patch_attach_rotation = use_attachment_patch and {x=0, y=180, z=0} or nil,
  1459. group = "cabin",
  1460. },
  1461. },
  1462. seat_groups = {
  1463. cabin={
  1464. name = "Brakeman's Cabin",
  1465. access_to = {},
  1466. require_doors_open = false,
  1467. },
  1468. },
  1469. assign_to_seat_group = {"cabin"},
  1470. drives_on={default=true},
  1471. max_speed=15,
  1472. visual_size = {x=1, y=1},
  1473. wagon_span=2.4375,
  1474. wheel_positions = {1.3, -1.0},
  1475. collisionbox = {-1.0,-0.5,-1.0,1.0,2.5,1.0},
  1476. coupler_types_front = {chain=true},
  1477. coupler_types_back = {chain=true},
  1478. drops={dlxtrains.materials.steelblock},
  1479. has_inventory = true,
  1480. get_inventory_formspec = function(wagon, pname, invname)
  1481. return "size[8,8]"..
  1482. "list["..invname..";box;0,0;8,3;]"..
  1483. "list[current_player;main;0,4;8,4;]"..
  1484. "listring[]"..
  1485. get_wagon_proprties_button_spec(wagon.id, pname, 2, 3)
  1486. end,
  1487. inventory_list_sizes = {
  1488. box=8*3,
  1489. },
  1490. techage_liquid_capacity = 1000,
  1491. }
  1492. if use_attachment_patch then
  1493. advtrains_attachment_offset_patch.setup_advtrains_wagon(wagon_def);
  1494. end
  1495. advtrains.register_wagon(wagon_type, wagon_def, S("European Small Tank Wagon with Brakeman's Cabin"), "dlxtrains_industrial_wagons_tank_type1_inv.png")
  1496. end
  1497. -- ////////////////////////////////////////////////////////////////////////////////////
  1498. if dlxtrains_industrial_wagons.max_wagon_length >= 4.875 then
  1499. local wagon_type = "dlxtrains_industrial_wagons:tank_type2"
  1500. dlxtrains.register_livery_templates(wagon_type, mod_name, livery_templates)
  1501. advtrains.register_wagon(wagon_type, {
  1502. mesh = meshes_industrial_wagon_tank_type2.default,
  1503. textures = {dlxtrains.get_init_texture()},
  1504. set_textures = function(wagon, data)
  1505. dlxtrains.set_textures_for_livery_scheme(wagon, data, livery_scheme_industrial_wagon_tank_type2, meshes_industrial_wagon_tank_type2)
  1506. end,
  1507. custom_may_destroy = function(wagon, puncher, time_from_last_punch, tool_capabilities, direction)
  1508. return not dlxtrains.update_livery(wagon, puncher, livery_scheme_industrial_wagon_tank_type2)
  1509. end,
  1510. seats = {},
  1511. drives_on={default=true},
  1512. max_speed=15,
  1513. visual_size = {x=1, y=1},
  1514. wagon_span=2.4375,
  1515. wheel_positions = {1.3, -1.0},
  1516. collisionbox = {-1.0,-0.5,-1.0,1.0,2.5,1.0},
  1517. coupler_types_front = {chain=true},
  1518. coupler_types_back = {chain=true},
  1519. drops={dlxtrains.materials.steelblock},
  1520. has_inventory = true,
  1521. get_inventory_formspec = function(wagon, pname, invname)
  1522. return "size[8,8]"..
  1523. "list["..invname..";box;0,0;8,3;]"..
  1524. "list[current_player;main;0,4;8,4;]"..
  1525. "listring[]"..
  1526. get_wagon_proprties_button_spec(wagon.id, pname, 2, 3)
  1527. end,
  1528. inventory_list_sizes = {
  1529. box=8*3,
  1530. },
  1531. techage_liquid_capacity = 1000,
  1532. }, S("European Small Tank Wagon"), "dlxtrains_industrial_wagons_tank_type2_inv.png")
  1533. end
  1534. -- ////////////////////////////////////////////////////////////////////////////////////
  1535. if dlxtrains_industrial_wagons.max_wagon_length >= 6 then
  1536. local wagon_type = "dlxtrains_industrial_wagons:transition_type1"
  1537. dlxtrains.register_livery_templates(wagon_type, mod_name, livery_templates)
  1538. advtrains.register_wagon(wagon_type, {
  1539. mesh = meshes_industrial_wagon_transition_type1.default,
  1540. textures = {dlxtrains.get_init_texture()},
  1541. set_textures = function(wagon, data)
  1542. dlxtrains.set_textures_for_livery_scheme(wagon, data, livery_scheme_industrial_wagon_transition_type1, meshes_industrial_wagon_transition_type1)
  1543. end,
  1544. custom_may_destroy = function(wagon, puncher, time_from_last_punch, tool_capabilities, direction)
  1545. return not dlxtrains.update_livery(wagon, puncher, livery_scheme_industrial_wagon_transition_type1)
  1546. end,
  1547. seats = {},
  1548. drives_on={default=true},
  1549. max_speed=20,
  1550. visual_size = {x=1, y=1},
  1551. wagon_span=3,
  1552. wheel_positions = {2.0, -2.0},
  1553. collisionbox = {-1.0,-0.5,-1.0,1.0,2.5,1.0},
  1554. coupler_types_front = {chain=true},
  1555. coupler_types_back = {knuckle=true},
  1556. drops={dlxtrains.materials.steelblock},
  1557. has_inventory = true,
  1558. get_inventory_formspec = function(wagon, pname, invname)
  1559. return "size[8,8]"..
  1560. "box[0,0;.8,.88;#077]".. -- Highlight slots that impact visible loads
  1561. "box[0,1;.8,.88;#077]"..
  1562. "box[0,2;.8,.88;#077]"..
  1563. "list["..invname..";box;0,0;8,3;]"..
  1564. "list[current_player;main;0,4;8,4;]"..
  1565. "listring[]"..
  1566. get_wagon_proprties_button_spec(wagon.id, pname, 2, 3)
  1567. end,
  1568. inventory_list_sizes = {
  1569. box=8*3,
  1570. },
  1571. }, S("Buffer/Knuckle Transition Wagon"), "dlxtrains_industrial_wagons_transition_type1_inv.png")
  1572. end