Skip to content

A minecraft mod which aims to add a "second player" into the game which will actually be intelligent.

License

Notifications You must be signed in to change notification settings

A11v1r15/AI-Player

 
 

Repository files navigation

Read this section please.

This project so far is the result of thousands of hours of endless reasearch, trials and errors, and just the simple goal of eliminating loneliness from minecraft as much as possible. If you liked my work, please consider donating so that I can continue to work on this project in peace and can actually prove to my parents that my work is making a difference. (Also not having to ask for pocket money from mom).

Just know that I won't ever give up on this project.

"Buy Me A Coffee"

Paypal

https://paypal.me/shasankp000


Also, THIS!

If anyone is interested on the underlying algorithms I am working on for increased intelligence for the minecraft bot, feel free to check out this repository:

https://github.com/shasankp000/AI-Tricks

I am open to suggestions/improvements, if any. (Obviously there will be improvements from my own end).


Project description


The footages for the bot conversation and config manager here in the github page is a bit outated. Check the modrinth page and download the mod to stay updated.

A minecraft mod which aims to add a "second player" into the game which will actually be intelligent.

Ever felt lonely while playing minecraft alone during that two-week phase? Well, this mod aims to solve that problem of loneliness, not just catering to this particular use case, but even (hopefully in the future) to play in multiplayer servers as well.

Please note that this is not some sort of a commercialised AI product. This project is just a solution to a problem many Minecraft players have faced and do continue to face.

I had to add that statement up there to prevent misunderstandings.

This mod relies on the internal code of the Carpet mod, please star the repository of the mod: https://github.com/gnembon/fabric-carpet (Giving credit where it's due)

This mod also relies on the ollama4j project. https://github.com/amithkoujalgi/ollama4j


Download links

  1. From this github page, just download from the releases section or follow the steps in usage section to build and test.
  2. Modrinth: https://modrinth.com/mod/ai-player/ [Recommended as the github version is often unstable]
  3. Curseforge: Will upload soon after a few more patches and updates.

Progress: 60%

For the nerds

Sucessfully implemented the intellgence update.

So, for the tech savvy people, I have implemented the following features.

LONG TERM MEMORY: This mod now features concepts used in the field AI like Natural Language Processing (much better now) and something called

Retrieval Augmented Generation (RAG).

How does it work?

Well:

Retrieval Augmented Generation process outline

Vectors

We convert the user input, to a set of vector embeddings which is a list of numbers.

Then physics 101!

A vector is a representation of 3 coordinates in the XYZ plane. It has two parts, a direction and a magnitude.

If you have two vectors, you can check their similarity by checking the angle between them.

The closer the vectors are to each other, the more similar they are!

Now if you have two sentences, converted to vectors, you can find out whether they are similar to each other using this process.

In this particular instance I have used a method called cosine similarity

Cosine similarity

Where you find the similarity using the formula

(x, y) = x . y / |x| . |y|

where |x| and |y| are the magnitudes of the vectors.

So we use this technique to fetch a bunch of stored conversation and event data from an SQL database, generate their vector embeddings, and then run that against the user's prompt. We get then further sort on the basis on let's say timestamps and we get the most relevant conversation for what the player said.

Pair this with function calling. Which combines Natural Language processing to understand what the player wants the bot to do, then call a pre-coded method, for example movement and block check, to get the bot to do the task.

Save this data, i.e what the bot did just now to the database and you get even more improved memory!

To top it all off, Llama 2 is the best performing model for this mod right now, so I will suggest y'all to use llama2.

In fact some of the methods won't even run without llama2 like the RAG for example so it's a must.


image

Successfully managed to spawn a "second player" bot.

Added basic bot movement.

botmovement.webm

Implemented basic bot conversation

bandicam.2024-07-19.11-12-07-431.webm

Added a mod configuration menu (Still a work in progress)

2024-07-22.02-36-49.mp4

Implemented intermediate XZ pathfinding for the bot

2024-07-27_14-16-32.mp4

Implemented Natural Language Processing for the bot to understand the intention and context of the user input and execute methods Can only understand if you want the bot to go some coordinates.

https://vimeo.com/992051891?share=copy

Implemented nearby entity detection

2024-07-31.14-52-47.mp4

Usage

If you want to manually build and test this project, follow from step 1.

For playing the game, download the jar file either from modrinth or the releases section and go directly to step 6.

Step 1. Download Java 21.

This project is built on java 21 to support carpet mod's updated API.

Go to: https://bell-sw.com/pages/downloads/#jdk-21-lts

Click on Download MSI and finish the installation process.

image

Step 2. Download IntelliJ idea community edition.

https://www.jetbrains.com/idea/download/?section=windows

Screenshot 2024-07-21 123239

Step 3. Download the project.

If you have git setup in your machine already you can just clone the project to your machine and then open it in intellij

Or alternatively download it as a zip file, extract it and then open it in intellij

image

Step 4. Configure the project SDK.

image

Click on the settings gear.

image

Go to Project Structure

image

Configure the SDK here, set it to liberica 21

Step 5. Once done wait for intellij to build the project sources, this will take a while as it basically downloads minecraft to run in a test version.

If you happen to see some errors, go to the right sidebar, click on the elephant icon (gradle)

image

And click on the refresh button, besides the plus icon. Additionally you can go to the terminal icon on the bottom left

image

And type ./graldew build

Step 6. Setup ollama.

Go to https://ollama.com/

image

Download based on your operating system.

After installation, run ollama from your desktop. This will launch the ollama server.

This can be accessed in your system tray

image

Now open a command line client, on windows, search CMD or terminal and then open it.

Depending on your specs, you can download a language model and then configure in the project to use it.

For now, in the terminal, type image

In this example we are going with the phi3 model.

For the updated version 1.0.2, you will need to download the llama2 model: ollama pull llama2 And another model nomic-embed-text: ollama pull nomic-embed-text

Without llama2, intelligence will be very low Without nomic-embed-text, the mod will crash.

I do intend to add an option in the mod to change and configure models within the game GUI.

Once done. Go to the next step.

Step 7. Go to the files section

image

Click on the ollamaClient

Go to line 199.

2024-07-21.13-34-42.mp4

Remove the current model type, then follow the video and set it to OllamaModelType.PHI3

Although intelliJ autosaves but press CTRL+S to save.

Step 8. Finally click on the gradle icon again in the right sidebar.

image

Fine the runClient task, and double click it to run minecraft with the mod.


Mod usage

This section is to describe the usage of the mod in-game

Commands

Main command

/bot

Sub commands:

spawm <botName> This command is used to spawn a bot with the desired name. ==For testing purposes, please keep the bot name to Steve==.

walk <botName> <till> This command will make the bot walk forward for a specific amount of seconds.

/goTo <botName> <x> <y> <z> This command is supposed to make the bot go to the specified co-ordinates, by finding the shortest path to it. It is still a work in progress as of the moment.

/sendAMessage <botName> <message> This command will help you to talk to the bot.

/teleportForward <botName> This command will teleport the bot forward by 1 positive block

/testChatMessage <botName> A test command to make sure that the bot can send messages.

Example Usage:

/bot spawn Steve

About

A minecraft mod which aims to add a "second player" into the game which will actually be intelligent.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%