Esempio n. 1
0
def test_world_nametags():
    with mock.patch('picraft.world.Connection') as c:
        w = World()
        with pytest.raises(AttributeError):
            w.nametags_visible
        c().server_version = 'minecraft-pi'
        w.nametags_visible = False
        c().send.assert_called_once_with('world.setting(nametags_visible,0)')
        c().server_version = 'raspberry-juice'
        with pytest.raises(NotSupported):
            w.nametags_visible = False
Esempio n. 2
0
def test_world_immutable():
    with mock.patch('picraft.world.Connection') as c:
        w = World()
        with pytest.raises(NotImplementedError):
            w.immutable
        c().server_version = 'minecraft-pi'
        w.immutable = False
        c().send.assert_called_once_with('world.setting(world_immutable,0)')
        c().server_version = 'raspberry-juice'
        with pytest.raises(NotSupported):
            w.immutable = False
Esempio n. 3
0
       low_corner.x + 25 > block.x and
       low_corner.z < block.z and
       low_corner.z + 25 > block.z)
   return myfilter




rink_height = 17

config = ConfigParser.ConfigParser()

config.read('config.properties')
hostname = config.get('PiCraft','hostname');

w = World(host=hostname)

#allow time to go back to the game
sleep(3)

origin = Vector(45,7,-9);

## Build stares

base_of_stairs = [origin, origin + 3*X]

for y in range(0, 10):
    left_stair = base_of_stairs[0] + y*Z + y*Y
    right_stair = base_of_stairs[1] + y*Z + y*Y
    stairs = list(line(left_stair, right_stair))
    w.blocks[stairs] = Block("planks")
Esempio n. 4
0
from __future__ import division

import math
from picraft import World, Vector, O, X, Y, Z, lines

def polygon(sides, center=O, radius=5):
    angle = 2 * math.pi / sides
    for side in range(sides):
        yield Vector(
                center.x + radius * math.cos(side * angle),
                center.y + radius * math.sin(side * angle))

def shapes():
    for sides in range(3, 9):
        yield lines(polygon(sides, center=3*Y))

w = World()
for shape in shapes():
    # Draw the shape
    with w.connection.batch_start():
        for p in shape:
            w.blocks[p] = Block('stone')
    sleep(0.5)
    # Wipe the shape
    with w.connection.batch_start():
        for p in shape:
            w.blocks[p] = Block('air')
Esempio n. 5
0
def test_world_context():
    with mock.patch('picraft.world.Connection') as c:
        with World():
            pass
        c().close.assert_called_once_with()
Esempio n. 6
0
from __future__ import division

from time import sleep
from picraft import World, Vector, X, Y, Z, vector_range, Block


def animation_frames(count):
    cube_range = vector_range(Vector() - 2, Vector() + 2 + 1)
    for frame in range(count):
        state = {}
        for v in cube_range:
            state[v.rotate(15 * frame, about=X).round() + (5 * Y)] = Block('stone')
        yield state


world = World()
world.checkpoint.save()
try:
    for frame in animation_frames(10):
        # Draw frame
        with world.connection.batch_start():
            for v, b in frame.items():
                world.blocks[v] = b
        sleep(0.2)
        # Wipe frame
        with world.connection.batch_start():
            for v, b in frame.items():
                world.blocks[v] = Block('air')
finally:
    world.checkpoint.restore()
Esempio n. 7
0
from picraft import World, Block, Vector, X, Y, Z, vector_range, line

world = World()
world.checkpoint.save()
world.events.track_players = world.players

p = world.player.tile_pos
GAME_AREA = vector_range(p - Vector(30, 2, 25), p + Vector(25, 20, 25) + 1)
DRAWING_AREA = vector_range(p - Vector(25, 1, 25), p + Vector(25, -1, 25) + 1)
WALKING_AREA = vector_range(DRAWING_AREA.start + Y, DRAWING_AREA.stop + Y)
CLEAR_BUTTON = p - Vector(30, 0, -23)
QUIT_BUTTON = p - Vector(30, 0, -25)

with world.connection.batch_start():
    world.blocks[GAME_AREA[:Vector(None, 2, None)]] = Block('dirt')
    world.blocks[GAME_AREA[Vector(None, 2, None):]] = Block('air')
    world.blocks[DRAWING_AREA] = Block('sand')
    world.blocks[QUIT_BUTTON] = Block('#ff0000')
    world.blocks[CLEAR_BUTTON] = Block('#ffff00')

def track_changes(old_state, new_state, default=Block('sand')):
    changes = {v: b for v, b in new_state.items() if old_state.get(v) != b}
    changes.update({v: default for v in old_state if v not in new_state})
    return changes

def draw_lines(old_state, lines):
    new_state = {
        v: Block('brick_block')
        for line_start, line_finish in lines
        for v in line(line_start, line_finish)
        }
Esempio n. 8
0
from picraft import World, Vector
import time

w = World()
mc.postToChat("xyz " + w.player.pos)
#Load the picraft API
from picraft import World, Block, Vector
world = World()

#Say hello
world.say("Hello, World!")
Esempio n. 10
0
#Load the picraft API
from picraft import World, Block, Vector

#Connect API to the world
world = World()

############ Write your program below #############
Esempio n. 11
0
from __future__ import unicode_literals

import time
from picraft import World, Vector, Block
from collections import deque

world = World(ignore_errors=True)
world.say("Auto-bridge active")
try:
    bridge = deque()
    last_pos = None
    while True:
        this_pos = world.player.pos
        if last_pos is not None:
            # Has the player moved more than 0.1 units in a horizontal direction?
            movement = (this_pos - last_pos).replace(y=0.0)
            if movement.magnitude > 0.1:
                # Find the next tile they're going to step on
                next_pos = (this_pos + movement.unit).floor() - Vector(y=1)
                if world.blocks[next_pos] == Block("air"):
                    with world.connection.batch_start():
                        bridge.append(next_pos)
                        world.blocks[next_pos] = Block("diamond_block")
                        while len(bridge) > 10:
                            world.blocks[bridge.popleft()] = Block("air")
        last_pos = this_pos
        time.sleep(0.01)
except KeyboardInterrupt:
    world.say("Auto-bridge deactivated")
    with world.connection.batch_start():
        while bridge:
Esempio n. 12
0
#Load the picraft API
from picraft import World, Block, Vector

#Connect API to the world
world = World()

############ Write your program below #############

world.say("Hello, World!")
Esempio n. 13
0
#Load the picraft API
from picraft import World, Block, Vector

#Connect API to the world
world = World()

############ Write your program below #############

#Get the player position
position = world.player.tile_pos

#lower the position below the player
position -= Vector(y=1)

#place a block there
world.blocks[position] = Block('gold_block')

Esempio n. 14
0
        yield {
            v.rotate(15 * frame, about=X).round() + (5 * Y): Block('stone')
            for v in cube_range
        }


def track_changes(states, default=Block('air')):
    old_state = None
    for state in states:
        # Assume the initial state of the blocks is the default ('air')
        if old_state is None:
            old_state = {v: default for v in state}
        # Build a dict of those blocks which changed from old_state to state
        changes = {v: b for v, b in state.items() if old_state.get(v) != b}
        # Blank out blocks which were in old_state but aren't in state
        changes.update({v: default for v in old_state if v not in state})
        yield changes
        old_state = state


world = World()
world.checkpoint.save()
try:
    for state in track_changes(animation_frames(20)):
        with world.connection.batch_start():
            for v, b in state.items():
                world.blocks[v] = b
        sleep(0.2)
finally:
    world.checkpoint.restore()
Esempio n. 15
0
#Change block
#change the block the player is standing on

#API setup
from picraft import Vector
from picraft import World, Block
world = World()

#-------Your Code-------#

#get block below player
position = world.player.tile_pos
position -= Vector(y=1) 

#set the block
world.blocks[position] = Block(1, 0)
Esempio n. 16
0
def main():
	#API setup
	world = World()

	while True:
Esempio n. 17
0
sleep(3)

def polygon(sides, center=O, radius=5):
    angle = 2 * math.pi / sides
    for side in range(sides):
        yield Vector(
                center.x + radius * math.cos(side * angle),
                center.y + radius * math.sin(side * angle),
                center.z).round()

def shapes(center=O):
    for sides in range(3, 7):
        yield lines(polygon(sides, center=center))


w = World(host=hostname)

for shape in shapes(w.player.tile_pos + 15*Y + 10*Z):
    # Copy the generator into a list so we can re-use
    # the coordinates
    shape = list(shape)

    # Draw the shape
    with w.connection.batch_start():
        for p in shape:
            w.blocks[p] = Block('gold_block')

    sleep(3)
    # Wipe the shape
    with w.connection.batch_start():
        for p in shape:
Esempio n. 18
0
from random import randint
from picraft import World, X, Y, Z, Vector, Block

world = World()

p = world.player.tile_pos
white_pos = p - 2 * X
black_pos = p - 3 * X

world.blocks[white_pos] = Block('#ffffff')
world.blocks[black_pos] = Block('#000000')

@world.events.on_block_hit(pos=black_pos)
def stop_script(event):
    world.connection.close()

@world.events.on_block_hit(pos=white_pos)
def make_it_rain(event):
    rain = Vector(p.x + randint(-10, 10), p.y + 20, p.z + randint(-10, 10))
    rain_end = world.height[rain]
    world.blocks[rain] = Block('wool', randint(1, 15))
    while rain != rain_end:
        with world.connection.batch_start():
            world.blocks[rain] = Block('air')
            rain -= Y
            world.blocks[rain] = Block('wool', randint(1, 15))

world.events.main_loop()

Esempio n. 19
0
from picraft import World, Model, Block

m = Model('shuttle.obj').render(materials=lambda face: Block('stone'))

with World() as w:
    with w.connection.batch_start():
        for v, b in m.items():
            w.blocks[v + 20 * Y] = b
Esempio n. 20
0
from random import randint
from picraft import World, X, Y, Z, Vector, Block

world = World()

p = world.player.tile_pos
white_pos = p - 2 * X
black_pos = p - 3 * X

world.blocks[white_pos] = Block('#ffffff')
world.blocks[black_pos] = Block('#000000')


@world.events.on_block_hit(pos=black_pos)
def stop_script(event):
    world.connection.close()


@world.events.on_block_hit(pos=white_pos)
def make_it_rain(event):
    rain = Vector(p.x + randint(-10, 10), p.y + 20, p.z + randint(-10, 10))
    rain_end = world.height[rain]
    world.blocks[rain] = Block('wool', randint(1, 15))
    while rain != rain_end:
        with world.connection.batch_start():
            world.blocks[rain] = Block('air')
            rain -= Y
            world.blocks[rain] = Block('wool', randint(1, 15))


world.events.main_loop()
Esempio n. 21
0
from picraft import World, Vector, Block, O, X, Y, Z, line, lines, filled
from time import sleep, time
from random import randint,choice
import ConfigParser

config = ConfigParser.ConfigParser()

config.read('config.properties')
hostname = config.get('PiCraft','hostname');

w = World(host=hostname)


count = 0
for i in reversed(range(0,30)):
    origin = Vector(67,-2,128) + count*Y + count*X + count*Z;
    print("o: %s" % str(origin))
    side = (2*i)
    print("side: %s" % side)

    corner1 = origin + side*X
    corner2 = origin + side*X + side*Z
    corner3 = origin + side*Z
    corners = [origin, corner1, corner2, corner3]

    count = count + 1

    row = lines(corners)

    if(True):
        w.blocks[row] = Block("sandstone")
Esempio n. 22
0
from time import sleep
from picraft import World

world = World()

while True:
    for event in world.events.poll():
        world.say('Player %d hit face %s of block at %d,%d,%d' % (
            event.player.player_id, event.face,
            event.pos.x, event.pos.y, event.pos.z))
    sleep(0.1)

Esempio n. 23
0
import time

from picraft import World, Vector, Block

world = World()

world.say("connected")

def stairs_to_heaven():
    pos = world.player.tile_pos
    #print(world.player.direction)
    if world.blocks[pos + Vector(x=1)].id == 0:
        world.blocks[pos + Vector(x=1)] = Block('stone')
while True:
    time.sleep(0.05)
    stairs_to_heaven()
Esempio n. 24
0
#Load the picraft API
from picraft import World, Block, Vector

#Connect API to the world
world = World()

############ Write your program below #############

while True:
    #Get the player position
    position = world.player.tile_pos

    #lower the position below the player
    position -= Vector(y=1)

    #make sure the player is touching something
    if world.blocks[position] != Block('air'):
        #place a block there
        world.blocks[position] = Block('gold_block')

Esempio n. 25
0
from __future__ import unicode_literals

import time
from picraft import World, Vector, Block, Y

world = World()
last_pos = None
while True:
    this_pos = world.player.pos
    if last_pos is not None:
        # Has the player moved more than 0.1 units in a horizontal direction?
        movement = (this_pos - last_pos).replace(y=0.0)
        if movement.magnitude > 0.1:
            # Find the next tile they're going to step on
            next_pos = (this_pos + movement.unit).floor() - Y
            world.blocks[next_pos] = Block('diamond_block')
    last_pos = this_pos
    time.sleep(0.01)

Esempio n. 26
0
# Load the picraft API
from picraft import World, Block, Vector

# Connect API to the world
world = World()

############ Write your program below #############

while True:
    # get recent sword hits
    hits = world.events.poll()

    # for each recent hit
    for hit in hits:
        # place some TNT at the hit location
        currentpos = hit.pos
        world.blocks[currentpos] = Block(46, 1)
        # place additional blocks
        world.blocks[currentpos + Vector(x=1)] = Block(46, 1)
        world.blocks[currentpos - Vector(x=1)] = Block(46, 1)
        world.blocks[currentpos + Vector(y=1)] = Block(46, 1)
        world.blocks[currentpos - Vector(y=1)] = Block(46, 1)
        world.blocks[currentpos + Vector(z=1)] = Block(46, 1)
        world.blocks[currentpos - Vector(z=1)] = Block(46, 1)
Esempio n. 27
0
    for frame in range(count):
        yield {
            v.rotate(15 * frame, about=X).round() + (5 * Y): Block('stone')
            for v in cube_range}


def track_changes(states, default=Block('air')):
    old_state = None
    for state in states:
        # Assume the initial state of the blocks is the default ('air')
        if old_state is None:
            old_state = {v: default for v in state}
        # Build a dict of those blocks which changed from old_state to state
        changes = {v: b for v, b in state.items() if old_state.get(v) != b}
        # Blank out blocks which were in old_state but aren't in state
        changes.update({v: default for v in old_state if v not in state})
        yield changes
        old_state = state


world = World()
world.checkpoint.save()
try:
    for state in track_changes(animation_frames(20)):
        with world.connection.batch_start():
            for v, b in state.items():
                world.blocks[v] = b
        sleep(0.2)
finally:
    world.checkpoint.restore()
Esempio n. 28
0
#!/usr/bin/env python

from __future__ import unicode_literals

import time
from picraft import World, Vector, Block
from collections import deque

world = World(ignore_errors=True)
world.say('Auto-bridge active')
try:
    bridge = deque()
    last_pos = None
    while True:
        this_pos = world.player.pos
        if last_pos is not None:
            # Has the player moved more than 0.1 units in a horizontal direction?
            movement = (this_pos - last_pos).replace(y=0.0)
            if movement.magnitude > 0.1:
                # Find the next tile they're going to step on
                next_pos = (this_pos + movement.unit).floor() - Vector(y=1)
                if world.blocks[next_pos] == Block('air'):
                    with world.connection.batch_start():
                        bridge.append(next_pos)
                        world.blocks[next_pos] = Block('diamond_block')
                        while len(bridge) > 10:
                            world.blocks[bridge.popleft()] = Block('air')
        last_pos = this_pos
        time.sleep(0.01)
except KeyboardInterrupt:
    world.say('Auto-bridge deactivated')
Esempio n. 29
0
from random import randint
from picraft import World, X, Y, Z, Vector, Block

world = World()

p = world.player.tile_pos
white_pos = p - 2 * X
black_pos = p - 3 * X

world.blocks[white_pos] = Block('#ffffff')
world.blocks[black_pos] = Block('#000000')

running = True
while running:
    for event in world.events.poll():
        if event.pos == white_pos:
            rain = Vector(p.x + randint(-10, 10), p.y + 20, p.z + randint(-10, 10))
            rain_end = world.height[rain]
            world.blocks[rain] = Block('wool', randint(1, 15))
            while rain != rain_end:
                with world.connection.batch_start():
                    world.blocks[rain] = Block('air')
                    rain -= Y
                    world.blocks[rain] = Block('wool', randint(1, 15))
        elif event.pos == black_pos:
            running = False
Esempio n. 30
0
from picraft import World, Vector, Block, O, X, Y, Z, line, lines, filled
from time import sleep, time
from random import randint,choice


import ConfigParser


config = ConfigParser.ConfigParser()

config.read('config.properties')
hostname = config.get('PiCraft','hostname');

w = World(host=hostname)


#allow time to go back to the game
sleep(3)


def eyes(player_pos):
    height = player_pos + 9*Y
    left_eye = height + -3*Z
    right_eye = height + 3*Z


    for eye in (right_eye,left_eye):
        yield list(filled([
            eye,
            eye + -1*Y,
            eye + 1*Z,
Esempio n. 31
0
# Change block
# change the block the player is standing on

# API setup
from picraft import Vector
from picraft import World, Block

world = World()

# -------Your Code-------#

# get block below player
position = world.player.tile_pos
position -= Vector(y=1)

# set the block
world.blocks[position] = Block(1, 0)
Esempio n. 32
0
def test_world_init():
    with mock.patch('picraft.world.Connection') as c:
        World()
        c.assert_called_once_with('localhost', 4711, 1.0, True)