Learn to Program with Minecraft by Craig Richardson
Author:Craig Richardson
Language: eng
Format: mobi, epub
Publisher: No Starch Press, Inc.
Published: 2016-08-28T04:00:00+00:00
block = 57
➋ mc.setBlock(destX, destY, destZ, block)
mc.postToChat("Block set")
while True:
pos = mc.player.getPos()
➌ distance = math.sqrt((pos.x - destX) ** 2 + (pos.z - destZ) ** 2)
➍ if distance > 100:
mc.postToChat("Freezing")
elif distance > 50:
mc.postToChat("Cold")
elif distance > 25:
mc.postToChat("Warm")
elif distance > 12:
mc.postToChat("Boiling")
elif distance > 6:
mc.postToChat("On fire!")
elif distance == 0:
➎ mc.postToChat("Found it")
Listing 7-2: The start of the Hot and Cold program
Before randomly placing a block, the program makes sure that the block won’t be placed underground. To do so, it uses the getHeight() function ➊, which finds the block that is the highest y-coordinate (that is, on the surface) for any position in the game. Then it places a diamond block at a random position ➋.
The code at ➌ calculates the distance to the diamond block. It uses the sqrt() function, which is in the math module—this is why import math is needed at the beginning of the program. The sqrt() function calculates the square root of a number.
NOTE
Listing 7-2 uses a formula called the Pythagorean theorem. The formula uses two sides of a triangle to calculate the length of the third. In this case, I use the distance from the player to the hidden block on the x-axis and the z-axis to calculate the distance to the hidden block in a straight line.
Download
Learn to Program with Minecraft by Craig Richardson.epub
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Coloring Books for Grown-Ups | Humor |
Movies | Performing Arts |
Pop Culture | Puzzles & Games |
Radio | Sheet Music & Scores |
Television | Trivia & Fun Facts |
The Infinite Retina by Robert Scoble Irena Cronin(5193)
Harry Potter and the Cursed Child: The Journey by Harry Potter Theatrical Productions(4289)
The Sports Rules Book by Human Kinetics(4041)
Molly's Game: From Hollywood's Elite to Wall Street's Billionaire Boys Club, My High-Stakes Adventure in the World of Underground Poker by Molly Bloom(3309)
A Knight of the Seven Kingdoms by George R R Martin(3001)
Quidditch Through the Ages by J.K. Rowling(2970)
How To by Randall Munroe(2889)
Quidditch Through the Ages by J K Rowling & Kennilworthy Whisp(2862)
Quidditch Through the Ages by Kennilworthy Whisp by J.K. Rowling(2734)
Flowers For Algernon by Daniel Keyes(2702)
Quidditch through the Ages by J. K. Rowling(2682)
Stacked Decks by The Rotenberg Collection(2660)
Quidditch Through The Ages by J. K. Rowling(2648)
776 Stupidest Things Ever Said by Ross Petras(2562)
What If?: Serious Scientific Answers to Absurd Hypothetical Questions by Randall Munroe(2524)
Ready Player One: A Novel by Ernest Cline(2519)
Beautiful Oblivion by Jamie McGuire(2442)
The Book of Questions: Revised and Updated by Gregory Stock Ph.d(2423)
Champions of Illusion by Susana Martinez-Conde & Stephen Macknik(2301)
