mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2025-01-08 08:09:32 +01:00
Implement gamerule tntExplodes
This commit is contained in:
parent
b16607cffc
commit
f43fdc07bb
3 changed files with 21 additions and 8 deletions
|
@ -1,14 +1,22 @@
|
||||||
local S = minetest.get_translator(minetest.get_current_modname())
|
local S = minetest.get_translator(minetest.get_current_modname())
|
||||||
local explosions_griefing = minetest.settings:get_bool("mcl_explosions_griefing", true)
|
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 = {}
|
||||||
|
|
||||||
tnt.BOOMTIMER = 4
|
tnt.BOOMTIMER = 4
|
||||||
tnt.BLINKTIMER = 0.25
|
tnt.BLINKTIMER = 0.25
|
||||||
|
|
||||||
---@param pos Vector
|
---@param pos vector.Vector
|
||||||
---@param entname string
|
---@param entname string
|
||||||
---@return ObjectRef?
|
---@return core.ObjectRef?
|
||||||
local function spawn_tnt(pos, entname)
|
local function spawn_tnt(pos, entname)
|
||||||
minetest.sound_play("tnt_ignite", { pos = pos, gain = 1.0, max_hear_distance = 15 }, true)
|
minetest.sound_play("tnt_ignite", { pos = pos, gain = 1.0, max_hear_distance = 15 }, true)
|
||||||
local ent = minetest.add_entity(pos, entname)
|
local ent = minetest.add_entity(pos, entname)
|
||||||
|
@ -18,8 +26,8 @@ local function spawn_tnt(pos, entname)
|
||||||
return ent
|
return ent
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param pos Vector
|
---@param pos vector.Vector
|
||||||
---@return ObjectRef?
|
---@return core.ObjectRef?
|
||||||
function tnt.ignite(pos)
|
function tnt.ignite(pos)
|
||||||
minetest.remove_node(pos)
|
minetest.remove_node(pos)
|
||||||
local e = spawn_tnt(pos, "mcl_tnt:tnt")
|
local e = spawn_tnt(pos, "mcl_tnt:tnt")
|
||||||
|
@ -30,7 +38,7 @@ end
|
||||||
---Add smoke particle of entity at pos.
|
---Add smoke particle of entity at pos.
|
||||||
---
|
---
|
||||||
---Intended to be called every step.
|
---Intended to be called every step.
|
||||||
---@param pos Vector
|
---@param pos vector.Vector
|
||||||
function tnt.smoke_step(pos)
|
function tnt.smoke_step(pos)
|
||||||
minetest.add_particle({
|
minetest.add_particle({
|
||||||
pos = vector.offset(pos, 0, 0.5, 0),
|
pos = vector.offset(pos, 0, 0.5, 0),
|
||||||
|
@ -201,6 +209,8 @@ end
|
||||||
end]]
|
end]]
|
||||||
|
|
||||||
function TNT:on_step(dtime, _)
|
function TNT:on_step(dtime, _)
|
||||||
|
if self._removed then return end
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
tnt.smoke_step(pos)
|
tnt.smoke_step(pos)
|
||||||
self.timer = self.timer + dtime
|
self.timer = self.timer + dtime
|
||||||
|
@ -215,8 +225,10 @@ function TNT:on_step(dtime, _)
|
||||||
self.blinkstatus = not self.blinkstatus
|
self.blinkstatus = not self.blinkstatus
|
||||||
end
|
end
|
||||||
if self.timer > tnt.BOOMTIMER then
|
if self.timer > tnt.BOOMTIMER then
|
||||||
mcl_explosions.explode(self.object:get_pos(), 4, {}, self.object)
|
if gamerule_tntExplodes then
|
||||||
self.object:remove()
|
mcl_explosions.explode(self.object:get_pos(), 4, {}, self.object)
|
||||||
|
end
|
||||||
|
mcl_util.remove_entity(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# textdomain: mcl_tnt
|
# 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 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.=
|
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=
|
TNT=
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
name = mcl_tnt
|
name = mcl_tnt
|
||||||
depends = mcl_explosions, mcl_particles
|
depends = mcl_explosions, mcl_particles, vl_tuning
|
||||||
optional_depends = mcl_sounds, mcl_mobitems, doc_identifier, mesecons
|
optional_depends = mcl_sounds, mcl_mobitems, doc_identifier, mesecons
|
||||||
|
|
Loading…
Reference in a new issue