diff --git a/.luacheckrc b/.luacheckrc index 91c274f..8ceb8c3 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -7,7 +7,7 @@ globals = { "minetest", "core", --mod provided - + "home_vending_machines", } read_globals = { diff --git a/home_vending_machines/api.lua b/home_vending_machines/api.lua new file mode 100644 index 0000000..fb0b1d4 --- /dev/null +++ b/home_vending_machines/api.lua @@ -0,0 +1,59 @@ +local registered_currency = {} + +function home_vending_machines.register_currency(name, worth) + registered_currency[name] = worth +end + +local function reg_simple(name, def) + minetest.register_node(":" .. name, { + description = def.description, + drawtype = "mesh", + mesh = "home_vending_machines_machine.obj", + tiles = def.tiles, + paramtype = "light", + paramtype2 = "facedir", + groups = def.groups or {snappy=3}, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 1.5, 0.5} + }, + collision_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 1.5, 0.5} + }, + sounds = def.sounds, + on_rotate = function(pos, node, user, mode, new_param2) + if minetest.get_modpath("screwdriver") then + return screwdriver.rotate_simple(pos, node, user, mode, new_param2) + end + end, + on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + local pname = clicker:get_player_name() + local iname = itemstack:get_name() + local dpos = vector.add((vector.multiply(minetest.facedir_to_dir(node.param2), -1)), pos) + + if registered_currency[iname] and registered_currency[iname] == 1 then + local item = def._vmachine.item + if type(item) == "table" then + item = item[math.random(#item)] + end + + minetest.spawn_item(dpos, item) + + if not minetest.is_creative_enabled(pname) then + itemstack:take_item() + return itemstack + end + else + minetest.chat_send_player(pname, "Please insert valid currency.") + end + end + }) +end + +function home_vending_machines.register_machine(type, name, def) + if type == "simple" then + reg_simple(name, def) + end + --TODO: add more complex machine type with formspec and selections +end \ No newline at end of file diff --git a/home_vending_machines/init.lua b/home_vending_machines/init.lua new file mode 100644 index 0000000..cf44cf6 --- /dev/null +++ b/home_vending_machines/init.lua @@ -0,0 +1,8 @@ +local modpath = minetest.get_modpath("home_vending_machines") +home_vending_machines = {} + +dofile(modpath .. "/api.lua") +dofile(modpath .. "/machines.lua") +dofile(modpath .. "/items.lua") + +home_vending_machines.init = true \ No newline at end of file diff --git a/home_vending_machines/items.lua b/home_vending_machines/items.lua new file mode 100644 index 0000000..6240218 --- /dev/null +++ b/home_vending_machines/items.lua @@ -0,0 +1,12 @@ +local function reg_item(name, evalue) + minetest.register_craftitem("home_vending_machines:" .. name, { + description = string.gsub(name, "_", " "), + inventory_image = "home_vending_machines_" .. name .. ".png", + on_use = minetest.item_eat(evalue), + }) +end + +reg_item("soda_can", 2) +minetest.register_alias("home_workshop_misc:soda_can", "home_vending_machines:soda_can") + +reg_item("water_bottle", 3) \ No newline at end of file diff --git a/home_vending_machines/machines.lua b/home_vending_machines/machines.lua new file mode 100644 index 0000000..f9e3195 --- /dev/null +++ b/home_vending_machines/machines.lua @@ -0,0 +1,29 @@ +home_vending_machines.register_currency("default:gold_ingot", 1) +home_vending_machines.register_currency("currency:minegeld_cent_25", 1) + +home_vending_machines.register_machine("simple", "home_workshop_misc:soda_machine", { + description = "Soda vending machine", + tiles = {"home_vending_machines_soda_machine.png"}, + sounds = nil, + _vmachine = { + item = "home_vending_machines:soda_can" + } +}) + +home_vending_machines.register_machine("simple", "home_vending_machines:drink_machine", { + description = "Drinks vending machine", + tiles = {"home_vending_machines_drink_machine.png"}, + sounds = nil, + _vmachine = { + item = {"home_vending_machines:soda_can", "home_vending_machines:water_bottle"} + } +}) + +home_vending_machines.register_machine("simple", "home_vending_machines:sweet_machine", { + description = "Sweets vending machine", + tiles = {"home_vending_machines_sweet_machine.png"}, + sounds = nil, + _vmachine = { + item = "home_vending_machines:soda_can" + } +}) \ No newline at end of file diff --git a/home_vending_machines/mod.conf b/home_vending_machines/mod.conf new file mode 100644 index 0000000..185da03 --- /dev/null +++ b/home_vending_machines/mod.conf @@ -0,0 +1 @@ +optional_depends = "screwdriver" \ No newline at end of file diff --git a/home_workshop_misc/models/home_workshop_misc_soda_machine.obj b/home_vending_machines/models/home_vending_machines_machine.obj similarity index 100% rename from home_workshop_misc/models/home_workshop_misc_soda_machine.obj rename to home_vending_machines/models/home_vending_machines_machine.obj diff --git a/home_vending_machines/readme.txt b/home_vending_machines/readme.txt new file mode 100644 index 0000000..5564aab --- /dev/null +++ b/home_vending_machines/readme.txt @@ -0,0 +1,11 @@ +code wsor MIT + +VanessaE (cc-by-sa 4.0): +home_vending_machines_machine.obj +home_vending_machines_soda_can.png +home_vending_machines_soda_machine.png + +Andrey01 (CC BY-SA 3.0): +home_vending_machines_drimk_machine.png +home_vending_machines_sweet_machine.png +home_vending_machines_water_bottle.png diff --git a/home_workshop_misc/textures/home_workshop_misc_soda_can.png b/home_vending_machines/textures/items/home_vending_machines_soda_can.png similarity index 100% rename from home_workshop_misc/textures/home_workshop_misc_soda_can.png rename to home_vending_machines/textures/items/home_vending_machines_soda_can.png diff --git a/home_vending_machines/textures/items/home_vending_machines_water_bottle.png b/home_vending_machines/textures/items/home_vending_machines_water_bottle.png new file mode 100644 index 0000000..31b146f Binary files /dev/null and b/home_vending_machines/textures/items/home_vending_machines_water_bottle.png differ diff --git a/home_vending_machines/textures/machines/home_vending_machines_drink_machine.png b/home_vending_machines/textures/machines/home_vending_machines_drink_machine.png new file mode 100644 index 0000000..25e44bb Binary files /dev/null and b/home_vending_machines/textures/machines/home_vending_machines_drink_machine.png differ diff --git a/home_workshop_misc/textures/home_workshop_misc_soda_machine.png b/home_vending_machines/textures/machines/home_vending_machines_soda_machine.png similarity index 100% rename from home_workshop_misc/textures/home_workshop_misc_soda_machine.png rename to home_vending_machines/textures/machines/home_vending_machines_soda_machine.png diff --git a/home_vending_machines/textures/machines/home_vending_machines_sweet_machine.png b/home_vending_machines/textures/machines/home_vending_machines_sweet_machine.png new file mode 100644 index 0000000..db8d367 Binary files /dev/null and b/home_vending_machines/textures/machines/home_vending_machines_sweet_machine.png differ diff --git a/home_workshop_common/init.lua b/home_workshop_common/init.lua deleted file mode 100644 index b58bce1..0000000 --- a/home_workshop_common/init.lua +++ /dev/null @@ -1,2 +0,0 @@ --- nothing to see here :P --- this is just a stub to provide a few textures diff --git a/home_workshop_misc/init.lua b/home_workshop_misc/init.lua index 059ffab..7a75952 100644 --- a/home_workshop_misc/init.lua +++ b/home_workshop_misc/init.lua @@ -79,60 +79,13 @@ minetest.register_node("home_workshop_misc:beer_mug", { sounds = default.node_sound_glass_defaults(), selection_box = beer_cbox, on_use = function(itemstack, user, pointed_thing) - if not minetest.is_creative_enabled_for(user:get_player_name()) then + if not minetest.is_creative_enabled(user:get_player_name()) then minetest.do_item_eat(2, "vessels:drinking_glass 1", itemstack, user, pointed_thing) return itemstack end end }) -local svm_cbox = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 1.5, 0.5} -} - -minetest.register_node("home_workshop_misc:soda_machine", { - description = S("Soda vending machine"), - drawtype = "mesh", - mesh = "home_workshop_misc_soda_machine.obj", - tiles = {"home_workshop_misc_soda_machine.png"}, - paramtype = "light", - paramtype2 = "facedir", - groups = {snappy=3}, - selection_box = svm_cbox, - collision_box = svm_cbox, - expand = { top="placeholder" }, - sounds = default.node_sound_wood_defaults(), - on_rotate = minetest.get_modpath("screwdriver") and screwdriver.rotate_simple or nil, - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) - local playername = clicker:get_player_name() - local wielditem = clicker:get_wielded_item() - local wieldname = wielditem:get_name() - local fdir_to_fwd = { {0, -1}, {-1, 0}, {0, 1}, {1, 0} } - local fdir = node.param2 - local pos_drop = { x=pos.x+fdir_to_fwd[fdir+1][1], y=pos.y, z=pos.z+fdir_to_fwd[fdir+1][2] } - if wieldname == "currency:minegeld_cent_25" then - minetest.spawn_item(pos_drop, "home_workshop_misc:soda_can") - minetest.sound_play("insert_coin", { - pos=pos, max_hear_distance = 5 - }) - if not minetest.is_creative_enabled_for(playername) then - wielditem:take_item() - clicker:set_wielded_item(wielditem) - return wielditem - end - else - minetest.chat_send_player(playername, S("Please insert a 25 Mg cent coin in the machine.")) - end - end -}) - -minetest.register_craftitem("home_workshop_misc:soda_can", { - description = S("Soda Can"), - inventory_image = "home_workshop_misc_soda_can.png", - on_use = minetest.item_eat(2), -}) - if minetest.get_modpath("homedecor_common") then minetest.register_alias("home_workshop_misc:drawer_small", "homedecor:drawer_small") else diff --git a/home_workshop_misc/mod.conf b/home_workshop_misc/mod.conf index 9620e00..8549a3f 100644 --- a/home_workshop_misc/mod.conf +++ b/home_workshop_misc/mod.conf @@ -1,3 +1,3 @@ name = home_workshop_misc -depends = default, home_workshop_common +depends = default optional_depends = currency, screwdriver, homedecor_common diff --git a/home_workshop_common/textures/home_workshop_common_drawer_small.png b/home_workshop_misc/textures/home_workshop_common/home_workshop_common_drawer_small.png similarity index 100% rename from home_workshop_common/textures/home_workshop_common_drawer_small.png rename to home_workshop_misc/textures/home_workshop_common/home_workshop_common_drawer_small.png diff --git a/home_workshop_common/textures/home_workshop_common_generic_metal.png b/home_workshop_misc/textures/home_workshop_common/home_workshop_common_generic_metal.png similarity index 100% rename from home_workshop_common/textures/home_workshop_common_generic_metal.png rename to home_workshop_misc/textures/home_workshop_common/home_workshop_common_generic_metal.png diff --git a/home_workshop_common/textures/home_workshop_common_generic_metal_bright.png b/home_workshop_misc/textures/home_workshop_common/home_workshop_common_generic_metal_bright.png similarity index 100% rename from home_workshop_common/textures/home_workshop_common_generic_metal_bright.png rename to home_workshop_misc/textures/home_workshop_common/home_workshop_common_generic_metal_bright.png