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

Часть функционала Scaffold | ExosWare

Начинающий
Начинающий
Статус
Оффлайн
Регистрация
25 Дек 2023
Сообщения
9
Реакции
0
Выберите загрузчик игры
  1. Fabric
Простенький скафолд ( тестил на ФТ,СТ, работает , не срите меня первые темы мои )
Scaffold:
Expand Collapse Copy
package ru.levin.modules.player;

import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import org.joml.Vector2f;
import ru.levin.events.Event;
import ru.levin.events.impl.EventUpdate;
import ru.levin.modules.Function;
import ru.levin.modules.FunctionAnnotation;
import ru.levin.modules.Type;
import ru.levin.util.Timer;


import java.util.Arrays;
import java.util.List;

@FunctionAnnotation(name = "Scaffold", keywords = "Build", type = Type.Player, desc = "Автоматически ставит блоки под ногами при движении")
public class Scaffold extends Function {

    private static final List<Block> BLACKLIST = Arrays.asList(
            Blocks.CHEST,
            Blocks.ENDER_CHEST,
            Blocks.TRAPPED_CHEST,
            Blocks.SAND,
            Blocks.CRAFTING_TABLE,
            Blocks.FURNACE,
            Blocks.STONE_PRESSURE_PLATE,
            Blocks.OAK_PRESSURE_PLATE,
            Blocks.BIRCH_PRESSURE_PLATE,
            Blocks.SPRUCE_PRESSURE_PLATE,
            Blocks.JUNGLE_PRESSURE_PLATE,
            Blocks.ACACIA_PRESSURE_PLATE,
            Blocks.DARK_OAK_PRESSURE_PLATE,
            Blocks.CRIMSON_PRESSURE_PLATE,
            Blocks.WARPED_PRESSURE_PLATE
    );

    private final Timer placeTimer = new Timer();
    private final Vector2f rotate = new Vector2f(0f, 0f);
    private int originalSlot = -1;
    private boolean active = false;
    private int tickDelay = 0;

    @Override
    public void onEnable() {
        if (mc.player == null || mc.world == null) {
            toggle();
            return;
        }

        originalSlot = mc.player.getInventory().selectedSlot;
        active = true;
        tickDelay = 0;
        placeTimer.reset();
    }

    @Override
    public void onDisable() {
        if (mc.player != null && originalSlot != -1) {
            mc.player.getInventory().selectedSlot = originalSlot;
        }
        active = false;
        tickDelay = 0;
    }

    @Override
    public void onEvent(Event event) {
        if (!active) return;
        if (!(event instanceof EventUpdate)) return;

        if (tickDelay > 0) {
            tickDelay--;
            return;
        }

        BlockPos below = getPredictedPos();
        if (mc.world.getBlockState(below).isAir()) {
            int slot = findBlockSlot();
            if (slot == -1) {
                slot = findInventoryBlock();
                if (slot != -1) {

                }
            }

            if (slot != -1 && mc.player.getInventory().selectedSlot != slot) {
                mc.player.getInventory().selectedSlot = slot;
            } else if (slot == -1) {
                return; // Нет блоков для размещения
            }

            if (placeTimer.finished(50L)) {
                BlockHitResult hit = findHit(below);
                if (hit == null) return;

                Vec3d hitVec = hit.getPos();
                rotateTo(hit.getBlockPos());

                ActionResult result = mc.interactionManager.interactBlock(mc.player, Hand.MAIN_HAND, hit);
                if (result.isAccepted()) {
                    mc.player.swingHand(Hand.MAIN_HAND);
                    placeTimer.reset();
                    tickDelay = 1;
                }
            }
        }
    }

    private BlockPos getPredictedPos() {
        Vec3d vel = mc.player.getVelocity();
        int dx = (int) Math.round(vel.x);
        int dz = (int) Math.round(vel.z);
        BlockPos pos = mc.player.getBlockPos().add(dx, 0, dz);
        return pos.down();
    }

    private int findInventoryBlock() {
        for (int i = 0; i < 27; i++) {
            ItemStack stack = mc.player.getInventory().getStack(i + 9);
            if (stack.getCount() > 0 && stack.getItem() instanceof BlockItem blockItem && !BLACKLIST.contains(blockItem.getBlock())) {
                return i;
            }
        }
        return -1;
    }

    private int findBlockSlot() {
        for (int i = 0; i < 9; i++) {
            ItemStack stack = mc.player.getInventory().getStack(i);
            if (stack.getCount() > 0 && stack.getItem() instanceof BlockItem blockItem && !BLACKLIST.contains(blockItem.getBlock())) {
                return i;
            }
        }
        return -1;
    }

    private BlockHitResult findHit(BlockPos target) {
        Direction[] faces = new Direction[]{Direction.DOWN, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST};

        for (Direction face : faces) {
            BlockPos neighbour = target.offset(face);
            if (!mc.world.getBlockState(neighbour).isAir()) {
                Vec3d hitVec = Vec3d.ofCenter(neighbour).add(Vec3d.of(face.getVector()).multiply(0.5));
                return new BlockHitResult(hitVec, face.getOpposite(), neighbour, false);
            }
        }
        return null;
    }

    private void rotateTo(BlockPos pos) {
        if (mc.player == null) return;
        double dx = pos.getX() + 0.5 - mc.player.getX();
        double dy = pos.getY() + 0.5 - (mc.player.getY() + mc.player.getEyeHeight(mc.player.getPose()));
        double dz = pos.getZ() + 0.5 - mc.player.getZ();

        double distXZ = Math.sqrt(dx * dx + dz * dz);
        float yaw = (float) Math.toDegrees(Math.atan2(dz, dx)) - 90.0f;
        float pitch = (float) -Math.toDegrees(Math.atan2(dy, distXZ));

        rotate.x = yaw;
        rotate.y = pitch;
    }
}
 
Назад
Сверху Снизу