[solved]Rotate Node, facedir, auto-off-axis

sirrobzeroone
Member
 
Posts: 104
Joined: Mon Jul 16, 2018 07:56

[solved]Rotate Node, facedir, auto-off-axis

by sirrobzeroone » Mon Sep 02, 2019 10:32

I'm not really understanding the rotation options for placing a node. What I want to do is when I place a node is instead of "facedir" facing the player I want it to be rotated 90 degrees so "facedir+90"

I worked out the two main axis for param2 (x,z) are 2 and 3

So essentially when param2== 3 then set param2 = 2, when param2 ==2 then set param2=3

I cant workout were to write my if/else statement, I tried on_place no good, then I tried place_param2 but that appears to be expecting a number, interestingly have something like:
Code: Select all
   paramtype2 = "facedir",
   place_param2 = 0,

Results in the block always flicking to a specific axis,

Also tried on_place = minetest.rotate_node, but not entirely sure what that does since facedir seems to always bounce the node to face the player and the function inputs available seem to make little sense to me....

anyways appreciate the help, I just cant connect all the dots on this one.
Last edited by sirrobzeroone on Tue Sep 03, 2019 07:42, edited 1 time in total.
 

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

Re: Rotate Node, facedir, auto-off-axis

by Krock » Mon Sep 02, 2019 16:14

1) Get the player's view direction
view_dir = player:get_view_dir()
https://github.com/minetest/minetest/bl ... .txt#L5508

2) Convert it to the facedir param2 value
param2 = minetest.dir_to_facedir(vector.multiply(view_dir, -1))
https://github.com/minetest/minetest/bl ... 4552-L4556

OR do it like the chests from the default mod:
https://github.com/minetest/minetest_ga ... ts.lua#L81
>> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
 

sirrobzeroone
Member
 
Posts: 104
Joined: Mon Jul 16, 2018 07:56

Re: Rotate Node, facedir, auto-off-axis

by sirrobzeroone » Tue Sep 03, 2019 05:48

Hi Krock, really appreciate the help and direction, i've spent a bit of time playing around and reading, but i'm still missing something, i think understanding of callbacks.

I ended up with the below, at the moment just going to debug:

Code: Select all
rest of node...   
after_place_node = function(pos, placer, itemstack, pointed_thing)
      local para = minetest.dir_to_facedir(placer:get_look_dir())
      local para2 = minetest.dir_to_facedir(vector.add(placer:get_look_dir(),-1))
      minetest.debug(para, para2)
   end,


I use para as a base calculation and then para2 as my amended however these calculations dont always appear accurate:
3 blocks placed side by side (added the para and para2 for clarity)
Code: Select all
2019-09-03 15:27:11: ACTION[Server]: facedir: 2
2019-09-03 15:27:11: [Server]: para:2   para2:2
2019-09-03 15:27:13: ACTION[Server]: singleplayer places node brickblock:brick1x2 at (-7,-9,9)
2019-09-03 15:27:13: ACTION[Server]: facedir: 2
2019-09-03 15:27:13: [Server]: para:2   para2:2
2019-09-03 15:27:16: ACTION[Server]: singleplayer places node brickblock:brick1x2 at (-4,-8,16)
2019-09-03 15:27:16: ACTION[Server]: facedir: 1
2019-09-03 15:27:16: [Server]: para:1   para2:2
2019-09-03 15:27:19: ACTION[Main]: Server: Shutting down


second issue I have no clue how to update "param2" in the after_place_node block. I can't seem to figure out how to update the param2. I tried some obvious things like param2 = para2 or node.param2 = para2 but no luck on any front. I also just wrote some code trying to just hard set param2 to a number so no matter placement it locked, more so I could be 100% sure I was affecting the value but again no luck.

I did find this thread although it seems slightly different issue: viewtopic.php?f=47&t=20021

Which mentions this -
minetest.set_node(pos, {name = "nodename", param2 = N})


Which I could give a try replacing "N" with my new number, but that seems a bit heavy weight as from the debug above I can see debug is outputting facedir inside the "after_place_node" (must be some standard feature in that as I have nil code to output that). Some I'm guessing I should be able to update facedir inside "the_after_place" node callback.

Really appreciate any help from anyone at this point. I'll keep playing around and trying and if I get lucky or get it to work post what I did.
 

sirrobzeroone
Member
 
Posts: 104
Joined: Mon Jul 16, 2018 07:56

Re: Rotate Node, facedir, auto-off-axis

by sirrobzeroone » Tue Sep 03, 2019 07:39

That last idea did indeed work (from the other thread), however I'm slightly confused as I thought the param2 settings in regards to axis where:

^ 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().
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


I go that from rubenwardy's big book of cool reference stuff - https://rubenwardy.com/minetest_modding ... html#nodes which I trust way more than myself so I suspect I'm not understanding fully.

This code did work but it still seems heavy handed to me in that I'm essentially replacing a whole node, excuse the if/else's just what I used to be 100% sure what was doing what:

Code: Select all
   after_place_node = function(pos, placer, itemstack, pointed_thing)   
      local para = minetest.dir_to_facedir(placer:get_look_dir())      
      if para == 0 then
         para3 = 3
      elseif para == 3 then
         para3 = 2
      elseif para == 2 then
         para3 = 1
      elseif para == 1 then
         para3 = 0
      end      
      --minetest.debug("para", para, para3)
      minetest.set_node(pos, {name = "yourmode:yournode", param2 = para3})
   end,


It basically rotates the node 90 degrees to the right no matter which z/x plane you place it down on (I'm assuming y axis holds as vertical in this space same as mapgen land). There is a visible delay between place and twist, which when I think about it I vaguely recall seeing when using other mods.

param2 and paramtype2 are not much fun to get dig into....I'm going to leave this problem at this point as I have a "working" even if I believe its sub-optimal/not very efficient solution and I'll come back to it later. Maybe revisit what Krock pointed me to.

EDIT - found this in another thread which explains the 0,1,2,3 issue - yep my poor understanding :):

+ Spoiler
Last edited by sirrobzeroone on Wed Sep 04, 2019 06:11, edited 2 times in total.
 

sirrobzeroone
Member
 
Posts: 104
Joined: Mon Jul 16, 2018 07:56

Re: [solved]Rotate Node, facedir, auto-off-axis

by sirrobzeroone » Wed Sep 04, 2019 05:59

Had a bit of another go at this one trying to use on_place. The below code works but still visibly can see the block turn, it might be marginally quicker but hard to say.

I haven't done comprehensive testing on this, so it maybe flawed

Code: Select all
...rest of node
   on_place = function(itemstack, placer, pointed_thing)      
   local para = minetest.dir_to_facedir(placer:get_look_dir())
         if para == 0 then
         param2 = 3
      elseif para == 3 then
         param2= 2
      elseif para == 2 then
         param2 = 1
      elseif para == 1 then
         param2 = 0
      end   
   minetest.item_place(itemstack, placer, pointed_thing, param2)   
   end,
 


Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 5 guests