from mcpi.minecraft import Minecraft
mc = Minecraft.create()
import time
pos = mc.player.getTilePos()
x = pos.x + 1
y = pos.y
z = pos.z
# Add 10 glass blocks (ID 20) to this empty list
blocks = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20]
barBlock = 22 # Lapis lazuli
count = 0
while count <= len(blocks): # len (the number of items) of an object
mc.setBlock(x, y, z, blocks[0])
mc.setBlock(x, y + 1, z, blocks[1])
mc.setBlock(x, y + 2, z, blocks[2])
mc.setBlock(x, y + 3, z, blocks[3])
mc.setBlock(x, y + 4, z, blocks[4])
mc.setBlock(x, y + 5, z, blocks[5])
mc.setBlock(x, y + 6, z, blocks[6])
mc.setBlock(x, y + 7, z, blocks[7])
mc.setBlock(x, y + 8, z, blocks[8])
mc.setBlock(x, y + 9, z, blocks[9])
count += 1
# Delete the last block in the list
del blocks[9]
# Insert a lapis lazuli block at the first position in the list
blocks.insert(0, barBlock)
time.sleep(.5)
This code stacks ten glass cubes (picture 1 below), and then the cubes fill up with blue (barBlock) to give the look of a progress bar (picture 2 below). The progress bar only counts upward and stops when it's full. This code works beautifully. What I'm trying to do now is write code that says 'Once the progress bar fills up, make the progress bar count down in the opposite direction.' Please help me.
This code is all about manipulating lists. I've tried adding an item using block.append(barBlock)
. I've tried inserting an item using block.insert(9, barBlock)
. I've tried deleting an item using del block[9]
. I've tried changing a list item using block[9] = barBlock
. Let me be clear. The code I have thus far is correct. I know this because I'm reading a book, and they give comments that are meant as hints and I've done that efficiently. Now, they add this bonus objective of counting back down on the progress bar in the opposite direction. So, the solution is to add a little bit more code and this is where YOU come in. Please help me. Thank you in advance.