[Mod] Better slab/log placement [place_rotated]

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

[Mod] Better slab/log placement [place_rotated]

by 12Me21 » Post

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: 1147
Joined: Wed Sep 24, 2014 17:47
GitHub: NathanSalapat
IRC: NathanS21
In-game: NathanS21
Location: Bigsby Texas
Contact:

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

by Nathan.S » Post

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
GreenXenith
Member
Posts: 1356
Joined: Wed Oct 28, 2015 01:26
GitHub: GreenXenith
Location: UTC-8:00
Contact:

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

by GreenXenith » Post

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).
YouTube | Mods | Patreon | Minetest Discord @greenxenith

You should not be able to read this message.

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

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

by 12Me21 » Post

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
GreenXenith
Member
Posts: 1356
Joined: Wed Oct 28, 2015 01:26
GitHub: GreenXenith
Location: UTC-8:00
Contact:

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

by GreenXenith » Post

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.
YouTube | Mods | Patreon | Minetest Discord @greenxenith

You should not be able to read this message.

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

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

by bosapara » Post

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
GitHub: 12Me21
Location: (Ignore all of my posts before 2018)

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

by 12Me21 » Post

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 » Post

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 » Post

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
GitHub: 12Me21
Location: (Ignore all of my posts before 2018)

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

by 12Me21 » Post

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
Desour
Member
Posts: 1469
Joined: Thu Jun 19, 2014 19:49
GitHub: Desour
IRC: Desour
In-game: DS
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.

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

by Desour » Post

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.
he/him; Codeberg; GitHub; ContentDB; public personal TODO list; "DS" is preferred (but often too short)

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

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

by 12Me21 » Post

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.

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

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

by Desour » Post

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,
})
he/him; Codeberg; GitHub; ContentDB; public personal TODO list; "DS" is preferred (but often too short)

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

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

by 12Me21 » Post

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
GitHub: ManElevation
IRC: ManElevation
In-game: ManElevation
Location: Madrid,Spain

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

by ManElevation » Post

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

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

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

by TumeniNodes » Post

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
A Wonderful World

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

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

by FiftySix » Post

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

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

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

by R-One » Post

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: 3217
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

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

by Linuxdirk » Post

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: 160
Joined: Wed Dec 20, 2017 23:06
Location: Nice, France

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

by R-One » Post

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: 3217
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

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

by Linuxdirk » Post

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
Desour
Member
Posts: 1469
Joined: Thu Jun 19, 2014 19:49
GitHub: Desour
IRC: Desour
In-game: DS
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.

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

by Desour » Post

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.
he/him; Codeberg; GitHub; ContentDB; public personal TODO list; "DS" is preferred (but often too short)

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

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

by R-One » Post

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

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

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

by Linuxdirk » Post

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

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

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

by R-One » Post

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
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)
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

Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests