mirror of
https://github.com/mt-mods/home_workshop_modpack.git
synced 2025-07-13 22:10:27 +02:00
add ending machines and code cleanup
This commit is contained in:
59
home_vending_machines/api.lua
Normal file
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
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
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
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
1
home_vending_machines/mod.conf
Normal file
@ -0,0 +1 @@
|
||||
optional_depends = "screwdriver"
|
@ -0,0 +1,29 @@
|
||||
v 0.5 -0.5 -0.5
|
||||
v 0.5 -0.5 0.5
|
||||
v -0.5 -0.5 0.5
|
||||
v -0.5 -0.5 -0.5
|
||||
v 0.5 1.5 -0.5
|
||||
v 0.5 1.5 0.5
|
||||
v -0.5 1.5 0.5
|
||||
v -0.5 1.5 -0.5
|
||||
vt 0.25 0.25
|
||||
vt 0 0.25
|
||||
vt 0 0
|
||||
vt 0.25 0
|
||||
vt 0.25 0.75
|
||||
vt 0.25 1
|
||||
vt 0 1
|
||||
vt 0 0.75
|
||||
vt 1 0.25
|
||||
vt 1 0.75
|
||||
vt 0.75 0.75
|
||||
vt 0.75 0.25
|
||||
vt 0.5 0.75
|
||||
vt 0.5 0.25
|
||||
s off
|
||||
f 1/1 2/2 3/3 4/4
|
||||
f 5/5 8/6 7/7 6/8
|
||||
f 1/1 5/5 6/8 2/2
|
||||
f 2/9 6/10 7/11 3/12
|
||||
f 3/12 7/11 8/13 4/14
|
||||
f 5/5 1/1 4/14 8/13
|
11
home_vending_machines/readme.txt
Normal file
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
|
Binary file not shown.
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 |
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
Reference in New Issue
Block a user