Skip to content

Commit

Permalink
update README.md and scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSPoon committed Feb 8, 2025
1 parent 6d0ddce commit 993e436
Show file tree
Hide file tree
Showing 15 changed files with 494 additions and 169 deletions.
243 changes: 109 additions & 134 deletions libraries/minecraft-npc-in-metta/README.md
Original file line number Diff line number Diff line change
@@ -1,184 +1,159 @@
# πŸ—οΈ Metta-MCBot
A **Minecraft AI bot** powered by **MCProtocolLib, Prolog (JPL), and MeTTa**.
# 🏰️ Metta-MCBot

This bot can:
- Connect to a **Minecraft server**.
- Process **chat messages** and send them to **MeTTa**.
- Work with **MeTTa scripts** for decision-making.
- Interact with the world using **Voxel space recognition**.
A **Minecraft AI bot** powered by **MCProtocolLib, Prolog (JPL), and MeTTa**.

---
## πŸš€ Features

## πŸš€ Features
βœ” **Connects to a Minecraft server**
βœ” **Receives chat messages and processes them**
βœ” **Uses MeTTa scripts to control bot behavior**
βœ” **Voxel-based world interaction for automation**
βœ” **Connects to a Minecraft server**\
βœ” **Receives chat messages and processes them**\
βœ” **Uses MeTTa scripts to control bot behavior**\
βœ” **Voxel-based world interaction for automation**

⚠ **You will need a Minecraft client** to **connect and interact with the bot**.
⚠ **You will need a Minecraft client** to **connect and interact with the bot**.\
The bot does **not provide a graphical interface**, so you must use a **Minecraft game client** to chat with and observe the bot in action.

---

## πŸ“Œ Project Structure
```
β”œβ”€β”€ minecraft_bot_hello.metta # MeTTa AI script
β”œβ”€β”€ minecraft_bot_driver.metta # MeTTa AI Driver script
β”œβ”€β”€ prolog/ # Prolog scripts directory
β”‚ β”œβ”€β”€ minecraft_bot_hello.pl # Start logic
β”‚ β”œβ”€β”€ minecraft_bot_driver.pl # Driver logic
β”œβ”€β”€ pom.xml # Maven project configuration
β”œβ”€β”€ README.md # Project documentation
β”œβ”€β”€ libs/ # External libraries
β”‚ β”œβ”€β”€ jpl8.jar # JPL (Java-Prolog) integration library
│── src/main/java/io/trueagi/mettalog/minecraft/
β”‚ β”œβ”€β”€ BotController.java # Main bot logic
β”‚ β”œβ”€β”€ BotExample.java # Example bot usage
β”‚ β”œβ”€β”€ VoxelGetter.java # Handles voxel-based world interaction
β”‚ β”œβ”€β”€ SWIPrologBuilder.java # Prolog integration utilities
β”‚ β”œβ”€β”€ WorldBuilder.java # Builds world-related data
## πŸ›  Prerequisites

```
Before running the bot, ensure you have:

