Ghaydn's miscellaneous modding questions

Post Reply
User avatar
Ghaydn
Member
Posts: 54
Joined: Sat Sep 26, 2020 11:58
In-game: ghaydn
Location: Moscow, Russia

Ghaydn's miscellaneous modding questions

by Ghaydn » Post

How to make a tool that could be rightclick-placed as a node? And it must keep it's wear. Wear is the only thing why I need tool for that instead of a regular node. I tried to do this by registering a standalone node that would be placed with "on_place" (and it worked). But now I cannot figure out how to convert wear into any of node properties and back. As I understand, to place a node I need to use this function:

Code: Select all

itemstack = minetest.item_place(fakestack, placer, pointed_thing, wdir)
But it cannot pass any node data.
And to pick i need to use drop = itemname, there is no possibility to use any function at all and I could not pass wear through it. When I tried do describe an itemstack (like {name = itemname, wear = mywear}), it just dropped nothing.
Google didn't help, also I could not find any similar examples in mods.

I renamed this topic so as not to create new ones.
Last edited by Ghaydn on Mon Mar 01, 2021 22:07, edited 1 time in total.
Nobody understands me... — вРН БШ ЯЙЮГЮКХ?

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

Re: Place tools as nodes

by Linuxdirk » Post

Nodes don't know what wear is. You could use node meta data to store the wear value but no idea how to apply it when digging the node.

If the tool is only a tool to store some kind of wear value ad it's not used as an actual tool to dig nodes maybe use meta data in general instead of a wear value.

I do this for my Unified Hammers mod to have perfect control over how often the hammers can be used (and to do other things that are not possible with current Minetest API).

User avatar
Ghaydn
Member
Posts: 54
Joined: Sat Sep 26, 2020 11:58
In-game: ghaydn
Location: Moscow, Russia

Re: Place tools as nodes

by Ghaydn » Post

