init.lua 5.6 KB

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