Exemplo n.º 1
0
        //-- Creates a spherical crater where the meteor made contact with the ground --//
        private void CreateCrater(Vec3d meteorDirection, Vec3d shrapnelDirection)
        {
            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.WalkBlocks(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;
                }
            });


            //-- 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, bpos) =>
            {
                if (bpos.DistanceTo(centerPos.ToBlockPos()) < explosionRadius)
                {
                    ExplodeBlock(block, bpos, shrapnelDirection);
                }
            });

            PlaceMeteorResources(meteorDirection, shrapnelDirection, centerPos, explosionRadius);

            blockAccessor.Commit();
        }
Exemplo n.º 2
0
        public List <Vec3i> GetNeighbours(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            //Finds blocks in a line around this block. Stops if theres a break in the line.
            PlugnFeatherBE BE       = world.BlockAccessor.GetBlockEntity(blockSel.Position) as PlugnFeatherBE;
            Vec3i          checkDir = new Vec3i();
            Vec3i          startPos = blockSel.Position.ToVec3i();

            List <Vec3i> returnBlocks = new List <Vec3i>();

            if (BE.facing == null)
            {
                return(null);
            }

            if (BE.facing == "north" || BE.facing == "south")
            {
                checkDir = new Vec3i(1, 0, 0);
            }
            else if (BE.facing == "east" || BE.facing == "west")
            {
                checkDir = new Vec3i(0, 0, 1);
            }

            bool p1 = true;
            bool p2 = true;

            for (int i = 1; i <= maxSearchRange; i++)
            {
                Vec3i checkPos1 = new Vec3i(startPos.X + (checkDir.X * i), startPos.Y + (checkDir.Y * i), startPos.Z + (checkDir.Z * i));
                Vec3i checkPos2 = new Vec3i(startPos.X - (checkDir.X * i), startPos.Y - (checkDir.Y * i), startPos.Z - (checkDir.Z * i));

                Block block1 = world.BlockAccessor.GetBlock(checkPos1.ToBlockPos());
                Block block2 = world.BlockAccessor.GetBlock(checkPos2.ToBlockPos());

                PlugnFeatherBE blocke1 = world.BlockAccessor.GetBlockEntity(checkPos1.ToBlockPos()) as PlugnFeatherBE;
                PlugnFeatherBE blocke2 = world.BlockAccessor.GetBlockEntity(checkPos2.ToBlockPos()) as PlugnFeatherBE;

                //Debug.WriteLine(FirstCodePart(1));
                if (p1 == true)
                {
                    if (block1.Code.Path.Contains(FirstCodePart()) && block1.FirstCodePart(1) == this.FirstCodePart(1) && block1.Code.Path.Contains(FirstCodePart(3)) && block1.Code.Path.Contains(FirstCodePart(4)) && blocke1.master == null)
                    {
                        //Debug.WriteLine("block1");
                        //Debug.WriteLine(checkPos1);
                        returnBlocks.Add(checkPos1);
                    }
                    else
                    {
                        p1 = false;
                    }
                }

                if (p2 == true)
                {
                    if (block2.Code.Path.Contains(FirstCodePart()) && block2.FirstCodePart(1) == this.FirstCodePart(1) && block2.Code.Path.Contains(FirstCodePart(3)) && block2.Code.Path.Contains(FirstCodePart(4)) && blocke2.master == null)
                    {
                        //Debug.WriteLine("block2");
                        //Debug.WriteLine(checkPos2);
                        returnBlocks.Add(checkPos2);
                    }
                    else
                    {
                        p2 = false;
                    }
                }

                if (returnBlocks.Count == maxSearchRange - 1)
                {
                    break;
                }
            }

            return(returnBlocks);
        }
Exemplo n.º 3
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();
        }