init.lua 5.8 KB

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