Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add paramtype2s for 4 horizontal rotations and 64 colors #11431

Merged
merged 4 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add 4dir, color4dir paramtype2 (horizontal rotate)
  • Loading branch information
Wuzzy2 committed Sep 8, 2022
commit 8ec6af9ceb5b4c30800fe986666397e44c6c3a39
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
20 changes: 20 additions & 0 deletions 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
45 changes: 41 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,34 @@ 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)
* `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 +1139,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 +5807,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 +5825,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 +7930,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
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
Loading
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
8 changes: 7 additions & 1 deletion src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3462,7 +3462,9 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
param2 = dir.Z < 0 ? 5 : 4;
}
} else if (predicted_f.param_type_2 == CPT2_FACEDIR ||
predicted_f.param_type_2 == CPT2_COLORED_FACEDIR) {
predicted_f.param_type_2 == CPT2_COLORED_FACEDIR ||
predicted_f.param_type_2 == CPT2_4DIR ||
predicted_f.param_type_2 == CPT2_FACEDIR) {
Wuzzy2 marked this conversation as resolved.
Show resolved Hide resolved
v3s16 dir = nodepos - floatToInt(client->getEnv().getLocalPlayer()->getPosition(), BS);

if (abs(dir.X) > abs(dir.Z)) {
Expand Down Expand Up @@ -3501,6 +3503,7 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
// Apply color
if (!place_param2 && (predicted_f.param_type_2 == CPT2_COLOR
|| predicted_f.param_type_2 == CPT2_COLORED_FACEDIR
|| predicted_f.param_type_2 == CPT2_COLORED_4DIR
|| predicted_f.param_type_2 == CPT2_COLORED_WALLMOUNTED)) {
const auto &indexstr = selected_item.metadata.
getString("palette_index", 0);
Expand All @@ -3514,6 +3517,9 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
} else if (predicted_f.param_type_2 == CPT2_COLORED_FACEDIR) {
// param2 = pure palette index + other
param2 = (index & 0xe0) | (param2 & 0x1f);
} else if (predicted_f.param_type_2 == CPT2_COLORED_4DIR) {
// param2 = pure palette index + other
param2 = (index & 0xfc) | (param2 & 0x03);
}
}
}
Expand Down
21 changes: 16 additions & 5 deletions src/mapnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ u8 MapNode::getFaceDir(const NodeDefManager *nodemgr,
if (f.param_type_2 == CPT2_FACEDIR ||
f.param_type_2 == CPT2_COLORED_FACEDIR)
return (getParam2() & 0x1F) % 24;
if (f.param_type_2 == CPT2_4DIR ||
f.param_type_2 == CPT2_COLORED_4DIR)
return getParam2() & 0x03;
if (allow_wallmounted && (f.param_type_2 == CPT2_WALLMOUNTED ||
f.param_type_2 == CPT2_COLORED_WALLMOUNTED))
return wallmounted_to_facedir[getParam2() & 0x07];
Expand Down Expand Up @@ -196,7 +199,8 @@ void MapNode::rotateAlongYAxis(const NodeDefManager *nodemgr, Rotation rot)
{
ContentParamType2 cpt2 = nodemgr->get(*this).param_type_2;

if (cpt2 == CPT2_FACEDIR || cpt2 == CPT2_COLORED_FACEDIR) {
if (cpt2 == CPT2_FACEDIR || cpt2 == CPT2_COLORED_FACEDIR ||
cpt2 == CPT2_4DIR || cpt2 == CPT2_COLORED_4DIR) {
static const u8 rotate_facedir[24 * 4] = {
// Table value = rotated facedir
// Columns: 0, 90, 180, 270 degrees rotation around vertical axis
Expand Down Expand Up @@ -232,10 +236,17 @@ void MapNode::rotateAlongYAxis(const NodeDefManager *nodemgr, Rotation rot)
22, 21, 20, 23,
23, 22, 21, 20
};
u8 facedir = (param2 & 31) % 24;
u8 index = facedir * 4 + rot;
param2 &= ~31;
param2 |= rotate_facedir[index];
if (cpt2 == CPT2_FACEDIR || cpt2 == CPT2_COLORED_FACEDIR) {
u8 facedir = (param2 & 31) % 24;
u8 index = facedir * 4 + rot;
param2 &= ~31;
param2 |= rotate_facedir[index];
} else {
Wuzzy2 marked this conversation as resolved.
Show resolved Hide resolved
u8 fourdir = param2 & 3;
u8 index = fourdir + rot;
param2 &= ~3;
param2 |= rotate_facedir[index];
}
} else if (cpt2 == CPT2_WALLMOUNTED ||
cpt2 == CPT2_COLORED_WALLMOUNTED) {
u8 wmountface = (param2 & 7);
Expand Down
Loading