promotional bannermobile promotional banner

the ki

An autonomous Minecraft AI mod where an intelligent brain reacts to health, hunger, danger, time and resources, chooses actions independently, and can access approved Minecraft information online now.
Back to Files

MinecraftAI-Demo.jar

File nameMinecraftAI-Demo.jar
Uploaded
Nov 4, 2026
Downloads
6
Size
4.0 KB
Mod Loaders
Fabric
File ID
9439586
Type
R
Release
Supported game versions
  • 1.21.1

Curse Maven Snippet

Fabric

modImplementation "curse.maven:the-ki-1784059:9439586"

Learn more about Curse Maven

What's new

package com.example.minecraftai;

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Locale;
import java.util.Set;

/**
 * Das selbstständige Gehirn der Minecraft-KI.
 *
 * Die KI entscheidet, was sie in Minecraft tun möchte.
 * Zusätzlich kann sie Informationen aus vorher erlaubten
 * Minecraft-Webseiten abrufen.
 */
public final class MinecraftAIBrain {

    public enum Action {
        EXPLORE,
        FIND_FOOD,
        FIND_SHELTER,
        DEFEND,
        GATHER_RESOURCES,
        REST
    }

    private Action currentAction = Action.EXPLORE;
    private int thinkingCycles = 0;

    private final MinecraftInternetAccess internetAccess =
            new MinecraftInternetAccess();

    /**
     * Die KI entscheidet selbstständig, was als Nächstes wichtig ist.
     */
    public Action think(AIState state) {
        thinkingCycles++;

        if (state.health() <= 6.0f) {
            currentAction = Action.FIND_SHELTER;
            return currentAction;
        }

        if (state.foodLevel() <= 8) {
            currentAction = Action.FIND_FOOD;
            return currentAction;
        }

        if (state.enemyNearby()) {
            currentAction = Action.DEFEND;
            return currentAction;
        }

        if (state.isNight()) {
            currentAction = Action.FIND_SHELTER;
            return currentAction;
        }

        if (state.resourcesLow()) {
            currentAction = Action.GATHER_RESOURCES;
            return currentAction;
        }

        currentAction = Action.EXPLORE;
        return currentAction;
    }

    /**
     * Fragt eine erlaubte Minecraft-Webseite nach Informationen.
     *
     * Andere Internetseiten werden automatisch blockiert.
     */
    public String searchMinecraftInformation(String url) {
        return internetAccess.getMinecraftInformation(url);
    }

    public Action getCurrentAction() {
        return currentAction;
    }

    public int getThinkingCycles() {
        return thinkingCycles;
    }

    /**
     * Ein sicherer Zustand, den Minecraft an die KI übergibt.
     */
    public record AIState(
            float health,
            int foodLevel,
            boolean enemyNearby,
            boolean isNight,
            boolean resourcesLow
    ) {
    }

    /**
     * Kontrollierter Internetzugriff für Minecraft-Informationen.
     *
     * Nur diese Domains sind erlaubt. Jede andere Adresse wird blockiert.
     */
    private static final class MinecraftInternetAccess {

        private static final Set<String> ALLOWED_HOSTS = Set.of(
                "www.minecraft.net",
                "minecraft.net",
                "www.minecraft.net"
        );

        private final HttpClient httpClient = HttpClient.newHttpClient();

        public String getMinecraftInformation(String url) {
            try {
                URI uri = URI.create(url);

                String host = uri.getHost();
                if (host == null) {
                    return "BLOCKIERT: Ungültige Internetadresse.";
                }

                host = host.toLowerCase(Locale.ROOT);

                // Nur HTTPS und erlaubte Minecraft-Seiten.
                if (!"https".equalsIgnoreCase(uri.getScheme())
                        || !ALLOWED_HOSTS.contains(host)) {
                    return "BLOCKIERT: Diese Webseite ist nicht erlaubt.";
                }

                HttpRequest request = HttpRequest.newBuilder()
                        .uri(uri)
                        .GET()
                        .build();

                HttpResponse<String> response = httpClient.send(
                        request,
                        HttpResponse.BodyHandlers.ofString()
                );

                if (response.statusCode() >= 200
                        && response.statusCode() < 300) {
                    return response.body();
                }

                return "FEHLER: Die Minecraft-Webseite antwortete mit "
                        + response.statusCode();

            } catch (Exception exception) {
                return "FEHLER: Die Internetanfrage konnte nicht ausgeführt werden.";
            }
        }
    }
}

This mod has no additional files