[Question] Pre-Dig function when crack_anylength.png is used[Answered]

Post Reply
User avatar
sirrobzeroone
Member
Posts: 279
Joined: Mon Jul 16, 2018 07:56

[Question] Pre-Dig function when crack_anylength.png is used[Answered]

by sirrobzeroone » Post

I'm trying to find the piece of code that applies the crack_anylength.png while your digging/hitting a node but before its dug. I did hunt through all the builtin lua code but no luck I did try skimming some of the relevant C code but nothing jumped out and I couldnt find a reference to crack_anylength.png.

Mainly Im intrested in how it applies crack_anylength so that slower tools show the frames slower and faster tools show them faster.

I'm looking at this as depending on conditions I want the same tool digging the same node to dig faster or slower which Im fairly means I need a custom on_use function, but as much as possible I wish to retain all the default functionality so Im hoping that code is in lua but even if it's not I'd like to look at the C code to see what it does.

Thanks for the help or any suggestions a to a better way to go.
Last edited by sirrobzeroone on Fri Feb 19, 2021 22:50, edited 1 time in total.

User avatar
Krock
Developer
Posts: 4589
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: [Question] Pre-Dig function when crack_anylength.png is used

by Krock » Post

https://github.com/minetest/minetest/bl ... 1362-L1368

What it does is very simple:
1) Load the texture and get its dimensions
2) Get the amount of animated frames (height / width)
3) (in Game::handleDigging) get the ratio of the digging time to its whole duration and select the correct frame
4) overlay the texture over the node
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

User avatar
sirrobzeroone
Member
Posts: 279
Joined: Mon Jul 16, 2018 07:56

Re: [Question] Pre-Dig function when crack_anylength.png is used

by sirrobzeroone » Post

Thanks Krock, I actually hoped it was something as simple as that as I want to "break" or change the minmum default behaviour that I can/re-replicate.

ShadMOrdre
Member
Posts: 755
Joined: Mon Dec 29, 2014 08:07
GitHub: ShadMOrdre
In-game: shadmordre
Location: USA

Re: [Question] Pre-Dig function when crack_anylength.png is used[Answered]

by ShadMOrdre » Post

I know this is answered, but was wondering if using a nodebox to show node degradation could be implemented. While the crack animation is nice, I've always wanted a more 3D representation of a node being mined.

Shad
MY MODS: lib_ecology lib_materials lib_clouds lib_node_shapes ---- Inspired By: Open Source Virtual World Simulator Opensimulator.

User avatar
sirrobzeroone
Member
Posts: 279
Joined: Mon Jul 16, 2018 07:56

Re: [Question] Pre-Dig function when crack_anylength.png is used[Answered]

by sirrobzeroone » Post

I have hit a couple of snags which I think would also cause problems using a node box overlay, although Im at a fairly basic level of Lua scripting so these might be easier to overcome than I think.
  • Capturing when LMB is held down. I've been trying to refresh or reget this value inside a loop inside on_use, even went so far as to setup a global variable inside an onstep but when im inside the loop inside on_use no luck getting the global variable to update its like everything is frozen when im in that on_use loop for my player character.
  • Second one I hit was working out how to dynamically overlay a texture on the fly on a node. I hit this one in my Comboblock mod as well and for that I ended up having to register every combo as a new node. I think for this one I might be able to cheat replace the node with an entity and stick another entity over the top but I havent tried that yet, not sure if I can put an entity over the node but if i can that might work better...lots of if's and buts there...
The first issue i've hit a bit of a wall on the second one i still have ideas to try which if they work might also work with a nodebox overlay...er assumign entities support nodebox's??

I'd be very happy to take thoughts and ideas though :)

ShadMOrdre
Member
Posts: 755
Joined: Mon Dec 29, 2014 08:07
GitHub: ShadMOrdre
In-game: shadmordre
Location: USA

Re: [Question] Pre-Dig function when crack_anylength.png is used[Answered]

by ShadMOrdre » Post

Since there is technically only about 4 frames of animation used to represent the crack, each frame a rough estimation of damage done to the node, I was thinking of implementing 4 nodeboxes, each a rough estimation of damage done. The nodeboxes would be premade, much like the crack.png animation. I would also argue that the nodeboxes should be divided at no more than 16x16 divisions, so as to allow the various texture resolutions to still be used, and look nice.

Since some of this is handled by the engine, this is probably a dead end. This would also look out of place for any node that uses overlays or multiple textures. Where would the textures be placed on the degraded nodeboxes? For basic nodes like stone or tree, this would look ok, but leaves and dirt with grass would not, I think. Still, as a feature, it would be nice to use a nodebox instead of an animated texture.

Not all games use dirt with grass.....


Shad
MY MODS: lib_ecology lib_materials lib_clouds lib_node_shapes ---- Inspired By: Open Source Virtual World Simulator Opensimulator.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 2 guests