// Receives a Drop Item notification and creates the DropItemAI Entity private void DropItem(byte[] data, ulong id) { float3 pos, rot, move; ushort itemCode; byte amount; NetMessage message = new NetMessage(NetCode.ITEMENTITYDATA); pos = NetDecoder.ReadFloat3(data, 1); rot = NetDecoder.ReadFloat3(data, 13); move = NetDecoder.ReadFloat3(data, 25); itemCode = NetDecoder.ReadUshort(data, 37); amount = data[39]; CastCoord coord = new CastCoord(pos); ChunkPos cp = coord.GetChunkPos(); ulong code = this.entityHandler.AddItem(pos, rot, move, itemCode, amount, id, this.cl); message.ItemEntityData(pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, itemCode, amount, code); this.SendToClients(cp, message); }
// Gets chunk information to player private void RequestChunkLoad(byte[] data, ulong id) { ChunkPos pos = NetDecoder.ReadChunkPos(data, 1); // If is loaded if (this.cl.chunks.ContainsKey(pos) && this.cl.chunks[pos].needsGeneration == 0) { if (!this.cl.loadedChunks.ContainsKey(pos)) { this.cl.loadedChunks.Add(pos, new HashSet <ulong>()); } if (!this.cl.loadedChunks[pos].Contains(id)) { this.cl.loadedChunks[pos].Add(id); } NetMessage message = new NetMessage(NetCode.SENDCHUNK); message.SendChunk(this.cl.chunks[pos]); this.Send(message.GetMessage(), message.size, id); } else { // If it's not loaded yet if (!this.cl.toLoad.Contains(pos)) { this.cl.toLoad.Add(pos); } NetMessage message = new NetMessage(NetCode.FAILEDCHUNKREQUEST); message.FailedChunkRequest(pos); this.Send(message.GetMessage(), message.size, id); return; } NetMessage playerMessage = new NetMessage(NetCode.PLAYERDATA); // Sends logged in players data if (this.playersInChunk.ContainsKey(pos)) { foreach (ulong code in this.playersInChunk[pos]) { if (code == id) { continue; } if (this.cl.regionHandler.allPlayerData[code].IsOnline()) { this.connectionGraph[code].Add(id); playerMessage.PlayerData(this.cl.regionHandler.allPlayerData[code]); this.Send(playerMessage.GetMessage(), playerMessage.size, id); } } } NetMessage itemMessage = new NetMessage(NetCode.ITEMENTITYDATA); // Connects new Dropped items to player if (this.entityHandler.Contains(EntityType.DROP, pos)) { foreach (ulong itemCode in this.entityHandler.dropObject[pos].Keys) { itemMessage.ItemEntityData(this.entityHandler.dropObject[pos][itemCode].position.x, this.entityHandler.dropObject[pos][itemCode].position.y, this.entityHandler.dropObject[pos][itemCode].position.z, this.entityHandler.dropObject[pos][itemCode].rotation.x, this.entityHandler.dropObject[pos][itemCode].rotation.y, this.entityHandler.dropObject[pos][itemCode].rotation.z, (ushort)this.entityHandler.dropObject[pos][itemCode].its.GetID(), this.entityHandler.dropObject[pos][itemCode].its.GetAmount(), itemCode); } } }