Подписывайтесь на наш Telegram и не пропускайте важные новости! Перейти

Часть функционала AutoCrystal Rockstar 2.0

Начинающий
Начинающий
Статус
Оффлайн
Регистрация
4 Янв 2023
Сообщения
11
Реакции
0
Выберите загрузчик игры
  1. Fabric
Сливаю автокристал со своего чита. Вот сам код:

AutoCrystal:
Expand Collapse Copy
package org.nexora.systems.modules.modules.combat;

import org.nexora.Nexora;
import org.nexora.systems.event.EventListener;
import org.nexora.systems.event.impl.network.ReceivePacketEvent;
import org.nexora.systems.event.impl.player.ClientPlayerTickEvent;
import org.nexora.systems.event.impl.player.ClientPlayerTickEndEvent;
import org.nexora.systems.modules.api.ModuleCategory;
import org.nexora.systems.modules.api.ModuleInfo;
import org.nexora.systems.modules.impl.BaseModule;
import org.nexora.systems.setting.settings.BooleanSetting;
import org.nexora.systems.setting.settings.ModeSetting;
import org.nexora.systems.setting.settings.SliderSetting;
import org.nexora.utility.game.CrystalManager;
import org.nexora.utility.game.ExplosionUtility;
import org.nexora.utility.inventory.InventoryUtility;
import org.nexora.utility.inventory.group.SlotGroup;
import org.nexora.utility.inventory.group.SlotGroups;
import org.nexora.utility.inventory.slots.HotbarSlot;
import org.nexora.utility.inventory.slots.OffhandSlot;
import org.nexora.utility.math.MathUtility;
import org.nexora.utility.rotations.*;
import org.nexora.utility.time.Timer;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.entity.Entity;
import net.minecraft.entity.decoration.EndCrystalEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Items;
import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket;
import net.minecraft.network.packet.s2c.play.ExplosionS2CPacket;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;

import java.util.ArrayList;
import java.util.List;

@ModuleInfo(
        name = "Auto Crystal",
        category = ModuleCategory.COMBAT,
        desc = "Автоматически ставит и взрывает кристаллы"
)

public class AutoCrystal extends BaseModule {
    private final ModeSetting targetLogic = new ModeSetting(this, "Выбор цели");
    private final ModeSetting.Value DISTANCE = new ModeSetting.Value(targetLogic, "По дистанции").select();
    private final ModeSetting.Value HEALTH = new ModeSetting.Value(targetLogic, "По здоровью");

    private final ModeSetting timing = new ModeSetting(this, "Тайминг");
    private final ModeSetting.Value NORMAL = new ModeSetting.Value(timing, "Normal").select();
    private final ModeSetting.Value SEQUENTIAL = new ModeSetting.Value(timing, "Sequential");

    private final SliderSetting targetRange = new SliderSetting(this, "Дальность цели")
            .min(1f).max(15f).step(0.5f).currentValue(10f);
    private final SliderSetting placeRange = new SliderSetting(this, "Дальность установки")
            .min(1f).max(6f).step(0.5f).currentValue(5f);
    private final SliderSetting breakRange = new SliderSetting(this, "Дальность взрыва")
            .min(1f).max(6f).step(0.5f).currentValue(5f);
    private final SliderSetting placeDelay = new SliderSetting(this, "Задержка установки")
            .min(0).max(500).step(10).currentValue(0);
    private final SliderSetting breakDelay = new SliderSetting(this, "Задержка взрыва")
            .min(0).max(500).step(10).currentValue(0);

    private final SliderSetting minDamage = new SliderSetting(this, "Мин. урон")
            .min(2f).max(20f).step(0.5f).currentValue(6f);
    private final SliderSetting maxSelfDamage = new SliderSetting(this, "Макс. урон по себе")
            .min(2f).max(20f).step(0.5f).currentValue(10f);

