Block that place other blocks

Post Reply
User avatar
X17
Member
Posts: 32
Joined: Sat Apr 24, 2021 17:44

Block that place other blocks

by X17 » Post

I will make a mod with a node. I want that the node place other blocks, but I don't know how I can make this. Can who say me how???

X17

User avatar
TenPlus1
Member
Posts: 3715
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: Block that place other blocks

by TenPlus1 » Post

This is how beds mod places 2 nodes after a bed is placed: https://github.com/minetest/minetest_ga ... pi.lua#L50

User avatar
X17
Member
Posts: 32
Joined: Sat Apr 24, 2021 17:44

Re: Block that place other blocks

by X17 » Post

Do you mean "minetest.set_node"?

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

Re: Block that place other blocks

by Linuxdirk » Post

You could use after_place_node in your node's definition to do something after the node was placed. There you can invoke minetest.set_node() to set a specific node in a specific location.

User avatar
X17
Member
Posts: 32
Joined: Sat Apr 24, 2021 17:44

Re: Block that place other blocks

by X17 » Post

So I must write "after_place_node = {minetest.set_node(name = "ITEMNAME")},"?

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

Re: Block that place other blocks

by Linuxdirk » Post

You must read the API :) I even linked the relevant part.

Code: Select all

minetest.register_node('modname:nodename', {
    [... node definition stuff ...]
    after_place_node = function(pos, placer, itemstack, pointed_thing)
        -- do whatever you want here. You have access to the placed node's position,
        -- the player who placed the node, the itemstack and the thing the node was
        -- placed against.
    end,
    [... node definition stuff ...]
})
How to handle the parameters/variables is also described in the API documentation.

User avatar
X17
Member
Posts: 32
Joined: Sat Apr 24, 2021 17:44

Re: Block that place other blocks

by X17 » Post

What I must write when I want that the second block is on my block? y=1 ??

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

Re: Block that place other blocks

by Linuxdirk » Post

In the function you have access to the position of the node you placed. pos is a table containing x, y, z as entries. You need to place your new node at pos.y-1.

Code: Select all

minetest.set_node({ x = pos.x, y = pos.y-1, z = pos.z }, { name = 'mymod:mynode' })
Again: everything you need is fully documented in lua_api.txt.


Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests