voxel_manip and get_node

Posts: 778
Joined: Mon Mar 10, 2014 00:36

voxel_manip and get_node

by Kilarin » Mon Jun 10, 2019 03:09

I've run into a little issue while trying to switch from creating a beanstalk at mapgen time, and creating it later in an already generated area.

I switched from get_mapgen_object to get_voxel_manip, and that seems to be working.
And I can place a node just fine using data[vn]=<content_id of node I want to place>

But I need to ROTATE that node to a specific orientation. And that is where I've run into an important difference between mapgen time and after mapgen time.

At mapgen time I was able to get the node I had just placed using:
local node=minetest.get_node(pos)
Change the facedir, and use minetest.swap_node(pos,node) to put it back, rotated correctly.

BUT, this doesn't work when running after mapgen. get_node(pos) returns the node that is currently in the map, not the new node I just placed into data[vn].

I tried just getting the correct node using minetest.registered_nodes[nodename], rotating it, and using swap_node to put it into the map rotated correctly, BUT, when I save the voxelmanip to the map, it overwrites it, of course.

Do I have to save the map, and THEN rotate nodes? Is there no way to put them into the map rotated as I am working with the voxel manip?

TLDR: I need to know how to rotate nodes in a voxel manip when generating a large object AFTER map generation time.

Thank you,

User avatar
Posts: 4449
Joined: Thu Oct 03, 2013 07:48
Location: Switzerland
GitHub: SmallJoker

Re: voxel_manip and get_node

by Krock » Mon Jun 10, 2019 06:50

Mixing get_node and set_node with VManip functions is not great as you might undo changes by writing the data using VManip.
The rotation is defined using the u8 param2 for each node which has a paramtype2 of wallmounted, facedir, degrotate, colorwallmounted and colorfacedir. The latter two are a mix of rotation and color bits for which there are some API functions for easier conversion.

Use local param2data = vm:get_param2_data() to modify the rotation of the nodes you need, directly inside the VManip part of your placement code. Don't forget to use set_param2_data(param2data) afterwards to apply the changes.

Alternatively you can also do the slower method of accessing each node manually after the placement: *et_node_at(pos)
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

Posts: 778
Joined: Mon Mar 10, 2014 00:36

Re: voxel_manip and get_node

by Kilarin » Mon Jun 10, 2019 10:43

Krock wrote:local param2data = vm:get_param2_data()

Thank you! That is the command I needed!

Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 0 guests