particles, on_blast(), luacheckrc

This commit is contained in:
NatureFreshMilk 2019-07-29 13:13:46 +02:00
parent 655d4bb191
commit b60bc6328f
3 changed files with 72 additions and 15 deletions

22
.luacheckrc Normal file

@ -0,0 +1,22 @@
unused_args = false
allow_defined_top = true
globals = {
"minetest",
"spacecannon"
}
read_globals = {
-- Stdlib
string = {fields = {"split"}},
table = {fields = {"copy", "getn"}},
-- mod deps
"technic", "default",
-- Minetest
"minetest",
"vector", "ItemStack",
"dump"
}

@ -57,13 +57,13 @@ local register_spacecannon = function(def)
end end
if collided then if collided then
spacecannon.destroy(pos, def.range) spacecannon.destroy(pos, def.range, def.intensity)
self.object:remove() self.object:remove()
end end
elseif node.name ~= "air" and node.name ~= "vacuum:vacuum" then elseif node.name ~= "air" and node.name ~= "vacuum:vacuum" then
-- collision -- collision
spacecannon.destroy(pos, def.range) spacecannon.destroy(pos, def.range, def.intensity)
self.object:remove() self.object:remove()
end end
@ -71,8 +71,8 @@ local register_spacecannon = function(def)
on_activate = function(self, staticdata) on_activate = function(self, staticdata)
minetest.after(def.timeout, minetest.after(def.timeout,
function(self) function(me)
self.object:remove() me.object:remove()
end, end,
self) self)
end end
@ -143,8 +143,6 @@ local register_spacecannon = function(def)
end, end,
on_receive_fields = function(pos, formname, fields, sender) on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.get_meta(pos);
if fields.fire then if fields.fire then
spacecannon.fire(pos, def.color, def.speed, def.range) spacecannon.fire(pos, def.color, def.speed, def.range)
end end
@ -170,6 +168,7 @@ end
register_spacecannon({ register_spacecannon({
color = "green", color = "green",
range = 1, range = 1,
intensity = 1,
timeout = 8, timeout = 8,
speed = 10, speed = 10,
desc = "fast,low damage", desc = "fast,low damage",
@ -179,6 +178,7 @@ register_spacecannon({
register_spacecannon({ register_spacecannon({
color = "yellow", color = "yellow",
range = 3, range = 3,
intensity = 2,
timeout = 8, timeout = 8,
speed = 5, speed = 5,
desc = "medium speed, medium damage", desc = "medium speed, medium damage",
@ -188,6 +188,7 @@ register_spacecannon({
register_spacecannon({ register_spacecannon({
color = "red", color = "red",
range = 5, range = 5,
intensity = 4,
timeout = 15, timeout = 15,
speed = 3, speed = 3,
desc = "slow, heavy damage", desc = "slow, heavy damage",

@ -20,7 +20,6 @@ spacecannon.fire = function(pos, color, speed, range)
-- check fuel/power -- check fuel/power
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
if meta:get_int("powerstorage") < spacecannon.config.powerstorage * range then if meta:get_int("powerstorage") < spacecannon.config.powerstorage * range then
-- not enough power -- not enough power
@ -45,12 +44,14 @@ end
-- destroy stuff in range -- destroy stuff in range
-- TODO: resilient material list -- TODO: resilient material list
spacecannon.destroy = function(pos,range) spacecannon.destroy = function(pos, range, intensity)
if not spacecannon.can_destroy(pos) then if not spacecannon.can_destroy(pos) then
return return
end end
local particle_texture = nil
for x=-range,range do for x=-range,range do
for y=-range,range do for y=-range,range do
for z=-range,range do for z=-range,range do
@ -64,6 +65,18 @@ spacecannon.destroy = function(pos,range)
local n = minetest.get_node_or_nil(np) local n = minetest.get_node_or_nil(np)
if n and n.name ~= "air" then if n and n.name ~= "air" then
local node_def = minetest.registered_nodes[n.name]
if node_def and node_def.tiles and node_def.tiles[1] then
particle_texture = node_def.tiles[1]
end
if node_def.on_blast then
-- custom on_blast
node_def.on_blast(np, intensity)
else
-- default behavior
minetest.set_node(np, {name="air"}) minetest.set_node(np, {name="air"})
local itemstacks = minetest.get_node_drops(n.name) local itemstacks = minetest.get_node_drops(n.name)
for _, itemname in ipairs(itemstacks) do for _, itemname in ipairs(itemstacks) do
@ -73,6 +86,8 @@ spacecannon.destroy = function(pos,range)
end end
end end
end end
end
end end
end end
end end
@ -98,6 +113,25 @@ spacecannon.destroy = function(pos,range)
glow = 5 glow = 5
}) })
if particle_texture then
minetest.add_particlespawner({
amount = 64,
time = 0.5,
minpos = vector.subtract(pos, radius / 2),
maxpos = vector.add(pos, radius / 2),
minvel = {x = -10, y = -10, z = -10},
maxvel = {x = 10, y = 10, z = 10},
minacc = vector.new(),
maxacc = vector.new(),
minexptime = 1,
maxexptime = 2.5,
minsize = radius * 3,
maxsize = radius * 5,
texture = particle_texture,
glow = 5
})
end
minetest.sound_play("tnt_explode", {pos = pos, gain = 1.5, max_hear_distance = math.min(radius * 20, 128)}) minetest.sound_play("tnt_explode", {pos = pos, gain = 1.5, max_hear_distance = math.min(radius * 20, 128)})
end end