Showing posts with label minecraft. Show all posts
Showing posts with label minecraft. Show all posts

Monday, July 18, 2016

Minecraft Pi backup Worlds on exit

My kids love building cities on the Raspberry Pi version of Minecraft.  They're not programming them yet, but they spend hours placing blocks and designing houses, hotels, swimming pools, and other building and gardens.
All of which is great.
Except I also use the Raspberry Pi for programming and other things where due to my fumbling around I end up borking the SD card and have to start again.

That's OK. If you backup all the files in ~/.minecraft/games/com.mojang/ and then put them on the new SD card all is good.  Really simple backup.
Only problem is I keep forgetting this step and delete weeks or months or effort.

Rather than expecting somehow that I will remember in the future I thought it would be a good idea to solve the problem with a bit of code and a little modification to the menu.

The goal is to replace the command that runs minecraft-pi with a command that runs minecraft-pi and then on exit archives the worlds and sends them to an ftp server.
In this way the backup is off the Pi and even if I do reformat it I can get the backup minecraft worlds and just reinstate them.

All this is being done with Raspbian as the OS.

For the ftp server I have OSMC set up on a Raspberry Pi (1) B+ that I use mainly as a media server for a couple of Blu-Ray player and tablets in the house so it is on 24x7.

The code is quite short made up of a python script that does the archiving and ftping of the file and a bash script that runs minecraft-pi and then runs the backup script.
The code is available at https://github.com/winkleink/MinecraftPi_backup

Just copy it into pi user home folder '/home/pi'
If you copy the code somewhere else then you will need to modify the bash script and the files to take it in to account.
Once copied change the file preferences to permit execution. Since you're in the GUI the easiest way to do this is right click on the file and select [Properties].
The go to Permissions and set Execute.  I chose Anyone, but if you're only going to run as user pi then you can select 'Only owner'

Change Execute permissions so this is a program that can be run

You need to do this for the 2 files (minec.sh and ftpzipminecraft.py)

minec.sh is the bash script to run the 2 commands. With the semicolon at the end of the first command it knows to run them in sequence (one after each other) rather than potentially at the same time. No modification is needed unless you save the ftpzipminecraft.py program somewhere other than the pi home folder

minec.sh

#!/bin/bash
minecraft-pi; 
/home/pi/ftpzipminecraft.py

ftpzipminecraft.py runs after minecraft-pi closes and this does the archiving to local file in the pi home folder and then connects to the ftp server and transfers the archive to the server.
You have to change 3 items in the file for it to work.  I've highlighted them in red below.

FTP SERVER NAME/IP ADDRESS
USERNAME
PASSWORD

ftpzipminecraft.py

#!/usr/bin/python3
# Script to backup the MinecraftPi worlds and then upload them to an FTP server
# By Winkleink (July 2016)
# https://github.com/winkleink/MinecraftPi_backup
# MIT Licence
# This is a quick fix so use at your peril
import os
import zipfile
import datetime

import ftplib

now = datetime.datetime.now()
year= str(now.year)
month = str(now.month)
day = str(now.day)
hour = str(now.hour)
minute= str(now.minute)

uploadfile = "minecraft"+year+"-"+month+"-"+day+"-_-"+hour+"-"+minute+".tar.gz"

print(uploadfile)
os.system ("tar zcvf " + uploadfile + " /home/pi/.minecraft/games/com.mojang")

# Enter your FTP Server Name or IP address, Username and Password in the following line
session = ftplib.FTP("FTP SERVER NAME/IP ADDRESS","USERNAME","PASSWORD")
file = open("/home/pi/"+uploadfile, "rb")
session.storbinary("STOR " + uploadfile, file)
file.close()
session.quit()
print("Done")





Once both files are in place and are set to executable we need to modify the menu entry for Minecraft so it runs our new script minec.sh

From the main menu select [Preferences] [Main Menu Editor]


Then on the left select [Games] and pick [Minecraft] and then click [Properties] on the right.


Finally, replace the 'minecraft-pi' command with '/home/pi/minec.sh'


Its not shown here, but so I know it's the one I've changed I modified the Comment to 'Minecraft + Backup' so when I mouse over the menu entry I can see it the one with the backup.

With this little change I will hopefully never lose my kids amazing creations in Minecraft on the Raspberry Pi.


Tuesday, May 3, 2016

Minecraft on Raspberry Pi Zero using OTG USB Ethernet connection with RealVNC server and client


In my previous post I connected to a Raspberry Pi 3 using RealVNC to connected over Ethernet.
To achieve this you would need:
Laptop
Raspberry Pi
PSU for Pi
Ethernet cable

