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

Commit

Permalink
v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
torralbaa committed Apr 13, 2020
1 parent 9e21068 commit c02d094
Show file tree
Hide file tree
Showing 17 changed files with 381 additions and 34 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Python stuff

__pycache__/
build/
*.pyc
Binary file added .install_files/application-x-mcpimod.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
9 changes: 9 additions & 0 deletions .install_files/mcpimod.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>

<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/x-mcpimod">
<comment>Minecraft Pi Mod</comment>
<icon name="application-x-mcpimod" />
<glob pattern="*.mcpi" />
</mime-type>
</mime-info>
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[Desktop Entry]
Name=MCPIL
Comment=Minecraft Pi Launcher
Exec=$(EXECUTABLE_PATH)
Icon=$(ICON_PATH)
Exec=$(EXECUTABLE_PATH) %f
Icon=mcpil
Terminal=false
Type=Application
Categories=Application;Game;
MimeType=application/x-mcpimod
StartupNotify=true
GenericName=Minecraft Pi Launcher
34 changes: 29 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,49 @@ A simple launcher for Minecraft: Pi Edition.

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

### Installation
To install MCPIL, download or clone the repository:
``` shell
```shell
git clone https://github.com/Alvarito050506/MCPIL.git
```
and then run the file ``install.py``. It will create a desktop file that you can access in the "Games" category.
and then run the `install.py` file. It will create a desktop file that you can access in the "Games" category.

## Features
+ Switch between Minecraft Pi and PE
+ Username change
+ Skin change
+ Mod load
+ Mod API
+ Mod compilation
+ World game mode and name change
+ Coming soon: join non-local server
+ Join non-local servers
+ Coming soon: Pi Realms

## Usage
Launch the MCPIL desktop file or run the ``mcpil.py`` file to see the magick! :wink:
Launch the MCPIL desktop file or run the `mcpil.py` file to see the magick! :wink:

## API
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

## 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
./mcpim.py example.py
```
will produce a `example.mcpi` mod file.

## Thanks
To [@Phirel](https://www.minecraftforum.net/members/Phirel) for his Pi2PE (a.k.a. "survival") patch.
Expand Down
41 changes: 41 additions & 0 deletions api/mcpil/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# __init__.py
#
# Copyright 2020 Alvarito050506 <donfrutosgomez@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#

import sys
import psutil
from os import environ

def get_user_name():
return environ.get("MCPIL_USERNAME");

def get_world_name():
mcpi_process = psutil.Process(int(environ.get("MCPIL_PID")));
return mcpi_process.open_files()[-1].path.split("/")[-2];

def get_game_mode():
world_name = get_world_name();
world_file = open("/root/.minecraft/games/com.mojang/minecraftWorlds/" + world_name + "/level.dat", "rb");
world_file.seek(0x16);
game_mode = int.from_bytes(world_file.read(1), "little");
world_file.close();
return game_mode;
42 changes: 42 additions & 0 deletions api/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# setup.py
#
# Copyright 2020 Alvarito050506 <donfrutosgomez@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#

from distutils.core import setup
from os import chdir, path

chdir(path.dirname(__file__));

setup(
name="mcpil",
version="v0.1.1",
description="MCPI API extensions",
author="Alvarito050506",
packages=["mcpil"],
classifiers=[
"Development Status :: 3 - Alpha",
"Environment :: Console",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3 :: Only",
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)"
]
);
8 changes: 7 additions & 1 deletion mods/example.py → example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
import sys
import time
from mcpi import *
from mcpil import *

mc = minecraft.Minecraft.create();

def main(args):
mc.setting("world_immutable", True);
mc.camera.setFollow();
mc.saveCheckpoint();
mc.postToChat("Welcome to Minecraft Pi.");
mc.postToChat("Welcome to Minecraft Pi, " + get_user_name() + ".");
mc.postToChat("The name of this awesome world is \"" + get_world_name() + "\".");
if get_game_mode() == 0:
mc.postToChat("You are in Survival mode.");
else:
mc.postToChat("You are in Creative mode.");
time.sleep(5);
mc.setting("world_immutable", False);
mc.setting("nametags_visible", True);
Expand Down
43 changes: 37 additions & 6 deletions install.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# install.py
#
# Copyright 2020 Alvarito050506 <donfrutosgomez@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#

import subprocess
import sys
Expand All @@ -14,31 +34,42 @@ def main():

if os.geteuid() != 0:
sys.stdout.write("Error: You need to have root privileges to run this installer.\n");
return 1;

sys.stdout.write("Installing dependencies... ");
subprocess.call(["sudo", "apt-get", "install", "python3-tk", "wget", "bspatch", "-qq"]);
subprocess.call(["sudo", "pip3", "install", "psutil", "-qq"]);
sys.stdout.write("OK.\n");

sys.stdout.write("Downloading Minecraft... ");
subprocess.call(["sudo", "apt-get", "install", "minecraft-pi", "-qq"]);
sys.stdout.write("OK.\n");

sys.stdout.write("Installing Minecraft... ");
subprocess.call(["bspatch", "/opt/minecraft-pi/minecraft-pi", "/opt/minecraft-pi/minecraft-pe", "install_files/minecraft-pe.bsdiff"]);
subprocess.call(["bspatch", "/opt/minecraft-pi/minecraft-pi", "/opt/minecraft-pi/minecraft-pe", "./.install_files/minecraft-pe.bsdiff"]);
subprocess.call(["chmod", "a+x", "/opt/minecraft-pi/minecraft-pe"]);
sys.stdout.write("OK.\n");

sys.stdout.write("Installing API... ");
subprocess.call(["python3", "./api/setup.py", "-q", "install"]);
sys.stdout.write("OK.\n");

sys.stdout.write("Configuring... ");

desktop_template = open("install_files/mcpil.desktop", "r");
desktop_file = open("/usr/share/applications/mcpil.desktop", "w");
desktop_file.write(desktop_template.read().replace("$(EXECUTABLE_PATH)", os.getcwd() + "/mcpil.py").replace("$(ICON_PATH)", os.getcwd() + "/install_files/icon.png"));
desktop_template = open("./.install_files/tk.mcpi.mcpil.desktop", "r");
desktop_file = open("/usr/share/applications/tk.mcpi.mcpil.desktop", "w");
desktop_file.write(desktop_template.read().replace("$(EXECUTABLE_PATH)", os.getcwd() + "/mcpil.py").replace("$(ICON_PATH)", os.getcwd() + "/.install_files/icon.png"));
desktop_template.close();
desktop_file.close();
shutil.copy2("./install_files/minecraft-pe", "/usr/bin/minecraft-pe");

shutil.copy2("./.install_files/minecraft-pe", "/usr/bin/minecraft-pe");
subprocess.call(["chmod", "a+x", "/usr/bin/minecraft-pe"]);
subprocess.call(["chmod", "a+x", "mcpil.py"]);

shutil.copy2("./.install_files/icon.png", "/usr/share/pixmaps/mcpil.png");
shutil.copy2("./.install_files/application-x-mcpimod.png", "/usr/share/pixmaps/application-x-mcpimod.png");
shutil.copy2("./.install_files/mcpimod.xml", "/usr/share/mime/packages/application-x-mcpimod.xml");
subprocess.call(["update-mime-database", "/usr/share/mime"]);
sys.stdout.write("OK.\n");
return 0;

Expand Down
Loading

0 comments on commit c02d094

Please sign in to comment.