Пример #1
0
        //-- Creates a spherical crater where the meteor made contact with the ground --//
        private void CreateCrater(Vec3d meteorDirection, Vec3d shrapnelDirection)
        {
            List <LandClaim> claims       = serverAPI.World.Claims.All;
            List <BlockPos>  ashPositions = new List <BlockPos>();

            blockAccessor = serverAPI.World.GetBlockAccessorBulkUpdate(true, true);

            Vec3i centerPos = this.entity.ServerPos.XYZInt;

            BlockPos craterPos = new BlockPos();

            //-- Initial scan to see if the meteor crater should fill with liquid instead of air --//
            blockAccessor.SearchFluidBlocks(new BlockPos(centerPos.X - explosionRadius, centerPos.Y - explosionRadius, centerPos.Z - explosionRadius),
                                            new BlockPos(centerPos.X + explosionRadius, centerPos.Y + explosionRadius, centerPos.Z + explosionRadius), (block, bPos) =>
            {
                if (block.DrawType == EnumDrawType.Liquid)
                {
                    liquidAsset = new AssetLocation(block.Code.Domain, block.Code.Path);

                    fillWithLiquid = true;
                    fillHeight     = bPos.Y;

                    return(true);
                }

                return(false);
            });


            //-- Scans every block in a cube determined by the explosion radius and determines whether that block fits within the explosion sphere --//
            blockAccessor.WalkBlocks(new BlockPos(centerPos.X - explosionRadius, centerPos.Y - explosionRadius, centerPos.Z - explosionRadius),
                                     new BlockPos(centerPos.X + explosionRadius, centerPos.Y + explosionRadius, centerPos.Z + explosionRadius), (block, xPos, yPos, zPos) =>
            {
                BlockPos blockPos      = new BlockPos(xPos, yPos, zPos);
                float distanceToCenter = blockPos.DistanceTo(centerPos.ToBlockPos());

                if (distanceToCenter < explosionRadius)
                {
                    if (serverAPI.World.Config.GetBool("ClaimsProtected") == true)
                    {
                        bool isClaimed = false;

                        foreach (LandClaim claim in claims)
                        {
                            if (claim.PositionInside(blockPos))
                            {
                                isClaimed = true;
                            }
                        }

                        if (isClaimed == false)
                        {
                            ExplodeBlock(block, blockPos, shrapnelDirection);

                            if (fillWithLiquid == false)
                            {
                                if (centerPos.Y - blockPos.Y == explosionRadius - 1)
                                {
                                    if (explosionRand.Next(0, 100) < ashBlockChance)
                                    {
                                        ashPositions.Add(blockPos + new BlockPos(0, 1, 0));
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        ExplodeBlock(block, blockPos, shrapnelDirection);

                        if (fillWithLiquid == false)
                        {
                            if (centerPos.Y - blockPos.Y == explosionRadius - 1)
                            {
                                if (explosionRand.Next(0, 100) < ashBlockChance)
                                {
                                    ashPositions.Add(blockPos.Copy() + new BlockPos(0, 1, 0));
                                }
                            }
                        }
                    }
                }
            });

            PlaceMeteor(meteorDirection, shrapnelDirection, centerPos, explosionRadius, claims);
            PlaceAsh(ashPositions);

            blockAccessor.Commit();
        }