[JAVA] "Minecraft where a heckler flies" Generate appropriate text with Deep Learning ~ Move with mod ~

With the help of Deep Learning, I made software that reads out sentences related to the game while playing Minecraft.

↓ Such a guy でもミニ.gif

Actually playing video

Since it is difficult to combine them into one article, I will divide it into several articles. This section describes the ** application part ** </ font>.

↓ Other articles

-Overall flow

-Prepare data

-Deep Learning

Thing you want to do

Use Minecraft to determine if there are zombies nearby. If there are zombies, display sentences related to zombies.

(For the place to prepare the text itself, go to another article)

Minecraft mod

Minecraft has a mod made by volunteers. With mods, you have a lot of freedom to modify your game.

With MCreator, you can start mod production right away. For simple changes, you don't even have to write code.

I want to embed a Python program

Minecraft mod is written in Java.

--Java I don't know much. ――I want to use Python because I want to run the model of Deep Learning as well.

Raspberry Jam Mod(mcpi) You can operate some Minecraft from Python. You can do many things. However, the part that acquires game information is delicate.

Communicate with Python and Java

Take a look at the code in mcpi. It seems that they are communicating via Socket communication. It seems that you can specify the port and go to the hospital.

--The Python side modifies the Connection class of mcpi

--Java side writes by pushing -Java Socket Communication -Communicate with Python

Find out if there are zombies nearby

Finally, mod implementation. I used MCreator 1.9.1.

Creating a new workspace with MCreator creates a mod template.

--You can create new commands with GUI. Create an empty command. --Write in the ʻexecuteProcedure` function of something like hogehogeCommandExecuted.

--Packing what you want to do in another function. --Prepare Socket --Continue to acquire / send / receive data

--When executing a command, execute the created function in another process. --Since I am a mod amateur (+ Java amateur), I wanted to separate it from mod. ――For brain death, Try using something called Thread.

Get in-game information

Minecraft mc = Minecraft.getMinecraft()
WorldClient world = mc.world;
List<Entity> entities = world.getEntities(Entity.class, (entity)->!entity.isInvisible());

Now you can get non-transparent enemy mobs and animal mobs in the world.

Entity player = world.getEntityByID(mc.player.getEntityId());

Then take an instance of the player.

String minecraftData;
for (Entity e: entities) {
    if (e.getDistance(player) < 8.0f) {
        minecraftData += e.getName() + ",";
    }
}

You can find the distance between Entity with getDistance. Get the name of a nearby Entity with getName and add it to the send string.

display

Put letters in the chat in Minecraft.

MinecraftServer mcserv;
mcserv.getPlayerList().sendMessage(new TextComponentString("hogehoge"));

Site that seems to be helpful

-Reference? -Article listing functions in Japanese

Be careful with mod

The specifications of the library differ slightly depending on the version. The source of the library can also be found from MCreator. If you understand it, you can read it directly.

Prepare a character string.

Since the statement related to which object is divided in advance, it is randomly selected based on the data from the mod. I put the first word of the sentence into the generative model and tried to generate the sentence. See another article for details.

bonus

Just displaying it is not tasteful. I tried to speak slowly. Easy, I did it like this (windows).

subprocess.call("start C:\hoge\softalk\SofTalk.exe /R: /W: "+"The text you want to read", shell=True)

Summary

Minecraft mods are famous, so I thought there were plenty of commentary articles, but that wasn't the case.

Building an environment that does not use MCreator is troublesome and has not been done. I feel inconvenient when I try to code hard, so I want to do something about it.

Minecraft has a lot of potential, so I hope everyone will try it.

Recommended Posts

"Minecraft where a heckler flies" Generate appropriate text with Deep Learning ~ Move with mod ~
"Minecraft where a heckler flies" Generate appropriate text with Deep Learning ~ Collect data ~
Generate Pokemon with Deep Learning
PPLM: A simple deep learning technique to generate sentences with specified attributes
A story about predicting exchange rates with Deep Learning
A scene where GPU is useful for deep learning?
Try to build a deep learning / neural network with scratch
[Evangelion] Try to automatically generate Asuka-like lines with Deep Learning
(Now) Build a GPU Deep Learning environment with GeForce GTX 960
I tried to divide with a deep learning language model