Skip to content

Commit

Permalink
handle interactions w/ explosions (#3)
Browse files Browse the repository at this point in the history
* don't let explosions destroy sign entities

* destroy sign entities if sign node is exploded

* remove redundant destructor call

* make sure other things don't try to interact w/ the signs entity

* name will be "" for non-players or unknown players.

* remove default value from initial values

---------

Co-authored-by: Niklp <[email protected]>
  • Loading branch information
fluxionary and Niklp09 authored Oct 3, 2023
1 parent e25588c commit 2c1efed
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
16 changes: 15 additions & 1 deletion display_api/display.lua
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,15 @@ function display_api.on_destruct(pos)
end
end

function display_api.on_blast(pos, intensity)
if not minetest.is_protected(pos, "") then
local node = minetest.get_node(pos)
local drops = minetest.get_node_drops(node, "tnt:blast")
minetest.remove_node(pos)
return drops
end
end

-- On_rotate (screwdriver) callback for display_api items. Prevents invalid
-- rotations and reorients entities.
function display_api.on_rotate(pos, node, user, _, new_param2)
Expand All @@ -272,12 +281,17 @@ function display_api.register_display_entity(entity_name)
initial_properties = {
collisionbox = {0, 0, 0, 0, 0, 0},
visual = "upright_sprite",
textures = {}
textures = {},
collide_with_objects = false,
pointable = false
},
on_activate = display_api.on_activate,
get_staticdata = function(self)
return minetest.serialize({ nodepos = self.nodepos })
end,
on_blast = function(self, damage)
return false, false, {}
end,
})
end
end
Expand Down
6 changes: 6 additions & 0 deletions ontime_clocks/nodes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ minetest.register_node("ontime_clocks:green_digital", {
on_place = display_api.on_place,
on_construct = clock_on_construct,
on_destruct = display_api.on_destruct,
on_blast = display_api.on_blast,
on_rotate = display_api.on_rotate,
on_timer = clock_on_timer,
})
Expand Down Expand Up @@ -92,6 +93,7 @@ minetest.register_node("ontime_clocks:red_digital", {
on_place = display_api.on_place,
on_construct = clock_on_construct,
on_destruct = display_api.on_destruct,
on_blast = display_api.on_blast,
on_rotate = display_api.on_rotate,
on_timer = clock_on_timer,
})
Expand Down Expand Up @@ -124,6 +126,7 @@ minetest.register_node("ontime_clocks:white", {
on_place = display_api.on_place,
on_construct = clock_on_construct,
on_destruct = display_api.on_destruct,
on_blast = display_api.on_blast,
on_rotate = display_api.on_rotate,
on_timer = clock_on_timer,
})
Expand Down Expand Up @@ -156,6 +159,7 @@ minetest.register_node("ontime_clocks:frameless_black", {
on_place = display_api.on_place,
on_construct = clock_on_construct,
on_destruct = display_api.on_destruct,
on_blast = display_api.on_blast,
on_rotate = display_api.on_rotate,
on_timer = clock_on_timer,
})
Expand Down Expand Up @@ -188,6 +192,7 @@ minetest.register_node("ontime_clocks:frameless_gold", {
on_place = display_api.on_place,
on_construct = clock_on_construct,
on_destruct = display_api.on_destruct,
on_blast = display_api.on_blast,
on_rotate = display_api.on_rotate,
on_timer = clock_on_timer,
})
Expand Down Expand Up @@ -220,6 +225,7 @@ minetest.register_node("ontime_clocks:frameless_white", {
on_place = display_api.on_place,
on_construct = clock_on_construct,
on_destruct = display_api.on_destruct,
on_blast = display_api.on_blast,
on_rotate = display_api.on_rotate,
on_timer = clock_on_timer,
})
Expand Down
5 changes: 5 additions & 0 deletions signs/compatibility.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ minetest.register_lbm({ name = "signs:conpatibility_1",
-- We need to have this entity registered to be able to remove it.
if minetest.registered_entities["signs:text"] == nil then
minetest.register_entity("signs:text", {
on_activate = function(self)
if self.object then
self.object:remove()
end
end,
initial_properties = {
collisionbox = {0, 0, 0, 0, 0, 0},
visual = "upright_sprite",
Expand Down
1 change: 1 addition & 0 deletions signs_api/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ function signs_api.register_sign(mod, name, model)
display_api.on_construct(pos)
end,
on_destruct = display_api.on_destruct,
on_blast = display_api.on_blast,
on_rotate = signs_api.on_rotate,
on_receive_fields = signs_api.on_receive_fields,
on_punch = function(pos, node, player, pointed_thing)
Expand Down
1 change: 1 addition & 0 deletions steles/nodes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ for i, material in ipairs(steles.materials) do
set_formspec(pos)
end,
on_destruct = display_api.on_destruct,
on_blast = display_api.on_blast,
on_rotate = display_api.on_rotate,
on_receive_fields = function(pos, formname, fields, player)
if not minetest.is_protected(pos, player:get_player_name()) then
Expand Down

0 comments on commit 2c1efed

Please sign in to comment.