def main(): mc = Minecraft.create("192.168.1.10") x, y, z = mc.player.getPos() mc.postToChat(f"drawing! {x} {y} {z}") mc.setBlock(x+2, y, z, 1) for i in range(100): mc.setBlock(SPAWN[0], SPAWN[1]+i, SPAWN[2], 1) mcdraw = MinecraftDrawing(mc) # draw a diagonal line mcdraw.drawLine(SPAWN[0], SPAWN[1], SPAWN[2], SPAWN[0] - 10, SPAWN[1] + 10, SPAWN[2]+10, block.STONE.id) mcdraw.drawSphere(SPAWN[0]+5, SPAWN[1]+80, SPAWN[2]+20, 20, block.GOLD_BLOCK.id)
import mcpi.minecraft as minecraft import mcpi.block as block # Connect to minecraft server 127.0.0.1 as player 'steve' mc = minecraft.Minecraft.create(address="127.0.0.1", name="steve") mc.player.setPos(-25, 0, -25) #clear area mc.setBlocks(-25, 0, -25, 25, 25, 25, block.AIR.id) #create drawing object mcDrawing = MinecraftDrawing(mc) #line mcDrawing.drawLine(0, 0, -10, -10, 10, -5, block.STONE.id) #circle mcDrawing.drawCircle(-15, 15, -15, 10, block.WOOD.id) #sphere mcDrawing.drawSphere(-15, 15, -15, 5, block.OBSIDIAN.id) #face - solid triangle faceVertices = [] faceVertices.append(minecraft.Vec3(0, 0, 0)) faceVertices.append(minecraft.Vec3(5, 10, 0)) faceVertices.append(minecraft.Vec3(10, 0, 0)) mcDrawing.drawFace(faceVertices, True, block.SNOW_BLOCK.id) #face - wireframe square - using Points
import mcpi.minecraft as minecraft import mcpi.block as block #connect to minecraft mc = minecraft.Minecraft.create() #test MinecraftDrawing #clear area mc.setBlocks(-25, 0, -25, 25, 25, 25, block.AIR.id) #create drawing object mcDrawing = MinecraftDrawing(mc) #line mcDrawing.drawLine(0,0,-10,-10,10,-5,block.STONE.id) #circle mcDrawing.drawCircle(-15,15,-15,10,block.WOOD.id) #sphere mcDrawing.drawSphere(-15,15,-15,5,block.OBSIDIAN.id) #face - solid triangle faceVertices = [] faceVertices.append(minecraft.Vec3(0,0,0)) faceVertices.append(minecraft.Vec3(5,10,0)) faceVertices.append(minecraft.Vec3(10,0,0)) mcDrawing.drawFace(faceVertices, True, block.SNOW_BLOCK.id) #face - wireframe square - using Points
class SpikeyCircle(): """ Draws lines out from the centre, the lenght determines the value, the longer the line the greater the value """ ANGLEINCREMENT = 15 def __init__(self, mc, pos, maxRadius, minValue, maxValue, blocksToUse=None, angleIncrement=ANGLEINCREMENT): self.mc = mc self.pos = pos self.maxRadius = maxRadius self.minValue = minValue self.maxValue = maxValue #if no blocks to use have been passed, set them to the wool colours if blocksToUse == None: blocksToUse = [] for col in range(0, 15): blocksToUse.append(Block(block.WOOL.id, col)) self.blocksToUse = blocksToUse self.angleIncrement = angleIncrement self.currentBlock = 0 self.angle = 0 #create a dictionary of the lines for the angles in the circle # to keep track of the values so they can be cleared self.lines = {} #create the minecraft drawing object which will be used to draw the lines self.draw = MinecraftDrawing(mc) def addValue(self, value): """ Add a single value to the spikey circle ` """ if value > self.maxValue: value = self.maxValue if value < self.minValue: value = self.minValue #has a line already been drawn at this angle if self.angle in self.lines: #clear the line endX = self.lines[self.angle][0] endY = self.lines[self.angle][1] self.draw.drawLine(self.pos.x, self.pos.y, self.pos.z, endX, endY, self.pos.z, block.AIR.id) #calculate the length of the line lineLen = self._calcLength(value) #calculate the new end of the line endX, endY = self._findPointOnCircle(self.pos.x, self.pos.y, self.angle, lineLen) #draw the line self.draw.drawLine(self.pos.x, self.pos.y, self.pos.z, endX, endY, self.pos.z, self.blocksToUse[self.currentBlock].id, self.blocksToUse[self.currentBlock].data) #save the line to the dictionary, so next time we can clear it self.lines[self.angle] = [endX, endY] #increment the angle self._incrementAngle() #increment the block self._incrementBlock() def _incrementBlock(self): #increment the block self.currentBlock += 1 #if its the end, go back to the start if self.currentBlock + 1 > len(self.blocksToUse): self.currentBlock = 0 def _incrementAngle(self): #increment the angle self.angle += self.angleIncrement #if its over 360 go back to the start if self.angle >= 360: self.angle -= 360 def _calcLength(self, value): scale = self.maxValue - self.minValue flatValue = value - self.minValue return int(round((flatValue / scale) * self.maxRadius)) def _findPointOnCircle(self, cx, cy, angle, radius): x = cx + sin(radians(angle)) * radius y = cy + cos(radians(angle)) * radius x = int(round(x, 0)) y = int(round(y, 0)) return (x, y) def clear(self): """ Clears the spikey circle ` """ for angle in self.lines: endX = self.lines[angle][0] endY = self.lines[angle][1] self.draw.drawLine(self.pos.x, self.pos.y, self.pos.z, endX, endY, self.pos.z, block.AIR.id) #reset self.angle = 0 self.currentBlock = 0
class SpikeyCircle(): """ Draws lines out from the centre, the lenght determines the value, the longer the line the greater the value """ ANGLEINCREMENT = 15 def __init__( self, mc, pos, maxRadius, minValue, maxValue, blocksToUse = None, angleIncrement = ANGLEINCREMENT): self.mc = mc self.pos = pos self.maxRadius = maxRadius self.minValue = minValue self.maxValue = maxValue #if no blocks to use have been passed, set them to the wool colours if blocksToUse == None: blocksToUse = [] for col in range(0,15): blocksToUse.append(Block(block.WOOL.id, col)) self.blocksToUse = blocksToUse self.angleIncrement = angleIncrement self.currentBlock = 0 self.angle = 0 #create a dictionary of the lines for the angles in the circle # to keep track of the values so they can be cleared self.lines = {} #create the minecraft drawing object which will be used to draw the lines self.draw = MinecraftDrawing(mc) def addValue(self, value): """ Add a single value to the spikey circle ` """ if value > self.maxValue: value = self.maxValue if value < self.minValue: value = self.minValue #has a line already been drawn at this angle if self.angle in self.lines: #clear the line endX = self.lines[self.angle][0] endY = self.lines[self.angle][1] self.draw.drawLine( self.pos.x, self.pos.y, self.pos.z, endX, endY, self.pos.z, block.AIR.id) #calculate the length of the line lineLen = self._calcLength(value) #calculate the new end of the line endX, endY = self._findPointOnCircle( self.pos.x, self.pos.y, self.angle, lineLen) #draw the line self.draw.drawLine( self.pos.x, self.pos.y, self.pos.z, endX, endY, self.pos.z, self.blocksToUse[self.currentBlock].id, self.blocksToUse[self.currentBlock].data) #save the line to the dictionary, so next time we can clear it self.lines[self.angle] = [endX, endY] #increment the angle self._incrementAngle() #increment the block self._incrementBlock() def _incrementBlock(self): #increment the block self.currentBlock += 1 #if its the end, go back to the start if self.currentBlock + 1 > len(self.blocksToUse): self.currentBlock = 0 def _incrementAngle(self): #increment the angle self.angle += self.angleIncrement #if its over 360 go back to the start if self.angle >= 360: self.angle -= 360 def _calcLength(self, value): scale = self.maxValue - self.minValue flatValue = value - self.minValue return int(round((flatValue / scale) * self.maxRadius)) def _findPointOnCircle(self, cx, cy, angle, radius): x = cx + sin(radians(angle)) * radius y = cy + cos(radians(angle)) * radius x = int(round(x, 0)) y = int(round(y, 0)) return(x,y) def clear(self): """ Clears the spikey circle ` """ for angle in self.lines: endX = self.lines[angle][0] endY = self.lines[angle][1] self.draw.drawLine( self.pos.x, self.pos.y, self.pos.z, endX, endY, self.pos.z, block.AIR.id) #reset self.angle = 0 self.currentBlock = 0
from minecraftstuff import Vec3, MinecraftDrawing, ShapeBlock from mcpi.minecraft import Minecraft #connect to minecraft mc = Minecraft.create() #test MinecraftDrawing #clear area mc.setBlocks(-25, 0, -25, 25, 25, 25, "air") #create drawing object mcDrawing = MinecraftDrawing(mc) #line mcDrawing.drawLine(0,0,-10,-10,10,-5,"stone") #circle mcDrawing.drawCircle(-15,15,-15,10,"WOOD") #sphere mcDrawing.drawSphere(-15,15,-15,5,"OBSIDIAN") #face - solid triangle faceVertices = [] faceVertices.append(Vec3(0,0,0)) faceVertices.append(Vec3(5,10,0)) faceVertices.append(Vec3(10,0,0)) mcDrawing.drawFace(faceVertices, True, "snow_block") faceVertices = []
#hour hours = timeNow.hour if hours >= 12: hours = timeNow.hour - 12 minutes = timeNow.minute seconds = timeNow.second hourHandAngle = (360 / 12) * hours hourHandX, hourHandY = findPointOnCircle(clockMiddle.x, clockMiddle.y, HOUR_HAND_LENG, hourHandAngle) # HOUR mcdrawing.drawLine(clockMiddle.x, clockMiddle.y, clockMiddle.z, hourHandX, hourHandY, clockMiddle.z, block.DIRT.id) minHandAngle = (360 / 60) * minutes minHandX, minHandY = findPointOnCircle(clockMiddle.x, clockMiddle.y, MIN_HAND_LENG, minHandAngle) # MIN mcdrawing.drawLine(clockMiddle.x, clockMiddle.y, clockMiddle.z - 1, minHandX, minHandY, clockMiddle.z - 1, block.WOOD_PLANKS.id) secHandAngle = (360 / 60) * seconds secHandX, secHandY = findPointOnCircle(clockMiddle.x, clockMiddle.y, SEC_HAND_LENG, secHandAngle) # SEC
from mcpi.minecraft import Minecraft from mcpi import block from minecraftstuff import MinecraftDrawing #pip install minecraftstuff mc = Minecraft.create() mcdraw = MinecraftDrawing(mc) # draw a diagonal line mcdraw.drawLine(0, 0, 0, 10, 10, 10, block.STONE.id)