def pre_build_hook(self, player, builddata): item, metadata, x, y, z, face = builddata if item.slot != items["paintings"].slot: return True, builddata, False if face in ["+y", "-y"]: # No paintings on the floor. return False, builddata, False # Make sure we can remove it from the inventory. if not player.inventory.consume((item.slot, 0), player.equipped): return False, builddata, False entity = factory.create_entity(x, y, z, "Painting", direction=face_to_direction[face], motive=random.choice(painting_names)) factory.broadcast(entity.save_to_packet()) # Force the chunk (with its entities) to be saved to disk. factory.world.mark_dirty((x, y, z)) return False, builddata, False
def use_hook(self, player, target, button): # Block coordinates. x, y, z = target.location.x, target.location.y, target.location.z # Offset coords according to direction. A painting does not # occupy a block, therefore we drop the pickup right in front of the # block it is attached to. face = direction_to_face[target.direction] if face == "-x": x -= 1 elif face == "+x": x += 1 elif face == "-z": z -= 1 elif face == "+z": z += 1 # Pixel coordinates. coords = (x * 32 + 16, y * 32, z * 32 + 16) factory.destroy_entity(target) factory.give(coords, (items["paintings"].slot, 0), 1) packet = make_packet("destroy", eid=target.eid) factory.broadcast(packet) # Force the chunk (with its entities) to be saved to disk. factory.world.mark_dirty((x, y, z))
def chat_command(self, username, parameters): from bravo.packets.beta import make_packet arg = "".join(parameters) if arg == "start": factory.broadcast(make_packet("state", state="start_rain")) elif arg == "stop": factory.broadcast(make_packet("state", state="stop_rain")) else: return ("Couldn't understand you!",) return ("*%s did the rain dance*" % (username),)
def chat_command(self, username, parameters): from bravo.beta.packets import make_packet arg = "".join(parameters) if arg == "start": factory.broadcast( make_packet("state", state="start_rain", creative=False)) elif arg == "stop": factory.broadcast( make_packet("state", state="stop_rain", creative=False)) else: return ("Couldn't understand you!", ) return ("*%s did the rain dance*" % (username), )
def console_command(self, parameters): # Let's shutdown! message = "Server shutting down." yield message # Use an error packet to kick clients cleanly. packet = make_packet("error", message=message) factory.broadcast(packet) yield "Saving all chunks to disk..." for chunk in factory.world.dirty_chunk_cache.itervalues(): factory.world.save_chunk(chunk) yield "Halting." reactor.stop()
def chat_command(self, username, parameters): make = True position = factory.protocols[username].location if len(parameters) == 1: mob = parameters[0] number = 1 elif len(parameters) == 2: mob = parameters[0] number = int(parameters[1]) else: make = False return ("Couldn't understand you!",) if make: # try: for i in range(0,number): print mob, number entity = factory.create_entity(position.x,position.y,position.z,mob) factory.broadcast(entity.save_to_packet()) factory.world.mob_manager.start_mob(entity) return ("Made mob!",)
def chat_command(self, username, parameters): make = True position = factory.protocols[username].location if len(parameters) == 1: mob = parameters[0] number = 1 elif len(parameters) == 2: mob = parameters[0] number = int(parameters[1]) else: make = False return ("Couldn't understand you!", ) if make: # try: for i in range(0, number): print mob, number entity = factory.create_entity(position.x, position.y, position.z, mob) factory.broadcast(entity.save_to_packet()) factory.world.mob_manager.start_mob(entity) return ("Made mob!", )
def use_hook(self, player, target, button): # Block coordinates. x, y, z = target.location.x, target.location.y, target.location.z # Offset coords according to direction. A painting does not # occupy a block, therefore we drop the pickup right in front of the # block it is attached to. face = direction_to_face[target.direction] x, y, z = adjust_coords_for_face((x, y, z), face) # Pixel coordinates. coords = (x * 32 + 16, y * 32, z * 32 + 16) factory.destroy_entity(target) factory.give(coords, (items["paintings"].slot, 0), 1) packet = make_packet("destroy", eid=target.eid) factory.broadcast(packet) # Force the chunk (with its entities) to be saved to disk. factory.world.mark_dirty((x, y, z))
def console_command(self, parameters): message = "[Server] %s" % " ".join(parameters) yield message packet = make_packet("chat", message=message) factory.broadcast(packet)