add ending machines and code cleanup
|
@ -7,7 +7,7 @@ globals = {
|
|||
"minetest", "core",
|
||||
|
||||
--mod provided
|
||||
|
||||
"home_vending_machines",
|
||||
}
|
||||
|
||||
read_globals = {
|
||||
|
|
59
home_vending_machines/api.lua
Normal 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
|
8
home_vending_machines/init.lua
Normal 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
|
12
home_vending_machines/items.lua
Normal 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)
|
28
home_vending_machines/machines.lua
Normal file
|
@ -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"
|
||||
}
|
||||
})
|
1
home_vending_machines/mod.conf
Normal file
|
@ -0,0 +1 @@
|
|||
optional_depends = "screwdriver"
|
11
home_vending_machines/readme.txt
Normal 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
|
Before Width: | Height: | Size: 155 B After Width: | Height: | Size: 155 B |
After Width: | Height: | Size: 381 B |
After Width: | Height: | Size: 920 B |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.3 KiB |
|
@ -1,2 +0,0 @@
|
|||
-- nothing to see here :P
|
||||
-- this is just a stub to provide a few textures
|
|
@ -86,53 +86,6 @@ minetest.register_node("home_workshop_misc:beer_mug", {
|
|||
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
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
name = home_workshop_misc
|
||||
depends = default, home_workshop_common
|
||||
depends = default
|
||||
optional_depends = currency, screwdriver, homedecor_common
|
||||
|
|
Before Width: | Height: | Size: 225 B After Width: | Height: | Size: 225 B |
Before Width: | Height: | Size: 218 B After Width: | Height: | Size: 218 B |
Before Width: | Height: | Size: 186 B After Width: | Height: | Size: 186 B |