What if you could replace the PSU and Ethernet with just a microUSB cable and replace the Pi3 by a PiZero.
Well, this is absolutely possible and quite simple due to the hard work of a number of people including Andrew Mulholland who created a guide on setting up Ethernet over USB using OTG that I hope to make even more simple here. Then it's a matter of installing RealVNC to get the Raspbian desktop on your laptop.

OTG stands for On-The-Go or it's full name USB On-The-Go
Put simply OTG allows a USB device to act like a host and have peripherals  such as keyboard and external storage attached to the device or act like a slave so it can be a network device or a mass storage device.
This is most used on phones an tablets where it's great to be able to plug in a USB stick and access the files (host) or plug the phone into your computer and download the files (slave)

For OTG is enabled by the ID-pin which is available on the PiZero as the USB port is directly connected to SOC and it uses a microUSB connector which has the extra pin for the ID.

Back in December Andrew posted a guide on setting up OTG.
It includes a lot extra information that is worth reading and understanding, but here I want to just do the facts and steps needed to enable Ethernet over USB.

I'm assuming you have already installed Raspbian on your PiZero 

Next you need your PiZero to be connected to the network to be able to download and install some files. For this I used an Wii USB Ethernet adapter.  This adapter is supported by default. They're about £10 on eBay.  Just search Wii USB Ethernet.

With the PiZero connected to the network I found the Pis IP address using Fing on my phone.
With the IP address known I used putty to ssh in. (Yes, this is the correct link for downloading)

Once logged in do the usual housekeeping.
sudo raspi-config to expand the filesystem and set GPU memory to 128MB
sudo apt-get update
sudo apt-get upgrade

Then it's a matter of running the following commands one after another to get Ethernet over USB set up. Andrew's guide explains what they do and also the other OTG options available.


sudo BRANCH=next rpi-update

echo "dtoverlay=dwc2" | sudo tee -a /boot/config.txt

echo "dwc2" | sudo tee -a /etc/modules

echo "g_ether" | sudo tee -a /etc/modules

echo -e "interface usb0 \nstatic ip_address=169.254.64.64" | sudo tee -a /etc/dhcpcd.conf

Now Ethernet over USB should be set up.

Next RealVNC server needs to be installed.  The guide for installing the latest Alpha that supports Minecraft can be  found here. https://github.com/RealVNC/raspi-preview

With the relevant commands being:
curl -OL https://github.com/RealVNC/raspi-preview/releases/download/5.3.1.18206/VNC-Server-5.3.1-raspi-alpha1.deb

sudo dpkg -i VNC-Server-5.3.1-raspi-alpha1.deb

sudo systemctl enable vncserver-x11-serviced.service

These install RealVNC server and enable it as a service that starts at boot up.

Shutdown your PiZero using
sudo shutdown 0

Unplug the cabled.
Plug single microUSB cable into the USB port on the PiZero and the other end into your laptop USB port. The PiZero uses so little power it can safely be powered from the laptop USB with no issues.
Mine laptop is running Windows 10 and the device is automatically detected and the drivers installed.  I didn't have to do anything.
This creates a new Ethernet device.

Download and install RealVNC Viewer 

Run RealVNC Viewer on your laptop and enter the fixed IP address of 169.254.64.64 used when setting up the PiZero.
It will ask for your login. On mine it defaults to the laptop username. so, just change to pi/raspberry assuming you haven't changed it.

RealVNC should now login to the PiZero.
It's that simple.

RealVNC recommend some optimisation that I definitely found to improve performance.

On the VNC Viewer toolbar (top of the Window), click the Options button.
Click Advanced..., then the Expert tab.
Set PreferredEncoding to JPEG, AutoSelect to False, and ColorLevel to Full

These changes really make RealVNC smoother.

If using Minecraft you have to make one more selection.
Press [F8] to go back to the menu and select Relative Pointer Motion
Then start Minecraft as normal.
All should work perfectly.

You will notice that the RealVNC window is quite small this is because there is no resolution details set by a display so the Raspberry Pi defaults to 640x480 as the safest mode.

To increase the resolution you have to make some minor changes to config.txt
RealVNC give full details on this on the following support page

But to put it simply to set the resolution to 800x600 do the following

Open a terminal window
cd /boot
sudo cp config.txt config.txt.backup
sudo nano config.txt

This makes a backup of config.txt and then opens it with nano

Remove the # in front of hdmi_force_hotplug and set it to 1
hdmi_force_hotplug=1


Enter the following line into config.txt

hdmi_ignore_edid=0xa5000080