---
- **A running Minecraft server**: The bot requires a Minecraft server to connect to. You can download and set up a **Minecraft Java Edition server** from [Mojang's official site](https://www.minecraft.net/en-us/download/server) or use a custom server like **PaperMC** or **Spigot**.

- Ensure your server is running and accessible at `localhost:25565`.
- Configure your server properties (`server.properties`) to allow non-premium accounts if needed.

- **A Minecraft client**: Since the bot has no graphical interface, you need **Minecraft Java Edition** to connect and interact with it.

- Open **Multiplayer** in Minecraft.
- Add a server with the address `localhost:25565`.
- Connect and use the in-game chat to interact with the bot.

- **Java 21+** installed:

## πŸ›  Prerequisites
Before running the bot, ensure you have:
- **Java 17+** installed:
```sh
java -version
```
- **Apache Maven** installed:

- **Apache Maven** installed: using Instructions from:
[Upgrade Maven Installation](https://lightspeed001.medium.com/upgrade-existing-maven-installation-to-latest-0c17074a866a)

```sh
mvn -version
```
- **SWI-Prolog** installed:
```sh
swipl --version

Expected output:

```
- **MeTTaLog** installed:
```sh
mettalog --version
Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae)
Maven home: /opt/apache-maven-3.9.6
Java version: 21.0.5, vendor: Oracle Corporation, runtime: /usr/lib/jvm/jdk-21.0.5-oracle-x64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.15.167.4-microsoft-standard-wsl2", arch: "amd64", family: "unix"
```
- **A running Minecraft server** (e.g., `localhost:25565`).
- **A Minecraft game client** (e.g., **Minecraft Java Edition**) to connect and interact with the bot.

---
### **πŸ”Ž Hiding Java 17 from JPL**

JPL does not support Java 21+ when Java 17 is visible in the system. To prevent conflicts, ensure Java 17 is hidden:

## πŸš€ Running the Minecraft Bot
### **1️⃣ Build the Project**
```sh
mvn clean package
```
### **2️⃣ Generate Classpath for Dependencies**
Since the JAR requires dependencies, first generate the classpath:
```sh
mvn dependency:build-classpath -Dmdep.outputFile=classpath.txt
sudo update-alternatives --config java
```
### **3️⃣ Start the Minecraft Server**
Ensure you have a Minecraft **1.20+ server** running on `localhost:25565`.
You can use **PaperMC, Spigot, or a vanilla server**.

### **4️⃣ Run the Bot**
Select Java 21 as the default version.

Ensure that `LD_LIBRARY_PATH` does not point to Java 17:

```sh
java -cp "$(cat classpath.txt):target/mettalog.minecraft-1.0-SNAPSHOT.jar" io.trueagi.mettalog.minecraft.BotController
```
### **5️⃣ Connect with a Graphical Minecraft Client**
- **Launch your Minecraft Java Edition client**.
- Go to **Multiplayer** β†’ **Direct Connect**.
- Connect to `localhost:25565`.
- **Interact with the bot in chat!** (e.g., type `hello bot`).

### **6️⃣ Test Prolog Integration**
Open SWI-Prolog and consult the Prolog scripts:
```prolog
?- consult('src/main/prolog/minecraft_bot_driver.pl').
?- consult('src/main/prolog/minecraft_bot_hello.pl').
echo $LD_LIBRARY_PATH
```

---
If necessary, update `.bashrc` or `/etc/environment`:

## πŸ—οΈ Developing the Bot
### **πŸ“ Writing MeTTa AI Logic**
MeTTa scripts define bot behavior. Example (`minecraft_bot_hello.metta`):
```metta
(: on_chat "hello bot" (say "Hello, human!"))
(: on_chat "where are you?" (say "I'm exploring the world."))
```sh
export JAVA_HOME=/usr/lib/jvm/jdk-21.0.5-oracle-x64
export PATH="$JAVA_HOME/bin:$PATH"
export LD_LIBRARY_PATH="$JAVA_HOME/lib/server/"
```

### **πŸ”Ή Prolog Integration**
Prolog scripts (`minecraft_bot_hello.pl`) handle game logic:
```prolog
on_chat_message("hello bot") :-
writeln('Bot: Hello, player!').
```
### **⚠️ Cannot use with Java 17**

---
If you encounter the following error:

## πŸ“Œ Useful Commands
### **➑️ Move the bot**
```prolog
?- move(1, 0, 0). % Move forward
?- move(0, 1, 0). % Jump
```sh
ERROR: Java exception: java.lang.UnsupportedClassVersionError: io/trueagi/mettalog/minecraft/BotController
has been compiled by a more recent version of the Java Runtime (class file version 65.0),
this version of the Java Runtime only recognizes class file versions up to 61.0
```

### **πŸ’¬ Chat from Prolog**
```prolog
?- chat("I am a MeTTa-powered bot!").
```
This likely means that **SWI-Prolog is still using Java 17** instead of Java 21. To resolve this:

### **🧊 Voxel Space Querying**
```prolog
?- get_voxel_data(X, Y, Z, BlockID).
```
1. Verify which Java version SWI-Prolog is using:
```sh
swipl
?- jpl_get_default_jvm_version(V).
```
2. If it is using Java 17, update `LD_LIBRARY_PATH` and `JAVA_HOME` to point to Java 21.
3. Restart your terminal or source your environment settings:
```sh
source ~/.bashrc
```

---

## πŸ”§ Troubleshooting
### **"Bot not connecting to server"**
- Ensure **Minecraft server is running** (`localhost:25565`).
- Check **firewall settings** allowing connections.
## πŸš€ Running the Minecraft Bot

You have **four methods** to run the bot:

1. **Using Java Only** (to ensure basic connectivity)
```sh
source hello_java_only.sh
```
2. **Using Java**
```sh
source java_run.sh
```
3. **Using MeTTa**
```sh
source metta_run.sh
```
4. **Using Prolog**
```sh
source prolog_run.sh
```

### **"Prolog script not loading"**
- Ensure SWI-Prolog is installed and working:
```sh
swipl --version
```
- Use **full file paths** when consulting:
```prolog
?- consult('/absolute/path/to/minecraft_bot_hello.pl').
```
---

### **"Maven build fails"**
- Try **forcing a dependency update**:
```sh
mvn clean package -U
```
- Ensure **JPL is in `libs/`**:
```sh
ls libs/jpl8.jar
```
## πŸ—οΈ Developing the Bot

### **"Bot does not respond to chat"**
- Ensure **you are using a Minecraft Java Edition client** to chat with the bot.
- Make sure **the bot is properly connected** to the Minecraft server (`localhost:25565`).
- Check the **Prolog script logic** to confirm responses are correctly defined.
### **πŸ“ Writing MeTTa AI Logic**

---
MeTTa scripts define bot behavior. Example (`minecraft_bot_hello.metta`):

## 🀝 Contributing
We welcome contributions!
1. Fork the repo
2. Create a new branch: `feature-name`
3. Submit a PR πŸŽ‰
```metta
!(import! &self minecraft_bot_driver.metta )
(event-trigger (on_chat "hello bot") (say "Hello, human!"))
(event-trigger (on_chat "who are you?") (say "I am a MeTTa-powered bot!"))
(event-trigger (on_chat "what can you do?") (say "I can move, chat, and explore using voxel data!"))
(event-trigger (on_chat "move forward") (move 1 0 0))
(event-trigger (on_chat "move up") (move 0 1 0))
(event-trigger (on_chat "scan area") (enumerate_voxel_space))
(event-trigger (on_chat "goodbye") (say "Goodbye, see you soon!"))
```

---
### **πŸ”Ή Prolog Integration**

## πŸ“ License
This project is licensed under **MIT License**.
Prolog scripts (`minecraft_bot_hello.pl`) handle game logic:

```prolog
on_chat_message("hello bot") :-
writeln('Bot: Hello, player!').
```

---

## πŸ“ž Contact
## πŸ“ž Contact

For support, open an issue on GitHub. πŸš€

Loading

0 comments on commit 993e436

Please sign in to comment.