Build a Dedicated Raspberry Pi Minecraft server with LED Player Indicator

Source & original idea via Instructables.

Disclaimer: Since updates and deprecations are bound to occur, you are advised to use your discretion to make changes and tinker with codes wherever you see fit to make the project work for you.

Are you a fan of Minecraft? Have you ever wondered how much fun it would be to have your Minecraft server to share with other players or friends? Having your shared world in Minecraft can double the entertainment experience you get out of playing Minecraft. This project will help you create a Raspberry Pi dedicated Minecraft server with a unique feature: it resembles an ore block, which lights up in different colors based on how many people are playing in the world. 

The server will allow your friends to join you if they own Minecraft’s PC edition. You would be able to share your address with anyone and have anyone over into your Minecraft world. In addition, the server will stay up 24/7 so people in your world would be able to keep building while you are away. The server will also make backups so you can avoid any tragedies. 
 
Sounds interesting? Let’s get started.

Step 1: Tools and software required for the project 

Following is the comprehensive list of parts, tools, and software that you will need for this project. You can order them online or pick them from your nearest hardware store. If you can find them cheaper somewhere, get them there. 

Tools:

You will need the following tools for this project: 

  • Soldering equipment 
  • 3D printer (Only if you would like to make the casing)
  • MicroSD card reader 
  • A screwdriver (small) 

Parts:

Following parts are needed for this project: :

  • Raspberry Pi 3 and its power supply
  • MicroSD card (16 or 32 GB)
  • Micro USB right angle adapter 
  • 2.5mm screws (quantity: 4) 
  • Short GPIO wires (quantity: 3)
  • Adafruit Neopixel Jewel 
  • White tissue paper or paper 
  • 3D printing filament of any type (silver or gray) (Again – Only if you would like to make the casing)

Software: 

The following software would be required for this project: 

  • Raspbian lite ISO
  • Filezilla or any other similar FTP client
  • Etcher.io
  • Minecraft java PC edition
  • Putty or SSH terminal client

See the image below to get a good understanding of the components, tools, and software required for the Raspberry Pi dedicated Minecraft server. 

Step 2: Setup your Raspberry Pi 

Before you install the server, you have to prepare your Raspberry Pi with certain configuration steps which are defined below:

I. Start with the MicroSD card 

Use etcher.io to put Raspbian OS onto the MicroSD card. Here’s how you can do that:

  • Insert the card into the card reader and then connect the card reader to the USB port on your personal computer.
  • Next, run etcher, select the image button, and load the Rasbian OS.
  • Choose the MicroSD card as the installation drive and click flash. 
  • After the above process, etcher will successfully disconnect the MicroSD card, but you need to install one more file to connect it back. The MicroSD card will be labeled as “boot”. Create a blank file “ssh” in the “boot” drive and then disconnect the MicroSD card. Your MicroSD card is now all configured for the Pi.

Note: You can easily create your own “ssh” file, by renaming the blank “txt” file. See the screenshots below for a better understanding. 

II. Connect SD to the Pi 

After your Pi has the OS, it’s time to turn it on and get started!

Plug in the power supply and the wired ethernet cable to the Pi. Pi 3 comes with a built-in Wi-Fi, but it’s much better to have a wired connection. 

Next, retrieve the Raspberry Pi’s IP address from the router. This step will be different for different router brands. However, you should be able to locate a DHCP client list with the entry label “raspberry pi”. We recommend that you set Pi’s IP as “permanent” or “reserved” to make sure it remains unique. If you find this step a bit difficult, please consult your router’s manual. 

Next, enter the IP address in the Putty. Inside the “Host Name” field. Click “Open” and you are ready for the next step. 

If the above steps are successful, you should see a black screen that reads “login as:”. This is the Pi’s terminal; the place where you’ll be working for the rest of the project to set up the server. Keep in mind that your mouse may not be of much use here, so get your keyboard to use with the terminal screen. 

III. Setup Raspi-configuration 

Login using the default credentials as shown below: 

login as: pi
password: raspberry

Now, make some changes to the default Pi setting through the following code:

sudo raspi-config

Here, you need to make several changes. Below you’ll find those changes in the exact order as they are required. 

  1. Change the User password. Since everyone knows it, you must change it as the first step to increase security. 
  2. Next, go to Network Options. By default, the Hostname will be “raspberry pi”. You can leave it as is. 
  3. No change required.
  4. Country/localization Options. Make changes based on your country of origin. By: 
  • Changing locale: Find the entry for “en-GB” with a star (*) next to it. Use the spacebar and you will remove the *. Go down and find “en-US.UTF-8”. Again, press the spacebar and you will mark it with the *. 
  • Changing timezone: Make sure that it matches your location as it is important for the timed tasks. 
  • Changing keyboard layout: You can skip this option but not changing it to your country may have some effects on the keyboard symbols’ functions. 
  1. Interfacing options
  • No change is required in the first step. 
  • SSH: Enable this option so you can keep using Putty after you reboot the Pi. 
  1. This step remains unchanged. 
  2. Advanced Options:
  • Expand Filesystem: This option will ensure that the Raspberry Pi can use all the space on the MicroSD. 
  • The next step in this option remains unchanged. 
  • Memory Split: Choose 16 to clear up more space. 

Click “Finish” and select “yes” for Pi’s reboot. 

This action will reboot the Pi and terminate the Putty session. After the reboot is complete, open Putty again and reconnect it to the Pi’s IP address. Don’t forget to use your new password. 

Step 3: Dedicated server installation

This step requires a lot of Linux commands that can be both tiring and boring. But do not give up! It will all be worth it in the end. 

Understand that the Minecraft server you are trying to build is very complex. Running it on something as small as Raspberry Pi requires a lot of configuration and streamlining. If you follow the following steps right, there’s a very small chance that this would turn out bad.

After you are logged in with your new password, you can start adding commands to install the necessary server files. 

Copy-paste the commands as shown below in the terminal. 

First, add this command to get the software up-to-date: 

sudo apt-get update && sudo apt-get upgrade

Now you will see requests for installation approval. Type “y” and enter. 

Minecraft uses Java, but Raspbian Lite doesn’t. So here we’ll install that. Use the code

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/jdk-8u161-linux-arm32-vfp-hflt.tar.gz

Note: Make sure that you update to the latest Java version or you may run into an error. You can do so by visiting Oracle’s Java downloads page

After you have downloaded the latest Java files, you can install them via the following code:

sudo mkdir /usr/java
cd /usr/java

If you change the download link for the newer version, change the version number via these commands: 

sudo tar xf ~/jdk-8u161-linux-arm32-vfp-hflt.tar.gz
sudo update-alternatives --install /usr/bin/java java /usr/java/jdk1.8.0_161/bin/java 1000
sudo update-alternatives --install /usr/bin/javac javac /usr/java/jdk1.8.0_161/bin/javac 1000
cd ~

After Java is installed, you can install what you have been waiting for. The Minecraft server. Note that this is a specialized version of the Minecraft server (known as Paper). It offers several optimizations for better performance.

