From daf04bd400db59cc10b908d1c7a1c01a0e60b1f2 Mon Sep 17 00:00:00 2001 From: unknown <24964441+wsor4035@users.noreply.github.com> Date: Sun, 28 Nov 2021 11:40:59 -0500 Subject: [PATCH] add ending machines and code cleanup --- .luacheckrc | 2 +- home_vending_machines/api.lua | 59 ++++++++++++++++++ home_vending_machines/init.lua | 8 +++ home_vending_machines/items.lua | 12 ++++ home_vending_machines/machines.lua | 28 +++++++++ home_vending_machines/mod.conf | 1 + .../models/home_vending_machines_machine.obj | 0 home_vending_machines/readme.txt | 11 ++++ .../items/home_vending_machines_soda_can.png | Bin .../home_vending_machines_water_bottle.png | Bin 0 -> 381 bytes .../home_vending_machines_drink_machine.png | Bin 0 -> 920 bytes .../home_vending_machines_soda_machine.png | Bin .../home_vending_machines_sweet_machine.png | Bin 0 -> 1335 bytes home_workshop_common/init.lua | 2 - home_workshop_misc/init.lua | 47 -------------- home_workshop_misc/mod.conf | 2 +- .../home_workshop_common_drawer_small.png | Bin .../home_workshop_common_generic_metal.png | Bin ...e_workshop_common_generic_metal_bright.png | Bin 19 files changed, 121 insertions(+), 51 deletions(-) create mode 100644 home_vending_machines/api.lua create mode 100644 home_vending_machines/init.lua create mode 100644 home_vending_machines/items.lua create mode 100644 home_vending_machines/machines.lua create mode 100644 home_vending_machines/mod.conf rename home_workshop_misc/models/home_workshop_misc_soda_machine.obj => home_vending_machines/models/home_vending_machines_machine.obj (100%) create mode 100644 home_vending_machines/readme.txt rename home_workshop_misc/textures/home_workshop_misc_soda_can.png => home_vending_machines/textures/items/home_vending_machines_soda_can.png (100%) create mode 100644 home_vending_machines/textures/items/home_vending_machines_water_bottle.png create mode 100644 home_vending_machines/textures/machines/home_vending_machines_drink_machine.png rename home_workshop_misc/textures/home_workshop_misc_soda_machine.png => home_vending_machines/textures/machines/home_vending_machines_soda_machine.png (100%) create mode 100644 home_vending_machines/textures/machines/home_vending_machines_sweet_machine.png delete mode 100644 home_workshop_common/init.lua rename {home_workshop_common/textures => home_workshop_misc/textures/home_workshop_common}/home_workshop_common_drawer_small.png (100%) rename {home_workshop_common/textures => home_workshop_misc/textures/home_workshop_common}/home_workshop_common_generic_metal.png (100%) rename {home_workshop_common/textures => home_workshop_misc/textures/home_workshop_common}/home_workshop_common_generic_metal_bright.png (100%) 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..edefbc9 --- /dev/null +++ b/home_vending_machines/machines.lua @@ -0,0 +1,28 @@ +home_vending_machines.register_currency("default:gold_ingot", 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 0000000000000000000000000000000000000000..31b146fd7a41137a39abbab9c873fa1450fcca6f GIT binary patch literal 381 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzwj^(N7l!{JxM1({$v_d#0*}aI z1_o|n5N2eUHAey{$X?><>&pI+iG|->)3*KQRiKb;W=KSdbAE1aYF-JD%fR4Vl$uzQ znxasiS(2gP?&%wlqL<1J6o2UH;usQfI5}kj&mZ?B<4MU3!pu(_CJLSP3HfAeW_Ok` zROWz->gktKT>m*O9{hKR^ec9skYsQ%E7Id!(NT5|={v6vc&uTT@Z@TI#C&A+yHbTy zHEL~)Y&|Kdwl#{3A1y<@JWUS#`p=+L`0${{s}=J&Brp7Z$H3dmTrmItvf|V)ugqL; zX%;m&zsXsX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