dig particles - cleanup and improvements

master
Juraj Vajda 2018-12-08 11:34:58 -05:00
parent 5425e54ab2
commit 62823d8623
1 changed files with 104 additions and 47 deletions

151
mover.lua
View File

@ -1102,9 +1102,44 @@ minetest.register_node("basic_machines:mover", {
local positions = minetest.find_nodes_in_area({x = pos1.x - r, y = pos1.y, z = pos1.z - r}, {x = pos1.x + r, y = pos1.y + 16, z = pos1.z + r}, node1.name)
local def = minetest.registered_nodes[node1.name]
local distance_ok = vector.distance(pos1, pos2) <= 16
local texture = "default_dirt.png"
-- try to find a node texture
if def then
if def.tiles then
if #def.tiles > 0 then
if type(def.tiles[1]) == "string" then
texture = def.tiles[1]
end
end
end
end
for _, pos3 in ipairs(positions) do
minetest.set_node(pos3, {name = "air"})
count = count + 1
-- add particles only when not too far
if distance_ok then
minetest.add_particlespawner({
amount = math.random(1, 3),
time = 0.5,
minpos = {x=pos3.x-0.7, y=pos3.y, z=pos3.z-0.7},
maxpos = {x=pos3.x+0.7, y=pos3.y+0.75, z=pos3.z+0.7},
minvel = {x = -0.5, y = -4, z = -0.5},
maxvel = {x = 0.5, y = -2, z = 0.5},
minacc = {x = -0.5, y = -4, z = -0.5},
maxacc = {x = 0.5, y = -2, z = 0.5},
minexptime = 0.5,
maxexptime = 1,
minsize = 0.5,
maxsize = 2,
collisiondetection = true,
texture = texture
})
end
end
-- if tree or cactus was digged up
@ -1224,12 +1259,17 @@ minetest.register_node("basic_machines:mover", {
if vector.distance(pos1, pos2) <= 16 then
local texture = "default_dirt.png"
if type(def.tiles[1]) == "string" then
texture = def.tiles[1]
-- try to find a node texture
if def.tiles then
if #def.tiles > 0 then
if type(def.tiles[1]) == "string" then
texture = def.tiles[1]
end
end
end
minetest.add_particlespawner({
amount = math.random(5, 10),
amount = math.random(3, 6),
time = 0.5,
minpos = {x=pos2.x-0.7, y=pos2.y, z=pos2.z-0.7},
maxpos = {x=pos2.x+0.7, y=pos2.y+0.75, z=pos2.z+0.7},
@ -1250,31 +1290,39 @@ minetest.register_node("basic_machines:mover", {
else
minetest.set_node(pos2, {name = node1.name})
-- add particles only when not too far
if def and vector.distance(pos1, pos2) <= 16 then
local texture = "default_dirt.png"
if def then
-- add particles only when not too far
if vector.distance(pos1, pos2) <= 16 then
local texture = "default_dirt.png"
if type(def.tiles[1]) == "string" then
texture = def.tiles[1]
-- try to find a node texture
if def.tiles then
if #def.tiles > 0 then
if type(def.tiles[1]) == "string" then
texture = def.tiles[1]
end
end
end
minetest.add_particlespawner({
amount = math.random(3, 6),
time = 0.5,
minpos = {x=pos2.x-0.7, y=pos2.y, z=pos2.z-0.7},
maxpos = {x=pos2.x+0.7, y=pos2.y+0.75, z=pos2.z+0.7},
minvel = {x = -0.5, y = -4, z = -0.5},
maxvel = {x = 0.5, y = -2, z = 0.5},
minacc = {x = -0.5, y = -4, z = -0.5},
maxacc = {x = 0.5, y = -2, z = 0.5},
minexptime = 0.5,
maxexptime = 1,
minsize = 0.5,
maxsize = 2,
collisiondetection = true,
texture = texture
})
end
minetest.add_particlespawner({
amount = math.random(5, 10),
time = 0.5,
minpos = {x=pos2.x-0.7, y=pos2.y, z=pos2.z-0.7},
maxpos = {x=pos2.x+0.7, y=pos2.y+0.75, z=pos2.z+0.7},
minvel = {x = -0.5, y = -4, z = -0.5},
maxvel = {x = 0.5, y = -2, z = 0.5},
minacc = {x = -0.5, y = -4, z = -0.5},
maxacc = {x = 0.5, y = -2, z = 0.5},
minexptime = 0.5,
maxexptime = 1,
minsize = 0.5,
maxsize = 2,
collisiondetection = true,
texture = texture
})
end
end
end
@ -1293,31 +1341,40 @@ minetest.register_node("basic_machines:mover", {
minetest.set_node(pos1, {name = "air"})
-- add particles only when not too far
if def and vector.distance(pos1, pos2) <= 16 then
local texture = "default_dirt.png"
if def then
-- add particles only when not too far
if vector.distance(pos1, pos2) <= 16 then
local texture = "default_dirt.png"
if type(def.tiles[1]) == "string" then
texture = def.tiles[1]
-- try to find a node texture
if def.tiles then
print(#def.tiles)
if #def.tiles > 0 then
if type(def.tiles[1]) == "string" then
texture = def.tiles[1]
end
end
end
minetest.add_particlespawner({
amount = math.random(3, 6),
time = 0.5,
minpos = {x=pos1.x-0.5, y=pos1.y, z=pos1.z-0.5},
maxpos = {x=pos1.x+0.5, y=pos1.y+0.75, z=pos1.z+0.5},
minvel = {x = -0.5, y = -4, z = -0.5},
maxvel = {x = 0.5, y = -2, z = 0.5},
minacc = {x = -0.5, y = -4, z = -0.5},
maxacc = {x = 0.5, y = -2, z = 0.5},
minexptime = 0.5,
maxexptime = 1,
minsize = 0.5,
maxsize = 2,
collisiondetection = true,
texture = texture
})
end
minetest.add_particlespawner({
amount = math.random(5, 10),
time = 0.5,
minpos = {x=pos1.x-0.5, y=pos1.y, z=pos1.z-0.5},
maxpos = {x=pos1.x+0.5, y=pos1.y+0.75, z=pos1.z+0.5},
minvel = {x = -0.5, y = -4, z = -0.5},
maxvel = {x = 0.5, y = -2, z = 0.5},
minacc = {x = -0.5, y = -4, z = -0.5},
maxacc = {x = 0.5, y = -2, z = 0.5},
minexptime = 0.5,
maxexptime = 1,
minsize = 0.5,
maxsize = 2,
collisiondetection = true,
texture = texture
})
end
end
end, -- /action_on - mover