Block with a custom vertical orientation

Post Reply
indyteo
New member
Posts: 4
Joined: Wed Jun 16, 2021 13:35

Block with a custom vertical orientation

by indyteo » Post

Hello,

I was wondering if there were a simple way to perform a vertical rotation of a block.
Explanations:
I have a custom, flat, block of type "facedir". This block is rotated horizontally from the player's rotation when he place it. I would like to be able to get and set vertical orientation of this block, to at least some predefined angles, or if possible to a custom angle value. It must be compatible with the horizontal rotation of facedir.
The anchor point would be either on the center (as shown in first row), or in a corner (second row), both are nice.
Image
(This would be a side view)

Thanks in advance for your answer!
Have a great day. :)

User avatar
v-rob
Developer
Posts: 970
Joined: Thu Mar 24, 2016 03:19
GitHub: v-rob
IRC: v-rob
Location: Right behind you.

Re: Block with a custom vertical orientation

by v-rob » Post

You can do rotation around the Y axis (yaw) using the drawtype "degrotate`, but that doesn't have the fine-tuned rotation that you want (and I think it might only work with "plantlike"). So, in your case, you'd have to define 8 different nodes with models set to each rotation you showed. If you need an infinite number of rotations, you'd need to use an entity with "set_rotation".
Core Developer | My Best Mods: Bridger - Slats - Stained Glass

indyteo
New member
Posts: 4
Joined: Wed Jun 16, 2021 13:35

Re: Block with a custom vertical orientation

by indyteo » Post

Hey,
Thanks for the reply!
However, as you said, the plantlike and degrotate solution doesn't fit in my case.
I would like to avoid the entity solution if possible.
Concerning the node models, do you know if there is any method to retrieve and update the node appearance dynamically in the "on_rightclick" callback?
Maybe defining texture variants, and then switch between them, instead of changing the complete block?
Thanks

User avatar
v-rob
Developer
Posts: 970
Joined: Thu Mar 24, 2016 03:19
GitHub: v-rob
IRC: v-rob
Location: Right behind you.

Re: Block with a custom vertical orientation

by v-rob » Post

Unfortunately, as of now, there is no way to only change the model, such as through paramtype2. There are proposals to do so (and I like the idea), but it hasn't been implemented yet. There's a few difficulties with making it work well with facedir. However, it's fairly simple to make node variants without a lot of copy and paste:

Code: Select all

function make_node_def(model, next_node, not_in_creative_inventory)
	not_in_creative_inventory = not_in_creative_inventory or 1
	return {
		description = "Some Node",
		drawtype = "mesh",
		paramtype = "light",
		paramtype2 = "facedir",
		sunlight_propagates = true,
		mesh = model,
		groups = {--[[your groups]], not_in_creative_inventory = not_in_creative_inventory},
		on_rightclick = function(pos, node)
			minetest.set_node(pos, {name=next_node, param2=node.param2})
		end,
		-- Any other things here
	}
end

minetest.register_node("mymod:rotation_0",  make_node_def("mymod_0.obj", "mymod:rotation_30", 0)
minetest.register_node("mymod:rotation_30", make_node_def("mymod_30.obj", "mymod:rotation_45")
minetest.register_node("mymod:rotation_22", make_node_def("mymod_45.obj", "mymod:rotation_60")
minetest.register_node("mymod:rotation_60", make_node_def("mymod_60.obj", "mymod:rotation_90")
minetest.register_node("mymod:rotation_90", make_node_def("mymod_90.obj", "mymod:rotation_0")
Core Developer | My Best Mods: Bridger - Slats - Stained Glass

indyteo
New member
Posts: 4
Joined: Wed Jun 16, 2021 13:35

Re: Block with a custom vertical orientation

by indyteo » Post

Oh yes I see, thanks a lot for the tip, it helps me a lot!
And we hope to see the dynamic model changing in a near future :D
I'll test this solution and I am pretty sure it will fit my requirements, I'll let you know if it worked :)

ShadMOrdre
Member
Posts: 1118
Joined: Mon Dec 29, 2014 08:07
Location: USA

Re: Block with a custom vertical orientation

by ShadMOrdre » Post

You could also take the approach used in stu's Gears and Axles mod.

It uses a texture based approach, allowing for more frames. A simple cube should be rather easy to accomplish with the above approach.

Shad

indyteo
New member
Posts: 4
Joined: Wed Jun 16, 2021 13:35

Re: Block with a custom vertical orientation

by indyteo » Post

Perfect, it works like a charm!
I've choose the mesh solution using .obj files because it isn't a full block, but thanks for the second approach :)

Thank you all for your help and the quick answer time

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests