Skip to content
This repository has been archived by the owner on Feb 19, 2021. It is now read-only.

Commit

Permalink
Big updates!
Browse files Browse the repository at this point in the history
  • Loading branch information
torralbaa committed Aug 28, 2020
1 parent 3470fb7 commit b9ae094
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 322 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@

# Builds
*.pyc
*.so

# Python stuff
__pycache__/
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[submodule "libmcpi"]
path = libmcpi
url = https://github.com/MCPI-Devs/libmcpi
[submodule "mcpi-central"]
path = mcpi-central
url = https://github.com/MCPI-Devs/mcpi-central
[submodule "modpi"]
path = modpi
url = https://github.com/MCPI-Devs/modpi
[submodule "proxy"]
path = proxy
url = https://github.com/MCPI-Devs/proxy
47 changes: 18 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@ A simple launcher for Minecraft: Pi Edition.

## Getting started
### Prerequisites
To use MCPIL you need to have Python 3.7 pre-installed.
To use MCPIL you need to have `Python >= 3.7.x` pre-installed.

### Installation
To install MCPIL, download or clone the repository and run the `build.py` file in the root of the repo:
```shell
git clone https://github.com/MCPI-Devs/MCPIL.git
cd ./MCPIL/
python3.7 ./build.py
git clone --recurse-submodules https://github.com/MCPI-Devs/MCPIL.git
cd MCPIL
python3 ./build.py
```
It will generate a `install.pyc` file under the `build` directory, run it:
```shell
cd ./build/
python3.7 ./install.pyc
cd build
python3 ./install.pyc
```
It will "install" MCPI and MCPE, and configure the Launcher.

## Features
+ Switch between Minecraft Pi and PE
+ Username changing
+ Skin changing
+ Mod loading
+ Mod API
+ Mod compilation
+ World setting (game mode and name) changing
+ Join non-local servers
+ Coming soon: More stuff
+ Switch between Minecraft Pi and PE
+ Username changing
+ Skin changing
+ Mod loading
+ Mod API
+ Mod compilation
+ World setting (game mode and name) changing
+ Join non-local servers
+ Coming soon: More stuff

## Usage
Launch the MCPIL desktop file or run the `mcpil.pyc` file in the `build` folder as following to see the magic! :wink:
Expand All @@ -41,25 +41,14 @@ python3.7 ./mcpil.pyc
```

## API
**Warning**: The API will be refactored in the next release.
The API documentation was moved to the [ModPi repo](https://github.com/MCPI-Devs/modpi).

There is an MCPIL API that you can use by importing the `mcpil` module into your Python mod. It exposes the following functions:

### `def get_user_name()`
Returns the user name of the player.

### `def get_world_name()`
Returns the name of the current world.

### `def get_game_mode()`
Returns the game mode of the current world as an interger:
+ 0 = Survival
+ 1 = Creative
The old API still can be used, and its documentation is still avaiable [here](https://github.com/MCPI-Devs/MCPIL/tree/3470fb73b81510f5e819a34c04cca6f86457c2b2#api). However it is obsolete, it will be removed from future releases of the Launcher, and it is recommended to use the new ModPi API.

## Mod compilation
To compile (compress) a Python mod, run the `mcpim.py` file passing the filename of the mod as the first argument. For example:
```shell
python3.7 ./mcpim.pyc example.py
python3 ./mcpim.pyc example.py
```
This will produce an `example.mcpi` mod file.

Expand Down
7 changes: 5 additions & 2 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3.7
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# build.py
Expand All @@ -24,6 +24,7 @@
import sys
import py_compile
import glob
import subprocess
from os import chdir

def main(args):
Expand All @@ -32,7 +33,9 @@ def main(args):
while i < len(src):
py_compile.compile(src[i], cfile="./build/" + src[i].replace("./src", "").replace(".py", ".pyc"), optimize=2);
i += 1;

py_compile.compile("./proxy/proxy.py", cfile="./build/mcpip.pyc", optimize=2);
null = open("/dev/null", "wb");
subprocess.call(["make", "-C", "modpi"], stdout=null);
return 0;

if __name__ == '__main__':
Expand Down
2 changes: 2 additions & 0 deletions build/minecraft/minecraft-pi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ else
export LD_LIBRARY_PATH=./lib/brcm
fi

export LD_PRELOAD="./preload.so"

./minecraft-pi
Binary file removed example.mcpi
Binary file not shown.
50 changes: 0 additions & 50 deletions example.py

This file was deleted.

1 change: 1 addition & 0 deletions libmcpi
Submodule libmcpi added at 86c941
1 change: 1 addition & 0 deletions mcpi-central
Submodule mcpi-central added at eae4b1
1 change: 1 addition & 0 deletions modpi
Submodule modpi added at 67297f
1 change: 1 addition & 0 deletions proxy
Submodule proxy added at 805af1
41 changes: 0 additions & 41 deletions src/api/mcpil/__init__.py

This file was deleted.

47 changes: 0 additions & 47 deletions src/api/setup.py

This file was deleted.

42 changes: 22 additions & 20 deletions src/install.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3.7
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# install.py
Expand Down Expand Up @@ -26,34 +26,36 @@
from os import uname, getenv, path, makedirs, mkdir, getcwd, chdir
import shutil

def main():
def main(args):
if "arm" not in uname()[4] and "aarch" not in uname()[4]:
sys.stdout.write("Error: Minecraft Pi Launcher must run on a Raspberry Pi.\n");
return 1;

sizes = ["16", "32", "48", "64", "128"];
chdir(path.dirname(path.realpath(__file__)));

if not path.exists(getenv("HOME") + "/.mcpil"):
subprocess.call(["pip3.7", "install", "--user", "-qq", "psutil"]);
subprocess.call(["python3.7", "../src/api/setup.py", "-q", "install"]);
if not path.exists(getenv("HOME") + "/.local/share/applications"):
makedirs(getenv("HOME") + "/.local/share/applications");
i = 0;
while i < len(sizes):
subprocess.call(["xdg-icon-resource", "install", "--novendor", "--size", sizes[i], "./res/application-x-mcpimod_" + sizes[i] + "px.png", "application-x-mcpimod"]);
subprocess.call(["xdg-icon-resource", "install", "--novendor", "--size", sizes[i], "./res/mcpil_" + sizes[i] + "px.png", "mcpil"]);
i += 1;
subprocess.call(["xdg-mime", "install", "--novendor", "./res/mcpimod.xml"]);
subprocess.call(["pip3", "-q", "install", "mcpi"]);
subprocess.call(["pip3", "-q", "install", "../modpi/"]);
subprocess.call(["pip3", "-q", "install", "../mcpi-central/"]);
shutil.copy2("../modpi/build/preload.so", "./minecraft/preload.so");
if not path.exists(getenv("HOME") + "/.local/share/applications"):
makedirs(getenv("HOME") + "/.local/share/applications");
i = 0;
while i < len(sizes):
subprocess.call(["xdg-icon-resource", "install", "--novendor", "--size", sizes[i], "./res/application-x-mcpimod_" + sizes[i] + "px.png", "application-x-mcpimod"]);
subprocess.call(["xdg-icon-resource", "install", "--novendor", "--size", sizes[i], "./res/mcpil_" + sizes[i] + "px.png", "mcpil"]);
i += 1;
subprocess.call(["xdg-mime", "install", "--novendor", "./res/mcpimod.xml"]);
if not path.exists(getenv("HOME") + "/.mcpil/"):
mkdir(getenv("HOME") + "/.mcpil");
shutil.copytree("./minecraft", getenv("HOME") + "/.mcpil/minecraft");
shutil.copytree("./minecraft/", getenv("HOME") + "/.mcpil/minecraft/");
mkdir(getenv("HOME") + "/.mcpil/mods");
desktop_template = open("./res/tk.mcpi.mcpil.desktop", "r");
desktop_file = open(getenv("HOME") + "/.local/share/applications/tk.mcpi.mcpil.desktop", "w");
desktop_file.write(desktop_template.read().replace("$(EXECUTABLE_PATH)", "python3.7 " + getcwd() + "/mcpil.pyc"));
desktop_template.close();
desktop_file.close();
desktop_template = open("./res/tk.mcpi.mcpil.desktop", "r");
desktop_file = open(getenv("HOME") + "/.local/share/applications/tk.mcpi.mcpil.desktop", "w");
desktop_file.write(desktop_template.read().replace("$(EXECUTABLE_PATH)", "python3 " + getcwd() + "/mcpil.pyc"));
desktop_template.close();
desktop_file.close();
return 0;

if __name__ == '__main__':
sys.exit(main());
sys.exit(main(sys.argv));
20 changes: 11 additions & 9 deletions src/mcpil.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3.7
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# mcpil.py
Expand Down Expand Up @@ -79,10 +79,13 @@ def save_settings():
return 0;

def on_select_mods(event):
if mods.get(int(event.widget.curselection()[0])) is not None:
delete_button["state"] = NORMAL;
else:
delete_button["state"] = DISABLED;
try:
if mods.get(int(event.widget.curselection()[0])) is not None:
delete_button["state"] = NORMAL;
else:
delete_button["state"] = DISABLED;
except IndexError:
pass;
return 0;

def install_mod(mod_file=None):
Expand Down Expand Up @@ -119,7 +122,7 @@ def start_mods():
mods_env["MCPIL_USERNAME"] = mcpi_file.read(7).decode("utf-8");
mcpi_file.close();
mods_env["MCPIL_PID"] = str(mcpi_pid);
mods_process = subprocess.Popen(["python3.7", "./mcpim.pyc"], env=mods_env);
mods_process = subprocess.Popen(["python3", "./mcpim.pyc"], env=mods_env);
return 0;

def kill_mods():
Expand Down Expand Up @@ -161,7 +164,7 @@ def add_server():
global proxy_process;
server_addr = server_addr_entry.get();
server_port = server_port_entry.get();
proxy_process = subprocess.Popen(["python3.7", "./mcpip.pyc", server_addr, server_port]);
proxy_process = subprocess.Popen(["python3", "./mcpip.pyc", server_addr, server_port]);
return 0;

def kill_proxy():
Expand Down Expand Up @@ -332,14 +335,13 @@ def about_tab(parent):
title.config(font=("", 24));
title.pack();

version = Label(tab, text="v0.3.0");
version = Label(tab, text="v0.4.0");
version.config(font=("", 10));
version.pack();

author = Label(tab, text="by @Alvarito050506");
author.config(font=("", 10));
author.pack();
author.bind("<Button-1>", web_open);

url = Label(tab, text="https://github.com/MCPI-Devs/MCPIL", fg="blue", cursor="hand2");
url.config(font=("", 10));
Expand Down
Loading

0 comments on commit b9ae094

Please sign in to comment.