|Langue : , , , … | Allez on remonte !|
|« Retourner à la documentation|
[Minecraft] ComputerCraft: Code in Python!TL;DR Control ComputerCraft remotely (aka a backdoor) with, for instance and as shown here, Python.
I really like MC and especially modded MC such as the FTB modpacks.
One of the mods often included in those packs is ComputerCraft.
A very neat "little" (not really) mod that allows you to control computers or turtles ("computers" that can move around and interact with the world). You can skip directly to the code.
But it comes at one cost (at least IMHO), you gotta control it using the programming language named Lua, which I'm very not fond of.
I really prefer Python as a programming language.
Well, for one, the dev(s) of CC don't want to integrate (or switch over) Python in their mod.
Implementing the possibility of executing Python via CC would require to know how to mod the mod itself and thus coding in Java. meh…
(Note: Some ppl did it but I find it a bit edgy…)
My (a lil' hacky) solution?
Well, what would require the least knowledge to setup?
A "bridge"! Proxy, backdoor, … or whichever way you want to name it actually.
Yup, 20 lines of Lua and +20 lines of Python later, there you have it!
A way to control ComputerCraft turtles remotely from outside MC.
As a fact, "anything" could be used to control it but, you guessed it, I chose using Python personally.
local url = 'http://127.0.0.1:4343/'
A Python HTTP Server:
I chose flask for its simplicity. To install it, simply type "pip install flask" in your terminal.
# coding: utf-8
As the server is "blocking" input, I used a quick dirty workaround to be able to send requests to the server, which then send it back to the turtle who executes it.
# coding: utf-8
The final step, not featured here, will be to teach my Python program to be able "to translate" Python commands in Lua ones.
Dernière modification le 01/09/2015 à 0h08» Commenter cet article / 0 commentaire(s)