[Mod] Better slab/log placement [place_rotated]

User avatar
12Me21
Member
 
Posts: 873
Joined: Tue Mar 05, 2013 00:36
Location: (Ignore all of my posts before 2018)
GitHub: 12Me21

[Mod] Better slab/log placement [place_rotated]

by 12Me21 » Thu Aug 30, 2018 22:08

A long time ago, I had this idea for placing slabs in all orientations:
Image
Now I finally decided to actually do it:
Image
https://github.com/12Me21/place_rotated ... master.zip
So... right after I write 300 lines of code to calculate selection boxes and handle facedir and all that, I learn that there's a new feature being added in minetest 0.5 that does exactly what I need...

Version 0.5 change log:
-now uses Raycast
-no longer supporting minetest versions before 0.5
-removed wires since those are a separate mod now
-fixed all known bugs in the core functions
Version 0.4 change log:
-added wire demo
-fixed connected hitbox detection (hopefully)
Version 0.3 change log:
-slab placement now (hopefully) works on ALL surfaces!!! (except selection boxes that extend past 0.5)
-moved items into separate file
-added tool for checking node rotation
Version 0.2 change log:
-renamed
-added log placement function (more reliable than the default version)
-slab placement now works on all surfaces, except:
--nodes with more than one selection box
--nodes with the "connected" selection box type
--parts of the selection box that extend past +-0.5 (the upper half of doors, for example) (this is not possible to fix)
-(log placement should work on all surfaces)
-on_place functions now return the itemstack
Planned:
-placing slabs "inside" other slabs of the same type to get a full block
-stair placement(?) (I tried adding this, and just it didn't feel right...)

Items:
place_rotated:test_slab - example slab
place_rotated:test_tree - example log
place_rotated:test_diagram - node with a texture showing the different slab placement areas
place_rotated:level - tool for checking node rotation ...

Functions:
place_rotated.slab - on_place function for slabs
place_rotated.log - on_place function for logs/"wall mounted" nodes
These call and return the output of the default on_place function (minetest.item_place), with the param2 override set, so there shouldn't be any problems with violating protected nodes/duplicating items.
You should set node_placement_prediction = "" when using these functions.
place_rotated.get_point(placer) - returns the exact location within a node that the player is pointing at
Last edited by 12Me21 on Thu Sep 06, 2018 01:28, edited 8 times in total.
 

User avatar
Nathan.S
Member
 
Posts: 881
Joined: Wed Sep 24, 2014 17:47
Location: Bigsby Texas
GitHub: NathanSalapat
IRC: NathanS21
In-game: NathanS21

Re: [Mod] Better slab/log placement [place_rotated]

by Nathan.S » Sat Sep 01, 2018 17:53

This looks really neat.
I record Minetest videos, Mod reviews, Modding tutorials, and Lets plays.
Check out my website, and brand new Minetest Modding Course
 

User avatar
GreenDimond
Member
 
Posts: 1266
Joined: Wed Oct 28, 2015 01:26
Location: Yes
GitHub: GreenXenith
IRC: GreenDimond
In-game: GreenDimond

Re: [Mod] Better slab/log placement [place_rotated]

by GreenDimond » Sat Sep 01, 2018 18:30

Adding this code to the init.lua lets this apply to all slabs. I added stairs to it as well because I was fine with the behavior of it.
Code: Select all
minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack, pointed_thing)
   if newnode.name:gsub(".*:",""):find("slab") then
      minetest.set_node(pos, {name=newnode.name, param2=
         choose_slab_facedir(get_point(pointed_thing.above,pointed_thing.under,placer))
      }
      )
   elseif newnode.name:gsub(".*:",""):find("stair") then
      minetest.set_node(pos, {name=newnode.name, param2=
         choose_slab_facedir(get_point(pointed_thing.above,pointed_thing.under,placer))
      }
      )
   end
end)

This should catch all slabs or stairs nodes if they are named properly.
And yes, it still respects protection.

