Place and orient wallmounted node by a tool

Post Reply
User avatar
h-v-smacker
Member
Posts: 115
Joined: Wed Nov 29, 2017 23:04
GitHub: h-v-smacker
In-game: Smacker

Place and orient wallmounted node by a tool

by h-v-smacker » Post

I have a wallmounted node (for the time being, it's just called "paint_layer"), which is defined as follows:

Code: Select all

	description = "Paint",
	drawtype = "nodebox",
	tiles = {"paint.png^[colorize:#FF0000"},
	node_box = {
			type = "wallmounted",
			wall_bottom = {-0.5, -0.5, -0.5, 0.5, -0.499, 0.5},
			wall_top = {-0.5, 0.499, -0.5, 0.5, 0.5, 0.5},
			wall_side = {-0.5, -0.5, -0.5, -0.499, 0.5, 0.5},
                },
	drop = "",
	groups = {attached_node = 1},
	paramtype = "light",
	paramtype2 = "wallmounted"
I can place such a node by hand, and it sticks to other surfaces as I'd expect. No problems at all.

Now, I want to make a tool ("brush") to place such nodes on surfaces. My understanding is that, since it's an auto-rotated node, I need to use something like this:

Code: Select all

minetest.rotate_node(ItemStack({name = "paint:paint_layer"}), user, pointed_thing)
However, the result is that it only gets placed on surfaces (west-facing walls, ceiling, floor) when I face east. When I face some other direction, usually nothing happens. Sometimes (and I cannot figure out the pattern) I can manage to stand at such an angle that I can place it on south-facing surfaces, or that the node is placed, but misaligned (e.g. ends up horizontal when I pointed to a vertical surface).

What is the the proper way to achieve the desired result, if any? Namely, to have a tool that places wall-mounted nodes which get oriented the same was as if placed by player's hand directly?
Linux Forks, the Best Forks: linux-forks.de // Play @ LinuxWorks Next Generation

User avatar
h-v-smacker
Member
Posts: 115
Joined: Wed Nov 29, 2017 23:04
GitHub: h-v-smacker
In-game: Smacker

Re: Place and orient wallmounted node by a tool

by h-v-smacker » Post

Current solution:

Code: Select all

local diff = vector.subtract(pointed_thing.under, pointed_thing.above)
local wmd = minetest.dir_to_wallmounted(diff)
minetest.swap_node(pointed_thing.above, {name = "paint:paint_layer", param2 = wmd})
Curiously, minetest.place_node(pointed_thing.above) and minetest.swap_node(pointed_thing.above) place the new node in different locations when pointing at the very same target. Swap_node always uses the adjacent node, while place_node's result can end up in a position 1 node lower (if there is vertical space below).
Linux Forks, the Best Forks: linux-forks.de // Play @ LinuxWorks Next Generation

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests