forked from v-rob/slats
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi.lua
More file actions
94 lines (83 loc) · 2.48 KB
/
Copy pathapi.lua
File metadata and controls
94 lines (83 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
local has_default_mod = minetest.get_modpath("default")
-- main crafting ingredient for the slat recipe
local base_recipe_ingredient
if has_default_mod then
base_recipe_ingredient = "default:paper"
end
-- legacy register function with parameters
function slats.register_slat(subname, recipeitem, groups, image, description, sounds)
-- call new api with table
slats.register(subname, {
recipeitem = recipeitem,
groups = groups,
image = image, -- NOTE: full texture-string with modifiers
description = description,
sounds = sounds
})
end
-- new register function, with a table as second option
function slats.register(subname, opts)
-- provide defaults
assert(type(opts) == "table", "invalid options")
assert(type(opts.image) == "string" or type(opts.base_texture) == "string", "no image or base_texture defined")
if opts.groups then
-- copy groups to prevent accidental modification after registration
opts.groups = table.copy(opts.groups)
else
-- empty group table
opts.groups = {}
end
if opts.base_texture then
-- create texture with base-texture
opts.image = opts.base_texture .. "^slats_slat_overlay.png^[makealpha:255,126,126"
end
local nodename = "slats:slat_" .. subname
-- check for duplication
assert(not minetest.registered_nodes[nodename], "slat already registered: " .. subname)
opts.groups.slab = 1
-- nodebox limits
local nb1 = 0.5
local nb2 = 0.49
minetest.register_node(":" .. nodename, {
description = opts.description,
drawtype = "nodebox",
tiles = {opts.image},
inventory_image = opts.image,
wield_image = opts.image,
paramtype = "light",
paramtype2 = "wallmounted",
is_ground_content = false,
sunlight_propagates = true,
use_texture_alpha = "clip",
groups = opts.groups,
sounds = opts.sounds,
node_box = {
type = "wallmounted",
wall_top = {-nb1, nb2, -nb1, nb1, nb2, nb1},
wall_bottom = {-nb1, -nb2, -nb1, nb1, -nb2, nb1},
wall_side = {-nb2, -nb1, -nb1, -nb2, nb1, nb1},
},
})
if opts.recipeitem then
if base_recipe_ingredient then
minetest.register_craft({
type = "shapeless",
output = 'slats:slat_' .. subname .. ' 12',
recipe = {opts.recipeitem, base_recipe_ingredient},
})
end
-- Fuel
local baseburntime = minetest.get_craft_result({
method = "fuel",
width = 1,
items = {opts.recipeitem}
}).time
if baseburntime > 0 then
minetest.register_craft({
type = "fuel",
recipe = 'slats:slat_' .. subname,
burntime = math.floor(baseburntime * 0.5),
})
end
end
end