Page 1 of 1

Make one specific node unbreakable inside a world [solved]

PostPosted: Wed Mar 04, 2015 22:27
by minetestcr
Hello!

Is there a way to make one type of nodes unbreakable inside a world?
Wool nodes must be unbreakable, other nodes must keep their original attributes.

What file in the world folder must I change to specify this?

thanks a lot?

Re: Make one specific node unbreakable inside a world

PostPosted: Wed Mar 04, 2015 22:31
by rubenwardy
You need to edit a mod or make your own mod. Use the immortal group. (groups={immortal=1})

You can install mods in worlds/worldname/worldmods/

I can't write a mod for you ATM, but it'll be like this:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.override_item("wool:red", {
        groups={immortal=1}
})

Re: Make one specific node unbreakable inside a world

PostPosted: Wed Mar 04, 2015 22:45
by minetestcr
thanks a lot rubenwardy, I'm gonna try that. I'll let you know how it goes...

Re: Make one specific node unbreakable inside a world

PostPosted: Thu Mar 05, 2015 16:23
by minetestcr
Hello rubenwardy!

I made the mod and it's working fine for me. Thank you very much for your help, your answer gave me all the information I neded.

I was trying to upload the mod to the mods forum but I don't have the option to create a new topic for Mod Releases!!!! so, I'm attaching the file to this post.

This would be officially my first mod!!!!!!!!!!!!! = )

Re: Make one specific node unbreakable inside a world [solve

PostPosted: Thu Mar 05, 2015 18:13
by rubenwardy
You need to post in WIP Mods. See Minetest Modding Book > Releasing a mod

You may want to consider creating your own wool so that people can still place breakable wool.

Re: Make one specific node unbreakable inside a world [solve

PostPosted: Fri Mar 06, 2015 18:07
by minetestcr
rubenwardy wrote:You need to post in WIP Mods. See Minetest Modding Book > Releasing a mod

You may want to consider creating your own wool so that people can still place breakable wool.



I'm going to look into that, thanks!

Re: Make one specific node unbreakable inside a world [solve

PostPosted: Sat Mar 07, 2015 06:24
by Wuzzy
Actually, it is not quite as easy to make a node truly unbreakable.
It is not done by just adding your node to the group “immortal=1”.

This will only protect the node from being mined by ordinary mining tools.
There will still be many ways to break your node:

  • TNT from the default game
  • Similar TNT or explosive mods
  • Replacer Tool (does not actually break the node, but you can replace it and thus remove it from the world indirectly)
  • Shooting it with a mining laser from Technic mod
  • Possibly even the cave generator may remove it

You can “harden” your node by adding this code to the node definition (I added some comments, feel free to remove them afterwards):
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
diggable = false, --[[ protects against normal digging ]]
can_dig = function() return false end, --[[ some mods use this function to check for digging instead ]]
on_blast = function() end, -- [[this function is intended to be called by explosion mods such as TNT. It should handle a blast manually. Since we want to keep our node, we simply do nothing, thus keep our node.]]
is_ground_content = false, --[[ protects against cave generator ]]
drop = "", --[[ I don't know if this is really needed, but since your node is supposed to be unbreakable, drops are not needed anyways]]
groups = {immortal=1}, --[[ don't forget to add other groups you may want!]]


Sadly, most TNT mods (including TNT from minetest_game) ignore on_blast and call minetest.remove_node directly. There is no good way for a mod to defend itself against minetest.remove_node, so I consider this a problem in the TNT mod itself, because there is not anything you can do against it so far.
IMO mods should never call minetest.remove_node directly if its not for debugging or testing reasons, because this weakens “unbreakable” blocks.

Above code has been taken directly from my bedrock2 mod, where I have tried to ensure that bedrock is truly unbreakable (still haven't achieved this goal, thanks to TNT). I still have added on_blast because I hope that on_blast support will be added to the TNT mods in the future.



Additionally, it will still be possible to push and pull the node by pistons from the Mesecons mod. This is not the same as breaking the node, but in case you also want to prevent this, you first have to optionally depend on mesecons_mvps and then add this code into your mod (and don't forget to add your node name):
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-- NOTE: replace node_name with the name of your node
if minetest.get_modpath("mesecons_mvps") ~= nil then
   mesecon:register_mvps_stopper(node_name)
end



Further reading:
viewtopic.php?f=47&t=11272
viewtopic.php?f=9&t=11271

EDIT:
Minetest Game (development version) finally respects on_blast now. So it is now possible to create a block which can not be destroyed by Minetest Game's TNT.

Re: Make one specific node unbreakable inside a world [solve

PostPosted: Sun Mar 15, 2015 16:12
by minetestcr
Hello Wuzzy!


Very interesting all the information you gave with this answer. I guess my [solved] label isn't entirely true hahaha!

I was trying to make wool unbreakable for an specific world that will be played by my students in school, and so far it has worked well vecause they don't have access to tnt in this world. But I find your answer very helpful because I think I will need it for future projects.

I will try some mods with the things you mention here and I'll get back to you when I do. Thanks a lot.