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

            return(null);
        }
Пример #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);
            }
        }
Пример #5
0
 public IChunkColumn GetChunkColumn(int x, int z)
 {
     if (ChunkManager.TryGetChunk(new ChunkCoordinates(x, z), out IChunkColumn val))
     {
         return(val);
     }
     else
     {
         return(null);
     }
 }
Пример #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);
        }
Пример #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));
        }
Пример #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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #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);
            }
        }
Пример #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);
        }
Пример #14
0
        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));
        }
Пример #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;
        }
Пример #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);
        }
Пример #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);
        }
Пример #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));
        }
Пример #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);
            }
        }
Пример #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;
        }
Пример #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);
        }
Пример #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);
        }
Пример #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;
                    }
                }
            }
        }
Пример #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);
            }
        }
Пример #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);
                }
            }
        }
Пример #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);
            }
        }
Пример #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));
                }
            }
        }
Пример #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);
                }
            }
        }
Пример #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));
 }