Linuxdirk wrote:
Wed Feb 24, 2021 10:41
If the tool is only a tool to store some kind of wear value
Not just some kind of wear value, but wear value that is shown as wear value. AFAIK engine draws wear bar only on tools. So the main question is: how to pass any data to the just-created node and pass it back to the just-created item when digging that node?
Nodes don't know what wear is. You could use node meta data to store the wear value
I know that. I tried to use param1 for that purpose (it's fidelity is enough for me), but no matter - I could not find how to pass any value, no matter to param1 or to metadata.
Nobody understands me... — вРН БШ ЯЙЮГЮКХ?

ShadMOrdre
Member
Posts: 1118
Joined: Mon Dec 29, 2014 08:07
Location: USA

Re: Place tools as nodes

by ShadMOrdre » Post

One method would be to add the "tool" as an entity, instead of a node. If this is not desirable, then the next idea would be this. When "placing" the tool, you will need to add the wear to the node. Here you already use param1. The next step is to "drop" the item when it is "dug". Before removing the node, add the tool to the itemstack, set the wear after making the itemstack, and after the tool is updated, then remove the node.

Code: Select all

local input = inv:get_stack('input',1)

input:add_wear( saved_wear_value )
inv:set_stack("input", 1, input)

This code is from the anvil mod. When the user places the tool on the anvil, and then strikes the anvil with the hammer tool, the tool on the anvil is repaired, and the hammer is worn. In this case, however, the tool being repaired is an entity, not a node. The anvil is a node, like an itemframe.

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

Re: Place tools as nodes

by Linuxdirk » Post

Ghaydn wrote:
Wed Feb 24, 2021 15:35
how to pass any data to the just-created node and pass it back to the just-created item when digging that node?
I basically did this with custom on_use, etc. functions and manually setting wear.

User avatar
Ghaydn
Member
Posts: 54
Joined: Sat Sep 26, 2020 11:58
In-game: ghaydn
Location: Moscow, Russia

Re: Place tools as nodes

by Ghaydn » Post

ShadMOrdre wrote:
Wed Feb 24, 2021 16:32
an entity, instead of a node.
Not an option because of compatibility reasons. I'm overriding an existing default node.
Linuxdirk wrote:
Wed Feb 24, 2021 17:27
basically did this with custom on_use, etc. functions and manually setting wear.
I'm leaning towards the same path.

Thanks for your answers. Will think now.

Upd: what I did not know is that minetest.item_place returns two results: itemstack and position. Lua does things... This simplifies everything, because I was adraid to override that function, it is too complicated, and now I gotta override only on_dig, that I already almost did.
Nobody understands me... — вРН БШ ЯЙЮГЮКХ?

User avatar
rubenwardy
Moderator
Posts: 6977
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: Place tools as nodes

by rubenwardy » Post

One thing you can do is have a node registration and a tool registration. Tool registrations aren't limited, only node registrations. You can override on_place to place a node from a tool, and drops to drop a tool. This will be seamless

Doors in the door mod in MTG does this
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
Ghaydn
Member
Posts: 54
Joined: Sat Sep 26, 2020 11:58
In-game: ghaydn
Location: Moscow, Russia

Re: Place tools as nodes

by Ghaydn » Post

rubenwardy wrote:
Thu Feb 25, 2021 02:09
You can override on_place to place a node from a tool, and drops to drop a tool.
If I do that, wear will be reset every place/dig.
What I did is modified on_place and on_dig. It all works fine with an exception of just one thing. My node is attached_node=1, so it immediately turns into item when I dig block under it. It turns into item and loses it's wear. And I cannot understand: what callback should I override to prevent that? Or there's no such callback?
Nobody understands me... — вРН БШ ЯЙЮГЮКХ?

User avatar
Ghaydn
Member
Posts: 54
Joined: Sat Sep 26, 2020 11:58
In-game: ghaydn
Location: Moscow, Russia

Weird formspecs of furnace

by Ghaydn » Post

Recently I tried to understand how default furnace works in MTG. First of all that was an attempt to understand formspecs. But these two lines made me think that maybe it works on blood magic:

Code: Select all

		"image[3.75,1.5;1,1;gui_furnace_arrow_bg.png^[lowpart:"..
		(item_percent)..":gui_furnace_arrow_fg.png^[transformR270]"..
I actually understood what they mean. But still I have several questions:
Those brackets open and never close. Twice. Why doesn't engine behave as if it was an error?
This ^ symbol transforms original image somehow. Okay, maybe it can transform not only images? Where is it said?
This "lowpart" and "transformR270" are some kind of functions. What functionse else are there? What else is hidden in that mysterious deep?
And the main question is: where to get the book of spells?
Nobody understands me... — вРН БШ ЯЙЮГЮКХ?

User avatar
Skamiz Kazzarch
Member
Posts: 618
Joined: Fri Mar 09, 2018 20:34
GitHub: Skamiz
In-game: Skamiz
Location: la lojbaugag.

Re: Ghaydn's miscellaneous modding questions

by Skamiz Kazzarch » Post

Here is the book of all the spells: https://github.com/minetest/minetest/bl ... i.txt#L407
Though the specific ones you seek to learn are within the next 200 lines from the place I am pointing you to.

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

Re: Ghaydn's miscellaneous modding questions

by Linuxdirk » Post

^ is to concatenate textures and texture modifiers and [ denotes a texture modifier.

Check the Lua API documentation. Everything is described there.

https://github.com/minetest/minetest/bl ... i.txt#L407

User avatar
Ghaydn
Member
Posts: 54
Joined: Sat Sep 26, 2020 11:58
In-game: ghaydn
Location: Moscow, Russia

Re: Ghaydn's miscellaneous modding questions

by Ghaydn » Post

That was unexpected. I thought this is a part of formspec markup language. And also I thought that this lua_api describes the same as dev.minetest.net.
Thank you. Now I will probably read this txt from beginning to end. Pretty sure that there are much more details that I missed.
Nobody understands me... — вРН БШ ЯЙЮГЮКХ?

User avatar
Skamiz Kazzarch
Member
Posts: 618
Joined: Fri Mar 09, 2018 20:34
GitHub: Skamiz
In-game: Skamiz
Location: la lojbaugag.

Re: Ghaydn's miscellaneous modding questions

by Skamiz Kazzarch » Post

'dev.minetest.net' is... outdated at best. I have found it usefull in one or two cases where it provided helpfull example code, but in 99 % of cases the API is the place to go to.

User avatar
Ghaydn
Member
Posts: 54
Joined: Sat Sep 26, 2020 11:58
In-game: ghaydn
Location: Moscow, Russia

Re: Ghaydn's miscellaneous modding questions

by Ghaydn » Post

Is there any way to make an entity that rotates and stops sometimes? I can add a property "automatic_rotate = X" in the node registration, but seems like I cannot stop this automatic rotation after the entity has been spawned. I can register two entities: one is autorotating, second is not; but what if I want to change speed of this rotation?
Nobody understands me... — вРН БШ ЯЙЮГЮКХ?

User avatar
MisterE
Member
Posts: 693
Joined: Sun Feb 16, 2020 21:06
GitHub: MisterE123
IRC: MisterE
In-game: MisterE

Re: Ghaydn's miscellaneous modding questions

by MisterE » Post

you will have to implement the rotation yourself. in the onstep, increment the yaw with get_yaw and set_yaw.

User avatar
Ghaydn
Member
Posts: 54
Joined: Sat Sep 26, 2020 11:58
In-game: ghaydn
Location: Moscow, Russia

Re: Ghaydn's miscellaneous modding questions

by Ghaydn » Post

MisterE wrote:
Mon Dec 20, 2021 11:58
in the onstep, increment the yaw
That might decrease the performance if there will be many such entities. But okay, while they're 2-3, it works fine.
Nobody understands me... — вРН БШ ЯЙЮГЮКХ?

User avatar
AspireMint
Member
Posts: 415
Joined: Mon Jul 09, 2012 12:59
GitHub: AspireMint
IRC: AspireMint
In-game: AspireMint
Location: Stuck at spawn

Re: Ghaydn's miscellaneous modding questions

by AspireMint » Post

Create object with animation (tool rotation), and use set_animation (https://github.com/minetest/minetest/bl ... .txt#L6542), you can control speed (or stop animation).

User avatar
MisterE
Member
Posts: 693
Joined: Sun Feb 16, 2020 21:06
GitHub: MisterE123
IRC: MisterE
In-game: MisterE

Re: Ghaydn's miscellaneous modding questions

by MisterE » Post

Ghaydn wrote:
Wed Dec 22, 2021 05:13
MisterE wrote:
Mon Dec 20, 2021 11:58
in the onstep, increment the yaw
That might decrease the performance if there will be many such entities. But okay, while they're 2-3, it works fine.
it would be no worse than mobkit or mobsredo mobs, they do the same with looking at players, etc

User avatar
Ghaydn
Member
Posts: 54
Joined: Sat Sep 26, 2020 11:58
In-game: ghaydn
Location: Moscow, Russia

Re: Ghaydn's miscellaneous modding questions

by Ghaydn » Post

Does anybody know how collision detection worked in old MT (at least 5.2)? For entities, i mean. Because currently it's very easy: we have on_step(self, dtime, moveresult) and this moveresult contents all collisions. In 5.2 there was no moveresult.
Nobody understands me... — вРН БШ ЯЙЮГЮКХ?

User avatar
Mantar
Member
Posts: 589
Joined: Thu Oct 05, 2017 18:46
Contact:

Re: Ghaydn's miscellaneous modding questions

by Mantar » Post

AFAIK there was no way to get collision detection in LUA before it was added in 5.3. I saw a while back that Mineclone 2 used a workaround where an arrow "collides" with a target if it ends up in a node close to the target object's location.
Lead dev of Exile, git repo: https://codeberg.org/Mantar/Exile

User avatar
Ghaydn
Member
Posts: 54
Joined: Sat Sep 26, 2020 11:58
In-game: ghaydn
Location: Moscow, Russia

Re: Ghaydn's miscellaneous modding questions

by Ghaydn » Post

Mantar wrote:
Sun Dec 26, 2021 20:26
AFAIK there was no way to get collision detection in LUA before it was added in 5.3.
That's sad enough. Not too much, but still sad.

Another question.
MT automatically generates inventory images if those were not specified on node registration. There is a function "inventorycube" to make one for cubic drawtypes. But what about nodeboxes and meshes? Is there a way to generate an inventory image for all available drawtypes? I mean, useful texture, that could be modified, like texture^[modified .
(looks like there is no way to get it, that's sad too)
Nobody understands me... — вРН БШ ЯЙЮГЮКХ?

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests