Make glyph particles more close to MC and visible only for players in radius 15

This commit is contained in:
kay27 2021-01-04 21:58:53 +04:00 committed by Elias Fleckenstein
parent dc5ff37449
commit c2a14e2eae
1 changed files with 29 additions and 11 deletions

View File

@ -295,20 +295,38 @@ minetest.register_abm({
chance = 1, chance = 1,
nodenames = "mcl_enchanting:table", nodenames = "mcl_enchanting:table",
action = function(pos) action = function(pos)
local playernames = {}
for _, obj in ipairs(minetest.get_objects_inside_radius(pos, 15)) do
if obj:is_player() then
table.insert(playernames, obj:get_player_name())
end
end
if #playernames < 1 then
return
end
local absolute, relative = mcl_enchanting.get_bookshelves(pos) local absolute, relative = mcl_enchanting.get_bookshelves(pos)
for i, ap in ipairs(absolute) do for i, ap in ipairs(absolute) do
if math.random(10) == 1 then if math.random(5) == 1 then
local rp = relative[i] local rp = relative[i]
minetest.add_particle({ local t = math.random()+1 --time
pos = ap, local d = {x = rp.x, y=rp.y-0.7, z=rp.z} --distance
velocity = vector.subtract(vector.new(0, 5, 0), rp), local v = {x = -math.random()*d.x, y = math.random(), z = -math.random()*d.z} --velocity
acceleration = {x = 0, y = -9.81, z = 0}, local a = {x = 2*(-v.x*t - d.x)/t/t, y = 2*(-v.y*t - d.y)/t/t, z = 2*(-v.z*t - d.z)/t/t} --acceleration
expirationtime = 2, local s = math.random()+0.9 --size
size = 2, t = t - 0.1 --slightly decrease time to avoid texture overlappings
texture = "mcl_enchanting_glyph_" .. math.random(18) .. ".png", local tx = "mcl_enchanting_glyph_" .. math.random(18) .. ".png"
collision_detection = true, for _, name in pairs(playernames) do
collision_removal = true, minetest.add_particle({
}) pos = ap,
velocity = v,
acceleration = a,
expirationtime = t,
size = s,
texture = tx,
collisiondetection = false,
playername = name
})
end
end end
end end
end end