item questions how to do something on left and rigth and middle click ??

Post Reply
perromercenario
New member
Posts: 5
Joined: Wed Nov 04, 2020 00:06
In-game: perromercenario

item questions how to do something on left and rigth and middle click ??

by perromercenario » Post

Nigths good

im begining whith modding on minetest i have many questions
i have an item basic_stick

Code: Select all

minetest.register_craftitem("modmercenario:basic_stick", {
    description = "My Special Stick",
    inventory_image = "bstick.png"
})
how i do something on left click or rigth click or middle click whit the stick ?
can i get the position xyz from node or entity or whatever was click whit stick ?
can i store a value in the item like the position from the last question ?

can i set a block in the wordl where im clicking whit the stick ?

very much gratefull

perromercenario
New member
Posts: 5
Joined: Wed Nov 04, 2020 00:06
In-game: perromercenario

Re: item questions how to do something on left and rigth and middle click ??

by perromercenario » Post

i find something but not pretty clear how to use it
i find as an empty example this

Code: Select all

    on_rightclick = function(pos,node,clicker,itemstack)
    
    end,
i want to print on the chat window the content of pos to see the x y z values
is posible to print all the values inside an object like in the php print_r(object);
??

perromercenario
New member
Posts: 5
Joined: Wed Nov 04, 2020 00:06
In-game: perromercenario

Re: item questions how to do something on left and rigth and middle click ??

by perromercenario » Post

i find something but not pretty clear how to use it
i find as an empty example this

Code: Select all

    on_rightclick = function(pos,node,clicker,itemstack)
    
    end,
i want to print on the chat window the content of pos to see the x y z values
is posible to print all the values inside an object like in the php print_r(object);
??

User avatar
Andrey01
Member
Posts: 2469
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Re: item questions how to do something on left and rigth and middle click ??

by Andrey01 » Post

perromercenario wrote:
Wed Nov 04, 2020 02:17
how i do something on left click or rigth click or middle click whit the stick ?
To do something on right click you need to use on_place function. This function is a callback because it will be passed as an argument to the registration function and will be called there inside and therefore you need to define it in the table. For on left click there is on_use callback. There is like no a callback for the middle click.
perromercenario wrote:
Wed Nov 04, 2020 02:17
can i get the position xyz from node or entity or whatever was click whit stick ?
Yes, both those functions have pointed_thing table: https://github.com/minetest/minetest/bl ... .txt#L1479
perromercenario wrote:
Wed Nov 04, 2020 02:17
can i store a value in the item like the position from the last question ?
There is ItemStackMetaRef interface that used for saving some info and retrieving it from an itemstack: https://github.com/minetest/minetest/bl ... .txt#L6012 For accessing to that interface you need first to call itemstack:get_meta(): https://github.com/minetest/minetest/bl ... .txt#L5998 However, if you want to save a table, don`t forget to put it inside minetest.serialize().
perromercenario wrote:
Wed Nov 04, 2020 02:17
can i set a block in the wordl where im clicking whit the stick ?
You need to get above position when clicking and by some way to get a normal to that surface where you have clicked to. If you click on a floor, you can just add '0.5' to 'y' coord of the above:

Code: Select all

local new_pos = {x=pointed_thing.above.x, y=pointed_thing.above.y+0.5, z=pointed_thing.above.z}
and then call minetest.add_node(new_pos) or minetest.set_node(new_pos)

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests