init.lua 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. if minetest.get_modpath("reload") then
  32. reload.register_file("vending:core", minetest.get_modpath("easyvend") .. "/easyvend.lua")
  33. else
  34. dofile(minetest.get_modpath("easyvend") .. "/easyvend.lua")
  35. end
  36. if minetest.get_modpath("chests") ~= nil then
  37. easyvend.register_chest("chests:chest_locked_closed", "main", "owner")
  38. easyvend.register_chest("chests:chest_locked_open", "main", "owner")
  39. end
  40. local sounds
  41. local soundsplus = {
  42. place = { name = "easyvend_disable", gain = 1 },
  43. dug = { name = "easyvend_disable", gain = 1 }, }
  44. if minetest.get_modpath("coresounds") ~= nil then
  45. sounds = default.node_sound_wood_defaults(soundsplus)
  46. else
  47. sounds = soundsplus
  48. end
  49. local machine_template = {
  50. paramtype2 = "facedir",
  51. groups = utility.dig_groups("furniture", {vending=1}),
  52. after_place_node = function(...) return easyvend.after_place_node(...) end,
  53. can_dig = function(...) return easyvend.can_dig(...) end,
  54. on_receive_fields = function(...) return easyvend.on_receive_fields(...) end,
  55. sounds = sounds,
  56. allow_metadata_inventory_put = function(...) return easyvend.allow_metadata_inventory_put(...) end,
  57. allow_metadata_inventory_take = function(...) return easyvend.allow_metadata_inventory_take(...) end,
  58. allow_metadata_inventory_move = function(...) return easyvend.allow_metadata_inventory_move(...) end,
  59. on_punch = function(...)
  60. depositor.check_machine(...)
  61. return easyvend.machine_check(...)
  62. end,
  63. on_construct = function(...)
  64. depositor.on_construct(...)
  65. end,
  66. on_destruct = function(...)
  67. depositor.on_destruct(...)
  68. end,
  69. -- Called by rename LBM.
  70. _on_update_infotext = function(pos)
  71. local meta = minetest.get_meta(pos)
  72. local owner = meta:get_string("owner")
  73. -- Nobody placed this block.
  74. if owner == "" then
  75. return
  76. end
  77. local dname = rename.gpn(owner)
  78. meta:set_string("rename", dname)
  79. end,
  80. _on_update_formspec = function(pos)
  81. depositor.check_machine(pos)
  82. easyvend.machine_check(pos, minetest.get_node(pos))
  83. end,
  84. }
  85. if minetest.get_modpath("screwdriver") ~= nil then
  86. machine_template.on_rotate = screwdriver.rotate_simple
  87. end
  88. local vendor_on = table.copy(machine_template)
  89. vendor_on.description = "Vending Machine\n\nRemote trading possible; see Trade Kiosk."
  90. vendor_on.tiles ={"easyvend_vendor_bottom.png", "easyvend_vendor_bottom.png", "easyvend_vendor_side.png",
  91. "easyvend_vendor_side.png", "easyvend_vendor_side.png", "easyvend_vendor_front_on.png"}
  92. vendor_on.groups.not_in_creative_inventory = 1
  93. vendor_on.groups.not_in_doc = 1
  94. vendor_on.drop = "easyvend:vendor"
  95. local vendor_off = table.copy(machine_template)
  96. vendor_off.description = vendor_on.description
  97. vendor_off.tiles = table.copy(vendor_on.tiles)
  98. vendor_off.tiles[6] = "easyvend_vendor_front_off.png"
  99. local depositor_on = table.copy(machine_template)
  100. depositor_on.description = "Depositing Machine\n\nRemote trading possible; see Trade Kiosk."
  101. depositor_on.tiles ={"easyvend_depositor_bottom.png", "easyvend_depositor_bottom.png", "easyvend_depositor_side.png",
  102. "easyvend_depositor_side.png", "easyvend_depositor_side.png", "easyvend_depositor_front_on.png"}
  103. depositor_on.groups.not_in_creative_inventory = 1
  104. depositor_on.groups.not_in_doc = 1
  105. depositor_on.drop = "easyvend:depositor"
  106. local depositor_off = table.copy(machine_template)
  107. depositor_off.description = depositor_on.description
  108. depositor_off.tiles = table.copy(depositor_on.tiles)
  109. depositor_off.tiles[6] = "easyvend_depositor_front_off.png"
  110. minetest.register_node("easyvend:vendor", vendor_off)
  111. minetest.register_node("easyvend:vendor_on", vendor_on)
  112. minetest.register_node("easyvend:depositor", depositor_off)
  113. minetest.register_node("easyvend:depositor_on", depositor_on)
  114. minetest.register_craft({
  115. output = 'easyvend:vendor',
  116. recipe = {
  117. {'group:wood', 'group:wood', 'group:wood'},
  118. {'group:wood', 'default:copper_ingot', 'group:wood'},
  119. {'group:wood', 'default:steel_ingot', 'group:wood'},
  120. }
  121. })
  122. minetest.register_craft({
  123. output = 'easyvend:depositor',
  124. recipe = {
  125. {'group:wood', 'default:steel_ingot', 'group:wood'},
  126. {'group:wood', 'default:copper_ingot', 'group:wood'},
  127. {'group:wood', 'group:wood', 'group:wood'},
  128. }
  129. })