mkdir Paper
wget https://github.com/TheRemote/RaspberryPiMinecraft/archive/master.zip
unzip master.zip -d Paper
mv ~/Paper/RaspberryPiMinecraft-master/* ~/Paper/
cd Paper
chmod +x start.sh
wget https://ci.destroystokyo.com/job/PaperSpigot/lastSuccessfulBuild/artifact/paperclip.jar
java -jar -Xms512M -Xmx800M paperclip.jar

The last command in the above code will initiate the server and next you will have to agree with EULA with the following command: 

nano eula.txt

Change “eula=false” to “eula=true” and save changes by ctrl-x, Y, then enter. 

Now, you’ll make a couple of changes to the Server Properties. 

nano server.properties

There are several things you can change about the server here including changing game mode, MOTD, changing server name, and enabling certain commands. You can make other changes by opening this file anytime, but at this point, you need to make the following changes:

Max-players=8 

Server-port25565 

Eight players will keep the server performance at optimal. Higher players may make the system lazy and interrupt your gaming. 

You have to change the server port name because like the default Pi password, everyone knows it. 

After you are done with these changes, save your settings by pressing ctrl-x, y, and then enter. 

This next step will probably take you an hour. The following commands will pre-generate your Minecraft world so the server doesn’t have to when you are playing and exploring.

cd ~/Paper/plugins
wget --content-disposition -E https://dev.bukkit.org/projects/worldborder/files/latest
sudo apt-get install screen
cd Paper
./start.sh

You won’t notice it, but the above commands will start the server. Use the following code to interact with it: 

screen -r minecraft

Use the following code to re-generate the Minecraft world:

wb world set 1000 spawn
wb world fill 1000
wb fill confirm

This part will take time so let it be and check back in an hour or so. Once it’s done, shut down the Minecraft server with this command: 

stop

This command will save the server and return you to the Pi terminal. 

The final task is to set up the server so it starts automatically when the Pi is powered on. You can do that by adding the following commands: 

cd ~
nano startup.sh

Enter the following code into the empty window:

cd /home/pi/Paper
screen -dmS minecraft java -server -Dfile.encoding=UTF-8 -Xms512M -Xmx800M -XX:NewSize=300M -XX:MaxNewSize=500M -XX:+CMSIncrementalMode -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=4 -XX:+AggressiveOpts -XX:+AlwaysPreTouch -XX:+DisableExplicitGC -XX:SurvivorRatio=16 -XX:TargetSurvivorRatio=90 -jar /home/pi/Paper/paperclip.jar nogui

Save changes by pressing ctrl-x, y, and then enter. 

chmod +x startup.sh
chmod +x /etc/rc.local
sudo nano /etc/rc.local

Add this code above “exit 0” in the rc. local file:

su pi -c /home/pi/startup.sh

Once again, save the changes (ctrl-x, y, and then enter).

sudo reboot

You’ll receive the message that the connection is closed. Now you can shut down your Putty window. Congratulations, you are done with the server (and the hardest part of the process). You can now test it with your friends. 

Step 4: Test the Minecraft server 

Next, you can check whether the server is working and that you can invite your friends into your own Minecraft world. 

1. Start the Minecraft launcher on your personal computer and press “play”. Make sure that you are using the latest version so it matches with the Paper server. 

2. When you reach the main screen, choose multiplayer then add a new server. Enter the name and the Pi’s ID address and the port number. You can choose any name for the server list but the IP address and the port number will remain the same. Here’s how you can enter the IP address and the port number: 

192.168.1.115:26565

Notice that there is a colon between the port number and the IP address. 

Now click “done” and then “play” on the server. 

After a couple of seconds, you’ll be in your new Minecraft world. 

Now that everything is set up, it’s time to invite your friends.

The problem is that they can’t use the same Pi IP address, so here’s what you’ll need to do: 

  • Add a command in your router telling it to accept people from the outside. 
  • This process is called Port Forwarding. The exact process may differ depending on your router type. See the screenshots below to get an idea. 
  • In the Port Forwarding settings, enter the Pi’s IP address and the port number. After you are done with this setting, your router would know to let people connect with the same port number. 
  • Next, you can use the service called No-IP to build a unique IP address (Hostname). You will need to set up your PC or router to keep the new IP address updated. You can set that up by following the guidelines here. 

After you have set up a No-IP account, you can invite your friends to join. Tell them to add your new Hostname and port number in the multiplayer screen. It should look something like this: hostname.ddnd.net:26565 

See the screenshots below. 

Step 5: Set up automatic backups 

You can skip this step and go straight to building your new worlds on your new server, but this just may save your life (in Minecraft of course). The following commands will help you save your world every night and delete files that are more than a week old, keeping the system clear for more backups. 

You can choose to copy the old files on your personal computer or any other backup drive. 

To create automatic backups, you need to make a new script. Use Putty to reconnect to Pi and use the following command: 

nano dailybackup.sh

Now copy the following commands into the new script: 

# Stop the Minecraft server
screen -x minecraft -X stuff stop^M
sleep 5
# Copy Paper directory to backup/PaperYYDDMM
cp -a Paper/. backup/Paper$(date +%F)
# Delete backups older than 7 days
find backup/* -mindepth 0 -maxdepth 0 -type d -ctime +7 -exec rm -rf {} \;

Save the changes (ctrl-x, y and then enter). 

Next, you will use Crontab to create a recurring backup every night. 

crontab -e

You’ll come across several options, choose # 2 for Nano. This command will take you to a special file where you can schedule tasks. At the bottom, add the following code: 

5 0 * * * /home/pi/dailybackup.sh
15 0 * * * sudo reboot

The commands in the code will tell the Pi to run backups at a specific time every night and reboot after 10 minutes. You can change the time for backups and reboot based on your personal preference. Just remember that the three asterisks will keep the script running every day. In addition, the numbers should be written in 24hr format. 

Once you have the system up and running, you can save your backups in another location. You can easily accomplish this by using Filezilla. Drag and drop the backup folder from Filezilla and onto your PC. Once the files are transferred, you can store them for as long as you want to! 

To go to one of your saved files, first stop the server with the following code: 

screen -r minecraft
stop

Next, delete the Paper directory using Filezilla then drag one of the saved directories to the Pi. Delete the previous date so the file name becomes “Paper”. Then, restart the server using the following command: 

./startup.sh

And that’s it! You are back online. 

Step 6: Set up the LEDs

In this step, you will learn how to solder Neopixel Jewel to the Pi to add some lights! 

First, you will need to do the soldering and the attaching, second, you will need to install and run software to activate the LEDs. After the LEDs are all set, you will never have to wonder if someone is waiting to play with you. Adafruit’s Neopixel LEDs are RGB which allows them to turn into any color. With a couple of commands, you can change the colors whenever you want. To learn more about Neopixels, check out this Adafruit guide

The 7 LEDs of the Jewel will allow you to have strong colors. There are five solder points, but for this project, we will be using three. Use different colors for wires to avoid any confusion. In this project, the colors red, brown, and black are used. 

Enter the following commands and then shut down the Pi. 

screen -r minecraft
stop
sudo shutdown -h now

Next, you will cut 3 female GPIO wires. Make sure that you cut them just enough so that there’s still enough room for soldering. If you have excess wire left, you can wrap it up later. After you are done with cutting the wires, solder them carefully to the contacts on the Neopixel Jewel. Next, attach the Raspberry Pi GPIO pins to the female connectors. Here’s how how you will make the connections: 

PWR TO PIN1 = 3.3v 

IN to pin12 = GPIO 18 

GND to pin 6 = Ground 

Once the Neopixel Jewel is in its right place, power up the Pi back on and install and connect the LED software through Putty. Use the following commands for this action: 

sudo apt-get install build-essential python-dev git
sudo apt-get install scons
sudo apt-get install swig
git clone https://github.com/jgarff/rpi_ws281x.git
cd rpi_ws281x
scons

In the next step, we’ll be making small changes to the Jewel library. Without these changes, the LEDs will stop updating after a few hours. Use the following codes to make those necessary changes: 

cd python
python setup.py build
sudo nano build/lib.linux-armv7l-2.7/neopixel.py

Scroll past the code “class Adafruit_NeoPixel(object):”. Near this code, you will find a blue text “def _cleanup(self).” Copy and paste the following code into this section: 

ws.ws2811_fini(self._leds)

Again save changes by ctrl-x, y, and enter. 

cd ~
cd rpi_ws281x/python
sudo python setup.py install

Next, enter the following code to tell the system how many LEDs you want to use:

cd examples
sudo nano strandtest.py

Find the code that says LED_COUNT = 16 and change it to LED_COUNT = 7. Again ctrl-x, y, and enter to save changes.

sudo python strandtest.py

If the above commands have worked, you should now see flashing lights. Press ctrl-c to make them stop. They won’t turn off but they will stop flashing. 

See the images below for better understanding.

Step 7: Interface the LEDs with the server 

In this step, you will interface the LEDs with the Minecraft server. The LEDs will represent the current players on the Minecraft server: 

Players = Ore 

0 = Redstone 

1-2 = Iron 

3-4 = Gold 

5-6 = Emerald 

7-8 = Diamond 

If the Oreblock turns Coal, it would indicate that the LEDs are off. And if the status check fails to find an internet connection, the LEDs will blink a yellow light. 

Install status from one of Mojang’s developers, Nathan Adams here to retrieve the player count from the Minecraft server.

sudo apt-get install python-pip
sudo pip install mcstatus

Now copy the above python scripts, ledoff.py and mcled.py, to the server using Filezilla. Drag and drop the two scripts into the right box as shown in the screenshot. 

Now test ledoff.py with the following code: 

sudo python ledoff.py

During this step, you may notice an error “Segmentation fault”. This is an issue with the Neopixel.py library and will not affect this project. 

Note: mcled.py will assume that you are using port 26565 from this project. If your port is different, you need to make changes in the code to match. Use the commands below:

sudo nano mcled.py

Find the text that says “3 Get server player count”, and write below it, you can see a green line that says “localhost” with the port number beside it. Change the port number here and save changes (ctrl-x, y, and then enter) 

Add a few more lines in crontab to run the mcled.py script constantly (every minute) to receive constant updates regarding the server status. 

crontab -e

Here you’ll see two lines of code that you added earlier. We are going to add two more lines: 

* 6-20 * * * sudo python mcled.py
0 21 * * * sudo python ledoff.py

The first line of code tells the Raspberry Pi to execute mcled.py between 6 to 8:59 P.M. The second line of code instructs the Pi to switch off LEDs at 9 P.M. You can change the timings based on your preferences. 

Now save the changes, and the jewel will come back to life. When the server is running but not really in use, the jewel will turn red. After you join the server, the LEDs will come back to life again indicating server use.

Step 8: Build the Ore case

You are almost done. We are just going to build an ore block as the final step for this project. This project uses the Lulzbot TAZ63D printer. If you don’t have a personal 3D printer check in your area for any schools or libraries that allow access to 3D printers. 

In addition, you can use an online 3D printing service that will print and mail you the design. If you don’t want to use the above options, you can build the case out of cardboard and some Legos! 

For this project, we will use a 3D printer. Here are some of the things you need to keep in mind when you set up to print the case: 

  • Do not make any scaling changes. This will ensure that the mounting holes are in line with the Raspberry Pi. 
  • Make sure that the open end is facing up. 
  • Turn on the support settings to make sure overhangs on the walls don’t get messed up. 

Once the printing is complete, attach the Pi to the base of the case with screws (2.5mm). 

Next, cut a white sheet of paper and fit it inside the case. Remove all the extra support material. The white paper will diffuse the lights making a glowing effect much more prominent. Now, finalize your project by adding the right angle MicroUSB adapter, connecting it to the power port in a way that the cable extends out at the back of the case and resides next to the ethernet port. 

Now reconnect the ethernet cords and power, bring the top in place, and enjoy your very own Raspberry Pi dedicated Minecraft server! See the images below for better understanding.

You can get your Raspberry Pi and Power Supply for this project or many others here.

We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and affiliated sites.

Source via Instructables.

One thought on “Build a Dedicated Raspberry Pi Minecraft server with LED Player Indicator

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: