1 -- Minetest: builtin/item_s.lua
2 -- The distinction of what goes here is a bit tricky, basically it's everything
3 -- that does not (directly or indirectly) need access to ServerEnvironment,
4 -- Server or writable access to IGameDef on the engine side.
5 -- (The '_s' stands for standalone.)
8 -- Item definition helpers
11 function core.inventorycube(img1, img2, img3)
14 return "[inventorycube"
15 .. "{" .. img1:gsub("%^", "&")
16 .. "{" .. img2:gsub("%^", "&")
17 .. "{" .. img3:gsub("%^", "&")
20 function core.dir_to_facedir(dir, is6d)
21 --account for y if requested
22 if is6d and math.abs(dir.y) > math.abs(dir.x) and math.abs(dir.y) > math.abs(dir.z) then
26 if math.abs(dir.x) > math.abs(dir.z) then
42 if math.abs(dir.x) > math.abs(dir.z) then
57 --otherwise, place horizontally
58 elseif math.abs(dir.x) > math.abs(dir.z) then
73 -- Table of possible dirs
74 local facedir_to_dir = {
77 vector.new( 0, 0, -1),
79 vector.new( 0, -1, 0),
82 -- Mapping from facedir value to index in facedir_to_dir.
83 local facedir_to_dir_map = {
91 function core.facedir_to_dir(facedir)
92 return facedir_to_dir[facedir_to_dir_map[facedir % 32]]
95 function core.dir_to_wallmounted(dir)
96 if math.abs(dir.y) > math.max(math.abs(dir.x), math.abs(dir.z)) then
102 elseif math.abs(dir.x) > math.abs(dir.z) then
117 -- table of dirs in wallmounted order
118 local wallmounted_to_dir = {
119 [0] = vector.new( 0, 1, 0),
120 vector.new( 0, -1, 0),
121 vector.new( 1, 0, 0),
122 vector.new(-1, 0, 0),
123 vector.new( 0, 0, 1),
124 vector.new( 0, 0, -1),
126 function core.wallmounted_to_dir(wallmounted)
127 return wallmounted_to_dir[wallmounted % 8]
130 function core.dir_to_yaw(dir)
131 return -math.atan2(dir.x, dir.z)
134 function core.yaw_to_dir(yaw)
135 return vector.new(-math.sin(yaw), 0, math.cos(yaw))
138 function core.is_colored_paramtype(ptype)
139 return (ptype == "color") or (ptype == "colorfacedir") or
140 (ptype == "colorwallmounted") or (ptype == "colordegrotate")
143 function core.strip_param2_color(param2, paramtype2)
144 if not core.is_colored_paramtype(paramtype2) then
147 if paramtype2 == "colorfacedir" then
148 param2 = math.floor(param2 / 32) * 32
149 elseif paramtype2 == "colorwallmounted" then
150 param2 = math.floor(param2 / 8) * 8
151 elseif paramtype2 == "colordegrotate" then
152 param2 = math.floor(param2 / 32) * 32
154 -- paramtype2 == "color" requires no modification.