    private final BooleanSetting rotate = new BooleanSetting(this, "Поворот");
    private final BooleanSetting autoSwitch = new BooleanSetting(this, "Авто-смена");
    private final BooleanSetting predict = new BooleanSetting(this, "Предсказание");
    private final BooleanSetting silentRotations = new BooleanSetting(this, "Скрытие ротаций").enabled(true);

    private PlayerEntity target;
    private BlockPos bestPlacePos;
    private BlockHitResult bestPlaceResult;
    private EndCrystalEntity bestCrystal;
    private PlaceData currentPlaceData;

    private final Timer placeTimer = new Timer();
    private final Timer breakTimer = new Timer();
    private final Timer calcTimer = new Timer();
    private final CrystalManager crystalManager = new CrystalManager();

    private float renderDamage = 0;
    private float renderSelfDamage = 0;
    private int currentId = 0;

    private RotationHandler rotationHandler;
    private Rotation lastRotation;

    @Override
    public void onEnable() {
        reset();
        rotationHandler = Nexora.getInstance().getRotationHandler();
        super.onEnable();
    }

    @Override
    public void onDisable() {
        reset();
        super.onDisable();
    }

    private void reset() {
        target = null;
        bestPlacePos = null;
        bestPlaceResult = null;
        bestCrystal = null;
        currentPlaceData = null;
        crystalManager.reset();
        placeTimer.reset();
        breakTimer.reset();
        calcTimer.reset();
        lastRotation = null;
    }

    private final EventListener<ClientPlayerTickEvent> onTick = event -> {
        if (mc.player == null || mc.world == null) return;
        updateTarget();
        if (target == null) return;
        if (calcTimer.finished(100)) {
            calcPosition();
            calcTimer.reset();
        }
        findCrystalToBreak();
        if (timing.is(NORMAL)) {
            doActions();
        }
    };

    private final EventListener<ClientPlayerTickEndEvent> onPostTick = event -> {
        if (mc.player == null) return;
        if (timing.is(SEQUENTIAL)) {
            doActions();
        }
        if (rotate.isEnabled() && shouldRotate()) {
            applySilentRotation();
        }
    };

    private boolean shouldRotate() {
        return (bestPlaceResult != null || bestCrystal != null);
    }

    private void applySilentRotation() {
        Vec3d targetPoint = null;

        if (bestCrystal != null) {
            targetPoint = bestCrystal.getPos();
        } else if (bestPlaceResult != null) {
            targetPoint = bestPlaceResult.getPos();
        }

        if (targetPoint == null) return;

        Rotation targetRotation = RotationMath.getRotationTo(targetPoint);

        if (silentRotations.isEnabled()) {
            rotationHandler.rotate(
                    targetRotation,
                    MoveCorrection.SILENT,
                    360.0f,
                    360.0f,
                    360.0f,
                    RotationPriority.NORMAL
            );
        } else {
            rotationHandler.rotate(targetRotation, RotationPriority.NORMAL);
        }

        lastRotation = targetRotation;
    }

    private void doActions() {
        if (bestCrystal != null && breakTimer.finished((long) breakDelay.getCurrentValue())) {
            attackCrystal(bestCrystal);
            breakTimer.reset();
        }
        if (bestPlaceResult != null && placeTimer.finished((long) placeDelay.getCurrentValue())) {
            placeCrystal();
            placeTimer.reset();
        }
    }

    private void updateTarget() {
        if (mc.player == null || mc.world == null) return;
        PlayerEntity newTarget = null;
        float bestValue = Float.MAX_VALUE;
        for (PlayerEntity player : mc.world.getPlayers()) {
            if (player == mc.player) continue;
            if (player.isDead() || player.getHealth() <= 0) continue;
            if (mc.player.distanceTo(player) > targetRange.getCurrentValue()) continue;
            float value;
            if (targetLogic.is(DISTANCE)) {
                value = mc.player.distanceTo(player);
            } else {
                value = player.getHealth() + player.getAbsorptionAmount();
            }
            if (value < bestValue) {
                bestValue = value;
                newTarget = player;
            }
        }
        target = newTarget;
    }