No idea what it does and even RealVNC describe it as better safe than sorry.  I've run without it and it worked.

Remove the # in front of hdmi_group and set it to 2.
hdmi_group=2

Remove the # in front of hdmi_mode and set it to 9 which is the value for 800x600.
You can look up all the values and adjust according to your needs on the elinux.org page

Press [CTRL]-[x] to exit.
Select y for saving changes and then press [Enter]

Now your config.txt is up to date.

Restart the Raspberry Pi and it will restart with a resolution of 800x600 rather than 640x480 making everything a little easier.
If you want a higher resolution then hdmi_mode=16 is 1024x768 and hdmi_mode=39 is 1360x768

Finally, here is a (low quality recorded from my phone) video of it all running. You can see the speed is good and even programming in Python works well.


Sunday, May 1, 2016

Minecraft running over RealVNC from Raspberry Pi 3

Back at the PiParty in March RealVNC showed Minecraft running over VNC.  This doesn't seem like much of an achievement until you realise that Minecraft doesn't use X. It writes directly to the framebuffer, so for normal VNC Minecraft just comes up as black window.

I posted a short video from the party.  They had multiple sessions running on the one display.



Last wee RealVNC released the public Alpha of the new RealVNC server that enable Minecraft to run over VNC.

https://github.com/RealVNC/raspi-preview

I got a chance to install it today on a Pi3 and connect froma fairly low power laptop that cost £110.
Acer ES1-131 Celeron N3050 1.6GHz with 2GB RAM running Windows 10.

