Подведи собственные итоги года совместно с YOUGAME и забери ценные призы! Перейти

Часть функционала AutoExplosion | 1.21.8

Начинающий
Начинающий
Статус
Оффлайн
Регистрация
18 Апр 2025
Сообщения
112
Реакции
1
Выберите загрузчик игры
  1. Vanilla
Всем привет | функцию сделал для своего клиента решил слить вам || || || || || || || || ||
AutoExplosion -_-:
Expand Collapse Copy
package куда не куда;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.protocol.game.ServerboundInteractPacket;
import net.minecraft.network.protocol.game.ServerboundSetCarriedItemPacket;
import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.boss.enderdragon.EndCrystal;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
// сами поставьте свои импорты
import java.util.List;

public class AutoExplosion extends Module {

    public AutoExplosion() {
        super("AutoExplosion", ModuleCategory.COMBAT, "Автоматически ставит и взрывает кристалл");
    }

    private final BooleanSetting safeYourSelf = new BooleanSetting("Не взрывать себя", true).setParent(this);
    private final BooleanSetting safeFriend = new BooleanSetting("Не взрывать друзей", true).setParent(this);
    private final SliderSetting radius = new SliderSetting("Радиус", 5.0f, 1.0f, 10.0f, 0.1f).setParent(this);
    private final BooleanSetting onlyPvP = new BooleanSetting("Только в PvP", false).setParent(this);

    private BlockPos pos;
    private int ticksAction;
    private int hotSlot;

    @SubscribeEvent
    public void onBlockPlace(EventBlockPlace event) {
        if (mc.player == null || mc.level == null) return;

        if (event.getStack().getItem() != Item.byBlock(Blocks.OBSIDIAN)) return;
        if (pos != null) return;

        hotSlot = getSlotForCrystal();
        if (hotSlot == -1) return;

        pos = event.getPosition();
        ticksAction = 0;
    }

    @SubscribeEvent
    public void onUpdate(EventUpdate event) {
        if (mc.player == null || mc.level == null) return;
        if (pos == null) return;

        if (onlyPvP.isEnabled() && !ClientHelper.isPvP()) return;

        switch (ticksAction) {
            case 0 -> {
                mc.player.connection.send(new ServerboundSetCarriedItemPacket(hotSlot));
                placeCrystal(pos.above());
            }
            case 1 -> {
                mc.player.connection.send(new ServerboundSetCarriedItemPacket(mc.player.getInventory().selected));
            }
            case 2 -> {
                if (canExplode(pos.above())) {
                    attackCrystal(pos.above());
                }
            }
        }

        if (ticksAction >= 2) {
            pos = null;
        }
        ticksAction++;
    }
    private void placeCrystal(BlockPos pos) {
        Vec3 hitLoc = new Vec3(pos.getX() + 0.5, pos.getY() - 0.5, pos.getZ() + 0.5);
        BlockHitResult hitResult = new BlockHitResult(hitLoc, Direction.UP, pos.below(), false);
        mc.player.connection.send(new ServerboundUseItemOnPacket(InteractionHand.MAIN_HAND, hitResult, 0));
        mc.player.swing(InteractionHand.MAIN_HAND);
    }

    private void attackCrystal(BlockPos aboveObsidian) {
        List<EndCrystal> crystals = mc.level.getEntitiesOfClass(EndCrystal.class, mc.player.getBoundingBox().inflate(6));
        for (EndCrystal crystal : crystals) {
            if (crystal.blockPosition().equals(aboveObsidian)) {
                mc.player.connection.send(ServerboundInteractPacket.createAttackPacket(crystal, mc.player.isShiftKeyDown()));
                mc.player.swing(InteractionHand.MAIN_HAND);
                break;
            }
        }
    }

    private boolean canExplode(BlockPos crystalPos) {
        if (safeYourSelf.isEnabled()) {
            double playerY = mc.player.getY();
            double crystalY = crystalPos.getY();

            if (playerY >= crystalY) {
                return false;
            }
        }

        return !safeFriend.isEnabled() || !isFriendNearby(crystalPos);
    }

    private boolean isFriendNearby(BlockPos position) {
        double explosionRadius = radius.get();

        AABB area = new AABB(
                position.getX() - explosionRadius, position.getY() - explosionRadius, position.getZ() - explosionRadius,
                position.getX() + explosionRadius, position.getY() + explosionRadius, position.getZ() + explosionRadius
        );
        List<Entity> nearbyEntities = mc.level.getEntitiesOfClass(Entity.class, area);
        for (Entity entity : nearbyEntities) {
            if (entity instanceof Player player) {
                if (Fluent.getInstance().getFriend().isFriend(player.getName().getString())) {
                    return true;
                }
            }
        }

        return false;
    }

    private int getSlotForCrystal() {
        for (int i = 0; i < 9; i++) {
            if (mc.player.getInventory().getItem(i).getItem() == Items.END_CRYSTAL) {
                return i;
            }
        }
        return -1;
    }

    @Override
    protected void onDisable() {
        super.onDisable();
        pos = null;
        ticksAction = 0;
        hotSlot = 0;
    }
}

Пожалуйста, зарегистрируйтесь или авторизуйтесь, чтобы увидеть содержимое.

 
Назад
Сверху Снизу