Merge pull request #1 from mt-mods/vending_machines

add ending machines and code cleanup
This commit is contained in:
wsor4035 2021-11-28 14:33:22 -05:00 committed by GitHub
commit 7043a7d15d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 123 additions and 52 deletions

View File

@ -7,7 +7,7 @@ globals = {
"minetest", "core",
--mod provided
"home_vending_machines",
}
read_globals = {

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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"
}
})

View File

@ -0,0 +1 @@
optional_depends = "screwdriver"

View File

@ -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

View File

Before

Width:  |  Height:  |  Size: 155 B

After

Width:  |  Height:  |  Size: 155 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 381 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 920 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -1,2 +0,0 @@
-- nothing to see here :P
-- this is just a stub to provide a few textures

View File

@ -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

View File

@ -1,3 +1,3 @@
name = home_workshop_misc
depends = default, home_workshop_common
depends = default
optional_depends = currency, screwdriver, homedecor_common