master
Ginger88895 2015-09-20 11:18:35 +00:00
parent fda2357d2c
commit 1f66bf5483
1 changed files with 19 additions and 109 deletions

128
init.lua
View File

@ -43,55 +43,13 @@ local tnt_tables = {["bettertnt:tnt1"] = {r=6},
tnt = {}
tnt.force = {}
tnt.accl = {
["default:steelblock"] = true,
["default:obsidian"] = true,
}
local function drop_item(pos, nodename, player, count)
local drop = minetest.get_node_drops(nodename)
for _,item in ipairs(drop) do
if type(item) == "string" then
item = ItemStack(item)
end
for i=1,item:get_count() do
item:set_count(item:get_count() * count)
local obj = minetest.add_item(pos, item)
if obj == nil then
return
end
obj:get_luaentity().collect = true
obj:setacceleration({x=0, y=-10, z=0})
obj:setvelocity({x=math.random(0,6)-3, y=10, z=math.random(0,6)-3})
end
end
end
tnt.accl = {}
local function is_tnt(name)
if tnt_tables[name]~=nil then return true end
return false
end
local function destroy(pos, player, ents)
local nodename = minetest.get_node(pos).name
--local p_pos = area:index(pos.x, pos.y, pos.z)
--if nodes[p_pos] ~= tnt_c_air then
if nodename~="air" then
if tnt_tables[nodename]==nil then
ents[nodename] = (ents[nodename] or 0) + 1
end
if minetest.registered_nodes[nodename].groups.flammable ~= nil then
minetest.set_node(pos, {name = "fire:basic_flame"})
return
end
minetest.remove_node(pos)
end
end
local function combine_texture(texture_size, frame_count, texture, ani_texture)
local l = frame_count
local px = 0
@ -185,7 +143,7 @@ end
function boom_id(pos, time, player, id)
minetest.after(time, function(pos)
local tnt_range = tnt_tables[id].r * 6
local tnt_range = tnt_tables[id].r * 2
local t1 = os.clock()
pr = get_tnt_random(pos)
@ -220,91 +178,43 @@ function boom_id(pos, time, player, id)
end
end
local ents = {}
local storedPoses = {}
if id~="bettertnt:tnt1" then
for dx=-tnt_range,tnt_range do
for dz=-tnt_range,tnt_range do
for dy=-tnt_range,tnt_range do
--local p = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
local p = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
----------------------------------------
local dist = (dx^2) + (dy^2) + (dz^2)
dist = dist^(1/2.0)
if dist < tnt_range and dist + 1 >= tnt_range and dist~=0 then
local dir = {x=dx, y=dy, z=dz}
--local totalnum = math.abs(dir.x)+math.abs(dir.y)+math.abs(dir.z)
--dir = vector.normalize(dir)--vector.divide(dir, vector.new(totalnum, totalnum, totalnum))
dir.x = dir.x / dist
dir.y = dir.y / dist
dir.z = dir.z / dist
--local p = {x=pos.x, y=pos.y, z=pos.z} -- {x=0,y=0,z=0}--
local blast = tnt_range / 3
for i=1, dist do
-- i = i - 0.5
local pp = {x=dir.x*i, y=dir.y*i, z=dir.z*i}
local p = vector.add(pp, pos)
p.x = math.floor(p.x)
p.y = math.floor(p.y)
p.z = math.floor(p.z)
for i=1, #storedPoses do
if p.x==storedPoses[i].x and p.y==storedPoses[i].y and p.z==storedPoses[i].z then
--print("p: "..dump(p) .. " storedPoses: "..dump(storedPoses[i]))
p = nil
break
end
end
if p==nil then break end
--local p = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
--vector.add(p, dir)
----------------------------------------
if dist <= tnt_range then
--local p = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
--vector.add(p, dir)
----------------------------------------
-- local p_node = area:index(p.x, p.y, p.z)
-- local d_p_node = nodes[p_node]
local node = minetest.get_node(p)
-------------------------------------------------------------
blast = blast - 1
if tnt.accl[node.name]==true then
storedPoses[#storedPoses + 1] = {x=p.x, y=p.y, z=p.z}
local stored = minetest.get_meta(p):get_int("blast") or 0
blast = blast + stored
end
if blast <= 0 then
if tnt.accl[node.name]==true then
minetest.get_meta(p):set_int("blast", tnt.force[node.name] + blast)
end
break
end
-------------------------------------------------------------
-- if d_p_node == tnt_c_tnt
-- or d_p_node == tnt_c_tnt_burning then
if is_tnt(node.name)==true then
--nodes[p_node] = tnt_c_tnt
minetest.remove_node(p)
boom_id(p, 0.5, player, node.name) -- was {x=p.x, y=p.y, z=p.z}
elseif not (d_p_node == tnt_c_fire) then
--if math.abs(dx)<tnt_range and math.abs(dy)<tnt_range and math.abs(dz)<tnt_range then
destroy(p, player, ents)
--elseif pr:next(1,5) <= 4 then
-- destroy(p, player, ents)
--end
end
local node = minetest.get_node(p)
local nodename = node.name
if is_tnt(nodename)==true then
minetest.remove_node(p)
boom_id(p, 0.5, player, nodename) -- was {x=p.x, y=p.y, z=p.z}
elseif nodename~="air" then
--if math.abs(dx)<tnt_range and math.abs(dy)<tnt_range and math.abs(dz)<tnt_range then
minetest.remove_node(p)
--elseif pr:next(1,5) <= 4 then
-- destroy(p, player, ents)
--end
end
--------------------------------------------
end
--------------------------------------------
end
end
end
for name, val in pairs(ents) do
drop_item(pos, name, player, val)
end
end
minetest.add_particlespawner(
tnt_range * 100, --amount
100, --amount
1, --time
{x=pos.x-(tnt_range / 2), y=pos.y-(tnt_range / 2), z=pos.z-(tnt_range / 2)}, --minpos
{x=pos.x+(tnt_range / 2), y=pos.y+(tnt_range / 2), z=pos.z+(tnt_range / 2)}, --maxpos