Fix ender particle spam with particlespammers

This commit is contained in:
cora 2022-08-26 04:03:20 +02:00
parent a93bf3bf53
commit 94f07c2b3d
1 changed files with 42 additions and 12 deletions

View File

@ -219,6 +219,7 @@ local select_enderman_animation = function(animation_type)
end end
local mobs_griefing = minetest.settings:get_bool("mobs_griefing") ~= false local mobs_griefing = minetest.settings:get_bool("mobs_griefing") ~= false
local spawners = {}
mcl_mobs:register_mob("mobs_mc:enderman", { mcl_mobs:register_mob("mobs_mc:enderman", {
description = S("Enderman"), description = S("Enderman"),
@ -263,20 +264,42 @@ mcl_mobs:register_mob("mobs_mc:enderman", {
do_custom = function(self, dtime) do_custom = function(self, dtime)
-- PARTICLE BEHAVIOUR HERE. -- PARTICLE BEHAVIOUR HERE.
local enderpos = self.object:get_pos() local enderpos = self.object:get_pos()
local chanceOfParticle = math.random(0, 1) if self._particle_timer and self._particle_timer >= 1 then
if chanceOfParticle == 1 then for _,player in pairs(minetest.get_connected_players()) do
minetest.add_particle({ if not spawners[player] then spawners[player] = {} end
pos = {x=enderpos.x+math.random(-1,1)*math.random()/2,y=enderpos.y+math.random(0,3),z=enderpos.z+math.random(-1,1)*math.random()/2}, local dst = vector.distance(player:get_pos(),enderpos)
velocity = {x=math.random(-.25,.25), y=math.random(-.25,.25), z=math.random(-.25,.25)}, if dst < 128 and not spawners[player][self.object] then
acceleration = {x=math.random(-.5,.5), y=math.random(-.5,.5), z=math.random(-.5,.5)}, self._particle_timer = 0
expirationtime = math.random(), spawners[player][self.object] = minetest.add_particlespawner({
size = math.random(), amount = 5,
minpos = vector.new(-0.6,0,-0.6),
maxpos = vector.new(0.6,3,0.6),
minvel = vector.new(-0.25,-0.25,-0.25),
maxvel = vector.new(0.25,0.25,0.25),
minacc = vector.new(-0.5,-0.5,-0.5),
maxacc = vector.new(0.5,0.5,0.5),
minexptime = 0.2,
maxexptime = 3,
minsize = 0.2,
maxsize = 1.2,
collisiondetection = true, collisiondetection = true,
vertical = false, vertical = false,
time = 0,
texture = "mcl_portals_particle"..math.random(1, 5)..".png", texture = "mcl_portals_particle"..math.random(1, 5)..".png",
attached = self.object,
playername = player:get_player_name(),
}) })
elseif dst > 128 and spawners[player][self.object] then
minetest.delete_particlespawner(spawners[player][self.object])
spawners[player][self.object] = nil
end end
end
elseif not self._particle_timer then
self._particle_timer = 0
end
self._particle_timer = self._particle_timer + dtime
-- RAIN DAMAGE / EVASIVE WARP BEHAVIOUR HERE. -- RAIN DAMAGE / EVASIVE WARP BEHAVIOUR HERE.
enderpos = self.object:get_pos()
local dim = mcl_worlds.pos_to_dimension(enderpos) local dim = mcl_worlds.pos_to_dimension(enderpos)
if dim == "overworld" then if dim == "overworld" then
if mcl_weather.state == "rain" or mcl_weather.state == "lightning" then if mcl_weather.state == "rain" or mcl_weather.state == "lightning" then
@ -593,6 +616,13 @@ mcl_mobs:register_mob("mobs_mc:enderman", {
attack_type = "dogfight", attack_type = "dogfight",
}) })
minetest.register_on_leaveplayer(function(player)
for _,s in pairs(spawners[player]) do
minetest.delete_particlespawner(s)
end
spawners[player] = nil
end)
-- End spawn -- End spawn
mcl_mobs:spawn_specific( mcl_mobs:spawn_specific(