init.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. --[[
  2. Teleporter networks that allow players to choose a destination out of a list
  3. Copyright (C) 2013 Sokomine
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. --]]
  15. -- Required to save the travelnet data properly in all cases
  16. if not minetest.safe_file_write then
  17. error("[Mod travelnet] Your Minetest version is no longer supported. (version < 0.4.17)")
  18. end
  19. travelnet = {}
  20. travelnet.log = function(c, msg) minetest.log(c, "[travelnet] " .. msg) end
  21. travelnet.player_formspec_data = {}
  22. travelnet.path = minetest.get_modpath(minetest.get_current_modname())
  23. local function mod_dofile(filename)
  24. dofile(travelnet.path .. "/"..filename..".lua")
  25. end
  26. -- privs
  27. mod_dofile("privs")
  28. -- read the configuration
  29. mod_dofile("config")
  30. -- saving / reading
  31. mod_dofile("persistence")
  32. -- common functions
  33. mod_dofile("functions")
  34. mod_dofile("actions/main")
  35. -- formspec stuff
  36. mod_dofile("formspecs")
  37. mod_dofile("formspecs-legacy")
  38. -- travelnet / elevator update
  39. mod_dofile("update_formspec")
  40. -- add button
  41. mod_dofile("add_target")
  42. -- receive fields handler
  43. mod_dofile("on_receive_fields")
  44. -- meta-formspec migration lbm
  45. if travelnet.travelnet_cleanup_lbm then
  46. mod_dofile("migrate_formspecs_lbm")
  47. end
  48. -- invisible node to place inside top of travelnet box and elevator
  49. minetest.register_node(":travelnet:hidden_top", {
  50. drawtype = "airlike",
  51. paramtype = "light",
  52. sunlight_propagates = true,
  53. walkable = false,
  54. pointable = false,
  55. diggable = false,
  56. groups = {not_in_creative_inventory = 1},
  57. drop = "",
  58. })
  59. if travelnet.travelnet_effect_enabled then
  60. minetest.register_entity(":travelnet:effect", {
  61. hp_max = 1,
  62. physical = false,
  63. weight = 5,
  64. collisionbox = { -0.4, -0.5, -0.4, 0.4, 1.5, 0.4 },
  65. visual = "upright_sprite",
  66. visual_size = { x=1, y=2 },
  67. textures = { "travelnet_flash.png" }, -- number of required textures depends on visual
  68. spritediv = { x=1, y=1 },
  69. initial_sprite_basepos = { x=0, y=0 },
  70. is_visible = true,
  71. makes_footstep_sound = false,
  72. automatic_rotate = true,
  73. anz_rotations = 0,
  74. on_step = function(self)
  75. -- this is supposed to be more flickering than smooth animation
  76. self.object:set_yaw(self.object:get_yaw()+1)
  77. self.anz_rotations = self.anz_rotations+1
  78. -- eventually self-destruct
  79. if self.anz_rotations > 15 then
  80. self.object:remove()
  81. end
  82. end
  83. })
  84. end
  85. if travelnet.travelnet_enabled then
  86. -- register-functions for travelnet nodes
  87. mod_dofile("register_travelnet")
  88. -- default travelnet registrations
  89. mod_dofile("travelnet")
  90. end
  91. if travelnet.elevator_enabled then
  92. mod_dofile("elevator") -- allows up/down transfers only
  93. end
  94. if travelnet.doors_enabled then
  95. -- doors that open and close automaticly when the travelnet or elevator is used
  96. mod_dofile("doors")
  97. end
  98. if travelnet.enable_abm then
  99. -- restore travelnet data when players pass by broken networks
  100. mod_dofile("restore_network_via_abm")
  101. end
  102. -- upon server start, read the savefile
  103. travelnet.player_formspec_data = nil
  104. if minetest.get_modpath("mtt") and mtt.enabled then
  105. mod_dofile("mtt")
  106. mod_dofile("persistence.spec")
  107. end