Example #1
0
        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);
            }
        }
Example #2
0
        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);
            }
        }
Example #3
0
        public ChunkColumn GetChunk(ChunkCoordinates coordinates, bool cacheOnly = false)
        {
            if (ChunkManager.TryGetChunk(coordinates, out var c))
            {
                return((ChunkColumn)c);
            }

            return(null);
        }
Example #4
0
        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);
            }
        }
Example #5
0
 public IChunkColumn GetChunkColumn(int x, int z)
 {
     if (ChunkManager.TryGetChunk(new ChunkCoordinates(x, z), out IChunkColumn val))
     {
         return(val);
     }
     else
     {
         return(null);
     }
 }
Example #6
0
        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);
        }
Example #7
0
        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));
        }
Example #8
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);
        }
Example #9
0
        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);
        }
Example #10
0
        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);
        }
Example #11
0
        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);
        }
Example #12
0
        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);
            }
        }
Example #13
0
        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);
        }
Example #14
0
File: World.cs Project: K4mey/Alex
        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));
        }
Example #15
0
        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;
        }
Example #16
0
        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);
        }
Example #17
0
        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);
        }
Example #18
0
        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));
        }
Example #19
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);
            }
        }
Example #20
0
        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;
        }
Example #21
0
        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);
        }
Example #22
0
        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);
        }
Example #23
0
        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;
                    }
                }
            }
        }
Example #24
0
        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);
            }
        }
Example #25
0
        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);
                }
            }
        }
Example #26
0
        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);
            }
        }
Example #27
0
        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));
                }
            }
        }
Example #28
0
        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);
                }
            }
        }
Example #29
0
 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));
 }