def login(self): # Login Packet pk = Packet("login") pk.eid = self.entity.id pk.leveltype = "default" pk.mode = "survival" pk.dimension = "earth" pk.difficulty = "normal" pk.unused = 0 pk.maxplayers = self.server.max_players self.client.write(pk) # Tell the game we have joined self.game.playerJoin(self) # Preload Chunks in a 10x10 around the player self.loadChunkArea(5, 5) # Compass pk = Packet("compass") if self.entity.spawn: pk.x, pk.y, pk.z = self.entity.spawn else: pk.x, pk.y, pk.z = (0, 64, 0) self.client.write(pk) # Position reset self.pos.x = 0 self.pos.loc.y = 64 #64 self.pos.z = 0 self.client.write(self.getLocPak()) # Spawn the player in # Load a larger area for el playero self.game.tm.run(self.loadChunkArea, 10, 10)
def getPacket(self): #@TODO Support section-packets to save bandwith? inf = [] if self.c.dirty: self.world.level.generateLights() for y in range(0, 256, 16): Blocks = self.c.Blocks[..., y:y + 16].swapaxes(0, 2) inf.append(array(Blocks, 'uint8').tostring()) for y in range(0, 256, 16): Data = self.c.Data[..., y:y + 16].swapaxes(0, 2) inf.append(array(packNibbleArray(Data)).tostring()) for y in range(0, 256, 16): BlockLight = self.c.BlockLight[..., y:y + 16].swapaxes(0, 2) inf.append(array(packNibbleArray(BlockLight)).tostring()) for y in range(0, 256, 16): SkyLight = self.c.SkyLight[..., y:y + 16].swapaxes(0, 2) inf.append(array(packNibbleArray(SkyLight)).tostring()) inf.append("\x00" * 256) #@TODO biome data p = Packet("chunk") p.x, p.z = self.pos p.continuous = True p.primary = 65535 #@TODO LOL STATIC FTW p.add = 0x0 p.data = "".join(inf) return p
def getLocPak(self): #@TODO dis r brok again pk = Packet("location") self.pos.modifyPacket(pk) pk.x = self.pos.loc.x pk.y = self.pos.loc.y pk.z = self.pos.loc.z pk.stance = pk.y+1.62 pk.grounded = self.onGround return pk
def getSpawnPacket(self): p = Packet("spawn") p.eid = self.id p.type = self.entity_type p.x = self.loc.x p.y = self.loc.y p.z = self.loc.z p.pitch = self.rotation.pitch p.yaw = self.rotation.yaw p.data = 1 p.speedx = self.velo.x p.speedz = self.velo.z p.speedy = self.velo.y return p