    private void calcPosition() {
        if (mc.player == null || target == null) return;

        List<PlaceData> candidates = new ArrayList<>();
        BlockPos center = BlockPos.ofFloored(mc.player.getPos());
        int range = (int) Math.ceil(placeRange.getCurrentValue());

        for (int x = -range; x <= range; x++) {
            for (int y = -range; y <= range; y++) {
                for (int z = -range; z <= range; z++) {
                    BlockPos pos = center.add(x, y, z);
                    PlaceData data = getPlaceData(pos);
                    if (data != null) {
                        candidates.add(data);
                    }
                }
            }
        }

        candidates.removeIf(data -> data.damage < minDamage.getCurrentValue());
        PlaceData best = null;
        float bestDamage = 0;
        for (PlaceData data : candidates) {
            if (data.damage > bestDamage) {
                bestDamage = data.damage;
                best = data;
            } else if (Math.abs(data.damage - bestDamage) < 1 && data.selfDamage < best.selfDamage) {
                best = data;
            }
        }

        if (best != null) {
            bestPlacePos = best.pos;
            bestPlaceResult = best.bhr;
            currentPlaceData = best;
            renderDamage = best.damage;
            renderSelfDamage = best.selfDamage;
        } else {
            bestPlacePos = null;
            bestPlaceResult = null;
            currentPlaceData = null;
        }
    }

    private PlaceData getPlaceData(BlockPos pos) {
        if (mc.player == null || mc.world == null) return null;

        Block block = mc.world.getBlockState(pos).getBlock();
        if (block != Blocks.OBSIDIAN && block != Blocks.BEDROCK) {
            return null;
        }

        if (!mc.world.isAir(pos.up())) return null;

        Box crystalBox = new Box(pos.up());
        for (Entity entity : mc.world.getEntities()) {
            if (entity.getBoundingBox().intersects(crystalBox)) {
                if (entity instanceof EndCrystalEntity && crystalManager.isDead(entity.getId())) continue;
                return null;
            }
        }

        Vec3d crystalPos = new Vec3d(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5);

        if (mc.player.squaredDistanceTo(crystalPos) > placeRange.getCurrentValue() * placeRange.getCurrentValue()) {
            return null;
        }

        int predictTicks = predict.isEnabled() ? 5 : 0;
        float damage = ExplosionUtility.getAutoCrystalDamage(crystalPos, target, predictTicks, false);
        float selfDamage = ExplosionUtility.getSelfExplosionDamage(crystalPos, predictTicks, false);

        if (damage < minDamage.getCurrentValue()) return null;
        if (selfDamage > maxSelfDamage.getCurrentValue()) return null;

        BlockHitResult bhr = new BlockHitResult(
                crystalPos, Direction.UP, pos, false
        );
        return new PlaceData(pos, bhr, damage, selfDamage);
    }

    private void findCrystalToBreak() {
        if (mc.player == null || target == null) return;
        EndCrystalEntity best = null;
        float bestDamage = 0;

        for (Entity entity : mc.world.getEntities()) {
            if (!(entity instanceof EndCrystalEntity crystal)) continue;
            if (crystalManager.isDead(crystal.getId())) continue;

            if (mc.player.distanceTo(crystal) > breakRange.getCurrentValue()) continue;

            float damage = ExplosionUtility.getAutoCrystalDamage(crystal.getPos(), target, predict.isEnabled() ? 5 : 0, false);
            float selfDamage = ExplosionUtility.getSelfExplosionDamage(crystal.getPos(), predict.isEnabled() ? 5 : 0, false);

            if (damage < minDamage.getCurrentValue()) continue;
            if (selfDamage > maxSelfDamage.getCurrentValue()) continue;

            if (damage > bestDamage) {
                bestDamage = damage;
                best = crystal;
            }
        }
        bestCrystal = best;
        if (best != null) {
            renderDamage = bestDamage;
        }
    }