I should also note: This allows the stair functions to work as normal, so slabs of the same type do combine when placed "in" each other (crosses off #2 of your planned list).
Y▹uTube | Mods | Patreon | Minetest Discord | GreenDimond#3232
 

User avatar
12Me21
Member
 
Posts: 873
Joined: Tue Mar 05, 2013 00:36
Location: (Ignore all of my posts before 2018)
GitHub: 12Me21

Re: [Mod] Better slab/log placement [place_rotated]

by 12Me21 » Sat Sep 01, 2018 23:39

GreenDimond wrote:Adding this code to the init.lua lets this apply to all slabs. I added stairs to it as well because I was fine with the behavior of it.
...
This should catch all slabs or stairs nodes if they are named properly.
And yes, it still respects protection.

I should also note: This allows the stair functions to work as normal, so slabs of the same type do combine when placed "in" each other (crosses off #2 of your planned list).

It would be better to check the groups rather than the name, like:
Code: Select all
local definition=minetest.registered_nodes[newnode.name]
if definition and (definition.groups.slab or definition.groups.stair) then ...
 

User avatar
GreenDimond
Member
 
Posts: 1266
Joined: Wed Oct 28, 2015 01:26
Location: Yes
GitHub: GreenXenith
IRC: GreenDimond
In-game: GreenDimond

Re: [Mod] Better slab/log placement [place_rotated]

by GreenDimond » Sun Sep 02, 2018 03:47

12Me21 wrote:It would be better to check the groups rather than the name, like:
Code: Select all
local definition=minetest.registered_nodes[newnode.name]
if definition and (definition.groups.slab or definition.groups.stair) then ...

Adding that as well could be good yes, but that wont catch any stairs/slabs not in the stair/slab group.
Y▹uTube | Mods | Patreon | Minetest Discord | GreenDimond#3232
 

User avatar
bosapara
Member
 
Posts: 493
Joined: Fri Apr 07, 2017 08:49
GitHub: bosapara

Re: [Mod] Better slab/log placement [0.3] [place_rotated]

by bosapara » Sun Sep 02, 2018 12:15

Great, +10

Will be better if it could support moreblocks mod, or change placing
 

User avatar
12Me21
Member
 
Posts: 873
Joined: Tue Mar 05, 2013 00:36
Location: (Ignore all of my posts before 2018)
GitHub: 12Me21

Re: [Mod] Better slab/log placement [place_rotated]

by 12Me21 » Sun Sep 02, 2018 15:52

GreenDimond wrote:
12Me21 wrote:It would be better to check the groups rather than the name, like:
Code: Select all
local definition=minetest.registered_nodes[newnode.name]
if definition and (definition.groups.slab or definition.groups.stair) then ...

Adding that as well could be good yes, but that wont catch any stairs/slabs not in the stair/slab group.

Ah, that’s true. However, I'm worried that the simple name check might catch some nodes that aren't really slabs/stairs. From what I've seen, slabs usually have a name starting with "slab_", so a test like name:find(":slab_",1,true) should work.
 

todada
New member
 
Posts: 5
Joined: Sat Mar 18, 2017 18:49
GitHub: todada

Re: [Mod] Better slab/log placement [place_rotated]

by todada » Sun Sep 02, 2018 21:01

12Me21 wrote:
GreenDimond wrote:
12Me21 wrote:It would be better to check the groups rather than the name, like:
Code: Select all
local definition=minetest.registered_nodes[newnode.name]
if definition and (definition.groups.slab or definition.groups.stair) then ...

Adding that as well could be good yes, but that wont catch any stairs/slabs not in the stair/slab group.

Ah, that’s true. However, I'm worried that the simple name check might catch some nodes that aren't really slabs/stairs. From what I've seen, slabs usually have a name starting with "slab_", so a test like name:find(":slab_",1,true) should work.

No, please, please, use groups to identify nodes. This is the reason why they exist. If some mods don't set the group correctly, it should be corrected there.

Btw., really good job!
Hmmmm.....
 

User avatar
Beerholder
Member
 
Posts: 199
Joined: Wed Aug 03, 2016 20:23
GitHub: evrooije
In-game: Beerholder

Re: [Mod] Better slab/log placement + Wire test [place_rotat

by Beerholder » Mon Sep 03, 2018 13:36

Haven't tried this yet but most def will at some point to test it and maybe use it in my games :-D

I was wondering why you use the painting mod's way of determining where on the face you are clicking though... I happen to know there is a way to determine the absolute coordinate of the intersection point where you click. By translating the intersection point with the pointed thing's absolute world coordinate you should be able to get the relative (to the face) coordinates quite easily. In addition, you won't have to deal with the eye level offset (1.625, which needs to be modified for 0.5 to a different value, which is another issue with the painting mod ...)

From the Lua API doc:

`pointed_thing`
---------------

* `{type="nothing"}`
* `{type="node", under=pos, above=pos}`
* `{type="object", ref=ObjectRef}`

Exact pointing location (currently only `Raycast` supports these fields):
* `pointed_thing.intersection_point`: The absolute world coordinates of the
point on the selection box which is pointed at. May be in the selection box
if the pointer is in the box too.

* `pointed_thing.box_id`: The ID of the pointed selection box (counting starts
from 1).
* `pointed_thing.intersection_normal`: Unit vector, points outwards of the
selected selection box. This specifies which face is pointed at.
Is a null vector `{x = 0, y = 0, z = 0}` when the pointer is inside the
selection box.


Maybe you can play around with this a little bit? :-)
 

User avatar
12Me21
Member
 
Posts: 873
Joined: Tue Mar 05, 2013 00:36
Location: (Ignore all of my posts before 2018)
GitHub: 12Me21

Re: [Mod] Better slab/log placement + Wire test [place_rotat

by 12Me21 » Mon Sep 03, 2018 18:11

Beerholder wrote:Haven't tried this yet but most def will at some point to test it and maybe use it in my games :-D

I was wondering why you use the painting mod's way of determining where on the face you are clicking though... I happen to know there is a way to determine the absolute coordinate of the intersection point where you click. By translating the intersection point with the pointed thing's absolute world coordinate you should be able to get the relative (to the face) coordinates quite easily. In addition, you won't have to deal with the eye level offset (1.625, which needs to be modified for 0.5 to a different value, which is another issue with the painting mod ...)

From the Lua API doc:

...

Maybe you can play around with this a little bit? :-)


Wow, this is perfect!

Now I can replace like 300 lines of code with just 10.
 

User avatar
DS-minetest
Member
 
Posts: 1102
Joined: Thu Jun 19, 2014 19:49
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.
GitHub: DS-Minetest
In-game: DS

Re: [Mod] Better slab/log placement [place_rotated]

by DS-minetest » Fri Sep 07, 2018 12:45

Some time ago I've used the same way to place technic cable plates. (https://github.com/minetest-mods/technic/blob/29f746369f756651c60031a7c86194d79d47a4ce/technic/machines/register/cables.lua#L203-L236)
There are multiple mods that use this exact pointed pos, eg. digipad.
Do not call me -minetest.
Call me DS or DS-minetest.
I am German, so you don't have to pm me English if you are also German.
The background is a lie.
 

User avatar
12Me21
Member
 
Posts: 873
Joined: Tue Mar 05, 2013 00:36
Location: (Ignore all of my posts before 2018)
GitHub: 12Me21

Re: [Mod] Better slab/log placement [place_rotated]

by 12Me21 » Wed Sep 12, 2018 17:54

DS-minetest wrote:Some time ago I've used the same way to place technic cable plates. (https://github.com/minetest-mods/technic/blob/29f746369f756651c60031a7c86194d79d47a4ce/technic/machines/register/cables.lua#L203-L236)
There are multiple mods that use this exact pointed pos, eg. digipad.

Oh, nice, I didn't know about pointed_thing_to_face_pos. (Though, it appears to only work with full nodeboxes so really it's just a more convenient replacement for the intersect() function I was using)
Luckily now we have Raycast which is a lot easier to use and more accurate.
 

User avatar
DS-minetest
Member
 
Posts: 1102
Joined: Thu Jun 19, 2014 19:49
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.
GitHub: DS-Minetest
In-game: DS

Re: [Mod] Better slab/log placement [place_rotated]

by DS-minetest » Thu Sep 13, 2018 16:40

12Me21 wrote:Though, it appears to only work with full nodeboxes

I've planned to make a RP to change this. It's just so much work to get the correct selection box of a node because of the rotation. https://github.com/DS-Minetest/minetest ... #L723-L798
My testing tool says it gives nearly the same output as raycast.
Code: Select all
minetest.register_tool("test_fine_point:particlemaker", {
   description = "particlemaker testtool",
   inventory_image = "fly_btn.png",
   on_use = function(itemstack, user, pointed_thing)
      local pp = user:get_pos()
      pp.y = pp.y + user:get_properties().eye_height + user:get_eye_offset().y / 10
      local rp = minetest.raycast(pp, vector.add(pp, vector.multiply(user:get_look_dir(), 20)), false):next().intersection_point
      minetest.add_particle({
         pos = rp,
         velocity = {x=0, y=0, z=0},
         acceleration = {x=0, y=0, z=0},
         expirationtime = 1,
         size = 1,
         texture = "bubble.png",
         glow = 10,
      })

      local fp = minetest.any_pointed_thing_to_face_pos(user, pointed_thing)
      if not fp then
         minetest.chat_send_all("nil")
         return
      end
      minetest.chat_send_all(minetest.pos_to_string(vector.subtract(rp, fp)))
      minetest.add_particle({
         pos = fp,
         velocity = {x=0, y=0, z=0},
         acceleration = {x=0, y=0, z=0},
         expirationtime = 1,
         size = 1,
         texture = "heart.png",
         glow = 10,
      })
   end,
})
Do not call me -minetest.
Call me DS or DS-minetest.
I am German, so you don't have to pm me English if you are also German.
The background is a lie.
 

User avatar
12Me21
Member
 
Posts: 873
Joined: Tue Mar 05, 2013 00:36
Location: (Ignore all of my posts before 2018)
GitHub: 12Me21

Re: [Mod] Better slab/log placement [place_rotated]

by 12Me21 » Thu Sep 13, 2018 23:19

DS-minetest wrote:
12Me21 wrote:Though, it appears to only work with full nodeboxes

I've planned to make a RP to change this. It's just so much work to get the correct selection box of a node because of the rotation. https://github.com/DS-Minetest/minetest ... #L723-L798
My testing tool says it gives nearly the same output as raycast.

Here's how I rotated the selection boxes:
https://github.com/12Me21/place_rotated ... t.lua#L229
 

User avatar
ManElevation
Member
 
Posts: 896
Joined: Tue Aug 02, 2016 22:04
Location: Madrid,Spain
GitHub: ManElevation
IRC: ManElevation
In-game: ManElevation

Re: [Mod] Better slab/log placement [place_rotated]

by ManElevation » Tue Sep 18, 2018 13:20

hmm... minetest needs this in the default mod
My Public Mods! Discord: Rottweiler Games#3368
 

User avatar
TumeniNodes
Member
 
Posts: 2742
Joined: Fri Feb 26, 2016 19:49
Location: in the dark recesses of the mind
GitHub: TumeniNodes
IRC: tumeninodes
In-game: TumeniNodes

Re: [Mod] Better slab/log placement [place_rotated]

by TumeniNodes » Sat Nov 03, 2018 12:03

GreenDimond wrote:I should also note: This allows the stair functions to work as normal, so slabs of the same type do combine when placed "in" each other (crosses off #2 of your planned list).


I may give this a try, using your additional code.

Though I would point out, I removed the code which combined slabs recently
https://github.com/minetest/minetest_ga ... a6f13f1ead
Ich mag keine grünen Eier und Schinken, ich mag sie nicht Sam I Am
 

User avatar
FiftySix
Member
 
Posts: 14
Joined: Sun Jan 14, 2018 10:58
Location: Scotland
GitHub: BenjieFiftysix
In-game: fiftysix or benjie

Re: [Mod] Better slab/log placement [place_rotated]

by FiftySix » Fri Nov 16, 2018 19:07

This mod is really cool, but it is not working for me with a different camera height. I tested it with the player camera (player:set_eye_offset) set to {x=0, y=10, z=0}, and I can't work out how to get it to work.
I did notice, the values for the camera position seemed to work differently in minetest 5.0 than the previous version. (I had to cut it in (about) half?)
Thanks
Frustrated with formspec strings? Check my formspec editor!
 

R-One
Member
 
Posts: 129
Joined: Wed Dec 20, 2017 23:06
Location: Nice, France

Re: [Mod] Better slab/log placement [place_rotated]

by R-One » Fri Jul 19, 2019 13:07

Hi, this mod is really cool ...

But I can not integrate it to moreblocks someone would have a solution?

thank you in advance
 

User avatar
Linuxdirk
Member
 
Posts: 2055
Joined: Wed Sep 17, 2014 11:21
Location: Germany
In-game: Linuxdirk

Re: [Mod] Better slab/log placement [place_rotated]

by Linuxdirk » Fri Jul 19, 2019 13:27

Unfortunately Moreblocks completely destroys the on_place functionality. Not only for own nodes but also for default stairs and slabs by overwriting them with it's own objects.

One solution would be running a mod after Moreblocks is loaded (either depend on it or use the newly introduced mod loading feature for this) and fix the messed up on_place in Moreblocks's node definitions.

Or, well, https://github.com/minetest-mods/moreblocks/issues/138 :)
 

R-One
Member
 
Posts: 129
Joined: Wed Dec 20, 2017 23:06
Location: Nice, France

Re: [Mod] Better slab/log placement [place_rotated]

by R-One » Fri Jul 19, 2019 14:24

Thank you very much for the quick response.

So I have several questions:

- where is the load order function of the mods documented?

- Is there an alternative to MoreBlocks to have slopes without breaking the standards?

Thank you so much !
 

User avatar
Linuxdirk
Member
 
Posts: 2055
Joined: Wed Sep 17, 2014 11:21
Location: Germany
In-game: Linuxdirk

Re: [Mod] Better slab/log placement [place_rotated]

by Linuxdirk » Fri Jul 19, 2019 14:53

R-One wrote:- where is the load order function of the mods documented?

Afaik it is "random" (hash, or ID, or inode, or whatever, I don't remember) for mods that do not depend on other mods. All mods that depend on other mods are loaded after those mods were loaded

R-One wrote:- Is there an alternative to MoreBlocks to have slopes without breaking the standards?

I currently work on a mod doing the same but less intrusive and properly aligning nodes when placed - but without the slopes and 1/16 thin walls/corners. It breaks up the nodes in 1/8 pieces and players craft the shaped nodes from this pieces (only the nodes that are used for default stairs are supported). The mod is not ready for public yet (no proper documentation, etc.).

But Moreblocks is a nice mod and it deserves to be fixed. But there seems to be not enough dev time right now.
 

User avatar
DS-minetest
Member
 
Posts: 1102
Joined: Thu Jun 19, 2014 19:49
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.
GitHub: DS-Minetest
In-game: DS

Re: [Mod] Better slab/log placement [place_rotated]

by DS-minetest » Fri Jul 19, 2019 15:46

Linuxdirk wrote:
R-One wrote:- where is the load order function of the mods documented?

Afaik it is "random" (hash, or ID, or inode, or whatever, I don't remember) for mods that do not depend on other mods. All mods that depend on other mods are loaded after those mods were loaded

You can look into the source code: https://github.com/minetest/minetest/blob/a6f784835244111c90c05b6aae47092c2c5763a7/src/content/mods.cpp#L336 But note that this will probably be changed in near time, see #8603.
It's not really random. There's no guaranteed order if there's no dependency. I think, the alphabetic order of the mod names does influence the mod loading order.
Do not call me -minetest.
Call me DS or DS-minetest.
I am German, so you don't have to pm me English if you are also German.
The background is a lie.
 

R-One
Member
 
Posts: 129
Joined: Wed Dec 20, 2017 23:06
Location: Nice, France

Re: [Mod] Better slab/log placement [place_rotated]

by R-One » Fri Jul 19, 2019 16:09

Thank you for all these answers!

I'm looking forward to seeing your new mod Linuxdirk ... And you're right MoreBlocks is a very good mods, but it breaks the standards which is detrimental to the interoperability with other mods.

I do not have the skills to patch this situation so by waiting, I will do without this mod.

I also found mods that meet my needs for slopes:Thank you for all these answers!

I'm looking forward to seeing your new mod Linuxdirk ... And you're right MoreBlocks is a very good mods, but it breaks the standards which is detrimental to the interoperability with other mods.

I do not have the skills to patch this situation so by waiting, I will do without this mod.

I also found mods that meet my needs for slopes:

mywoodslopes : https://forum.minetest.net/viewtopic.php?f=11&t=11433

myroofs : https://forum.minetest.net/viewtopic.php?f=11&t=11416

And finally, thanks again to the whole community for your work
 

User avatar
Linuxdirk
Member
 
Posts: 2055
Joined: Wed Sep 17, 2014 11:21
Location: Germany
In-game: Linuxdirk
 

R-One
Member
 
Posts: 129
Joined: Wed Dec 20, 2017 23:06
Location: Nice, France

Re: [Mod] Better slab/log placement [place_rotated]

by R-One » Thu Aug 15, 2019 08:26

Hi,



Really cool job, thanks!

Small question, I tried to add the code to apply the mod to all slab and stair but I have an error, can someone debug?

+ Spoiler


The debug :

Code: Select all
ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'stairs' in callback item_OnPlace(): ...netest-5.0.1-Skyblock\bin\..\mods\place_rotated\init.lua:69: attempt to call method 'get_pos' (a nil value)

 ERROR[Main]: stack traceback:
 ERROR[Main]:    ...netest-5.0.1-Skyblock\bin\..\mods\place_rotated\init.lua:69: in function 'get_point'
 ERROR[Main]:    ...netest-5.0.1-Skyblock\bin\..\mods\place_rotated\init.lua:105: in function 'callback'


thank you in advance
 


Return to WIP Mods



Who is online

Users browsing this forum: No registered users and 1 guest