Skip to content

Commit

Permalink
Add paramtype2s for 4 horizontal rotations and 64 colors (minetest#11431
Browse files Browse the repository at this point in the history
)

4dir is like facedir, but only for 4 horizontal directions: NESW. It is identical in behavior to facedir otherwise. The reason why game makers would want to use this over facedir is 1) simplicity and 2) you get 6 free bits.
It can be used for things like chests and furnaces and you don't need or want them to "flip them on the side" (like you could with facedir).

color4dir is like colorfacedir, but you get 64 colors instead of only 8.
  • Loading branch information
Wuzzy2 committed Sep 16, 2022
1 parent b5e7280 commit 1d04903
Show file tree
Hide file tree
Showing 15 changed files with 298 additions and 27 deletions.
11 changes: 10 additions & 1 deletion builtin/game/falling.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,16 @@ core.register_entity(":__builtin:falling_node", {
local fdir = node.param2 % 32 % 24
-- Get rotation from a precalculated lookup table
local euler = facedir_to_euler[fdir + 1]
self.object:set_rotation(euler)
if euler then
self.object:set_rotation(euler)
end
elseif (def.paramtype2 == "4dir" or def.paramtype2 == "color4dir") then
local fdir = node.param2 % 4
-- Get rotation from a precalculated lookup table
local euler = facedir_to_euler[fdir + 1]
if euler then
self.object:set_rotation(euler)
end
elseif (def.drawtype ~= "plantlike" and def.drawtype ~= "plantlike_rooted" and
(def.paramtype2 == "wallmounted" or def.paramtype2 == "colorwallmounted" or def.drawtype == "signlike")) then
local rot = node.param2 % 8
Expand Down
6 changes: 5 additions & 1 deletion builtin/game/item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2,
newnode.param2 = core.dir_to_wallmounted(dir)
-- Calculate the direction for furnaces and chests and stuff
elseif (def.paramtype2 == "facedir" or
def.paramtype2 == "colorfacedir") and not param2 then
def.paramtype2 == "colorfacedir" or
def.paramtype2 == "4dir" or
def.paramtype2 == "color4dir") and not param2 then
local placer_pos = placer and placer:get_pos()
if placer_pos then
local dir = vector.subtract(above, placer_pos)
Expand All @@ -225,6 +227,8 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2,
color_divisor = 8
elseif def.paramtype2 == "colorfacedir" then
color_divisor = 32
elseif def.paramtype2 == "color4dir" then
color_divisor = 4
elseif def.paramtype2 == "colordegrotate" then
color_divisor = 32
end
Expand Down
25 changes: 24 additions & 1 deletion builtin/game/item_s.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,26 @@ function core.facedir_to_dir(facedir)
return facedir_to_dir[facedir_to_dir_map[facedir % 32]]
end

function core.dir_to_fourdir(dir)
if math.abs(dir.x) > math.abs(dir.z) then
if dir.x < 0 then
return 3
else
return 1
end
else
if dir.z < 0 then
return 2
else
return 0
end
end
end

function core.fourdir_to_dir(fourdir)
return facedir_to_dir[facedir_to_dir_map[fourdir % 4]]
end

function core.dir_to_wallmounted(dir)
if math.abs(dir.y) > math.max(math.abs(dir.x), math.abs(dir.z)) then
if dir.y < 0 then
Expand Down Expand Up @@ -137,7 +157,8 @@ end

function core.is_colored_paramtype(ptype)
return (ptype == "color") or (ptype == "colorfacedir") or
(ptype == "colorwallmounted") or (ptype == "colordegrotate")
(ptype == "color4dir") or (ptype == "colorwallmounted") or
(ptype == "colordegrotate")
end

function core.strip_param2_color(param2, paramtype2)
Expand All @@ -146,6 +167,8 @@ function core.strip_param2_color(param2, paramtype2)
end
if paramtype2 == "colorfacedir" then
param2 = math.floor(param2 / 32) * 32
elseif paramtype2 == "color4dir" then
param2 = math.floor(param2 / 4) * 4
elseif paramtype2 == "colorwallmounted" then
param2 = math.floor(param2 / 8) * 8
elseif paramtype2 == "colordegrotate" then
Expand Down
47 changes: 43 additions & 4 deletions doc/lua_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,17 @@ appropriate `paramtype2`:
first (= 0 + 1) pixel will be picked from the palette.
* `param2 = 35` is 1 * 32 + 3, so the rotation is 3 and the
second (= 1 + 1) pixel will be picked from the palette.
* `paramtype2 = "color4dir"` for nodes which use the first
six bits of `param2` for palette indexing. The remaining
two bits are describing rotation, as in `4dir` paramtype2.
Division by 4 yields the palette index (without stretching the
palette). These nodes can have 64 different colors, and the
palette should contain 64 pixels.
Examples:
* `param2 = 17` is 4 * 4 + 1, so the rotation is 1 and the
fifth (= 4 + 1) pixel will be picked from the palette.
* `param2 = 35` is 8 * 4 + 3, so the rotation is 3 and the
ninth (= 8 + 1) pixel will be picked from the palette.

To colorize a node on the map, set its `param2` value (according
to the node's paramtype2).
Expand Down Expand Up @@ -1058,18 +1069,36 @@ The function of `param2` is determined by `paramtype2` in node definition.
* Supported drawtypes: "torchlike", "signlike", "plantlike",
"plantlike_rooted", "normal", "nodebox", "mesh"
* The rotation of the node is stored in `param2`
* Node is 'mounted'/facing towards one of 6 directions
* You can make this value by using `minetest.dir_to_wallmounted()`
* Values range 0 - 5
* The value denotes at which direction the node is "mounted":
0 = y+, 1 = y-, 2 = x+, 3 = x-, 4 = z+, 5 = z-
* By default, on placement the param2 is automatically set to the
appropriate rotation, depending on which side was pointed at
* `paramtype2 = "facedir"`
* Supported drawtypes: "normal", "nodebox", "mesh"
* The rotation of the node is stored in `param2`. Furnaces and chests are
rotated this way. Can be made by using `minetest.dir_to_facedir()`.
* The rotation of the node is stored in `param2`.
* Node is rotated around face and axis; 24 rotations in total.
* Can be made by using `minetest.dir_to_facedir()`.
* Chests and furnaces can be rotated that way, and also 'flipped'
* Values range 0 - 23
* facedir / 4 = axis direction:
0 = y+, 1 = z+, 2 = z-, 3 = x+, 4 = x-, 5 = y-
* facedir modulo 4 = rotation around that axis
* By default, on placement the param2 is automatically set to the
horizondal direction the player was looking at (values 0-3)
* Special case: If the node is a connected nodebox, the nodebox
will NOT rotate, only the textures will.
* `paramtype2 = "4dir"`
* Supported drawtypes: "normal", "nodebox", "mesh"
* The rotation of the node is stored in `param2`.
* Allows node to be rotated horizontally, 4 rotations in total
* Can be made by using `minetest.dir_to_fourdir()`.
* Chests and furnaces can be rotated that way, but not flipped
* Values range 0 - 3
* 4dir modulo 4 = rotation
* Otherwise, behavior is identical to facedir
* `paramtype2 = "leveled"`
* Only valid for "nodebox" with 'type = "leveled"', and "plantlike_rooted".
* Leveled nodebox:
Expand Down Expand Up @@ -1112,6 +1141,10 @@ The function of `param2` is determined by `paramtype2` in node definition.
* Same as `facedir`, but with colors.
* The first three bits of `param2` tells which color is picked from the
palette. The palette should have 8 pixels.
* `paramtype2 = "color4dir"`
* Same as `facedir`, but with colors.
* The first six bits of `param2` tells which color is picked from the
palette. The palette should have 64 pixels.
* `paramtype2 = "colorwallmounted"`
* Same as `wallmounted`, but with colors.
* The first five bits of `param2` tells which color is picked from the
Expand Down Expand Up @@ -5776,6 +5809,12 @@ Item handling
* `minetest.facedir_to_dir(facedir)`
* Convert a facedir back into a vector aimed directly out the "back" of a
node.
* `minetest.dir_to_fourdir(dir)`
* Convert a vector to a 4dir value, used in `param2` for
`paramtype2="4dir"`.
* `minetest.fourdir_to_dir(fourdir)`
* Convert a 4dir back into a vector aimed directly out the "back" of a
node.
* `minetest.dir_to_wallmounted(dir)`
* Convert a vector to a wallmounted value, used for
`paramtype2="wallmounted"`.
Expand All @@ -5788,7 +5827,7 @@ Item handling
* Convert yaw (angle) to a vector
* `minetest.is_colored_paramtype(ptype)`
* Returns a boolean. Returns `true` if the given `paramtype2` contains
color information (`color`, `colorwallmounted` or `colorfacedir`).
color information (`color`, `colorwallmounted`, `colorfacedir`, etc.).
* `minetest.strip_param2_color(param2, paramtype2)`
* Removes everything but the color information from the
given `param2` value.
Expand Down Expand Up @@ -7893,7 +7932,7 @@ Used by `minetest.register_node`, `minetest.register_craftitem`, and
-- You can set the currently used color as the "palette_index" field of
-- the item stack metadata.
-- The palette is always stretched to fit indices between 0 and 255, to
-- ensure compatibility with "colorfacedir" and "colorwallmounted" nodes.
-- ensure compatibility with "colorfacedir" (and similar) nodes.

color = "#ffffffff",
-- Color the item is colorized with. The palette overrides this.
Expand Down
25 changes: 25 additions & 0 deletions games/devtest/mods/testnodes/meshes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,31 @@ minetest.register_node("testnodes:mesh_colorfacedir", {
groups = {dig_immediate=3},
})

minetest.register_node("testnodes:mesh_4dir", {
description = S("4dir Mesh Test Node"),
drawtype = "mesh",
mesh = "testnodes_ocorner.obj",
tiles = {"testnodes_mesh_stripes.png"},
paramtype = "light",
paramtype2 = "4dir",
collision_box = ocorner_cbox,

groups = {dig_immediate=3},
})

minetest.register_node("testnodes:mesh_color4dir", {
description = S("Color 4dir Mesh Test Node"),
drawtype = "mesh",
mesh = "testnodes_ocorner.obj",
tiles = {"testnodes_mesh_stripes3.png"},
paramtype = "light",
paramtype2 = "color4dir",
palette = "testnodes_palette_4dir.png",
collision_box = ocorner_cbox,

groups = {dig_immediate=3},
})

-- Wallmounted mesh: pyramid
minetest.register_node("testnodes:mesh_wallmounted", {
description = S("Wallmounted Mesh Test Node"),
Expand Down
64 changes: 57 additions & 7 deletions games/devtest/mods/testnodes/nodeboxes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,25 @@ minetest.register_node("testnodes:nodebox_leveled", {
groups = {dig_immediate=3},
})


local nodebox_wall = {
type = "connected",
fixed = {-0.125, -0.500, -0.125, 0.125, 0.500, 0.125},
connect_front = {-0.125, -0.500, -0.500, 0.125, 0.400, -0.125},
connect_back = {-0.125, -0.500, 0.125, 0.125, 0.400, 0.500},
connect_left = {-0.500, -0.500, -0.125, -0.125, 0.400, 0.125},
connect_right = {0.125, -0.500, -0.125, 0.500, 0.400, 0.125},
}

local nodebox_wall_thick = {
type = "connected",
fixed = {-0.25, -0.500, -0.25, 0.25, 0.500, 0.25},
connect_front = {-0.25, -0.500, -0.500, 0.25, 0.400, -0.25},
connect_back = {-0.25, -0.500, 0.25, 0.25, 0.400, 0.500},
connect_left = {-0.500, -0.500, -0.25, -0.25, 0.400, 0.25},
connect_right = {0.25, -0.500, -0.25, 0.500, 0.400, 0.25},
}

-- Wall-like nodebox that connects to neighbors
minetest.register_node("testnodes:nodebox_connected", {
description = S("Connected Nodebox Test Node"),
Expand All @@ -69,13 +88,44 @@ minetest.register_node("testnodes:nodebox_connected", {
paramtype = "light",
connects_to = {"group:connected_nodebox"},
connect_sides = {"front", "back", "left", "right"},
node_box = {
type = "connected",
fixed = {-0.125, -0.500, -0.125, 0.125, 0.500, 0.125},
connect_front = {-0.125, -0.500, -0.500, 0.125, 0.400, -0.125},
connect_back = {-0.125, -0.500, 0.125, 0.125, 0.400, 0.500},
connect_left = {-0.500, -0.500, -0.125, -0.125, 0.400, 0.125},
connect_right = {0.125, -0.500, -0.125, 0.500, 0.400, 0.125},
node_box = nodebox_wall,
})

minetest.register_node("testnodes:nodebox_connected_facedir", {
description = S("Facedir Connected Nodebox Test Node"),
tiles = {
"testnodes_1.png",
"testnodes_2.png",
"testnodes_3.png",
"testnodes_4.png",
"testnodes_5.png",
"testnodes_6.png",
},
groups = {connected_nodebox=1, dig_immediate=3},
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
connects_to = {"group:connected_nodebox"},
connect_sides = {"front", "back", "left", "right"},
node_box = nodebox_wall_thick,
})

minetest.register_node("testnodes:nodebox_connected_4dir", {
description = S("4Dir Connected Nodebox Test Node"),
tiles = {
"testnodes_1.png^[colorize:#FFFF00:127",
"testnodes_2.png^[colorize:#FFFF00:127",
"testnodes_3.png^[colorize:#FFFF00:127",
"testnodes_4.png^[colorize:#FFFF00:127",
"testnodes_5.png^[colorize:#FFFF00:127",
"testnodes_6.png^[colorize:#FFFF00:127",
},
groups = {connected_nodebox=1, dig_immediate=3},
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "4dir",
connects_to = {"group:connected_nodebox"},
connect_sides = {"front", "back", "left", "right"},
node_box = nodebox_wall_thick,
})

74 changes: 74 additions & 0 deletions games/devtest/mods/testnodes/param2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ minetest.register_node("testnodes:facedir", {
groups = { dig_immediate = 3 },
})

minetest.register_node("testnodes:4dir", {
description = S("4dir Test Node"),
paramtype2 = "4dir",
tiles = {
"testnodes_1.png^[colorize:#FFFF00:127",
"testnodes_2.png^[colorize:#FFFF00:127",
"testnodes_3.png^[colorize:#FFFF00:127",
"testnodes_4.png^[colorize:#FFFF00:127",
"testnodes_5.png^[colorize:#FFFF00:127",
"testnodes_6.png^[colorize:#FFFF00:127",
},

groups = { dig_immediate = 3 },
})

minetest.register_node("testnodes:facedir_nodebox", {
description = S("Facedir Nodebox Test Node"),
tiles = {
Expand All @@ -38,6 +53,27 @@ minetest.register_node("testnodes:facedir_nodebox", {
groups = {dig_immediate=3},
})

minetest.register_node("testnodes:4dir_nodebox", {
description = S("4dir Nodebox Test Node"),
tiles = {
"testnodes_1.png^[colorize:#ffff00:127",
"testnodes_2.png^[colorize:#ffff00:127",
"testnodes_3.png^[colorize:#ffff00:127",
"testnodes_4.png^[colorize:#ffff00:127",
"testnodes_5.png^[colorize:#ffff00:127",
"testnodes_6.png^[colorize:#ffff00:127",
},
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "4dir",
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.2, 0.2, 0.2},
},

groups = {dig_immediate=3},
})

minetest.register_node("testnodes:wallmounted", {
description = S("Wallmounted Test Node"),
paramtype2 = "wallmounted",
Expand Down Expand Up @@ -125,6 +161,44 @@ minetest.register_node("testnodes:colorfacedir_nodebox", {
groups = {dig_immediate=3},
})

minetest.register_node("testnodes:color4dir", {
description = S("Color 4dir Test Node"),
paramtype2 = "color4dir",
palette = "testnodes_palette_4dir.png",
tiles = {
"testnodes_1g.png",
"testnodes_2g.png",
"testnodes_3g.png",
"testnodes_4g.png",
"testnodes_5g.png",
"testnodes_6g.png",
},

groups = { dig_immediate = 3 },
})

minetest.register_node("testnodes:color4dir_nodebox", {
description = S("Color 4dir Nodebox Test Node"),
tiles = {
"testnodes_1g.png",
"testnodes_2g.png",
"testnodes_3g.png",
"testnodes_4g.png",
"testnodes_5g.png",
"testnodes_6g.png",
},
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "color4dir",
palette = "testnodes_palette_4dir.png",
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.2, 0.2, 0.2},
},

groups = {dig_immediate=3},
})

minetest.register_node("testnodes:colorwallmounted", {
description = S("Color Wallmounted Test Node"),
paramtype2 = "colorwallmounted",
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion src/client/content_mapblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,9 @@ void MapblockMeshGenerator::drawMeshNode()
int degrotate = 0;

if (f->param_type_2 == CPT2_FACEDIR ||
f->param_type_2 == CPT2_COLORED_FACEDIR) {
f->param_type_2 == CPT2_COLORED_FACEDIR ||
f->param_type_2 == CPT2_4DIR ||
f->param_type_2 == CPT2_COLORED_4DIR) {
facedir = n.getFaceDir(nodedef);
} else if (f->param_type_2 == CPT2_WALLMOUNTED ||
f->param_type_2 == CPT2_COLORED_WALLMOUNTED) {
Expand Down

0 comments on commit 1d04903

Please sign in to comment.