def action_place_item(): ''' Place different block on top of another, using item() to select items. Uses control.item(), which is only consistent when used from program start (i.e., separate_session=True) ''' mc = mc_create() # Place bottom block slow_look(down=300) control.item(2) # Cobblestone control.place(0.1) # Place top block slow_look(up=150) control.item(5) # Dirt control.place(0.1) # Verify blocks bottom_block = mc.getBlock(BOX_MIDDLE_TILE, 1, BOX_MIDDLE_TILE+1) top_block = mc.getBlock(BOX_MIDDLE_TILE, 2, BOX_MIDDLE_TILE+1) print("Bottom Block:", bottom_block) print("Top Block:", top_block) bottom_passed = block.Block(bottom_block) == block.COBBLESTONE top_passed = block.Block(top_block) == block.DIRT print("Bottom", "PASSED" if bottom_passed else "FAILED") print("Top", "PASSED" if top_passed else "FAILED") return bottom_passed and top_passed
def action_inventory(): ''' Test inventory by selecting and placing one block, and then repeating with a different block. ''' INVENTORY_WIDTH=13 INVENTORY_HEIGHT=8 DURATION=0.1 def inventory_move(move, times): for i in range(times): move(duration=DURATION) time.sleep(DURATION) mc = mc_create() # Select and place WOOD control.inventory() inventory_move(control.left, INVENTORY_WIDTH) inventory_move(control.forward, INVENTORY_HEIGHT) inventory_move(control.right, 3) inventory_move(control.backward, 1) control.enter() control.place(0.1) # Select and place SNOW_BLOCK control.inventory() inventory_move(control.left, INVENTORY_WIDTH) inventory_move(control.forward, INVENTORY_HEIGHT) inventory_move(control.right, 9) inventory_move(control.backward, 3) control.enter() control.place(0.1) block_1 = mc.getBlock(BOX_MIDDLE_TILE, 2, BOX_WIDTH) block_2 = mc.getBlock(BOX_MIDDLE_TILE, 2, BOX_WIDTH-1) print("Block 1:", block_1) print("Block 2:", block_2) passed_1 = block.Block(block_1) == block.WOOD passed_2 = block.Block(block_2) == block.SNOW_BLOCK print("Block 1", "PASSED" if passed_1 else "FAILED") print("Block 2", "PASSED" if passed_2 else "FAILED") return passed_1 and passed_2
def action_smash(): ''' Place block and smash it Uses control.item(), which is only consistent when used from program start (i.e., separate_session=True) ''' mc = mc_create() control.item(2) # Cobblestone control.place(0.1) block_before = mc.getBlock(BOX_MIDDLE_TILE, 2, BOX_WIDTH) control.smash(0.1) block_after = mc.getBlock(BOX_MIDDLE_TILE, 2, BOX_WIDTH) print("Block Before:", block_before) print("Block After:", block_after) before_passed = block.Block(block_before) == block.COBBLESTONE after_passed = block.Block(block_after) == block.AIR print("Before", "PASSED" if before_passed else "FAILED") print("After", "PASSED" if after_passed else "FAILED") return before_passed and after_passed
Sprite(arrow0deg).rotate(270), Sprite(arrow15deg).rotate(270), Sprite(arrow30deg).rotate(270), Sprite(arrow45deg).rotate(270), Sprite(arrow60deg).rotate(270), Sprite(arrow75deg).rotate(270), ] def vector_angle(start, end): return degrees(atan2(end.x - start.x, end.z - start.z)) compass = Button(24) fb = FrameBuffer() while block.Block(mc.getBlock(gold_pos)) == block.GOLD_BLOCK: if compass.presses(): heading = control.get_heading(mc) angle_to_gold = vector_angle(mc.player.getPos(), gold_pos) compass_angle = 90 + (angle_to_gold - heading) fb.erase() arrow_index = round(compass_angle / 15) % 24 fb.draw(arrows[arrow_index]) fb.show() for button, action in keymap.items(): if button.is_pressed(): action() else: action(release=True)
from rstem.mcpi import minecraft, control, block import time from random import randint control.show(hide_at_exit=True) mc = minecraft.Minecraft.create() ARENA_WIDTH = 3 GOLD_DEPTH = 0 gold_pos = mc.player.getTilePos() gold_pos.x += randint(-ARENA_WIDTH, ARENA_WIDTH) gold_pos.z += randint(-ARENA_WIDTH, ARENA_WIDTH) gold_pos.y = mc.getHeight(gold_pos.x, gold_pos.z) - GOLD_DEPTH mc.setBlock(gold_pos, block.GOLD_BLOCK) gold_exists = True while gold_exists: player_pos = mc.player.getTilePos() gold_exists = block.Block(mc.getBlock(gold_pos)) == block.GOLD_BLOCK time.sleep(0.01) mc.postToChat("You found the gold!") time.sleep(3)
"000000000000000000000", "000000000000000000000", "000000000000000000000", "000000000000000000000", "000000000000000000000", "000000000000000000000", "000000000000000000000", "000000000000000000000", ], ] block_types = [ block.AIR, # 0 block.GRASS, # 1 block.STONE, # 2 block.DIRT, # 3 block.Block(3, 1), # DIRT # 4 block.WOOD_PLANKS, # 5 block.Block(31, 1), # GRASS_TALL # 6 block.Block(139, 0), # 7 block.FLOWER_YELLOW, # 8 block.Block(17, 1), # WOOD # 9 block.Block(53, 2), # STAIRS_WOOD # A block.Block(175, 1), # B block.COBBLESTONE, # C block.Block(38, 3), # FLOWER_CYAN # D block.Block(53, 1), # STAIRS_WOOD # E block.Block(44, 8), # STONE_SLAB # F block.STONE_SLAB_DOUBLE, # G block.Block(38, 8), # FLOWER_CYAN # H block.FENCE, # I block.Block(175, 10), # J