def constructSelection(self, blockList): map = self.map block_action = BlockAction() block_action.value = BUILD_BLOCK block_action.player_id = 32 set_color = SetColor() set_color.player_id = 32 set_color.value = 0x707070 for block in blockList: blockExists = block[0] x = block[1][0] y = block[1][1] z = block[1][2] block_action.x, block_action.y, block_action.z = x, y, z if (not (0 <= x <= 512 or 0 <= y <= 512 or 0 <= y <= 64)): continue color = block[2] if (blockExists): #IF THERE SHOULD BE A BLOCK if (map.get_point(x, y, z)[0]): #IF THERE IS A BLOCK map.remove_point(x, y, z) #if(not map.get_point(x,y,z)[0]): #IF THERE IS NO BLOCK block_action.value = BUILD_BLOCK self.broadcast_contained(block_action) set_color.value = color map.set_point(x, y, z, colorIntToTuple(color)) self.broadcast_contained(set_color) else: #IF THERE SHOULD BE NO BLOCK if (z >= 63): continue if (map.get_point(x, y, z)[0]): #THERE IS A BLOCK block_action.value = DESTROY_BLOCK self.broadcast_contained(block_action) map.remove_point(x, y, z)
def constructSelection(self, blockList): map = self.map block_action = BlockAction() block_action.value = BUILD_BLOCK block_action.player_id = 32 set_color = SetColor() set_color.player_id = 32 set_color.value = Color(hex=0x6F6F6F).getInt() for block in blockList: exists = block[0] pos = block[1] x, y, z = pos color = block[2] block_action.x, block_action.y, block_action.z = x, y, z if (exists): #Should be a block if (map.get_point(x, y, z)[0]): #if there is a block map.remove_point( x, y, z) #Clear the block for rebuilding with color block_action.value = BUILD_BLOCK set_color.value = color.getInt() map.set_point(x, y, z, color.getTuple()) #Set color in the map vxl self.broadcast_contained(set_color) #Set color self.broadcast_contained( block_action) #Broadcast the build else: if (z >= 63): continue elif (map.get_point(x, y, z)[0]): #THERE IS A BLOCK block_action.value = DESTROY_BLOCK self.broadcast_contained(block_action) map.remove_point(x, y, z) return True
def place_estrogen_block(self, x, y, z): block_action = BlockAction() block_action.player_id = 31 set_color = SetColor() set_color.value = 0xFF66FF set_color.player_id = block_action.player_id self.send_contained(set_color, save=True) self.map.set_point(x, y, z, (255, 102, 255)) block_action.value = BUILD_BLOCK set_color.value = 0xFF66FF block_action.x = x block_action.y = y block_action.z = z self.send_contained(block_action, save=True)
def place_estrogen_block(self, x, y, z): block_action = BlockAction() block_action.player_id = 31 set_color = SetColor() set_color.value = 0xFF66FF set_color.player_id = block_action.player_id self.send_contained(set_color, save = True) self.map.set_point(x, y, z, (255, 102, 255)) block_action.value = BUILD_BLOCK set_color.value = 0xFF66FF block_action.x = x block_action.y = y block_action.z = z self.send_contained(block_action, save = True)
def santa_drop_block(self, x, y, z): """Places a gift from Santa""" block_action = BlockAction() block_action.player_id = 32 set_color = SetColor() set_color.value = 0xFF0000 set_color.player_id = block_action.player_id self.send_contained(set_color, save = True) self.map.set_point(x, y, z, (255,0,0)) block_action.value = BUILD_BLOCK set_color.value = 0xFF0000 block_action.x = x block_action.y = y block_action.z = z self.send_contained(block_action, save = True)
def cycle(self): if not self.blocks: self.loop.stop() if self.call_on_exhaustion: self.call_on_exhaustion() return blocks_left = self.blocks_per_cycle last_color = None while self.blocks and blocks_left: x, y, z, color = self.blocks.popleft() if color != last_color: set_color = SetColor() set_color.value = make_color(*color) set_color.player_id = 32 self.protocol.send_contained(set_color, save=True) last_color = color if not self.protocol.map.get_solid(x, y, z): block_action = BlockAction() block_action.value = BUILD_BLOCK block_action.player_id = 32 block_action.x = x block_action.y = y block_action.z = z self.protocol.send_contained(block_action, save=True) self.protocol.map.set_point(x, y, z, color) blocks_left -= 1 self.protocol.update_entities()
def build_gradient_line(protocol, colors, points): sp = cbc.ServerPlayer() block_action = BlockAction() block_action.player_id = sp.player_id block_action.value = BUILD_BLOCK set_color = SetColor() set_color.player_id = sp.player_id color_range = list(zip(*colors)) lp = len(points) - 1 map_ = protocol.map for i in range(len(points)): pct = 1 - (i + 0.0) / lp, (i + 0.0) / lp if lp else (1, 0) color = tuple( int(round(sum(c * p for c, p in zip(crng, pct)))) for crng in color_range) map_.set_point(*points[i], color=color) set_color.value = make_color(*color) protocol.send_contained(set_color, save=True) block_action.x, block_action.y, block_action.z = points[i] protocol.send_contained(block_action, save=True)
def build_gradient_line(protocol, colors, points): sp = cbc.ServerPlayer() block_action = BlockAction() block_action.player_id = sp.player_id block_action.value = BUILD_BLOCK set_color = SetColor() set_color.player_id = sp.player_id color_range = zip(*colors) lp = len(points) - 1 map = protocol.map for i in xrange(len(points)): if lp: pct = 1 - (i+0.0) / lp, (i+0.0) / lp else: pct = (1,0) color = tuple(int(round(sum(c*p for c,p in zip(crng, pct)))) for crng in color_range) map.set_point(*points[i], color = color) set_color.value = make_color(*color) protocol.send_contained(set_color, save = True) block_action.x, block_action.y, block_action.z = points[i] protocol.send_contained(block_action, save = True)
def build_filled_generator(protocol, x1, y1, z1, x2, y2, z2, color, god = False, god_build = False): # create a player instance, freed when the generator is done # other scripts that also use ServerPlayer won't get the same id! # this won't be necessary in 1.0 splayer = cbc.ServerPlayer() line = BlockLine() line.player_id = splayer.player_id set_color = SetColor() set_color.value = make_color(*color) set_color.player_id = splayer.player_id protocol.send_contained(set_color, save = True) packets = 1 check_protected = hasattr(protocol, 'protected') if god_build and protocol.god_blocks is None: protocol.god_blocks = set() map = protocol.map ranges = [xrange(min(x1 , x2) , max(x1 , x2)+1) , xrange(min(y1 , y2) , max(y1 , y2)+1) , xrange(min(z1 , z2) , max(z1 , z2)+1)] order = zip(*sorted(zip([len(x) for x in ranges], [0, 1, 2])))[1] # set the first block position prod = ordered_product(ranges, order) line.x1, line.y1, line.z1 = prod.next() line.x2 = line.x1 line.y2 = line.y1 line.z2 = line.z1 map.set_point(line.x1, line.y1, line.z1, color) for x, y, z in prod: packets = 0 if not god and check_protected and protocol.is_protected(x, y, z): continue if god_build: protocol.god_blocks.add((x, y, z)) changed = (line.x1 != x or line.x2 != x) + (line.y1 != y or line.y2 != y) + (line.z1 != z or line.z2 != z) dist = abs(line.x1 - x) + abs(line.y1 - y) + abs(line.z1 - z) if changed > 1 or dist >= MAX_LINE_BLOCKS: protocol.send_contained(line, save = True) packets += 2 line.x1 = x line.y1 = y line.z1 = z line.x2 = x line.y2 = y line.z2 = z map.set_point(x, y, z, color) yield packets, 0 protocol.send_contained(line, save = True) yield 1, 0
def random_color(self): (h, l, s) = self.team.hls l = randint(self.team.light_range[0], self.team.light_range[1]) color = byte_hls_to_rgb((h, l, s)) self.color = color set_color = SetColor() set_color.player_id = self.player_id set_color.value = make_color(*color) self.send_contained(set_color) self.protocol.send_contained(set_color, save=True)
def build_block(connection, x, y, z, color): set_color = SetColor() set_color.value = make_color(*color) set_color.player_id = 32 connection.protocol.send_contained(set_color) block_action.player_id = 32 block_action.x = x block_action.y = y block_action.z = z block_action.value = BUILD_BLOCK connection.protocol.map.set_point(x, y, z, color) connection.protocol.send_contained(block_action, save=True)
def quickbuild_generator(self, origin, structure, default_color): map = self.protocol.map protocol = self.protocol splayer = cbc.ServerPlayer() block_action = BlockAction() block_action.value = BUILD_BLOCK block_action.player_id = splayer.player_id set_color = SetColor() set_color.value = make_color(*default_color) set_color.player_id = splayer.player_id pcolor = default_color protocol.send_contained(set_color, save=True) if not isinstance(structure, dict): structure = dict(structure) for xyz, color in structure.iteritems(): x, y, z = [a + b for a, b in zip(xyz, origin)] if (x < 0 or x >= 512 or y < 0 or y >= 512 or z < 0 or z >= 62): continue if map.get_solid(x, y, z): continue color = color or default_color if color != pcolor: set_color.value = make_color(*color) protocol.send_contained(set_color, save=True) pcolor = color yield 1, 0 self.on_block_build(x, y, z) block_action.x, block_action.y, block_action.z = x, y, z protocol.send_contained(block_action, save=True) map.set_point(x, y, z, pcolor) yield 1, 0
def rebuild_block(player, x, y, z, color): set_color = SetColor() set_color.value = make_color(*color) set_color.player_id = 32 block_action = BlockAction() block_action.player_id = 32 block_action.x = x block_action.y = y block_action.z = z block_action.value = DESTROY_BLOCK player.send_contained(block_action) block_action.value = BUILD_BLOCK player.send_contained(set_color) player.send_contained(block_action)
def quickbuild_generator(self, origin, structure, default_color): map = self.protocol.map protocol = self.protocol splayer = cbc.ServerPlayer() block_action = BlockAction() block_action.value = BUILD_BLOCK block_action.player_id = splayer.player_id set_color = SetColor() set_color.value = make_color(*default_color) set_color.player_id = splayer.player_id pcolor = default_color protocol.send_contained(set_color, save = True) if not isinstance(structure, dict): structure = dict(structure) for xyz, color in structure.iteritems(): x, y, z = [a+b for a,b in zip(xyz, origin)] if (x < 0 or x >= 512 or y < 0 or y >= 512 or z < 0 or z >= 62): continue if map.get_solid(x, y, z): continue color = color or default_color if color != pcolor: set_color.value = make_color(*color) protocol.send_contained(set_color, save = True) pcolor = color yield 1, 0 self.on_block_build(x, y, z) block_action.x, block_action.y, block_action.z = x, y, z protocol.send_contained(block_action, save = True) map.set_point(x, y, z, pcolor) yield 1, 0
def setBlockColor(self, x, y, z, color): set_color = SetColor() set_color.value = make_color(*color) set_color.player_id = 32 self.protocol.send_contained(set_color, save=True) block_action = BlockAction() block_action.x = x block_action.y = y block_action.z = z block_action.player_id = 32 block_action.value = DESTROY_BLOCK self.protocol.send_contained(block_action, save=True) block_action.value = BUILD_BLOCK self.protocol.send_contained(block_action, save=True) self.protocol.map.set_point(x, y, z, color)
def build_gate(self): map_ = self.protocol_obj.map block_line = BlockLine() set_color = SetColor() set_color.value = make_color(*self.color) set_color.player_id = block_line.player_id = 32 self.protocol_obj.send_contained(set_color, save=True) for block_line_ in self.blocks: start_block, end_block = block_line_ points = world.cube_line(*(start_block + end_block)) if not points: continue for point in points: x, y, z = point if not map_.get_solid(x, y, z): map_.set_point(x, y, z, self.color) block_line.x1, block_line.y1, block_line.z1 = start_block block_line.x2, block_line.y2, block_line.z2 = end_block self.protocol_obj.send_contained(block_line, save=True)
def placeC4(connection, *args): if(connection.c4Count<=0): connection.send_chat("You have no c4 charges") return hit = connection.world_object.cast_ray(512) if(hit) connection.c4Count -= 1 map = connection.protocol.map block_action = BlockAction() block_action.value = BUILD_BLOCK block_action.player_id = 32 set_color = SetColor() set_color.player_id = 32 set_color.value = c4Color if(not map.get_point(*hit)[0]): block_action.x, block_action.y, block_action.z = hit connection.protocol.broadcast_contained(block_action) connection.protocol.broadcast_contained(set_color) connection.protocol.c4BlockPositions.append( (hit) ) connection.send_chat("Your next block placed will be a C4")
def cast_rocket(self, pos, ori, start_boom=True): if pos.z <= -1: self.send_chat_error("Too high. Go down to launch a rocket") return False obj = Rocket() obj.pos = pos obj.ori = ori obj.player = self self.protocol.rockets.append(obj) set_color = SetColor() set_color.value = make_color(*ROCKET_COLOR.get()) set_color.player_id = 32 self.protocol.broadcast_contained(set_color) if start_boom: grenade_packet = GrenadePacket() grenade_packet.value = 0 grenade_packet.player_id = self.player_id grenade_packet.position = self.world_object.position.get() grenade_packet.velocity = (0, 0, 0) self.protocol.broadcast_contained(grenade_packet) return True
def set(connection, *args): pos1 = connection.selectPos1 pos2 = connection.selectPos2 if pos1 is None or pos2 is None: connection.send_chat('You are missing a position, try /sel to see your positions') return block_action = BlockAction() block_action.value = DESTROY_BLOCK block_action.player_id = 32 set_color = SetColor() set_color.value = connection.selectColor if connection.selectColor is not None else 0x707070 set_color.player_id = 32 map = connection.protocol.map n = 0 for x in range(*(pos1[0], pos2[0] + 1) if pos1[0] < pos2[0] else (pos2[0], pos1[0] + 1)): block_action.x = x for y in range(*(pos1[1], pos2[1] + 1) if pos1[1] < pos2[1] else (pos2[1], pos1[1] + 1)): block_action.y = y for z in range(*(pos1[2], pos2[2] + 1) if pos1[2] < pos2[2] else (pos2[2], pos1[2] + 1)): block_action.z = z if 'air' in args: if map.get_point(x, y, z): connection.protocol.broadcast_contained(block_action) map.remove_point(x, y, z) n += 1 continue else: if not map.get_point(x, y, z): connection.protocol.broadcast_contained(block_action) if map.get_point(x, y, z): block_action.value = BUILD_BLOCK connection.protocol.broadcast_contained(block_action) connection.protocol.broadcast_contained(set_color) ctuple = (set_color.value >> 16 & 255, set_color.value >> 8 & 255, set_color.value & 255) map.set_point(x, y, z, ctuple) n += 1 connection.send_chat('set %s blocks' % n)
def create_rollback_generator(self, cur, new, start_x, start_y, end_x, end_y, ignore_indestructable): surface = {} block_action = BlockAction() block_action.player_id = 31 set_color = SetColor() set_color.value = make_color(*NON_SURFACE_COLOR) set_color.player_id = 31 self.send_contained(set_color, save=True) old = cur.copy() check_protected = hasattr(protocol, 'protected') for x in xrange(start_x, end_x): block_action.x = x for y in xrange(start_y, end_y): block_action.y = y if check_protected and self.is_protected(x, y, 0): continue for z in xrange(63): action = None cur_solid = cur.get_solid(x, y, z) new_solid = new.get_solid(x, y, z) if cur_solid and not new_solid: if (not ignore_indestructable and self.is_indestructable(x, y, z)): continue else: action = DESTROY_BLOCK cur.remove_point(x, y, z) elif new_solid: new_is_surface = new.is_surface(x, y, z) if new_is_surface: new_color = new.get_color(x, y, z) if not cur_solid and new_is_surface: surface[(x, y, z)] = new_color elif not cur_solid and not new_is_surface: action = BUILD_BLOCK cur.set_point(x, y, z, NON_SURFACE_COLOR) elif cur_solid and new_is_surface: old_is_surface = old.is_surface(x, y, z) if old_is_surface: old_color = old.get_color(x, y, z) if not old_is_surface or old_color != new_color: surface[(x, y, z)] = new_color action = DESTROY_BLOCK cur.remove_point(x, y, z) if action is not None: block_action.z = z block_action.value = action self.send_contained(block_action, save=True) yield 1 yield 0 last_color = None block_action.value = BUILD_BLOCK for pos, color in sorted(surface.iteritems(), key=operator.itemgetter(1)): x, y, z = pos packets_sent = 0 if color != last_color: set_color.value = make_color(*color) self.send_contained(set_color, save=True) packets_sent += 1 last_color = color cur.set_point(x, y, z, color) block_action.x = x block_action.y = y block_action.z = z self.send_contained(block_action, save=True) packets_sent += 1 yield packets_sent
def send_color(protocol, color): set_color_packet = SetColor() set_color_packet.value = make_color(*color) set_color_packet.player_id = 32 protocol.send_contained(set_color_packet, save=True)
def invisible(connection, player): """ Turn invisible /invisible [player] """ protocol = connection.protocol # TODO: move this logic to a more suitable place player.invisible = not player.invisible player.filter_visibility_data = player.invisible player.god = player.invisible player.god_build = False player.killing = not player.invisible if player.invisible: player.send_chat("You're now invisible") protocol.irc_say('* %s became invisible' % player.name) kill_action = KillAction() kill_action.kill_type = choice([GRENADE_KILL, FALL_KILL]) kill_action.player_id = kill_action.killer_id = player.player_id reactor.callLater(1.0 / NETWORK_FPS, protocol.broadcast_contained, kill_action, sender=player) else: player.send_chat("You return to visibility") protocol.irc_say('* %s became visible' % player.name) x, y, z = player.world_object.position.get() create_player = CreatePlayer() create_player.player_id = player.player_id create_player.name = player.name create_player.x = x create_player.y = y create_player.z = z create_player.weapon = player.weapon create_player.team = player.team.id world_object = player.world_object input_data = InputData() input_data.player_id = player.player_id input_data.up = world_object.up input_data.down = world_object.down input_data.left = world_object.left input_data.right = world_object.right input_data.jump = world_object.jump input_data.crouch = world_object.crouch input_data.sneak = world_object.sneak input_data.sprint = world_object.sprint set_tool = SetTool() set_tool.player_id = player.player_id set_tool.value = player.tool set_color = SetColor() set_color.player_id = player.player_id set_color.value = make_color(*player.color) weapon_input = WeaponInput() weapon_input.primary = world_object.primary_fire weapon_input.secondary = world_object.secondary_fire protocol.broadcast_contained(create_player, sender=player, save=True) protocol.broadcast_contained(set_tool, sender=player) protocol.broadcast_contained(set_color, sender=player, save=True) protocol.broadcast_contained(input_data, sender=player) protocol.broadcast_contained(weapon_input, sender=player) if connection is not player and connection in protocol.players.values(): if player.invisible: return '%s is now invisible' % player.name else: return '%s is now visible' % player.name
def set_color(prt, color, player_id = 32): c = SetColor() c.player_id = player_id c.value = color prt.send_contained(c)
def send_color(self, sender): set_color = SetColor() set_color.value = self.color set_color.player_id = 32 sender(set_color, team=self.team)
def create_rollback_generator(self, cur, new, start_x, start_y, end_x, end_y, ignore_indestructable): surface = {} block_action = BlockAction() block_action.player_id = 31 set_color = SetColor() set_color.value = make_color(*NON_SURFACE_COLOR) set_color.player_id = 31 self.send_contained(set_color, save = True) old = cur.copy() check_protected = hasattr(protocol, 'protected') x_count = abs(start_x - end_x) for x in xrange(start_x, end_x): block_action.x = x for y in xrange(start_y, end_y): block_action.y = y if check_protected and self.is_protected(x, y, 0): continue for z in xrange(63): action = None cur_solid = cur.get_solid(x, y, z) new_solid = new.get_solid(x, y, z) if cur_solid and not new_solid: if (not ignore_indestructable and self.is_indestructable(x, y, z)): continue else: action = DESTROY_BLOCK cur.remove_point(x, y, z) elif new_solid: new_is_surface = new.is_surface(x, y, z) if new_is_surface: new_color = new.get_color(x, y, z) if not cur_solid and new_is_surface: surface[(x, y, z)] = new_color elif not cur_solid and not new_is_surface: action = BUILD_BLOCK cur.set_point(x, y, z, NON_SURFACE_COLOR) elif cur_solid and new_is_surface: old_is_surface = old.is_surface(x, y, z) if old_is_surface: old_color = old.get_color(x, y, z) if not old_is_surface or old_color != new_color: surface[(x, y, z)] = new_color action = DESTROY_BLOCK cur.remove_point(x, y, z) if action is not None: block_action.z = z block_action.value = action self.send_contained(block_action, save = True) yield action is not None, ((x-start_x+0.0) / x_count) last_color = None block_action.value = BUILD_BLOCK i = 0.0 for pos, color in sorted(surface.iteritems()): x, y, z = pos packets_sent = 0 if color != last_color: set_color.value = make_color(*color) self.send_contained(set_color, save = True) packets_sent += 1 last_color = color cur.set_point(x, y, z, color) block_action.x = x block_action.y = y block_action.z = z self.send_contained(block_action, save = True) packets_sent += 1 i += 1 yield packets_sent, -(i / len(surface))
def build_filled_generator(protocol, x1, y1, z1, x2, y2, z2, color, god=False, god_build=False): # create a player instance, freed when the generator is done # other scripts that also use ServerPlayer won't get the same id! # this won't be necessary in 1.0 splayer = cbc.ServerPlayer() line = BlockLine() line.player_id = splayer.player_id set_color = SetColor() set_color.value = make_color(*color) set_color.player_id = splayer.player_id protocol.send_contained(set_color, save=True) packets = 1 check_protected = hasattr(protocol, 'protected') if god_build and protocol.god_blocks is None: protocol.god_blocks = set() map = protocol.map ranges = [ xrange(min(x1, x2), max(x1, x2) + 1), xrange(min(y1, y2), max(y1, y2) + 1), xrange(min(z1, z2), max(z1, z2) + 1) ] order = zip(*sorted(zip([len(x) for x in ranges], [0, 1, 2])))[1] # set the first block position prod = ordered_product(ranges, order) line.x1, line.y1, line.z1 = prod.next() line.x2 = line.x1 line.y2 = line.y1 line.z2 = line.z1 map.set_point(line.x1, line.y1, line.z1, color) for x, y, z in prod: packets = 0 if not god and check_protected and protocol.is_protected(x, y, z): continue if god_build: protocol.god_blocks.add((x, y, z)) changed = (line.x1 != x or line.x2 != x) + ( line.y1 != y or line.y2 != y) + (line.z1 != z or line.z2 != z) dist = abs(line.x1 - x) + abs(line.y1 - y) + abs(line.z1 - z) if changed > 1 or dist >= MAX_LINE_BLOCKS: protocol.send_contained(line, save=True) packets += 2 line.x1 = x line.y1 = y line.z1 = z line.x2 = x line.y2 = y line.z2 = z map.set_point(x, y, z, color) yield packets, 0 protocol.send_contained(line, save=True) yield 1, 0
def stack(connection, *args): pos1 = connection.selectPos1 pos2 = connection.selectPos2 try: offset = [(0,0,-1),(0,0,1),(0,-1,0),(1,0,0),(0,1,0),(-1,0,0)][['up', 'down', 'north', 'east', 'south', 'west'].index(args[0])] except ValueError: return if(None in (pos1,pos2)): return try: amount = int(args[1]) except Exception as E: amount = 1 map = connection.protocol.map xh = abs(pos1[0]-pos2[0])+1 #IN XYZ ORDER yh = abs(pos1[1]-pos2[1])+1 zh = abs(pos1[2]-pos2[2])+1 allBlocks = [None]*(xh*yh*zh) allPositions = [None]*len(allBlocks) i = 0 for x in range(*(pos1[0], pos2[0] + 1) if pos1[0] < pos2[0] else (pos2[0], pos1[0] + 1)): for y in range(*(pos1[1], pos2[1] + 1) if pos1[1] < pos2[1] else (pos2[1], pos1[1] + 1)): for z in range(*(pos1[2], pos2[2] + 1) if pos1[2] < pos2[2] else (pos2[2], pos1[2] + 1)): allBlocks[i] = map.get_point(x, y, z) allPositions = (x,y,z) i += 1 operations = [] for run in range(0, amount): operations.append([]) operations[run-1].append("NEW") block_action = BlockAction() block_action.value = DESTROY_BLOCK block_action.player_id = 32 set_color = SetColor() set_color.value = connection.selectColor if connection.selectColor is not None else 0x707070 set_color.player_id = 32 i = 0 for x in range(*(pos1[0], pos2[0] + 1) if pos1[0] < pos2[0] else (pos2[0], pos1[0] + 1)): block_action.x = x + (offset[0]*xh*(run+1)) for y in range(*(pos1[1], pos2[1] + 1) if pos1[1] < pos2[1] else (pos2[1], pos1[1] + 1)): block_action.y = y + (offset[1]*yh*(run+1)) for z in range(*(pos1[2], pos2[2] + 1) if pos1[2] < pos2[2] else (pos2[2], pos1[2] + 1)): block_action.value = DESTROY_BLOCK block_action.z = z + (offset[2]*zh*(run+1)) if(not allBlocks[i][0]): if map.get_point(block_action.x, block_action.y, block_action.z): connection.protocol.broadcast_contained(block_action) map.remove_point(block_action.x, block_action.y, block_action.z) i += 1 operations[run-1].append("blank") continue else: if(not map.get_point(block_action.x, block_action.y, block_action.z)): block = allBlocks[i] blockColor = block[1] icolor = blockColor[0]*(256**2) + blockColor[1]*256 + blockColor[2] set_color.value = icolor connection.protocol.broadcast_contained(set_color) else: block_action.value = BUILD_BLOCK connection.protocol.broadcast_contained(block_action) block = allBlocks[i] blockColor = block[1] icolor = blockColor[0]*(256**2) + blockColor[1]*256 + blockColor[2] icolor = blockColor[0]*(256**2) + blockColor[1]*256 + blockColor[2] set_color.value = icolor connection.protocol.broadcast_contained(set_color) ctuple = (set_color.value >> 16 & 255, set_color.value >> 8 & 255, set_color.value & 255) map.set_point(block_action.x, block_action.y, block_action.z, ctuple) i += 1 operations[run-1].append("block") continue
def updateColor(self, protocol, color): set_color = SetColor() set_color.value = make_color(*color) set_color.player_id = 32 protocol.broadcast_contained(set_color, save=True) return color
def set_color(prt, color, player_id=32): c = SetColor() c.player_id = player_id c.value = color prt.send_contained(c)