Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make TNT respect on_blast, implement on_blast for some nodes #450

Closed
wants to merge 6 commits into from

Conversation

Wuzzy2
Copy link
Contributor

@Wuzzy2 Wuzzy2 commented Mar 7, 2015

This PR alters the way how TNT destroys nodes in a way which I think is much saner and more mod-friendly.

It makes TNT check first whether the node which is about to be destoyed implements on_blast, a function which is supposed to be called when explosions occour (see lua_api.txt). If this function exists, this function will be called. If this function does not exist, the TNT reverts to the default behavior, which is destroying the node with minetest.remove_node.
This should now finally make it possible to define nodes which are able to “defend themselves” against TNT explosions.

While I was at it, I also implemented on_blast for the following nodes:

  • Steel Door: Ignores explosion (meaning that it does not get destroyed)
  • Locked Chest: Ignores explosion
  • Fire: Ignores explosion
  • TNT: Starts burning
  • Burning TNT: Ignores explosion
  • Gunpowder: Starts burning
  • Burning Gunpowder: Ignores explosion

This also replaces some of the destruction logic from the TNT node itself, it now only checks against air directly.

Implemented nodes:
- Steel Door: Ignores explosion
- Locked Chest: Ignores explosion
- Fire: Ignores explosion
- TNT: Starts burning
- Burning TNT: Explodes immediately
- Gunpowder: Starts burning
- Burning Gunpowder: Ignores explosion
@PilzAdam
Copy link
Contributor

PilzAdam commented Mar 7, 2015

👍
Maybe add a comment in the empty on_blast functions, to clarify that it means that they are not affected by explosions.

@Lymkwi
Copy link
Contributor

Lymkwi commented Mar 7, 2015

👍 It allows us to protect some nodes which souldn't be destroyed, be randomly destroyed or stay saved.
Also, when a chest is exploded, it should drop its content to the ground, with minetest.add_item, to keep the items placed being so players could get them back.

@C1ffisme
Copy link

C1ffisme commented Mar 7, 2015

👍

What about obsidian and default:cloud? They could ignore the explosion, just to give players and server moderators a way to protect their builds.

@Ekdohibs
Copy link
Member

Ekdohibs commented Mar 7, 2015

Looks good, but some normal nodes (I mean, nodes you can build with) could be protected against blast (perhaps nodes such as some metal blocks would be a good idea).

@C1ffisme
Copy link

C1ffisme commented Mar 7, 2015

Yeah, or perhaps each metal/obsidian block could have their own destruction scripts with a chance wheather or not they blow up.

@Wuzzy2
Copy link
Contributor Author

Wuzzy2 commented Mar 7, 2015

Comments have been added.
There does not seem to be a consensus about what to do with other nodes. Therefore, I won't add any further on_blast functions. If anyone insists, it can be done in a new PR. :P

@@ -82,7 +82,14 @@ local function destroy(drops, pos, cid)
if def and def.flammable then
minetest.set_node(pos, fire_node)
else
minetest.remove_node(pos)
local nodename = minetest.get_node(pos).name
local on_blast = minetest.registered_nodes[nodename].on_blast
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the cid_data cache for this to prevent the expensive lookups.

@sfan5
Copy link
Member

sfan5 commented Mar 8, 2015

👍

@Wuzzy2
Copy link
Contributor Author

Wuzzy2 commented Mar 8, 2015

@PilzAdam and @ShadowNinja: Done.

@Ekdohibs
Copy link
Member

You should make on_blast destruct the other part of the object for multi-node objects (doors, beds, etc.) too; otherwise, looks good.

@Wuzzy2
Copy link
Contributor Author

Wuzzy2 commented May 9, 2015

@Novatux: Done.

I have added on_blast for doors. When one piece of the door gets its on_blast called, both parts are destroyed. There are no drops.

Beds seem to already work out of the box, because they use on_destruct. Implementing on_blast seems to be redundant here. I have also tested it, blasts seem to always destroy the whole bed.

There are no other multi-node objects in Minetest Game as far I know.

@Ekdohibs
Copy link
Member

8bc8dd6

@Ekdohibs Ekdohibs closed this May 12, 2015
pos.y = pos.y - 1
check_and_blast(pos, name..other_door_type)
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use elseif rather than an else if then end chain.
Also, you can add a step value of 1 or -1 instead of copy-pasting the function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants