示例#1
0
def drow_portal(portalx, portaly, portalz):
    t = [
        Vec3(23 + portalx, 0 + portaly, 25 + portalz),
        Vec3(27 + portalx, 0 + portaly, 25 + portalz),
        Vec3(27 + portalx, 5 + portaly, 25 + portalz),
        Vec3(23 + portalx, 5 + portaly, 25 + portalz)
    ]
    mcDrawing.drawFace(t, False, block.OBSIDIAN)
 def check_carpet(self, hit_list):
     for hit in hit_list:
         if self.mc.getBlock(hit.pos) == block.WOOL.id and len(self.block_list) > 0:
             # print("Checking on the carpet")
             for carpet in self.block_list:
                 # print("Cleaning up Carpet")
                 self.mc.setBlocks(carpet - Vec3(1, 0, 1), carpet + Vec3(1, 0, 2), block.AIR)
             time.sleep(2)
             break
 def get_block_below(self, next_player_pos):
     block_below = Vec3(int(next_player_pos.x), int(next_player_pos.y), int(next_player_pos.z))
     if block_below.z < 0:
         block_below.z -= 1
     if block_below.x < 0:
         block_below.x -= 1
     block_below.y -= 1
     return block_below
示例#4
0
 def check_player(self, hit_list):
     for hit in hit_list:
         if matchVec3(hit.pos, Vec3(self.x, self.y + 1, self.z + 2)):
             block_data = mc.getBlockWithData(hit.pos)
             if block_data.id == 96 and block_data.data == 7:
                 mc.postToChat("stopping record player")
                 self.off()
                 break
             elif block_data.id == 96 and block_data.data == 3:
                 mc.postToChat("starting record player")
                 self.on()
                 break
         elif matchVec3(hit.pos, Vec3(self.x + 1, self.y, self.z + 2)):
             block_data = mc.getBlockWithData(hit.pos)
             if block_data.id == 47:
                 mc.postToChat("changing song")
                 self.next()
                 break
示例#5
0
    def circlePath(self, ox, oy, oz, r):
        """ returns a circle path for the circle specified """

        circlePath = {"coords": []}
        for i in range(0,361):
            ri = math.radians(i)
            x = ox + r * math.cos(ri) # oh very clever :-)
            z = oz + r * math.sin(ri)
            circlePath['coords'].append(Vec3(x,oy,z))
        return(circlePath)
示例#6
0
 def float_block(self, hit_block_pos, hit_block_data):
     """
     rotates between the hit block and the one above it, setting the one above to the same type as hit, the hit to air
     then assigning hit to that position, and next to one above that, looping 10 times
     :param hit_block_pos: The position of the hit block
     :param hit_block_data: The data of the hit block, used to set the air block above hit block to this
     :return:
     """
     # self.mc.postToChat("Block found floating now")
     for i in range(1, 10):
         next_block_pos = Vec3(hit_block_pos.x, hit_block_pos.y+1, hit_block_pos.z)
         # self.mc.postToChat("hit_block: {}\nnext_block: {}".format(hit_block_data.id, next_block_data.id))
         # Sets current block to Air
         self.mc.setBlock(hit_block_pos, 0)
         # Sets block above to the same type as the block that was hit
         self.mc.setBlock(next_block_pos, hit_block_data.id, 0)
         # sets the hit_block to the next_block position, and next block to one spot higher
         hit_block_pos = Vec3(next_block_pos.x, next_block_pos.y, next_block_pos.z)
         sleep(0.5)
 def __init__(self):
     """
     initilize the carpet
     """
     self.mc = Minecraft.create()
     self.mc.postToChat("Magic Carpet Activated")
     self.block_list = []
     self.last_player_pos = self.mc.player.getPos()
     self.player_pos = Vec3(0, 0, 0)
     self.running = True
     self.t1 = None
 def flying_carpet(self):
     """
     put a carpet under you
     :return:
     """
     while self.running:
         self.player_pos = self.mc.player.getPos()
         mov_x = self.last_player_pos.x - self.player_pos.x
         mov_z = self.last_player_pos.z - self.player_pos.z
         if mov_x < -0.2 or mov_x > 0.2 or mov_z < -0.2 or mov_z > 0.2:
             # DETECTED HORIZONTAL MOVEMENT
             next_player_pos = self.player_pos
             while self.match():
                 next_player_pos = Vec3(next_player_pos.x - mov_x,
                                        next_player_pos.y, next_player_pos.z - mov_z)
                 block_below = self.get_block_below(next_player_pos)
                 if self.mc.getBlock(block_below) == block.AIR.id:
                     self.mc.setBlocks(block_below - Vec3(1, 0, 1), block_below + Vec3(1, 0, 2), 35, 10)
                     self.block_list.append(block_below)
                     if len(self.block_list) > 2:
                         block_cleanup = self.block_list.pop(0)
                         self.mc.setBlocks(block_cleanup - Vec3(1, 0, 1), block_cleanup + Vec3(1, 0, 2), block.AIR)
             self.last_player_pos = self.player_pos
         time.sleep(0.2)
示例#9
0
    def _fire(self, x1, y1, z1, x2, y2, z2, speed):

        startPos = Vec3(x1, y1, z1)
        projectileShape = MinecraftShape(self.mc, startPos,
                                         self.projectileBlocks)

        mcDraw = MinecraftDrawing(self.mc)
        blocksBetween = mcDraw.getLine(x1, y1, z1, x2, y2, z2)

        for blockBetween in blocksBetween:
            projectileShape.move(blockBetween.x, blockBetween.y,
                                 blockBetween.z)
            # time to sleep between each block move
            sleep(speed)

        projectileShape.clear()
示例#10
0
 def check_air_sword(self, hit_list):
     """
     Checks the hit_list to see if it matches a block that is not air, and has nothing above it. If so will
     spin up a new thread to start that block floating up in the float_block function
     :param hit_list: a mcpi list of block hit data
     """
     if self.enable:
         for hit in hit_list:
             hit_block_data = self.mc.getBlockWithData(hit.pos)
             hit_block_pos = hit.pos
             next_block_pos = Vec3(hit.pos.x, hit.pos.y + 1, hit.pos.z)
             next_block_data = self.mc.getBlockWithData(next_block_pos)
             if hit_block_data.id != 0 and next_block_data.id == 0:
                 # self.mc.postToChat("Block found floating now")
                 t1 = Thread(target=self.float_block,
                             args=(hit_block_pos, hit_block_data))
                 t1.setDaemon(True)
                 t1.start()
                 break
示例#11
0
    def _draw(self):

        pos = self.pos
        mc = self.mc
        width = self.width
        height = self.height
        length = self.length

        #create trench
        mc.setBlocks(pos.x, pos.y, pos.z, pos.x + width, pos.y + height,
                     pos.z + length, block.WOOL.id, 15)

        mc.setBlocks(pos.x + 1, pos.y + 1, pos.z + 1, pos.x + width - 1,
                     pos.y + height, pos.z + length - 1, block.AIR.id)

        #find the exhaust port position
        self.exhaustPortPos = Vec3(pos.x + (width / 2), pos.y + (height / 2),
                                   pos.z + 1)

        #draw exhaust post
        mcDraw = mcstuff.MinecraftDrawing(self.mc)
        mcDraw.drawCircle(self.exhaustPortPos.x, self.exhaustPortPos.y,
                          self.exhaustPortPos.z, 2, block.IRON_BLOCK.id)
示例#12
0
        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


#test
if __name__ == "__main__":

    mc = Minecraft.create()
    pos = Vec3(0, 100, 0)
    mc.player.setTilePos(5, 100, 5)
    circle = SpikeyCircle(mc, pos, 20, 0, 30)
    try:
        sleep(1)
        for count in range(10, 30):
            print(count)
            circle.addValue(count)
            sleep(0.5)
        for count in range(10, 0, -1):
            circle.addValue(count)
            sleep(0.5)
    finally:
        circle.clear()

if __name__ == "__main__displaytube":
示例#13
0
def subtractPos(pos1, pos2):
    pos = Vec3(pos1.x - pos2.x,
               pos1.y - pos2.y,
               pos1.z - pos2.z)
    return pos
示例#14
0
class MCInteractiveAstroPi:
    """
    An interactive AstroPi in minecraft. Pass block positions to the .interact
    method and it will tell you whats there or make it work.
    """
    #the position of the top left of the LED grid
    LED_GRID_POS = Vec3(4, 1, -8)

    #WOOL colours to led colours
    LED_WOOL_COL = {
        0: [255, 255, 255],
        1: [255, 128, 0],
        2: [204, 0, 204],
        3: [102, 178, 255],
        4: [255, 255, 0],
        5: [0, 255, 0],
        6: [255, 204, 204],
        7: [96, 96, 96],
        8: [192, 192, 192],
        9: [0, 204, 204],
        10: [76, 0, 153],
        11: [0, 0, 255],
        12: [102, 51, 0],
        13: [0, 153, 0],
        14: [255, 0, 0],
        15: [0, 0, 0]
    }

    def __init__(self, mc, ap, pos):
        #store variables
        self.pos = pos
        self.mc = mc
        self.ap = ap

        #set the joystick to move the astro pi horizontally
        self.joy_horizontal = True

        #create the minecraft astro pi shape
        self.mcastropi = MCAstroPi(self.mc, self.pos)

        self.mc.postToChat("SpaceCRAFT - interactive Astro Pi")
        self.mc.postToChat(
            "Hit (right click) the Astro Pi with a sword to see what it does")

    def interact(self, pos):
        """
        If you pass a block position, the interactive astro pi will
        see if that block is an interactive one and take the neccessary action
        """
        #see if this block is an interactive one
        #get this blocks relative position
        shapeBlock = self.mcastropi.getShapeBlock(pos.x, pos.y, pos.z)
        if shapeBlock != None:
            #led grid
            if shapeBlock.tag == "led":
                #work out what colour to go to next
                nextWoolColour = shapeBlock.blockData + 1
                if nextWoolColour == 16: nextWoolColour = 0
                ledColour = self.LED_WOOL_COL[nextWoolColour]

                #find out where the led is
                ledX, ledY = self._turnLEDPosIntoXY(shapeBlock.originalPos)
                ap.set_pixel(ledX, ledY, ledColour)

                #change the colour of the block
                # this is the 'right' way to do it but its slow because it works out
                # all the potential changes before only changing 1 block
                #self.mcastropi.setBlock(shapeBlock.originalPos.x,
                #                        shapeBlock.originalPos.y,
                #                        shapeBlock.originalPos.z,
                #                        shapeBlock.blockType,
                #                        nextWoolColour,
                #                        shapeBlock.tag)

                shapeBlock.blockData = nextWoolColour
                mc.setBlock(pos.x, pos.y, pos.z, block.WOOL.id, nextWoolColour)

            elif shapeBlock.tag == "rpi_board":
                mc.postToChat("This is the Raspberry Pi computer")

            elif shapeBlock.tag == "astropi_board":
                mc.postToChat("This is the Astro Pi SENSE HAT, it can read")
                mc.postToChat(" lots of information about the world")

            elif shapeBlock.tag == "rpi_gpio":
                mc.postToChat("The Raspberry Pi's GPIO header, it talks to")
                mc.postToChat(" the Astro Pi through these pins")

            elif shapeBlock.tag == "astropi_gpio":
                mc.postToChat(
                    "The Astro Pi SENSE HAT GPIO header, it talks to")
                mc.postToChat(" the Rasberry Pi through these pins")

            elif shapeBlock.tag == "processor":
                mc.postToChat("This is the Raspberry Pi's CPU")

            elif shapeBlock.tag == "usb":
                mc.postToChat("USB ports where peripherals such as a keyboard")
                mc.postToChat(" and mouse can be connected.")

            elif shapeBlock.tag == "ethernet":
                mc.postToChat("An ethernet port which can be used to connect")
                mc.postToChat(" to the internet")

            elif shapeBlock.tag == "camera":
                mc.postToChat("A port where a camera can be connected to take")
                mc.postToChat(" pictures and video")

            elif shapeBlock.tag == "display":
                mc.postToChat("A port where a display can be connected")

            elif shapeBlock.tag == "power":
                mc.postToChat(
                    "Micro usb connector where you plug a power supply")
                mc.postToChat(" into the Raspberry Pi")

            elif shapeBlock.tag == "hdmi":
                mc.postToChat("HDMI port for connecting the Raspberry Pi to a")
                mc.postToChat(" TV or monitor")

            elif shapeBlock.tag == "composite":
                mc.postToChat(
                    "A composite video and audio connector, most used")
                mc.postToChat(" for plugging in headphones")

            elif shapeBlock.tag == "level_shifter":
                mc.postToChat(
                    "Astro Pi's Logic Level Shifter it allows electronics")
                mc.postToChat(" with different voltages to work together")

            elif shapeBlock.tag == "atmel":
                mc.postToChat(
                    "Astro Pi's Atmel Tiny micro controller which monitors")
                mc.postToChat(" the joystick and controls the led driver")

            elif shapeBlock.tag == "orientation":
                mc.postToChat(
                    "Astro Pi's Accelerometer, Magnetometer & Gyroscope")
                mc.postToChat(" which gets its orientation")
                orientation = self.ap.get_orientation()
                mc.postToChat(" yaw = {}, pitch = {}, roll = {}".format(
                    round(orientation["yaw"], 2),
                    round(orientation["pitch"], 2),
                    round(orientation["roll"], 2)))

            elif shapeBlock.tag == "humidity":
                mc.postToChat("Astro Pi's Humidity and Temperature Sensor")
                humidity = self.ap.get_humidity()
                temp = self.ap.get_temperature_from_humidity()
                mc.postToChat(" humidity = {}, temperature = {}".format(
                    round(humidity, 2), round(temp, 2)))

            elif shapeBlock.tag == "pressure":
                mc.postToChat("Astro Pi's Pressure and Temperature Sensor")
                pressure = self.ap.get_pressure()
                temp = self.ap.get_temperature_from_pressure()
                mc.postToChat(" pressure = {}, temperature = {}".format(
                    round(pressure, 2), round(temp, 2)))

            elif shapeBlock.tag == "eeprom":
                mc.postToChat(
                    "Astro Pi's ID EEPROM, this tells the Raspberry Pi what")
                mc.postToChat(" is attached")

            elif shapeBlock.tag == "led_driver":
                mc.postToChat(
                    "Astro Pi's LED driver which controls the LED matrix")

            elif shapeBlock.tag == "joy_up":
                self.joyUp()

            elif shapeBlock.tag == "joy_down":
                self.joyDown()

            elif shapeBlock.tag == "joy_left":
                self.joyLeft()

            elif shapeBlock.tag == "joy_right":
                self.joyRight()

            elif shapeBlock.tag == "joy_button":
                self.joyButton()

    def _turnLEDPosIntoXY(self, pos):
        """
        Internal. Turns a pos on the minecraft astro pi into a led x,y position
        on the real astro pi
        """
        y = (pos.x - self.LED_GRID_POS.x) * -1
        x = pos.z - self.LED_GRID_POS.z
        return x, y

    def joyButton(self):
        """
        Swaps the joy stick direction from horizontal to vertical or vice versa
        """
        if self.joy_horizontal:
            self.joy_horizontal = False
            mc.postToChat("Changed to vertical movement")
        else:
            self.joy_horizontal = True
            mc.postToChat("Changed to horizontal movement")

    def joyLeft(self):
        """
        Moves the astro Pi left or down
        """
        if self.joy_horizontal:
            self.mcastropi.moveBy(0, 0, -1)
        else:
            #move down
            self.mcastropi.moveBy(0, -1, 0)

    def joyRight(self):
        """
        Moves the astro Pi right or up
        """
        if self.joy_horizontal:
            self.mcastropi.moveBy(0, 0, 1)
        else:
            #move up
            self.mcastropi.moveBy(0, 1, 0)

    def joyUp(self):
        """
        Moves the astro Pi forward or up
        """
        if self.joy_horizontal:
            #move forward
            self.mcastropi.moveBy(1, 0, 0)
        else:
            self.mcastropi.moveBy(0, 1, 0)

    def joyDown(self):
        """
        Moves the astro Pi backward or down
        """
        if self.joy_horizontal:
            #move backward
            self.mcastropi.moveBy(-1, 0, 0)
        else:
            self.mcastropi.moveBy(0, -1, 0)

    def clear(self):
        """
        Clears the mc astro pi
        """
        self.ap.clear()
        self.mcastropi.clear()
示例#15
0
from deathstar import DeathStar
from starwarscraft import TieFighter, MilleniumFalcon, XWingFighter, XWingFighterDiagonal
from planet import Planet
from trench import Trench
from projectile import XWingMissile
from mcpi.minecraft import Minecraft
from mcpi.minecraft import Vec3
from mcpi import block
from time import sleep

#Main program

#create connection to minecraft
mc = Minecraft.create()

pos = Vec3(0, 30, 0)
mc.player.setTilePos(pos.x + 25, pos.y + 20, pos.z + 25)

#create Alderaan
alderaanPos = pos.clone()
alderaanPos.x += 50
alderaanPos.z += 50
alderaan = Planet(alderaanPos, 10, block.WOOL.id, 3)

#create DeathStar
sleep(15)
deathstarPos = pos.clone()
deathstar = DeathStar(deathstarPos, 15)
sleep(12)
mc.postToChat("Not Alderaan, we are peaceful, we have no weapons.")
示例#16
0
mc = Minecraft.create()

def render_tiles(pos_start, pos_end, tiles):
    
    x_tiles = list(range(pos_start.x, pos_end.x))
    z_tiles = list(range(pos_start.z, pos_end.z))
    y_tiles = list(range(pos_start.y, pos_end.y))
    
    for z in z_tiles:
        for x in x_tiles:
            for y in y_tiles:
                random_block = random.choice(tiles)
                mc.setBlock(x, y, z, random_block)
                

        
    
start = -128
end = 128

# Vec3() býr hlut með hnitum
world_start = Vec3(start, 0, start)
world_end = Vec3(end, 11, end)

roof_start = Vec3(start, 11, start)
roof_end = Vec3(start, 12, start)

clear_world(roof_start, roof_end, block.STONE)
render_tiles(world_start, world_end, [0, 0, 0, 4])
    
示例#17
0
def T():
    t = [Vec3(-10, -10, 0), Vec3(-10, 10, 0), Vec3(10, 0, 0)]
    mcDrawing.drawFace(t, False, block.DIAMOND_BLOCK)
示例#18
0
 def __init__(self):
     self.t = [Vec3(-10, -10, 0), Vec3(-10, 10, 0), Vec3(10, 0, 0)]
示例#19
0
        self._drawStairs(self.blockId, self.blockData)

    def clear(self):
        self._drawStairs(block.AIR.id)


#test
if __name__ == "__main__":

    mc = Minecraft.create()

    #isspos = Vec3(10, 70, 0)
    #mcastropipos = Vec3(0, 60, 0)
    #arrowpos = Vec3(0, 65, 0)
    #stairspos = Vec3(0,0,0)
    rocketpos = Vec3(10, 60, 0)

    #iss = ISS(mc, isspos)
    launchpad = LaunchPad(mc, rocketpos)
    #rocket= Rocket(mc, rocketpos)
    #mcastropi = MCAstroPi(mc, mcastropipos)
    #arrow = Arrow(mc, arrowpos)
    #stairs = Stairs(mc, stairspos, 5, 65, block.IRON_BLOCK.id)
    #stairs.draw()

    try:
        #sleep(1)
        #rocket.launch(75)
        #rocket.reset()
        sleep(5)
示例#20
0
def round_vec3(vec3):
    return Vec3(int(vec3.x), int(vec3.y), int(vec3.z))
示例#21
0
def render_tiles(pos, tile, width, length):

    width = int(width / 2)
    length = int(length / 2)
    x_tiles = list(range(pos.x - length, pos.x + length))
    z_tiles = list(range(pos.z - width, pos.z + width))
    y_tiles = list(range(pos.y - width, pos.y + width))
    #y = pos.y - 1

    for z in z_tiles:
        for x in x_tiles:
            for y in y_tiles:
                if not mc.getBlock(x, y, z) == 0:
                    mc.setBlock(x, y, z, tile)


while True:
    hits = mc.events.pollBlockHits()
    print(hits)
    if len(hits) > 0:

        x, y, z = hits[0].pos.x, hits[0].pos.y, hits[0].pos.z
        vec = Vec3(x, y, z)
        render_tiles(vec, 41, 10, 10)
        mc.events.clearAll()

        #print(mc.getBlockWithData(x, y, z))
        #mc.setBlock(x, y, z, 41)

    time.sleep(0.1)
示例#22
0
from mcpi.minecraft import Minecraft, Vec3
from mcpi import block

mc = Minecraft.create()


def clear_world(start, end, tile):

    # setBlocks() Byggir marga kubba í einu.
    mc.setBlocks(start.x, start.y, start.z, end.x, end.y, end.z, tile)


start = -127.7
end = 127.7

# Vec3() býr hlut með hnitum. Breyttu y til að hreinsa ákveðna lofthǽð.
block_start = Vec3(start, 0, start)
block_end = Vec3(end, 128, end)

# Sjá Minecraft API í kennsluefninu fyrir allar tegundir (eða block.py í /usr/lib/python3/dist-packages/mcpi)
clear_world(block_start, block_end, block.AIR)
示例#23
0
 def pos(self):
     return Vec3(self.x, self. y, self.z)