1
0
mirror of https://codeberg.org/tenplus1/mobs_redo.git synced 2024-12-25 10:10:21 +01:00

use tnt.boom() function instead of mobs:explosion

This commit is contained in:
TenPlus1 2017-07-08 21:11:22 +01:00
parent 7dc2d22ef6
commit 7e09281760
3 changed files with 8 additions and 118 deletions

121
api.lua
View File

@ -1683,33 +1683,21 @@ local do_states = function(self, dtime)
local pos = self.object:getpos() local pos = self.object:getpos()
local radius = self.explosion_radius or 1 local radius = self.explosion_radius or 1
local fire = self.explosion_fire or 1 local damage_radius = radius
local smoke = self.explosion_smoke or 1
-- dont damage anything if area protected or next to water -- dont damage anything if area protected or next to water
if minetest.find_node_near(pos, 1, {"group:water"}) if minetest.find_node_near(pos, 1, {"group:water"})
or minetest.is_protected(pos, "") then or minetest.is_protected(pos, "") then
mob_sound(self, self.sounds.explode) damage_radius = 0
self.object:remove()
-- effect(pos, 15, "tnt_smoke.png")
effect(pos, 32, "tnt_smoke.png", radius * 3, radius * 5, radius, 1, 0)
-- hurt player/mobs caught in blast area
entity_physics(pos, radius)
return
end end
pos.y = pos.y - 1
mobs:explosion(pos, radius, fire, smoke, self.sounds.explode)
self.object:remove() self.object:remove()
entity_physics(pos, radius) tnt.boom(pos, {
radius = radius,
damage_radius = damage_radius,
})
return return
end end
@ -2632,8 +2620,6 @@ minetest.register_entity(name, {
pathfinding = def.pathfinding, pathfinding = def.pathfinding,
immune_to = def.immune_to or {}, immune_to = def.immune_to or {},
explosion_radius = def.explosion_radius, explosion_radius = def.explosion_radius,
explosion_fire = def.explosion_fire,
explosion_smoke = def.explosion_smoke,
custom_attack = def.custom_attack, custom_attack = def.custom_attack,
double_melee_attack = def.double_melee_attack, double_melee_attack = def.double_melee_attack,
dogshoot_switch = def.dogshoot_switch, dogshoot_switch = def.dogshoot_switch,
@ -2863,101 +2849,6 @@ function mobs:spawn(def)
end end
-- set content id's
local c_air = minetest.get_content_id("air")
local c_ignore = minetest.get_content_id("ignore")
-- explosion (cannot break protected or unbreakable nodes)
function mobs:explosion(pos, radius, fire, smoke, sound)
radius = radius or 0
fire = fire or 0
smoke = smoke or 0
-- if area protected or near map limits then no blast damage
if minetest.is_protected(pos, "")
or not within_limits(pos, radius) then
return
end
-- explosion sound
if sound
and sound ~= "" then
minetest.sound_play(sound, {
pos = pos,
gain = 1.0,
max_hear_distance = 16
})
end
pos = vector.round(pos) -- voxelmanip doesn't work properly unless pos is rounded ?!?!
local vm = VoxelManip()
local minp, maxp = vm:read_from_map(vector.subtract(pos, radius), vector.add(pos, radius))
local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
local data = vm:get_data()
local p = {}
local pr = PseudoRandom(os.time())
if smoke > 0 then
--(pos, amount, texture, min_size, max_size, radius, gravity, glow)
effect(pos, 32, "tnt_smoke.png", radius * 3, radius * 5, radius, 1, 0)
end
for z = -radius, radius do
for y = -radius, radius do
local vi = a:index(pos.x + (-radius), pos.y + y, pos.z + z)
for x = -radius, radius do
p.x = pos.x + x
p.y = pos.y + y
p.z = pos.z + z
if (x * x) + (y * y) + (z * z) <= (radius * radius) + pr:next(-radius, radius)
and data[vi] ~= c_air
and data[vi] ~= c_ignore then
local n = node_ok(p).name
local on_blast = minetest.registered_nodes[n].on_blast
if on_blast then
on_blast(p)
elseif minetest.registered_nodes[n].groups.unbreakable == 1 then
-- do nothing
else
-- after effects
if fire > 0
and (minetest.registered_nodes[n].groups.flammable
or random(1, 100) < 60) then
-- Set fire (if node is present)
if minetest.registered_nodes[node_fire] then
minetest.set_node(p, {name = node_fire})
end
else
minetest.set_node(p, {name = "air"})
-- if smoke > 0 then
-- effect(p, 2, "tnt_smoke.png")
-- end
end
end
end
vi = vi + 1
end
end
end
end
-- register arrow for shoot attack -- register arrow for shoot attack
function mobs:register_arrow(name, def) function mobs:register_arrow(name, def)

View File

@ -90,8 +90,6 @@ This functions registers a new mob as a Minetest entity.
'double_melee_attack' if false then api will choose randomly between 'punch' and 'punch2' attack animations 'double_melee_attack' if false then api will choose randomly between 'punch' and 'punch2' attack animations
'on_blast' is called when an explosion happens near mob when using TNT functions, parameters are (object, damage) and returns (do_damage, do_knockback, drops) 'on_blast' is called when an explosion happens near mob when using TNT functions, parameters are (object, damage) and returns (do_damage, do_knockback, drops)
'explosion_radius' radius of explosion attack (defaults to 1) 'explosion_radius' radius of explosion attack (defaults to 1)
'explosion_fire' if true, explosion will create lots of fire (default: true)
'explosion_smoke' if true, explosion creates smoke particles (default: true)
'arrow' if the attack_type is "shoot" or "dogshoot" then the entity name of a pre-defined arrow is required, see below for arrow definition. 'arrow' if the attack_type is "shoot" or "dogshoot" then the entity name of a pre-defined arrow is required, see below for arrow definition.
'shoot_interval' the minimum shoot interval 'shoot_interval' the minimum shoot interval
'shoot_offset' +/- value to position arrow/fireball when fired 'shoot_offset' +/- value to position arrow/fireball when fired

View File

@ -1,7 +1,8 @@
default default
tnt
dye? dye?
farming? farming?
invisibility? invisibility?
intllib? intllib?
lucky_block? lucky_block?
cmi? cmi?