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 local cameraState = 0 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 = {} player.input.setSelectedSlot(1) 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 == 13 then local chestPos = findChestNear(particle.position) if chestPos then player.input.setSelectedSlot(0) 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 local function smoothReturn() if cameraState == 1 then cameraState = 2 end if cameraState == 2 then local currentRealRot = player.getRotation() local targetYaw = currentRealRot.yaw local targetPitch = currentRealRot.pitch silentRotations.rotateToYawPitch(targetYaw, targetPitch) silentRotations.update() local sRot = player.getSilentRotation() local currentSilentYaw = sRot.yaw or sRot local currentSilentPitch = sRot.pitch or 0 local yawDiff = (targetYaw - currentSilentYaw + 180) % 360 - 180 local pitchDiff = targetPitch - currentSilentPitch if math.abs(yawDiff) < 1.5 and math.abs(pitchDiff) < 1.5 then cameraState = 0 silentRotations.stop() end else silentRotations.update() end end registerClientTick(function() if not work then if cameraState > 0 then cameraState = 2 smoothReturn() end return end local playerPos = player.entity and player.entity.position if not playerPos then if cameraState > 0 then cameraState = 2 smoothReturn() end return end if #targets == 0 then smoothReturn() return end local bestTarget = nil local closestChestDistSq = math.huge for i = #targets, 1, -1 do local pt = targets[i] pt.age = pt.age + 1 local chestPos = findChestNear(pt) if pt.age > 40 or not chestPos then table.remove(targets, i) else local dx = chestPos.x - playerPos.x local dy = chestPos.y - playerPos.y local dz = chestPos.z - playerPos.z local chestDistSq = dx * dx + dy * dy + dz * dz if chestDistSq < closestChestDistSq then closestChestDistSq = chestDistSq bestTarget = pt end end end if bestTarget then local blockRot = world.getRotation(bestTarget.x, bestTarget.y, bestTarget.z) silentRotations.rotateToYawPitch(blockRot.yaw + random_double(-0.15, 0.15), blockRot.pitch + random_double(-0.15, 0.15)) silentRotations.update() cameraState = 1 else smoothReturn() end end)