Minecraft Modding For Kids For Dummies
Book image
Explore Book Buy On Amazon

After Iteration 1 you can move on to Iteration 2 and add in another player so that your Minecraft game becomes a multiplayer game. To add Player2, follow these simple steps:

  1. Start with main and look at the first function, SetupMulti­player. Add another variable named Player2, and put the Minecraft username of the second player there.

    Here’s an example where the two players are thoughtstem and thoughtstem2.

    image0.jpg

    It’s difficult to test the multiplayer version of your game without having a real-life second player to join you, so work with a friend who also has Minecraft and who can join your server when you’re ready to test.

    Back in main, the next function is arena. The arena function doesn’t need to know what players are playing, so you can skip to the next line.

    The third line in main is the event that calls the StartGame function when a block is broken.

  2. In the StartGame function, make sure both players are set to Survival mode. Also, because you don’t know which player broke the melon block, make sure both players are teleported to the center of the arena.

    This shows how to make those changes.

    image1.jpg
  3. Still in the StartGame function, rename the blocksDestroyed variable to become more specific to Player1, and then add another variable for blocks destroyed for Player2.

    image2.jpg
  4. Back in main, the next line is the event that is called whenever a player respawns.

    1. The SetupPlayer is called. To make SetupPlayer multiplayer-safe, add an else-if statement to the if statement that essentially does the same as Player1, but for Player2.

    2. Add a second message to let each player know how many blocks the other player has broken.

      Here are the changes to the SetupPlayer function.

      image3.jpg

    Be sure to use all the right variables for Player1 and Player2 or else when Player1 respawns, it will teleport Player2 back to the arena.

  5. Back in main, the next line is the event that is called when a player moves; the removeBlockAfterStep function is called. The image below shows the change to the if statement that takes place. If either Player1 or Player2 was the one who moved, call the removeBlock function.

    image4.jpg
  6. Change the removeBlock function also, to increment the correct blocksDestroyed counter and to announce the name of the 200-block destroyer.

    This is how to change this if statement.

    image5.jpg

    You’re done! Here are the final batches of code.

    image6.jpg

You can also check it out at mod.learntomod.com.

image7.jpg

About This Article

This article is from the book:

About the book authors:

Sarah Guthals, Ph.D. is the CTO of ThoughtSTEM and has dedicated her life to coding education.

Stephen Foster, Ph.D. is the CEO of ThoughtSTEM, a company that teaches computer science to kids across America.

Lindsey Handley, Ph.D. is the COO of ThoughtSTEM and has hundreds of hours of experience as a classroom instructor for Minecraft based science and computer science classes.

This article can be found in the category: