With the help of Deep Learning, I made software that reads out sentences related to the game while playing Minecraft.
↓ Such a guy
Since it is difficult to combine them into one article, I will divide it into several articles. This section describes the ** application part ** </ font>.
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 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.
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.
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
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.
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.
Put letters in the chat in Minecraft.
MinecraftServer mcserv;
mcserv.getPlayerList().sendMessage(new TextComponentString("hogehoge"));
-Reference? -Article listing functions in Japanese
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.
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.
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)
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