[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: 807
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: 1196
Joined: Wed Oct 28, 2015 01:26
Location: A place
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).
My YuTube channel | I moderate the HOMETOWN Server. | Click here to see my (5) mods!
 

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: 1196
Joined: Wed Oct 28, 2015 01:26
Location: A place
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.
My YuTube channel | I moderate the HOMETOWN Server. | Click here to see my (5) mods!
 

User avatar
bosapara
Member
 
Posts: 379
Joined: Fri Apr 07, 2017 08:49
GitHub: bosapara
In-game: Jozet

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: 198
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: 1025
Joined: Thu Jun 19, 2014 19:49
Location: in front of my pc (which is at home)
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: 1025
Joined: Thu Jun 19, 2014 19:49
Location: in front of my pc (which is at home)
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: 893
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: 2544
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
I'm not your buddy, guy...
 

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!
 


Return to WIP Mods



Who is online

Users browsing this forum: Bing [Bot] and 7 guests