public void SetBlockEntity(int x, int y, int z, BlockEntity blockEntity) { var coords = new BlockCoordinates(x, y, z); var chunkCoords = new ChunkCoordinates(x >> 4, z >> 4); ChunkColumn chunk; if (ChunkManager.TryGetChunk(chunkCoords, out chunk)) { var cx = x & 0xf; var cy = y & 0xff; var cz = z & 0xf; var chunkPos = new BlockCoordinates(cx, cy, cz); var blockAtPos = chunk.GetBlockState(cx, cy, cz); if (blockAtPos.Block.BlockMaterial == Material.Air) { return; } chunk.RemoveBlockEntity(chunkPos); EntityManager.RemoveBlockEntity(coords); chunk.AddBlockEntity(chunkPos, blockEntity); EntityManager.AddBlockEntity(coords, blockEntity); } }
public void SetBlockState(int x, int y, int z, BlockState block, int storage, BlockUpdatePriority priority = BlockUpdatePriority.High | BlockUpdatePriority.Neighbors) { var chunkCoords = new ChunkCoordinates(x >> 4, z >> 4); ChunkColumn chunk; if (ChunkManager.TryGetChunk(chunkCoords, out chunk)) { var cx = x & 0xf; var cy = y & 0xff; var cz = z & 0xf; chunk.SetBlockState(cx, cy, cz, block, storage); EntityManager.RemoveBlockEntity(new BlockCoordinates(x, y, z)); var type = ScheduleType.Full; if ((priority & BlockUpdatePriority.Neighbors) != 0) { UpdateNeighbors(x, y, z); CheckForUpdate(chunkCoords, cx, cz); } if ((priority & BlockUpdatePriority.NoGraphic) != 0) { type |= ScheduleType.LowPriority; } //chunk.SetDirty(); //chunk.IsDirty = true; ChunkManager.ScheduleChunkUpdate(chunkCoords, type, (priority & BlockUpdatePriority.Priority) != 0); } }
public ChunkColumn GetChunk(ChunkCoordinates coordinates, bool cacheOnly = false) { if (ChunkManager.TryGetChunk(coordinates, out var c)) { return((ChunkColumn)c); } return(null); }
public void SetSkyLight(BlockCoordinates coordinates, byte p1) { ChunkColumn chunk; if (ChunkManager.TryGetChunk(new ChunkCoordinates(coordinates), out chunk)) { chunk.SetSkyLight(coordinates.X & 0xf, coordinates.Y & 0xff, coordinates.Z & 0xf, p1); } }
public IChunkColumn GetChunkColumn(int x, int z) { if (ChunkManager.TryGetChunk(new ChunkCoordinates(x, z), out IChunkColumn val)) { return(val); } else { return(null); } }
public BlockState GetBlockState(int x, int y, int z, int storage) { ChunkColumn chunk; if (ChunkManager.TryGetChunk(new ChunkCoordinates(x >> 4, z >> 4), out chunk)) { return(chunk.GetBlockState(x & 0xf, y & 0xff, z & 0xf, storage)); } return(Airstate); }
public IBlockState GetBlockState(int x, int y, int z) { IChunkColumn chunk; if (ChunkManager.TryGetChunk(new ChunkCoordinates(x >> 4, z >> 4), out chunk)) { return(chunk.GetBlockState(x & 0xf, y & 0xff, z & 0xf)); } return(BlockFactory.GetBlockState(0)); }
public bool IsScheduled(int x, int y, int z) { IChunkColumn chunk; if (ChunkManager.TryGetChunk(new ChunkCoordinates(x >> 4, z >> 4), out chunk)) { return(chunk.IsScheduled(x & 0xf, y & 0xff, z & 0xf)); // return true; } return(false); }
public int GetHeight(BlockCoordinates coords) { ChunkColumn chunk; if (ChunkManager.TryGetChunk(new ChunkCoordinates(coords.X >> 4, coords.Z >> 4), out chunk)) { //Worlds.ChunkColumn realColumn = (Worlds.ChunkColumn)chunk; return(chunk.GetHeight(coords.X & 0xf, coords.Z & 0xf)); } return(255); }
public bool IsTransparent(int x, int y, int z) { IChunkColumn chunk; if (ChunkManager.TryGetChunk(new ChunkCoordinates(x >> 4, z >> 4), out chunk)) { return(chunk.IsTransparent(x & 0xf, y & 0xff, z & 0xf)); // return true; } return(true); }
public bool HasBlock(int x, int y, int z) { IChunkColumn chunk; if (ChunkManager.TryGetChunk(new ChunkCoordinates(x >> 4, z >> 4), out chunk)) { //Worlds.ChunkColumn realColumn = (Worlds.ChunkColumn)chunk; return(true); } return(false); }
public void SetBlockState(int x, int y, int z, BlockState block, int storage, BlockUpdatePriority priority = BlockUpdatePriority.High | BlockUpdatePriority.Neighbors) { var chunkCoords = new ChunkCoordinates(x >> 4, z >> 4); ChunkColumn chunk; if (ChunkManager.TryGetChunk(chunkCoords, out chunk)) { var cx = x & 0xf; var cy = y & 0xff; var cz = z & 0xf; //var previousBlock = chunk.GetBlockState(cx, cy, cz, storage); //if (block.Block.RequiresUpdate) { //block = block.Block.BlockPlaced(this, block, new BlockCoordinates(x,y,z)); } chunk.SetBlockState(cx, cy, cz, block, storage); EntityManager.RemoveBlockEntity(new BlockCoordinates(x, y, z)); var type = ScheduleType.Full; if ((priority & BlockUpdatePriority.Neighbors) != 0) { UpdateNeighbors(x, y, z); } if ((priority & BlockUpdatePriority.NoGraphic) != 0) { type |= ScheduleType.LowPriority; } var blockCoords = new BlockCoordinates(x, y, z); /*if (block.Block.BlockMaterial.BlocksLight) * { * SetBlockLight(blockCoords, 0); * } */ ChunkManager.SkyLightCalculator.Calculate(this, blockCoords); ChunkManager.BlockLightCalculations.Enqueue(blockCoords); //chunk.SetDirty(); //chunk.IsDirty = true; ChunkManager.ScheduleChunkUpdate(chunkCoords, type, (priority & BlockUpdatePriority.Priority) != 0); CheckForUpdate(chunkCoords, cx, cz); } }
public int GetBiome(int x, int y, int z) { IChunkColumn chunk; if (ChunkManager.TryGetChunk(new ChunkCoordinates(x >> 4, z >> 4), out chunk)) { Worlds.ChunkColumn realColumn = (Worlds.ChunkColumn)chunk; return(realColumn.GetBiome(x & 0xf, z & 0xf)); } //Log.Debug($"Failed getting biome: {x} | {y} | {z}"); return(-1); }
public void UpdatePlayerPosition(PlayerLocation location) { var oldPosition = Player.KnownPosition; if (!ChunkManager.TryGetChunk(new ChunkCoordinates(location), out _)) { Player.WaitingOnChunk = true; } Player.KnownPosition = location; Player.DistanceMoved += MathF.Abs(Vector3.Distance(oldPosition, location)); }
public IEnumerable <ChunkSection.BlockEntry> GetBlockStates(int x, int y, int z) { ChunkColumn chunk; if (ChunkManager.TryGetChunk(new ChunkCoordinates(x >> 4, z >> 4), out chunk)) { foreach (var bs in chunk.GetBlockStates(x & 0xf, y & 0xff, z & 0xf)) { yield return(bs); } } yield break; }
public byte GetBlockLight(int x, int y, int z) { if (y < 0 || y > ChunkColumn.ChunkHeight) { return(15); } IChunkColumn chunk; if (ChunkManager.TryGetChunk(new ChunkCoordinates(x >> 4, z >> 4), out chunk)) { return(chunk.GetBlocklight(x & 0xf, y & 0xff, z & 0xf)); } return(15); }
public Block GetBlock(int x, int y, int z) { // try // { ChunkColumn chunk; if (ChunkManager.TryGetChunk(new ChunkCoordinates(x >> 4, z >> 4), out chunk)) { return(chunk.GetBlockState(x & 0xf, y & 0xff, z & 0xf).Block); } //} // catch { } return(Airstate.Block); }
public IBlock GetBlock(int x, int y, int z) { // try // { IChunkColumn chunk; if (ChunkManager.TryGetChunk(new ChunkCoordinates(x >> 4, z >> 4), out chunk)) { return(chunk.GetBlock(x & 0xf, y & 0xff, z & 0xf)); } //} // catch { } return(BlockFactory.GetBlock(0)); }
public void ScheduleBlockUpdate(BlockCoordinates coordinates) { var chunkCoords = new ChunkCoordinates(coordinates.X >> 4, coordinates.Z >> 4); ChunkColumn chunk; if (ChunkManager.TryGetChunk(chunkCoords, out chunk)) { var cx = coordinates.X & 0xf; var cy = coordinates.Y & 0xff; var cz = coordinates.Z & 0xf; chunk.ScheduleBlockUpdate(cx, cy, cz); } }
public void GetBlockData(int x, int y, int z, out bool transparent, out bool solid) { IChunkColumn chunk; if (ChunkManager.TryGetChunk(new ChunkCoordinates(x >> 4, z >> 4), out chunk)) { chunk.GetBlockData(x & 0xf, y & 0xff, z & 0xf, out transparent, out solid); //return chunk.IsSolid(x & 0xf, y & 0xff, z & 0xf); // return true; return; } transparent = false; solid = false; //return false; }
public ChunkColumn GetChunk(ChunkCoordinates coordinates, bool cacheOnly = false) { if (coordinates == _coord) { return(_chunk); } if (_coord != ChunkCoordinates.None) { if (coordinates != _coord) { if (coordinates != _coord + ChunkCoordinates.Backward) { if (coordinates != _coord + ChunkCoordinates.Forward) { if (coordinates != _coord + ChunkCoordinates.Left) { if (coordinates != _coord + ChunkCoordinates.Right) { if (coordinates != _coord + ChunkCoordinates.Backward + ChunkCoordinates.Left) { if (coordinates != _coord + ChunkCoordinates.Backward + ChunkCoordinates.Right) { if (coordinates != _coord + ChunkCoordinates.Forward + ChunkCoordinates.Left) { if (coordinates != _coord + ChunkCoordinates.Forward + ChunkCoordinates.Right) { return(null); } } } } } } } } } } if (_worldProvider.TryGetChunk(coordinates, out ChunkColumn column)) { return((ChunkColumn)column); } return(null); //return _worldProvider.GenerateChunkColumn(coordinates, true); }
public bool TryGetBlockLight(BlockCoordinates coordinates, out byte blockLight) { blockLight = 0; if (coordinates.Y < 0 || coordinates.Y > ChunkColumn.ChunkHeight) { return(false); } ChunkColumn chunk; if (ChunkManager.TryGetChunk(new ChunkCoordinates(coordinates), out chunk)) { blockLight = chunk.GetBlocklight(coordinates.X & 0xf, coordinates.Y & 0xff, coordinates.Z & 0xf); return(true); } return(false); }
public void SetSkyLight(BlockCoordinates coordinates, byte p1) { var chunkCoords = new ChunkCoordinates(coordinates); ChunkColumn chunk; if (ChunkManager.TryGetChunk(chunkCoords, out chunk)) { if (chunk.SetSkyLight(coordinates.X & 0xf, coordinates.Y & 0xff, coordinates.Z & 0xf, p1)) { // if ((chunk.Scheduled & ScheduleType.Lighting) != ScheduleType.Lighting) { // ChunkManager.ScheduleChunkUpdate(chunkCoords, ScheduleType.Lighting); } // else { // chunk.Scheduled = chunk.Scheduled | ScheduleType.Lighting; } } } }
public void SetBlockState(int x, int y, int z, IBlockState block) { var chunkCoords = new ChunkCoordinates(x >> 4, z >> 4); IChunkColumn chunk; if (ChunkManager.TryGetChunk(chunkCoords, out chunk)) { var cx = x & 0xf; var cy = y & 0xff; var cz = z & 0xf; chunk.SetBlockState(cx, cy, cz, block); UpdateNeighbors(x, y, z); CheckForUpdate(chunkCoords, cx, cz); ChunkManager.ScheduleChunkUpdate(chunkCoords, ScheduleType.Scheduled | ScheduleType.Lighting, true); } }
private void ScheduleLightingUpdate(BlockCoordinates coordinates, bool blockLight = false) { var chunkCoords = new ChunkCoordinates(coordinates.X >> 4, coordinates.Z >> 4); ChunkColumn chunk; if (ChunkManager.TryGetChunk(chunkCoords, out chunk)) { var cx = coordinates.X & 0xf; var cy = coordinates.Y & 0xff; var cz = coordinates.Z & 0xf; if (blockLight) { chunk.ScheduleBlocklightUpdate(cx, cy, cz); } else { chunk.ScheduleSkylightUpdate(cx, cy, cz); } } }
public void SetBlock(Block block) { var x = block.Coordinates.X; var y = block.Coordinates.Y; var z = block.Coordinates.Z; var chunkCoords = new ChunkCoordinates(x >> 4, z >> 4); IChunkColumn chunk; if (ChunkManager.TryGetChunk(chunkCoords, out chunk)) { var cx = x & 0xf; var cy = y & 0xff; var cz = z & 0xf; chunk.SetBlock(cx, cy, cz, block); ChunkManager.ScheduleChunkUpdate(new ChunkCoordinates(x >> 4, z >> 4), ScheduleType.Scheduled | ScheduleType.Lighting, true); UpdateNeighbors(x, y, z); CheckForUpdate(chunkCoords, cx, cz); } }
public void SetSkyLight(BlockCoordinates coordinates, byte p1) { var chunkCoords = new ChunkCoordinates(coordinates); ChunkColumn chunk; if (ChunkManager.TryGetChunk(chunkCoords, out chunk)) { if (chunk.SetSkyLight(coordinates.X & 0xf, coordinates.Y & 0xff, coordinates.Z & 0xf, p1)) { var x = coordinates.X; var y = coordinates.Y; var z = coordinates.Z; ScheduleLightingUpdate(new BlockCoordinates(x + 1, y, z)); ScheduleLightingUpdate(new BlockCoordinates(x - 1, y, z)); ScheduleLightingUpdate(new BlockCoordinates(x, y, z + 1)); ScheduleLightingUpdate(new BlockCoordinates(x, y, z - 1)); ScheduleLightingUpdate(new BlockCoordinates(x, y + 1, z)); ScheduleLightingUpdate(new BlockCoordinates(x, y - 1, z)); } } }
public void SetBlockLight(BlockCoordinates coordinates, byte value) { var chunkCoords = new ChunkCoordinates(coordinates); ChunkColumn chunk; if (ChunkManager.TryGetChunk(chunkCoords, out chunk)) { if (chunk.SetBlocklight(coordinates.X & 0xf, coordinates.Y & 0xff, coordinates.Z & 0xf, value)) { var x = coordinates.X; var y = coordinates.Y; var z = coordinates.Z; ScheduleLightingUpdate(new BlockCoordinates(x + 1, y, z), true); ScheduleLightingUpdate(new BlockCoordinates(x + -1, y, z), true); ScheduleLightingUpdate(new BlockCoordinates(x, y, z + 1), true); ScheduleLightingUpdate(new BlockCoordinates(x, y, z + -1), true); ScheduleLightingUpdate(new BlockCoordinates(x, y + 1, z), true); ScheduleLightingUpdate(new BlockCoordinates(x, y + -1, z), true); } } }
public BlockCoordinates FindBlockPosition(BlockCoordinates coords, out IChunkColumn chunk) { ChunkManager.TryGetChunk(new ChunkCoordinates(coords.X >> 4, coords.Z >> 4), out chunk); return(new BlockCoordinates(coords.X & 0xf, coords.Y & 0xff, coords.Z & 0xf)); }