def main(): diamond = (0, 190, 250) gold = (250, 250, 0) redstone = (250, 0, 0) dy = 2 dx = 32 dz = 32 mc = Minecraft.create() my_id = mc.getPlayerEntityId("_Egor_S_") pos = mc.entity.getTilePos(my_id) a = pos - Vec3(dx, dy, dz) a.y = max(0, a.y) b = pos + Vec3(dx, dy, dz) b.y = min(256, b.y) img = Image.new("RGB", (b.x - a.x + 1, b.z - a.z + 1)) for bid, p in zip(mc.getBlocks(a, b), range_blocks(a, b)): ip = (p.x - a.x, p.z - a.z) if bid == DIAMOND_ORE.id: img.putpixel(ip, diamond) if bid == GOLD_ORE.id and img.getpixel(ip) not in [diamond]: img.putpixel(ip, gold) if bid == REDSTONE_ORE.id and img.getpixel(ip) not in [diamond, gold]: img.putpixel(ip, redstone) img.save("diamonds_map.png")
def main(): mc = Minecraft.create() bob_id = mc.getPlayerEntityId("_Egor_S_") pos = mc.entity.getTilePos(bob_id) corner_1 = pos + Vec3(0, -1, 0) corner_2 = pos + Vec3(15, -1, 15) ttt = TicTacToe(mc, (corner_1, corner_2)) ttt.build_field() ttt.done_step() # fake while True: cr = None for ev in mc.events.pollBlockHits(): cr = ttt.handle_click(ev.pos) if cr is not None: break if cr is False: mc.postToChat("Wrong move! Choose another cell.") elif cr is True: wr = ttt.check_winner() if wr is not None: mc.postToChat("{} is winner!".format(wr[0])) break else: ttt.done_step() time.sleep(0.5)
def _create_ground_floor_skeleton(self): builds = [] builds.append(SubBuilding(GroundFloor(Building.NORTH), Castle.WALLS_CORNER_POS['South East'])) self._add_section("Floor", builds) self._create_surrounding_walls("Ground floor enclosing walls", 0) # Side doors builds.append(Door(Door.HINGE_LEFT, Castle.WALLS_CORNER_POS['South East'] + Vec3(0,0,-15), block.DOOR_WOOD.withData(Door.EAST), description="East side door")) builds.append(Door(Door.HINGE_RIGHT, Castle.WALLS_CORNER_POS['South West'] + Vec3(0,0,-15), block.DOOR_WOOD.withData(Door.WEST), description="West side door")) # Front wall & door builds.append(Door(Door.HINGE_RIGHT, Castle.WALLS_CORNER_POS['South East'] + Vec3(-13,0,0), block.DOOR_WOOD.withData(Door.SOUTH), description="Front door")) builds.append(Door(Door.HINGE_LEFT, Castle.WALLS_CORNER_POS['South East'] + Vec3(-14,0,0), block.DOOR_WOOD.withData(Door.SOUTH), description="Front door")) self._add_section("Ground floor external doors", builds)
def _create_structure(self): super(GroundRoomBase, self)._create_structure() builds = [] builds.append( BuildingBlock(UpperRoomBase.WALLS_CORNER_POS['South East'], INTERIOR_WALLS, UpperRoomBase.WALLS_CORNER_POS['South West'] + Vec3(0, WALL_HEIGHT, 0), description="South wall")) builds.append( BuildingBlock(UpperRoomBase.WALLS_CORNER_POS['South West'], INTERIOR_WALLS, UpperRoomBase.WALLS_CORNER_POS['North West'] + Vec3(0, WALL_HEIGHT, 0), description="West wall")) builds.append( BuildingBlock(UpperRoomBase.WALLS_CORNER_POS['South East'], INTERIOR_WALLS, UpperRoomBase.WALLS_CORNER_POS['North East'] + Vec3(0, WALL_HEIGHT, 0), description="East wall")) # add exterior north wll last so corners are last written as exterior. builds.append( BuildingBlock(UpperRoomBase.WALLS_CORNER_POS['North East'], EXTERIOR_WALLS, UpperRoomBase.WALLS_CORNER_POS['North West'] + Vec3(0, WALL_HEIGHT, 0), description="North wall")) # add doors to south wall self._add_section("Upper room walls", builds) self._add_windows()
def _create_turret_access(self): builds = [] builds.append( BuildingBlock(self.column_se_corner + Vec3(self._get_x(0), 0, 0), block.STONE_BRICK, self.column_se_corner + Vec3(self._get_x(-1), 3, -1), description="turret access point")) builds.append( BuildingBlock(self.column_se_corner + Vec3(self._get_x(-1), 0, -1), block.AIR, self.column_se_corner + Vec3(self._get_x(-2), 2, -3), description="turret acces clearance")) hinge_type = Door.HINGE_LEFT door_orientation = Door.EAST if self.mirrored: hinge_type = Door.HINGE_RIGHT door_orientation = Door.WEST # Place door on east wall of access point, so doorways either side of gate face each other # this will probably be usefull if i have to leave assess between animal pens on east wall builds.append( Door(Door.hinge_type, self.column_se_corner + Vec3(self._get_x(0), 0, -1), block.DOOR_WOOD.withData(door_orientation), description="Turret access door")) self._add_section("Straight Turret access", builds)
def _create_structure(self): super(GroundRoomBase, self)._create_structure() # create walls builds = [] builds.append( BuildingBlock(GroundRoomBase.WALLS_CORNER_POS['South East'], EXTERIOR_WALLS, GroundRoomBase.WALLS_CORNER_POS['South West'] + Vec3(0, WALL_HEIGHT, 0), description="South wall")) builds.append( BuildingBlock(GroundRoomBase.WALLS_CORNER_POS['South West'], EXTERIOR_WALLS, GroundRoomBase.WALLS_CORNER_POS['North West'] + Vec3(0, WALL_HEIGHT, 0), description="West wall")) builds.append( BuildingBlock(GroundRoomBase.WALLS_CORNER_POS['North East'], EXTERIOR_WALLS, GroundRoomBase.WALLS_CORNER_POS['North West'] + Vec3(0, WALL_HEIGHT, 0), description="North wall")) builds.append( BuildingBlock(GroundRoomBase.WALLS_CORNER_POS['South East'], EXTERIOR_WALLS, GroundRoomBase.WALLS_CORNER_POS['North East'] + Vec3(0, WALL_HEIGHT, 0), description="East wall")) self._add_section("Base room walls", builds) self._add_windows()
def build_buildings(cls): # buildings (group of buildings) building_far = 40 # First the path from the town to the buildings p = cls.line_right.end_position p_z = p.z - (cls.house_length + 1) line_building = Line(Vec3(p.x - cls.line_width, p.y, p_z)) line_building.block = mcpi.block.SAND line_building.width = -building_far line_building.length = 2 line_building.build() # Now the buildings building_width = 10 p = line_building.end_position building1 = Building(Vec3(p.x, p.y, p.z - building_width / 2)) building1.width = building_width building1.house_mirror = True building1.build() p_z = p.z - 2 * building_width building2 = Building(Vec3(p.x, p.y, p_z)) building2.width = building_width building2.build()
def _create_structure(self): # sssggssggssssggssggsss 9 # wb T ffff T bw 8 # wb ffff bw 7 side walls lined with book shelves # wb c ffff c bw 6 c => chair # wb bw 5 # wT fccf Tw 4 fences posts 3 high around bed, wood slabs on top? # wt bb cw 3 t=> table, c=> chair # wtc bb cw 2 desk & chairs one side, sofa on the other? # wt T f f T w 1 # wwwwwwddwwwwwwddwwwwww 0 TODO: move doors # t t # 1098765432109876543210 # 2 1 super(Bedroom, self)._create_structure() self._create_walls_and_doors() self._create_windows() self._create_torches() builds = [] # bookshelves builds.append(BuildingBlock(Bedroom.WALLS_CORNER_POS['North East'] + Vec3(-1,0,1), block.BOOKSHELF, Bedroom.WALLS_CORNER_POS['North East'] + Vec3(-1,3,4), description="East bookshelves")) builds.append(BuildingBlock(Bedroom.WALLS_CORNER_POS['North West'] + Vec3(1,0,1), block.BOOKSHELF, Bedroom.WALLS_CORNER_POS['North West'] + Vec3(1,3,4), description="West bookshelves")) self._add_section("Bedroom bookshelves", builds) # TODO: fireplace, bed & chest, desk & chairs & sofa
def _create_singlepart_layer(self, orientation): WELL_CORE = (Vec3(-1,0,-2), Vec3(2,0,-5)) WELL_BASE = [] WELL_BASE.append(BuildingBlock(WELL_CORE[0], block.STONE, WELL_CORE[1])) sut = BuildingLayer(WELL_BASE, 0) sut = self._rotate_sut(sut, orientation) return sut
def __init__(self, *args, **kwargs): super(SmallHouseV2, self).__init__(*args, **kwargs) ####################################################################### # build the roof layer_blocks = [] # create the wall spans as wood for first layer of roof for pos1, pos2, desc in SmallHouseV2Base.WALL_SPANS: layer_blocks.append( BuildingBlock(pos1, block.WOOD, pos2, desc + " roof")) self.add_layer(BuildingLayer(layer_blocks, 4)) del layer_blocks[:] # create inner span as wood for second layer of roof layer_blocks.append( BuildingBlock(SmallHouseV2Base.WALLS_CORNER_POS['South East'] + Vec3(-1, 0, -1), block.WOOD, SmallHouseV2Base.WALLS_CORNER_POS['North West'] + Vec3(1, 0, 1), description="Roof inner")) self.add_layer(BuildingLayer(layer_blocks, 5)) del layer_blocks[:] self._set_orientation()
def build_jail(cls): # Create the Jail (Fenced town) jail_far = 50 fence_space = 5 # First the path from the town to the jail p = cls.line_left.position p_z = p.z + cls.house_length + 1 line_jail = Line(Vec3(p.x + cls.line_width, p.y, p_z)) line_jail.block = mcpi.block.SAND line_jail.width = +jail_far line_jail.length = 2 line_jail.build() # The jail town house_jail_width = 10 p = line_jail.end_position p_z = p.z - (2 * house_jail_width) p_x = p.x town_jail = Town(Vec3(p_x, p.y, p_z)) town_jail.space = 1 town_jail.house_width = house_jail_width town_jail.block = mcpi.block.STONE town_jail.build() fence_jail = Fence(None) fence_jail.thing = town_jail fence_jail.block = mcpi.block.BEDROCK fence_jail.fence_space = fence_space fence_jail.build()
def __init__(self, x, y, z): self.pos = Vec3(x, y, z) self.dir = Vec3(1, 0, 0) self.blockType = block.GOLD_ORE.id self.moveTime = getCurrentTime() self.timeUntilMove = 1000
def main(): target = DIAMOND_ORE.id dy = 4 dx = 16 dz = 16 mc = Minecraft.create() my_id = mc.getPlayerEntityId("_Egor_S_") pos = mc.entity.getTilePos(my_id) a = pos - Vec3(dx, dy, dz) a.y = max(0, a.y) b = pos + Vec3(dx, dy, dz) b.y = min(256, b.y) diamonds = [] for bid, p in zip(mc.getBlocks(a, b), range_blocks(a, b)): if bid == target: diamonds.append(p) print("Diamond ore at {}!".format(p)) mc.postToChat("Total diamonds: {}".format(len(diamonds))) if len(diamonds) > 0: closest = min(diamonds, key=lambda x: (pos - x).length()) mc.postToChat("The closest diamond ore: {}".format(closest)) else: mc.postToChat(":(")
def __init__(self, *args, **kwargs): super(Farm, self).__init__(width=Farm.WIDTH, *args, **kwargs) layer_blocks = [] layer_blocks.append(BuildingBlock(Farm.BOUNDARY_SPAN[0], block.WOOD, Farm.BOUNDARY_SPAN[1], description="Farm boundary")) layer_blocks.append(BuildingBlock(Farm.LAND_SPAN[0], block.FARMLAND, Farm.LAND_SPAN[1], description="Farm land")) layer_blocks.append(BuildingBlock(Farm.WATER_SPAN[0], block.WATER, Farm.WATER_SPAN[1], description="Farm irrigation")) self.add_layer(BuildingLayer(layer_blocks, 0)) del layer_blocks[:] # all wheat on one side , with random choice of ripeness layer_blocks.append(BuildingBlock(Farm.CROPS_LEFT_SPAN[0], Block(WHEAT.id, random.randint(3,7)), Farm.CROPS_LEFT_SPAN[1], description="Wheat crops")) layer_blocks.append(BuildingBlock(Farm.CROPS_RIGHT_SPAN[0], Block(POTATOES.id, random.randint(3,7)), Farm.CROPS_RIGHT_SPAN[1] + Vec3(1,0,0), description="Potatoes")) layer_blocks.append(BuildingBlock(Farm.CROPS_RIGHT_SPAN[0] + Vec3(-1,0,0,), Block(CARROTS.id, random.randint(3,7)), Farm.CROPS_RIGHT_SPAN[1], description="Carrots")) self.add_layer(BuildingLayer(layer_blocks, 1)) self._set_orientation()
def _create_structure(self): super(TurretTaper, self)._create_structure() builds = [] builds.append(BuildingBlock(Building.SE_CORNER_POS + Vec3(-2,WALL_HEIGHT+2,-4), EXTERIOR_WALLS, Building.SE_CORNER_POS + Vec3(-4,WALL_HEIGHT+2,-5))) builds.append(BuildingBlock(Building.SE_CORNER_POS + Vec3(-4,WALL_HEIGHT+2,-4), EXTERIOR_WALLS, Building.SE_CORNER_POS + Vec3(-5,WALL_HEIGHT+2,-2))) builds.append(BuildingBlock(Building.SE_CORNER_POS + Vec3(-1,WALL_HEIGHT+2,-4), EXTERIOR_WALLS)) builds.append(BuildingBlock(Building.SE_CORNER_POS + Vec3(-4,WALL_HEIGHT+2,-1), EXTERIOR_WALLS)) builds.append(BuildingBlock(Building.SE_CORNER_POS + Vec3(-2,WALL_HEIGHT+1,-4), EXTERIOR_WALLS, Building.SE_CORNER_POS + Vec3(-3,WALL_HEIGHT+1,-4))) builds.append(BuildingBlock(Building.SE_CORNER_POS + Vec3(-4,WALL_HEIGHT+1,-3), EXTERIOR_WALLS, Building.SE_CORNER_POS + Vec3(-4,WALL_HEIGHT+1,-2))) self._add_section("Turret base", builds)
def _create_upper_floor_and_main_staircase(self): builds = [] # after applying 2nd storey floor, add main stairs builds.append(SubBuilding(UpperFloor(Building.NORTH), Castle.WALLS_CORNER_POS['South East'] + Vec3(0,self.upper_floor_level,0))) builds.append(SubBuilding(MainStairs(Building.NORTH), Castle.WALLS_CORNER_POS['South East'] + Vec3(-11,0,-10))) self._add_section("Upper floor & staircase", builds)
def debug_crops(): global mc ps = mc.player.getTilePos() for z in range(-1, -10, -1): mc.setBlock(Vec3(ps.x, ps.y, ps.z + z), block.FARMLAND.withData(-(z) - 1)) mc.setBlock(Vec3(ps.x, ps.y + 1, ps.z + z), Block(59, -(z) - 1))
def test_addition(self): a = Vec3(10, -3, 4) b = Vec3(-7, 1, 2) c = a + b totV = Vec3(3, -2, 6) assert c == totV assert c - a == b assert c - b == a
def _clear_wall_walkway(self): builds = [] builds.append( BuildingBlock(self.column_se_corner + Vec3(-7, WALL_HEIGHT, -2), block.AIR, self.column_se_corner + Vec3(0, WALL_HEIGHT + 2, -3), description="clear turret moat end- air bove water")) self._add_section("Straight Turret - clear wall walkway", builds)
def debug_farms(): global mc ps = mc.player.getTilePos() build = LargeFarm(Building.NORTH) build.build_to_right(mc, ps + Vec3(2, 0, -2)) build = Farm(Building.NORTH) build.build_to_left(mc, ps + Vec3(-2, 0, -2))
def _create_base(self): builds = [] builds.append( BuildingBlock(Building.SE_CORNER_POS + Vec3(0, self.base_level, 0), block.DIRT, Building.SE_CORNER_POS + Vec3(-7, self.base_level, -7), description="turret moat base")) self._add_section("Wall turret moat - base", builds)
def test_equality(self): v1 = Vec3(2, -3, 8) v_same = Vec3(2, -3, 8) v_diff = Vec3(22, 63, 88) v_x_larger = Vec3(5, -3, 8) v_x_smaller = Vec3(0, -3, 8) v_y_larger = Vec3(2, 9, 8) v_y_smaller = Vec3(2, -10, 8) v_z_larger = Vec3(2, -3, 12) v_z_smaller = Vec3(2, -3, 4) assert v1 == v_same assert not v1 == v_diff assert v1 != v_diff otherVectors = [ v_x_larger, v_y_larger, v_z_larger, v_x_smaller, v_y_smaller, v_z_smaller ] for other in otherVectors: assert v1 != other for other in otherVectors: assert not v1 == other
def on_heart_beat(self): pos = self.player.getTilePos() blocks = self.get_blocks(Vec3(pos.x-1, pos.y-2, pos.z-1), Vec3(pos.x+1, pos.y-1, pos.z+1)) for p, b in blocks: if b in REPLACE_BLOCKS: self.set_block(p, block.ICE.id)
def main(): coord_to_save = [] ## build explorer ships x = -130 y = 40 Zs = [200, 250] gap_x = 30 for i in range(0, 8): for z in Zs: v = Vec3(x, y, z) explorer_data = CoordinateUtils.shift_coordinates(DATA['explorer'], v) scanner.print_3d(explorer_data) coord_to_save.append(explorer_data) explorer_data['name'] = 'explorer' x += gap_x ## build comand ship 1 x = -140 y = 40 z = 50 v = Vec3(x, y, z) command_data = CoordinateUtils.shift_coordinates(DATA['command'], v) scanner.print_3d(command_data) command_data['name'] = 'command' coord_to_save.append(command_data) ## build comand ship 2 x = 60 y = 40 z = 50 v = Vec3(x, y, z) command_data = CoordinateUtils.shift_coordinates(DATA['command'], v) scanner.print_3d(command_data) command_data['name'] = 'command' coord_to_save.append(command_data) ## build mother x = -40 y = 40 z = 50 v = Vec3(x, y, z) mother_data = CoordinateUtils.shift_coordinates(DATA['mother'], v) scanner.print_3d(mother_data) mother_data['name'] = 'mother' coord_to_save.append(mother_data) CoordinateUtils.save_data_to_file(coord_to_save, SPACESHIP_FLEET)
def _create_wall_clearances(self): builds = [] builds.append(BuildingBlock(Building.SE_CORNER_POS + Vec3(self._get_x(-3),0,-1), block.AIR, Building.SE_CORNER_POS + Vec3(self._get_x(-3),WALL_HEIGHT,-2), description="turret wall clearance")) builds.append(BuildingBlock(Building.SE_CORNER_POS + Vec3(self._get_x(-1),0,-3), block.AIR, Building.SE_CORNER_POS + Vec3(self._get_x(-2),WALL_HEIGHT,-3), description="turret wall clearance")) self._add_section("Wall clearances for turret", builds)
def test_find_vertices(self): a = Vec3(10, 20, 30) b = Vec3(0, -10, 50) result = CoordinateUtils._find_vertices(a, b) self.assertEquals(result[0].x, 0) self.assertEquals(result[0].y, -10) self.assertEquals(result[0].z, 30) self.assertEquals(result[1].x, 10) self.assertEquals(result[1].y, 20) self.assertEquals(result[1].z, 50)
def test_distance_to(self): coords_one = [2, -3, 8] coords_two = [-4, 5, 12] v1 = Vec3(coords_one[0], coords_one[1], coords_one[2]) v2 = Vec3(coords_two[0], coords_two[1], coords_two[2]) expect_dist = ( ((coords_two[0] - coords_one[0]) ** 2) + ((coords_two[1] - coords_one[1]) ** 2) + ((coords_two[2] - coords_one[2]) ** 2) ) ** 0.5 dist = v1.distanceTo(v2) assert dist == expect_dist
def _create_supporting_columns(self): builds = [] builds.append(Wood(Castle.WALLS_CORNER_POS['South East'] + Vec3(-11,0,-7), block.WOOD.withData(Wood.SPRUCE + Wood.UP_DOWN), Castle.WALLS_CORNER_POS['South East'] + Vec3(-11,WALL_HEIGHT,-7), description="Ground floor east supporting column")) builds.append(Wood(Castle.WALLS_CORNER_POS['South East'] + Vec3(-16,0,-7), block.WOOD.withData(Wood.SPRUCE + Wood.UP_DOWN), Castle.WALLS_CORNER_POS['South East'] + Vec3(-16,WALL_HEIGHT,-7), description="Ground floor west supporting column")) self._add_section("Ground floor supporting columns", builds)
def _create_structure(self): super(Brewery, self)._create_structure() builds = [] builds.append( Door(Door.HINGE_RIGHT, UpperRoomBase.WALLS_CORNER_POS['South East'] + Vec3(-1, 0, 0), block.DOOR_WOOD.withData(Door.SOUTH), description="Brewery room door")) builds.append( Door(Door.HINGE_LEFT, UpperRoomBase.WALLS_CORNER_POS['South East'] + Vec3(-2, 0, 0), block.DOOR_WOOD.withData(Door.SOUTH), description="Brewery room door")) self._add_section("Brewery doors", builds)
def _create_moat(self): builds = [] builds.append( BuildingBlock( Building.SE_CORNER_POS + Vec3(0, self.base_level, -2), block.DIRT, Building.SE_CORNER_POS + Vec3(self.x2, self.base_level, -5), description="Wall moat base")) builds.append( BuildingBlock(Building.SE_CORNER_POS + Vec3(0, self.foundation_depth, -5), block.STONE_BRICK, Building.SE_CORNER_POS + Vec3(self.x2, -1, -5), description="moat outer wall")) builds.append( BuildingBlock(Building.SE_CORNER_POS + Vec3(0, self.foundation_depth, -2), block.WATER, Building.SE_CORNER_POS + Vec3(self.x2, -2, -4), description="moat water")) builds.append( BuildingBlock(Building.SE_CORNER_POS + Vec3(0, -1, -2), block.AIR, Building.SE_CORNER_POS + Vec3(self.x2, -1, -4), description="clear blocks over water")) self._add_section("Wall - moat", builds)