Add Wuzzy to mailmap
[minetest_easyvend.git] / init.lua
blob575f2181d21099489fae62d027fef59a7184ad4f
1 --[[
2 Easy Vending Machines [easyvend]
3 Copyright (C) 2012 Bad_Command, 2016 Wuzzy
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 local S = minetest.get_translator("easyvend")
22 easyvend = {}
23 easyvend.VERSION = {}
24 easyvend.VERSION.MAJOR = 1
25 easyvend.VERSION.MINOR = 0
26 easyvend.VERSION.PATCH = 0
27 easyvend.VERSION.STRING = easyvend.VERSION.MAJOR .. "." .. easyvend.VERSION.MINOR .. "." .. easyvend.VERSION.PATCH
29 -- Set item which is used as payment for vending and depositing machines
30 easyvend.currency = minetest.settings:get("easyvend_currency")
31 if easyvend.currency == nil or minetest.registered_items[easyvend.currency] == nil then
32 -- Default currency
33 easyvend.currency = "default:gold_ingot"
34 end
36 -- Number of currency items required to earn for awarding “Pro Seller” award
37 easyvend.powerseller = 1000
39 if minetest.registered_items[easyvend.currency] == nil then
40 minetest.log("error", "[easyvend] Unknown currency item “"..tostring(easyvend.currency).."”!")
41 easyvend.currency = "unknown"
42 easyvend.currency_desc = "unknown"
43 else
44 easyvend.currency_desc = minetest.registered_items[easyvend.currency].description
45 if easyvend.currency_desc == nil or easyvend.currency_desc == "" then
46 easyvend.currency_desc = easyvend.currency
47 end
48 end
50 dofile(minetest.get_modpath("easyvend") .. "/easyvend.lua")
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("default") ~= nil then
57 sounds = default.node_sound_wood_defaults(soundsplus)
58 else
59 sounds = soundsplus
60 end
62 local machine_template = {
63 paramtype2 = "facedir",
64 groups = {choppy=2,oddly_breakable_by_hand=2},
65 is_ground_content = false,
67 after_place_node = easyvend.after_place_node,
68 can_dig = easyvend.can_dig,
69 on_receive_fields = easyvend.on_receive_fields,
70 sounds = sounds,
72 allow_metadata_inventory_put = easyvend.allow_metadata_inventory_put,
73 allow_metadata_inventory_take = easyvend.allow_metadata_inventory_take,
74 allow_metadata_inventory_move = easyvend.allow_metadata_inventory_move,
75 on_punch = easyvend.machine_check,
78 if minetest.get_modpath("screwdriver") ~= nil then
79 machine_template.on_rotate = screwdriver.rotate_simple
80 end
82 local vendor_on = table.copy(machine_template)
83 vendor_on.description = S("Vending Machine")
84 vendor_on.tiles ={"easyvend_vendor_bottom.png", "easyvend_vendor_bottom.png", "easyvend_vendor_side.png",
85 "easyvend_vendor_side.png", "easyvend_vendor_side.png", "easyvend_vendor_front_on.png"}
86 vendor_on.groups.not_in_creative_inventory = 1
87 vendor_on._doc_items_create_entry = false
88 vendor_on.drop = "easyvend:vendor"
90 local vendor_off = table.copy(machine_template)
91 vendor_off.description = vendor_on.description
92 vendor_off._doc_items_longdesc = string.format("A vending machine allows its owner to offer a certain item in exchange for money (%s). The users can pay with money and will some items in return.", easyvend.currency_desc)
93 vendor_off._doc_items_usagehelp = S("For customers:").."\n"..
94 S("Only if the upper green status LED lights up, the machine is ready for use. Point to see its owner and offer. Use it to open the buying menu. You can pay with the number of items shown at “Price” and you will get the item at “Offered item” in return. Click on “Buy” to buy this offer once.").."\n\n"..
96 S("For owners:").."\n"..
97 S("First, place a locked chest and fill it with the item you want to sell, make sure you leave some inventory slots empty for the price. Place the vending machine above or below the locked chest. Any locked chest connected in a unbroken vertical line of locked chests and vending/depositing machines will be accessed as storage.").."\n"..
98 S("Use the use key on the machine. Set the offered item by moving an item from your invenory into the slot. The price item can not be changed. Now set the number of items per sale and their price and click on “Confirm” to confirm. If the upper green status LED lights up, you're done, if not, check the message.").."\n"..
99 S("The earnings will go into the locked chest.").."\n"..
100 S("Hint: If you enter an “s” after the item number, it will be multiplied with the maximum stack size.")
102 vendor_off.tiles = table.copy(vendor_on.tiles)
103 vendor_off.tiles[6] = "easyvend_vendor_front_off.png"
105 local depositor_on = table.copy(machine_template)
106 depositor_on.description = S("Depositing Machine")
107 depositor_on.tiles ={"easyvend_depositor_bottom.png", "easyvend_depositor_bottom.png", "easyvend_depositor_side.png",
108 "easyvend_depositor_side.png", "easyvend_depositor_side.png", "easyvend_depositor_front_on.png"}
109 depositor_on.groups.not_in_creative_inventory = 1
110 depositor_on._doc_items_create_entry = false
111 depositor_on.drop = "easyvend:depositor"
113 local depositor_off = table.copy(machine_template)
114 depositor_off.description = depositor_on.description
115 depositor_off._doc_items_longdesc = S("A depositing machine allows its owner to offer money (@1) in exchange for a certain item. The users can supply the depositing machine with the requested item and will get money in return.", easyvend.currency_desc)
116 depositor_off._doc_items_usagehelp = S("For users:").."\n"..
117 S("To use a machine, check if its ready (the upper green LED lights up). Point the depositing machine to see its owner and the offer. Use it for the selling menu. You can give the number of items shown at “Requested item” and you will get the items at “Payment” in return. Click on “Sell” to exchange items, repeat this as often as you like.").."\n\n"..
119 S("For owners:").."\n"..
120 S("First, place a locked chest and supply it with the payment item, make sure you leave some inventory slots empty for the items you want to retrieve. Place the machine above or below the chest. Any chest connected in a unbroken vertical stack of locked chests and vending/depositing machines will be accessed.").."\n"..
121 S("Use the use key on the machine. Set the requested item by moving an item from your inventory into the slot. The payment item can not be changed. Now set the number of requested items and your payment and click on “Confirm” to confirm. If the upper green LED lights up, everything works fine, otherwise, check the message. The deposited items will end up in the chest.").."\n"..
122 S("Hint: If you enter an “s” after the item number, it will be multiplied with the maximum stack size.")
123 depositor_off.tiles = table.copy(depositor_on.tiles)
124 depositor_off.tiles[6] = "easyvend_depositor_front_off.png"
126 minetest.register_node("easyvend:vendor", vendor_off)
127 minetest.register_node("easyvend:vendor_on", vendor_on)
128 minetest.register_node("easyvend:depositor", depositor_off)
129 minetest.register_node("easyvend:depositor_on", depositor_on)
131 if minetest.get_modpath("default") ~= nil then
132 minetest.register_craft({
133 output = 'easyvend:vendor',
134 recipe = {
135 {'group:wood', 'group:wood', 'group:wood'},
136 {'group:wood', 'default:steel_ingot', 'group:wood'},
137 {'group:wood', 'default:steel_ingot', 'group:wood'},
141 minetest.register_craft({
142 output = 'easyvend:depositor',
143 recipe = {
144 {'group:wood', 'default:steel_ingot', 'group:wood'},
145 {'group:wood', 'default:steel_ingot', 'group:wood'},
146 {'group:wood', 'group:wood', 'group:wood'},
151 if minetest.get_modpath("doc") ~= nil and minetest.get_modpath("doc_items") ~= nil then
152 doc.add_entry_alias("nodes", "easyvend:vendor", "nodes", "easyvend:vendor_on")
153 doc.add_entry_alias("nodes", "easyvend:depositor", "nodes", "easyvend:depositor_on")