init.lua 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. --[[
  2. Easy Vending Machines [easyvend]
  3. Copyright (C) 2012 Bad_Command, 2016 Wuzzy
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (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 Lesser General Public
  13. License along with this library; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  15. ]]
  16. easyvend = {}
  17. easyvend.VERSION = {}
  18. easyvend.VERSION.MAJOR = 0
  19. easyvend.VERSION.MINOR = 3
  20. easyvend.VERSION.PATCH = 0
  21. easyvend.VERSION.STRING = easyvend.VERSION.MAJOR .. "." .. easyvend.VERSION.MINOR .. "." .. easyvend.VERSION.PATCH
  22. easyvend.traversable_node_types = {
  23. ["easyvend:vendor"] = true,
  24. ["easyvend:depositor"] = true,
  25. ["easyvend:vendor_on"] = true,
  26. ["easyvend:depositor_on"] = true,
  27. }
  28. easyvend.registered_chests = {}
  29. dofile(minetest.get_modpath("easyvend") .. "/ads.lua")
  30. dofile(minetest.get_modpath("easyvend") .. "/exchange.lua")
  31. dofile(minetest.get_modpath("easyvend") .. "/mail.lua")
  32. if minetest.get_modpath("reload") then
  33. reload.register_file("vending:core", minetest.get_modpath("easyvend") .. "/easyvend.lua")
  34. else
  35. dofile(minetest.get_modpath("easyvend") .. "/easyvend.lua")
  36. end
  37. if minetest.get_modpath("chests") ~= nil then
  38. easyvend.register_chest("chests:chest_locked_closed", "main", "owner")
  39. easyvend.register_chest("chests:chest_locked_open", "main", "owner")
  40. end
  41. local sounds
  42. local soundsplus = {
  43. place = { name = "easyvend_disable", gain = 1 },
  44. dug = { name = "easyvend_disable", gain = 1 }, }
  45. if minetest.get_modpath("coresounds") ~= nil then
  46. sounds = default.node_sound_wood_defaults(soundsplus)
  47. else
  48. sounds = soundsplus
  49. end
  50. local machine_template = {
  51. paramtype2 = "facedir",
  52. groups = utility.dig_groups("furniture", {vending=1}),
  53. after_place_node = function(...) return easyvend.after_place_node(...) end,
  54. can_dig = function(...) return easyvend.can_dig(...) end,
  55. on_receive_fields = function(...) return easyvend.on_receive_fields(...) end,
  56. sounds = sounds,
  57. allow_metadata_inventory_put = function(...) return easyvend.allow_metadata_inventory_put(...) end,
  58. allow_metadata_inventory_take = function(...) return easyvend.allow_metadata_inventory_take(...) end,
  59. allow_metadata_inventory_move = function(...) return easyvend.allow_metadata_inventory_move(...) end,
  60. on_punch = function(...)
  61. depositor.check_machine(...)
  62. return easyvend.machine_check(...)
  63. end,
  64. on_construct = function(...)
  65. depositor.on_construct(...)
  66. end,
  67. on_destruct = function(...)
  68. depositor.on_destruct(...)
  69. end,
  70. -- Called by rename LBM.
  71. _on_update_infotext = function(pos)
  72. local meta = minetest.get_meta(pos)
  73. local owner = meta:get_string("owner")
  74. -- Nobody placed this block.
  75. if owner == "" then
  76. return
  77. end
  78. local dname = rename.gpn(owner)
  79. meta:set_string("rename", dname)
  80. end,
  81. _on_update_formspec = function(pos)
  82. depositor.check_machine(pos)
  83. easyvend.machine_check(pos, minetest.get_node(pos))
  84. end,
  85. }
  86. if minetest.get_modpath("screwdriver") ~= nil then
  87. machine_template.on_rotate = screwdriver.rotate_simple
  88. end
  89. local vendor_on = table.copy(machine_template)
  90. vendor_on.description = "Vending Machine\n\nRemote trading possible; see Trade Kiosk."
  91. vendor_on.tiles ={"easyvend_vendor_bottom.png", "easyvend_vendor_bottom.png", "easyvend_vendor_side.png",
  92. "easyvend_vendor_side.png", "easyvend_vendor_side.png", "easyvend_vendor_front_on.png"}
  93. vendor_on.groups.not_in_creative_inventory = 1
  94. vendor_on.groups.not_in_doc = 1
  95. vendor_on.drop = "easyvend:vendor"
  96. local vendor_off = table.copy(machine_template)
  97. vendor_off.description = vendor_on.description
  98. vendor_off.tiles = table.copy(vendor_on.tiles)
  99. vendor_off.tiles[6] = "easyvend_vendor_front_off.png"
  100. local depositor_on = table.copy(machine_template)
  101. depositor_on.description = "Depositing Machine\n\nRemote trading possible; see Trade Kiosk."
  102. depositor_on.tiles ={"easyvend_depositor_bottom.png", "easyvend_depositor_bottom.png", "easyvend_depositor_side.png",
  103. "easyvend_depositor_side.png", "easyvend_depositor_side.png", "easyvend_depositor_front_on.png"}
  104. depositor_on.groups.not_in_creative_inventory = 1
  105. depositor_on.groups.not_in_doc = 1
  106. depositor_on.drop = "easyvend:depositor"
  107. local depositor_off = table.copy(machine_template)
  108. depositor_off.description = depositor_on.description
  109. depositor_off.tiles = table.copy(depositor_on.tiles)
  110. depositor_off.tiles[6] = "easyvend_depositor_front_off.png"
  111. minetest.register_node("easyvend:vendor", vendor_off)
  112. minetest.register_node("easyvend:vendor_on", vendor_on)
  113. minetest.register_node("easyvend:depositor", depositor_off)
  114. minetest.register_node("easyvend:depositor_on", depositor_on)
  115. minetest.register_craft({
  116. output = 'easyvend:vendor',
  117. recipe = {
  118. {'group:wood', 'group:wood', 'group:wood'},
  119. {'group:wood', 'default:copper_ingot', 'group:wood'},
  120. {'group:wood', 'default:steel_ingot', 'group:wood'},
  121. }
  122. })
  123. minetest.register_craft({
  124. output = 'easyvend:depositor',
  125. recipe = {
  126. {'group:wood', 'default:steel_ingot', 'group:wood'},
  127. {'group:wood', 'default:copper_ingot', 'group:wood'},
  128. {'group:wood', 'group:wood', 'group:wood'},
  129. }
  130. })