Implement gamerule tntExplodes

This commit is contained in:
teknomunk 2025-01-01 08:00:18 -06:00
parent b16607cffc
commit f43fdc07bb
3 changed files with 21 additions and 8 deletions

View file

@ -1,14 +1,22 @@
local S = minetest.get_translator(minetest.get_current_modname())
local explosions_griefing = minetest.settings:get_bool("mcl_explosions_griefing", true)
local gamerule_tntExplodes = true
vl_tuning.setting("gamerule:tntExplodes", "bool", {
set = function(value) gamerule_tntExplodes = value end,
get = function() return gamerule_tntExplodes end,
default = true,
description = S("Whether TNT explodes after activation."),
})
tnt = {}
tnt.BOOMTIMER = 4
tnt.BLINKTIMER = 0.25
---@param pos Vector
---@param pos vector.Vector
---@param entname string
---@return ObjectRef?
---@return core.ObjectRef?
local function spawn_tnt(pos, entname)
minetest.sound_play("tnt_ignite", { pos = pos, gain = 1.0, max_hear_distance = 15 }, true)
local ent = minetest.add_entity(pos, entname)
@ -18,8 +26,8 @@ local function spawn_tnt(pos, entname)
return ent
end
---@param pos Vector
---@return ObjectRef?
---@param pos vector.Vector
---@return core.ObjectRef?
function tnt.ignite(pos)
minetest.remove_node(pos)
local e = spawn_tnt(pos, "mcl_tnt:tnt")
@ -30,7 +38,7 @@ end
---Add smoke particle of entity at pos.
---
---Intended to be called every step.
---@param pos Vector
---@param pos vector.Vector
function tnt.smoke_step(pos)
minetest.add_particle({
pos = vector.offset(pos, 0, 0.5, 0),
@ -201,6 +209,8 @@ end
end]]
function TNT:on_step(dtime, _)
if self._removed then return end
local pos = self.object:get_pos()
tnt.smoke_step(pos)
self.timer = self.timer + dtime
@ -215,8 +225,10 @@ function TNT:on_step(dtime, _)
self.blinkstatus = not self.blinkstatus
end
if self.timer > tnt.BOOMTIMER then
mcl_explosions.explode(self.object:get_pos(), 4, {}, self.object)
self.object:remove()
if gamerule_tntExplodes then
mcl_explosions.explode(self.object:get_pos(), 4, {}, self.object)
end
mcl_util.remove_entity(self)
end
end

View file

@ -1,4 +1,5 @@
# textdomain: mcl_tnt
Whether TNT explodes after activation.=
An explosive device. When it explodes, it will hurt living beings and destroy blocks around it. TNT has an explosion radius of @1. With a small chance, blocks may drop as an item (as if being mined) rather than being destroyed. TNT can be ignited by tools, explosions, fire, lava and redstone signals.=
An explosive device. When it explodes, it will hurt living beings. TNT has an explosion radius of @1. TNT can be ignited by tools, explosions, fire, lava and redstone signals.=
TNT=

View file

@ -1,3 +1,3 @@
name = mcl_tnt
depends = mcl_explosions, mcl_particles
depends = mcl_explosions, mcl_particles, vl_tuning
optional_depends = mcl_sounds, mcl_mobitems, doc_identifier, mesecons