/* * public int GetMetadata(BlockPos pos) * { * Chunk chunk = GetChunk(ChunkPos.FromWorldSpace(pos)); * if (chunk == null || !chunk.HasData) * return -1; * * return chunk.GetMetadata(ChunkPos.ToChunkLocal(pos)); * }*/ /* * public void SetMetadata(BlockPos pos, int meta) * { * Chunk chunk = GetChunk(ChunkPos.FromWorldSpace(pos)); * if (chunk == null || !chunk.HasData) * return; * * chunk.SetMetadata(ChunkPos.ToChunkLocal(pos), meta); * }*/ public override void Update(Vector3 playerPos, int renderDistance) { _initalLoad = false; ChunkPos playerChunkPos = ChunkPos.FromWorldSpace(playerPos); for (int z = -renderDistance; z <= renderDistance; z++) { for (int x = -renderDistance; x <= renderDistance; x++) { ChunkPos pos = new ChunkPos(playerChunkPos.x + x, playerChunkPos.z + z); if (pos.DistanceTo(playerPos.Xz) < renderDistance * Chunk.ChunkSize) { if (GetChunk(pos) == null) { SharpCraft.Instance.ServerHandler.RequestChunk(pos); } } } } foreach (Chunk chunk in Chunks.Values) { chunk.Update(); if (chunk.Pos.DistanceTo(playerPos.Xz) > renderDistance * Chunk.ChunkSize + 50) { UnloadChunk(chunk.Pos); } } UpdateEntities(); }
public void SetBlockState(BlockPos pos, BlockState state) { Chunk chunk = GetChunk(ChunkPos.FromWorldSpace(pos)); if (chunk == null || !chunk.HasData) { return; } _worldLut.Put(state.Block.UnlocalizedName); chunk.SetBlockState(ChunkPos.ToChunkLocal(pos), state); }
public virtual BlockState GetBlockState(BlockPos pos) { if (pos.Y < 0 || pos.Y >= Chunk.ChunkHeight) { return(BlockRegistry.GetBlock <BlockAir>().GetState()); } Chunk chunk = GetChunk(ChunkPos.FromWorldSpace(pos)); if (chunk == null || !chunk.HasData) { return(BlockRegistry.GetBlock <BlockAir>().GetState()); } return(chunk.GetBlockState(ChunkPos.ToChunkLocal(pos))); }
private void UpdateEntities() { Entities.RemoveAll(e => { if (!IsChunkLoaded(ChunkPos.FromWorldSpace(e.Pos))) { return(false); } if (e.isAlive) { e.Update(); return(!e.isAlive); } return(true); }); }
public virtual void SetBlockState(BlockPos pos, BlockState state) { Chunk chunk = GetChunk(ChunkPos.FromWorldSpace(pos)); if (chunk == null || !chunk.HasData) { return; } _worldLut.Put(state.Block.UnlocalizedName); var localPos = ChunkPos.ToChunkLocal(pos); chunk.SetBlockState(localPos, state); if (state.Block.CreateTileEntity(this, pos) is TileEntity te) { chunk.AddTileEntity(localPos, te); } chunk.Save(); }