local player = require("player") local world = require("world") local creator = require("creator") local silentRotations = require("silent_rotations_v2") silentRotations.setRotationSpeed(18) silentRotations.setSilentMovementCorrection(true) local targets = {} local work = true registerServerSideRotationEvent(function(yaw, pitch) if yaw and pitch and yaw ~= 0 and pitch ~= 0 then work = false player.addMessage("You got rotated") --player.setRotation(yaw, pitch) end end) registerSoundPlay(function(info) if not info.name:find("minecraft:block.note_block") and not info.name:find("experience") then if info.name == "minecraft:block.chest.open" or info.name == "minecraft:entity.villager.no" then targets = {} end end end) local function findChestNear(pos) local radius = 1.5 local radiusSq = radius * radius local minX = math.floor(pos.x - radius) local maxX = math.floor(pos.x + radius) local minY = math.floor(pos.y - radius) local maxY = math.floor(pos.y + radius) local minZ = math.floor(pos.z - radius) local maxZ = math.floor(pos.z + radius) for x = minX, maxX do for y = minY, maxY do for z = minZ, maxZ do local block = world.getBlock(x, y, z) if block and block.identifier == "minecraft:chest" then local dx = (x + 0.5) - pos.x local dy = (y + 0.5) - pos.y local dz = (z + 0.5) - pos.z local distSq = dx * dx + dy * dy + dz * dz if distSq <= radiusSq then return { x = x + 0.5, y = y + 0.5, z = z + 0.5 } end end end end end return nil end registerSpawnParticle(function(particle) if particle.id == 6 then local chestPos = findChestNear(particle.position) if chestPos then table.insert(targets, { x = particle.position.x, y = particle.position.y, z = particle.position.z, age = 0 -- Начальный возраст в тиках }) end end end) -- Функция для поиска сундука в радиусе 1.5 вокруг партикла local function random_double(min, max) return min + math.random() * (max - min) end registerClientTick(function() if not work then return end local playerPos = player.entity and player.entity.position if not playerPos or #targets == 0 then return end local closestTarget = nil local minDistanceSq = math.huge -- Обходим список с конца for i = #targets, 1, -1 do local pt = targets[i] pt.age = pt.age + 1 -- Увеличиваем возраст партикла на 1 тик local chestPos = findChestNear(pt) -- Если прошло больше 15 тиков ИЛИ рядом нет сундука, удаляем партикл if pt.age > 40 or not chestPos then table.remove(targets, i) else -- Если партикл активен, считаем расстояние до него от игрока local dx = pt.x - playerPos.x local dy = pt.y - playerPos.y local dz = pt.z - playerPos.z local distSq = dx * dx + dy * dy + dz * dz if distSq < minDistanceSq then minDistanceSq = distSq closestTarget = pt end end end -- Если найден ближайший валидный партикл, поворачиваемся к его координатам if closestTarget then local blockRot = world.getRotation(closestTarget.x, closestTarget.y, closestTarget.z) silentRotations.rotateToYawPitch(blockRot.yaw + random_double(-0.15, 0.15), blockRot.pitch + random_double(-0.15, 0.15)) silentRotations.update() else silentRotations.update() end end)