Page 1 of 2

[Mod] Better slab/log placement [place_rotated]

Posted: Thu Aug 30, 2018 22:08
by 12Me21
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

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

Posted: Sat Sep 01, 2018 17:53
by Nathan.S
This looks really neat.

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

Posted: Sat Sep 01, 2018 18:30
by GreenXenith
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).

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

Posted: Sat Sep 01, 2018 23:39
by 12Me21
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 ...

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

Posted: Sun Sep 02, 2018 03:47
by GreenXenith
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.

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

Posted: Sun Sep 02, 2018 12:15
by bosapara
Great, +10

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

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

Posted: Sun Sep 02, 2018 15:52
by 12Me21
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.

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

Posted: Sun Sep 02, 2018 21:01
by todada
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!

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

Posted: Mon Sep 03, 2018 13:36
by Beerholder
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? :-)

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

Posted: Mon Sep 03, 2018 18:11
by 12Me21
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.

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

Posted: Fri Sep 07, 2018 12:45
by DS-minetest
Some time ago I've used the same way to place technic cable plates. (https://github.com/minetest-mods/techni ... #L203-L236)
There are multiple mods that use this exact pointed pos, eg. digipad.

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

Posted: Wed Sep 12, 2018 17:54
by 12Me21
DS-minetest wrote:Some time ago I've used the same way to place technic cable plates. (https://github.com/minetest-mods/techni ... #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.

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

Posted: Thu Sep 13, 2018 16:40
by DS-minetest
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,
})

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

Posted: Thu Sep 13, 2018 23:19
by 12Me21
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

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

Posted: Tue Sep 18, 2018 13:20
by ManElevation
hmm... minetest needs this in the default mod

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

Posted: Sat Nov 03, 2018 12:03
by TumeniNodes
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

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

Posted: Fri Nov 16, 2018 19:07
by FiftySix
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

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

Posted: Fri Jul 19, 2019 13:07
by R-One
Hi, this mod is really cool ...

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

thank you in advance

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

Posted: Fri Jul 19, 2019 13:27
by Linuxdirk
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 :)

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

Posted: Fri Jul 19, 2019 14:24
by R-One
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 !

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

Posted: Fri Jul 19, 2019 14:53
by Linuxdirk
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.

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

Posted: Fri Jul 19, 2019 15:46
by DS-minetest
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/bl ... s.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.

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

Posted: Fri Jul 19, 2019 16:09
by R-One
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 : viewtopic.php?f=11&t=11433

myroofs : viewtopic.php?f=11&t=11416

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

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

Posted: Fri Jul 19, 2019 16:48
by Linuxdirk
Maybe I'll get a WIP release up during the weekend. But no promises.

pssst, not announced yet, but get a first WIP release here

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

Posted: Thu Aug 15, 2019 08:26
by R-One
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