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

Вопрос Не могу посадить семена/нарост

Новичок
Новичок
Статус
Оффлайн
Регистрация
2 Фев 2025
Сообщения
1
Реакции
0
Багуется, не всегда сажает, что тут не так?

Java:
Expand Collapse Copy
private static void plantCrop(BlockPos pos, Item seedItem) {
        MinecraftClient client = MinecraftClient.getInstance();
        if (client.player == null || client.world == null) return;
        LOGGER.info("Trying to plant crop");

        boolean found = false;
        for (int i = 0; i < 9; i++) {
            if (client.player.getInventory().getStack(i).getItem() == seedItem) {
                client.player.getInventory().selectedSlot = i;
                found = true;
                LOGGER.info("Found seed item, placing...");
                break;
            }
        }

        if (!found) {
            return;
        }

        if (!isValidSoil(client.world.getBlockState(pos.down()))) {
            LOGGER.warn("Invalid soil at " + pos);
            return;
        }

        BlockState soilState = client.world.getBlockState(pos.down());
        if (!soilState.isOf(Blocks.FARMLAND) && !soilState.isOf(Blocks.SOUL_SAND)) {
            LOGGER.warn("Invalid soil at " + pos + ": " + soilState.getBlock().getTranslationKey());
            return;
        }

        BaritoneAPI.getProvider().getPrimaryBaritone().getInputOverrideHandler().clearAllKeys();

        BlockPos soilPos = pos.down();
        Vec3d hitVec = Vec3d.ofCenter(soilPos).add(0, 0.5, 0);
        client.player.lookAt(EntityAnchor.EYES, hitVec);
        LOGGER.info("Looking at block: " + soilPos);

        client.player.swingHand(Hand.MAIN_HAND);
        BlockHitResult hitResult = new BlockHitResult(
                hitVec,
                Direction.UP,
                soilPos,
                false
        );


        ActionResult result = client.interactionManager.interactBlock(client.player, Hand.MAIN_HAND, hitResult);
        if (result == ActionResult.FAIL) {
            LOGGER.warn("Failed to plant seeds at " + pos.down());
        } else {
            LOGGER.info("Planted seeds at " + pos.down());
        };

        BaritoneAPI.getProvider().getPrimaryBaritone().getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, false);

        client.execute(() -> {
            BlockState state = client.world.getBlockState(pos.down());
            if (state.isAir()) {
                LOGGER.warn("Planting failed! Block at " + pos.down() + " is air.");
            } else {
                LOGGER.info("Seed successfully placed at " + pos.down());
            }
        });

        client.execute(() -> {
            lastBrokenBlock = null;
            lastBrokenBlockPos = null;
            isFarming = false;
        });
    }
 
Назад
Сверху Снизу