    private void placeCrystal() {
        if (mc.player == null || bestPlaceResult == null) return;

        if (rotate.isEnabled() && bestPlacePos != null) {
            Rotation rotation = RotationMath.getRotationTo(new Vec3d(
                    bestPlacePos.getX() + 0.5,
                    bestPlacePos.getY() + 1,
                    bestPlacePos.getZ() + 0.5
            ));
            rotationHandler.rotate(rotation, MoveCorrection.SILENT, 360.0f, 360.0f, 360.0f, RotationPriority.NORMAL);
        }

        HotbarSlot crystalSlot = findCrystalInHotbar();
        OffhandSlot offhand = InventoryUtility.getOffHandSlot();
        boolean hasCrystal = (crystalSlot != null && !crystalSlot.isEmpty()) || offhand.contains(Items.END_CRYSTAL);

        if (!hasCrystal && autoSwitch.isEnabled()) {
            return;
        }

        int prevSlot = -1;
        if (autoSwitch.isEnabled() && crystalSlot != null && !offhand.contains(Items.END_CRYSTAL)) {
            prevSlot = mc.player.getInventory().selectedSlot;
            InventoryUtility.selectHotbarSlot(crystalSlot);
        }

        Hand hand = offhand.contains(Items.END_CRYSTAL) ? Hand.OFF_HAND : Hand.MAIN_HAND;
        mc.interactionManager.interactBlock(mc.player, hand, bestPlaceResult);
        mc.player.swingHand(hand);

        if (prevSlot != -1) {
            InventoryUtility.selectHotbarSlot(prevSlot);
        }

        crystalManager.addAwaitingPos(bestPlacePos);
    }

    private void attackCrystal(EndCrystalEntity crystal) {
        if (mc.player == null || crystal == null) return;

        if (rotate.isEnabled()) {
            Rotation rotation = RotationMath.getRotationTo(crystal.getPos());
            rotationHandler.rotate(rotation, MoveCorrection.SILENT, 360.0f, 360.0f, 360.0f, RotationPriority.NORMAL);
        }

        mc.interactionManager.attackEntity(mc.player, crystal);
        mc.player.swingHand(Hand.MAIN_HAND);
        crystalManager.setDead(crystal.getId(), System.currentTimeMillis());
    }

    private final EventListener<ReceivePacketEvent> onPacketReceive = event -> {
        if (mc.player == null) return;
        if (event.getPacket() instanceof EntitySpawnS2CPacket spawn) {
            try {
                java.lang.reflect.Field idField = EntitySpawnS2CPacket.class.getDeclaredField("entityId");
                idField.setAccessible(true);
                int entityId = idField.getInt(spawn);
                java.lang.reflect.Field typeField = EntitySpawnS2CPacket.class.getDeclaredField("entityTypeId");
                typeField.setAccessible(true);
                int entityTypeId = typeField.getInt(spawn);
                if (entityTypeId == 51) {
                    if (entityId > currentId) {
                        currentId = entityId;
                    }
                    for (BlockPos pos : crystalManager.getAwaitingPositions()) {
                        double x = spawn.getX();
                        double z = spawn.getZ();
                        if (x == pos.getX() + 0.5 && z == pos.getZ() + 0.5) {
                            crystalManager.confirmSpawn(pos);
                            break;
                        }
                    }
                }
            } catch (Exception e) {
            }
        }
        if (event.getPacket() instanceof ExplosionS2CPacket) {
            for (Entity entity : mc.world.getEntities()) {
                if (entity instanceof EndCrystalEntity) {
                    crystalManager.setDead(entity.getId(), System.currentTimeMillis());
                }
            }
        }
    };

    private HotbarSlot findCrystalInHotbar() {
        SlotGroup<HotbarSlot> hotbar = SlotGroups.hotbar();
        for (HotbarSlot slot : hotbar.getSlots()) {
            if (slot.contains(Items.END_CRYSTAL)) {
                return slot;
            }
        }
        return null;
    }

    private record PlaceData(BlockPos pos, BlockHitResult bhr, float damage, float selfDamage) {}

    public float getRenderDamage() {
        return renderDamage;
    }

    public PlayerEntity getTarget() {
        return target;
    }
}
 
Назад
Сверху Снизу