Firt run it went well, a little bit laggy (not sure if that's a real word).  I assumed it was because running over wifi.
Then I read the raspi-preview page again and noted there are a few optimisations available.

With the optimisation completed it ran really well.  Below is a short (sliglty out of focus) video of it running.



Now I'm looking forward to seeing the finals release of RealVNC.

Friday, August 14, 2015

9th Egham Jam – Show and Tell Competition – Prizes donated by Pimoroni


I really love the postal service as today another package arrived with prizes for the Show and Tell competition at the next Egham Jam on the 11th October.

This time from wonderful people at Pimoroni.
If you've been around the Raspberry Pi world for any amount of time the Pimoroni name will have popped up on your radar.

Assuming my facts are correct they are responsible for
Raspberry Pi Logo - yes that one.
Pibow Rainbow Case and now in many other colour variations
Unicorn Hat RGB LED matrix
Picade - Complete kit to make your own mini arcade machine

They also support the Picademy work and are very active in supporting the community and provide detailed tutorials. http://learn.pimoroni.com/

Specifically for the Show and Tell Competition they have provided 2 'Kit for the Book' sets

Kit for Adventures in Raspberry Pi by Carrie Anne Philbin (Book Link)
Kit for Adventures in Minecraft by David Whale and Martin O'Hanlon (Book Link)


Along with an Explorer Hat Pro and Explorer Hat Pro Parts Kit  for more fun making and lovely stickers. My favourite is 'I broke it better'

So if you have these books are considering getting them these kits include all the components and parts you need to make full use of the electronics based projects that are provided in the books.


With the Eben Upton signed cases from the Raspberry Pi Foundation, Deluxe Snap Rovers from Cyntech and now the Pimoroni  prizes the Prize Pool for the Competition is growing rapidly.

If you wish to enter the competition just have a project to show at the next Egham Jam on the 11th of October.  To attend (either showing or just visiting) please register on the Eventbrite page.  http://eghamjam9.eventbrite.com




Thursday, April 2, 2015

Try Sonic Pi and Minecraft Programming at the Egham Raspberry Jam on the 26th of April


Come and try out Sonic Pi and Minecraft/Python programming.

Sonic Pi is a great way to create music by programming. You can even do Live Coding giving you the ability to compose music as you playing. 

Sonic Pi is such an amazing way to learn about music and programming that the Raspberry Pi Foundation recently ran a competition for Sonic Pi compositions.
The 10 finalists are amazing.  Be a composer by coding.

Minecraft on the Raspberry Pi is a great open world environment where you can program what happens.  Build a Giant Clock or how about a Town Square 

How about mixing the two and creating music using Minecraft. See the Minecraft Piano

Now's your chance to try them out on the 26th April at the Egham Raspberry Jam.

The event is free to attend all you have to do is register on Eventbrite.

http://eghamjam7.eventbrite.com 
Places are limited to 100 and last time we sold out and had a waiting list for the final week and it's looking like it will be the same again this time.

So, if you're interested in trying Sonic Pi and Minecraft then get yourself registered and come along.

To see more of what happens at the Egham Jams checkout the write up and some pictures from the Jam we had on had in January. http://winkleink.blogspot.co.uk/2015/01/egham-raspberry-jam-25th-of-january.html

Monday, January 26, 2015

Egham Raspberry Jam - 25th of January

What a day. More than double the attendees. More than double the stands, more teachers and kids attending.  More fun and learning than ever before.

When the Egham Jam was announced back in December I thought we would do better than the last Jam (46 registrations) but was blown away by the response.
Maybe a lot of new Raspberry Pis were sold at Christmas.
We were not only 'SOLD OUT' but also had more people who wanted to attend as well as people who register who advised me they couldn't make it so their tickets were released.

In the end 90 attended, more than double the October event and a record for the Egham Jam.

I was also really delighted the number of educators who attended looking for ways to integrate the Raspberry Pi into their schools Computing work.

There were at least 12 show and tell standard, some of them had multiple displays making for a very interesting day.  Also, very delighted that on a number of stands children were leading the show and tells. Giving great demonstrations on what they have build.

I tried to meet everybody who attended as possible and got the chance to connect teachers and people with specific needs with others who I know from previous Jams demoed a similar project.

Below are some pictures from the event.  Lots of fun.  Roll on the next Egham Raspberry Jam.

Surrey & Hampshire Hackspace were out in force

Scrolling messages


Pirates and MiWars winner

Raspberry Pi Development solution in a box


Robots are go.  Controlled over Wifi

Kodi set up being demoed by a young engineer


PiTrol - build it yourself controller

Remote arm controlled in Python


RISCOS on an HDMIPi



Seven Segment of Pi display



Getting the Wifi network set up to demo Airplay

Minecraft and RetroPie


Scratch 




Robot arm controlled from Scratch


Seven Segments of Pi. It's a big one.



Monday, November 4, 2013

4th Egham Raspberry Jam - 3rd November 2013

Yesterday was the 4th Egham Raspberry Jam and we had a great day with a variety of projects on show and nice range of people attending.
Everything from people learning about the Raspberry Pi so they could teach their grand children about computers and computer technology to children looking to be inspired for school projects.

I arrived about 12:00 noon to get set up and people showing started to arrive around 1:00.

We had a great mix of projects.
Leo White's Big Trak http://www.mybigideas.co.uk/RPi/BigTrak/
Now upgraded with a new metal robotic arm.

Leo also has a project that just looked like flasking LEDs on the PiGlow until I had a quick chat with Leo and found out that it was all being done in BBC BASIC using RISCOS running on the Raspberry Pi. So, if your old enough to have programmed in BBC BASIC you will be right at home.











Carl Monk brought along his DeLorean Time Machine control panel and flux capacitor as featured on the Raspberry Pi website http://www.raspberrypi.org/archives/4856


Carl also brought along his Pumpkin Game. Great fun using Pumpkins to play a Scratch based game.

Stephen Cornes brought his excellent LED clock which displayed the time in multiple formats.  This project uses the excellent Pi-Lite board which communicates with the Raspberry Pi over serial.

Alan has his bi-direction motor controller running. Even though this is a small project it is a major milestone as Alan knew nothing about Linux, programming or electronics when he came to his first Jam and now he is writing python code on a Linux computer to control a real world motor using a H-bridge.

Matt Sendorek brought along his excellent Maplin robotic arm controlled from Scratch using an intermediary Python script.  Matt has been building this to to use in his after school computer club and from his picture on his write up of the  Egham Jam it looks like it's the perfect thing to get kids interested in computing http://mattrealm.me.uk/blog/?p=41

Matt has also put together a guide to getting the robotic arm working with Scratch

Marcus Taylor-Moore brought along his robots that were used in a maze challenge and also a really small quadcopter. All very exciting and I know I want both...



Nicholas Herriot had a great set up of home automation. I must admit I didn't get a change to chat much to Nick and so my knowledge of his project is very limited.

Then the amazing Neil Ford came with a show of his own. Not content with 1 display he brought 5
2 Wheel Robot controlled by Raspberry Pi. Perfect as a beginner robotic project with a build that requires no soldering and only a bit of glue.

Neil set up a station where visitors could try out Scratch. See how easy it is to use and how through some simple steps interesting and fun projects can be built.

We had some great music being composed using SonicPi. I must get some time to check this out as it really looks like a great way to introduce programming and giving immediate feedback in a fun way.

How about controlling real world objects with Python

Finally, a great Minecraft set up that was very busy during the day. With kids doing some playing and programming. 

My own little project was Halloween based with a PIR detecting motion and then flashing LEDS inside a couple of clear/greenish skulls and a 'Scream' mask and at the same time played a creepy sound. The sound was so convincing that my daughter didn't like me playing it at home.  All programmed up in Python and using Pygame to play the audio. I did up a PDF Guide with the build instructions and also the Python code. Special call out for Raspberry Pi Spy for his guide and code I used for the PIR motion sensor.  I was just looking for the details on the PIR as I bought it on ebay and so received no instructions. Not only did Raspberry Pi Spy provide details on the PIR he also provided code that works..

I also brought along the Surrey & Hampshire Hackspace 2 pager cheat sheet with details on programs to install on the Raspberry Pi, Controlling an LED, building a Sphere in Minecraft and other useful information on one page and the FOSSWire Linux Cheat Sheet which is a great reference for the often need Linux commands that somebody starting out may not have experience with.
The Hackspace is based in Farnborough and is a great place to meet like minded people who are interested in Raspberry Pi, Arduino, Linux, 3D Printing, Online security as many other fun activities.

I hope those who came had a great time and were inspired to try something new with their Raspberry Pi. It's an amazing little bit of kit that can be used in many different ways (as can be seen from the projects on show)

Here's looking forward to the next Egham Raspberry Jam.

Also, if you're into seeing what's going on with the Raspberry Pi and have a focus on Education the the Raspberry Jamboree on the 27th-28th February 2014. Some great presentations and workshops are already announced and more will be announced closer to the time. I plan to be there on the 28th at least. Maybe stay over for the party.  

Tuesday, February 26, 2013

Raspberry Pi Minecraft and Python - create lots of blank worlds to mess about in.

I've been playing with Python and Minecraft on the Raspberry Pi.  Using the API included you can write Python scripts to build in Minecraft.
I like to work with a blank world rather than an existing landscape because the landscape may not work or if I make a mistake it can be hard to undo.

So, I wanted to quickly create a bunch of disposable worlds that I can run my very rough scripts in to see where I need to tweak them.

NOTE: for some reason some flowers and things are left behind. It might be an attribute thing...

Code Below:

#!/usr/bin/python

import sys
import mcpi.minecraft as minecraft
import mcpi.block as block

mc = minecraft.Minecraft.create()

mc.postToChat("Clearing ALL")

blockId = block.AIR.id
mc.setBlocks(-127,-127,-127,127,127,127,blockId)

mc.postToChat("create floor")

blockId = block.DIRT.id
mc.setBlocks(-127,0,-127,127,0,127,blockId)


There are no indents so should just work if cut and pasted to a text file and saved.  I used clearall.py

Start Minecraft
Create a World

RUN:
python clearall.py

The whole world is made of AIR with a 'ground' of DIRT is added at Y=0.
This will take a while to run so be patient.

Now you have one blank world.

But that would be slow to do that every time you need a blank world.

Well with a bit of jiggery pokery you don't have to.
The method I used is probably a bit manual but it is faster than coding for new worlds every time.
Maybe somebody brighter than me can automate it.

Step 1. Make sure you can see hidden folders when browsing on your Raspberry Pi.
The got to ~/pi (if your username is pi)
Open .minecraft/games/com.mojang/minecraftWorlds
This is the directory where your saved Worlds are stored.
One per folder. For me the blank world I created was called world

Create a bunch of new directories. I used world-blank1, world-blank2 etc....
Make as many as you want.

Go into the original world directory and copy all the files.
Then paste those files into each of your world-blank directories.
Now you have replicated the blank world you created with the above script too all of these world maps.

If you go back into Minecraft they will be there. Only problem is they will all have the same name. Not ideal when you want to know which ones you have broken and which are still clean.

This is where it gets a bit more low level but still quite simple.

Installed ghex a gui based hex editor with sudo apt-get install ghex

Then for each folder open level.dat using ghex and find where it says world
Modify the text to a different name making sure to keep it the same size.  Maybe B0001.
Save the updated level.dat.
Do this for each of your new directories making sure to use a different name (B0002,B0003,...) .

If you run minecraft you will get a list of Worlds all with different names.  For me the order was still a bit mixed up but I can live with that.

Finally, rather than having to do this every time I created a new directory under com.mojang called backup-blank and copied all my newly made blank world into that directory.

Now I can mess about with the blank worlds. Building all kinds of strange shapes not caring about  it being perfect as I can just delete that world and replace it with a new clean one by just copying the saved worlds in backup-blank  back into the minecraftWorlds directory and start again.

Note: For me I have 20(ish) blank worlds created as I mess up a fair bit and this usually allows me to do one good session without having to copy across or create a new blank world.

Happy Coding.