Exemplo n.º 1
0
        public override bool TryPlaceBlockForWorldGen(IBlockAccessor blockAccessor, BlockPos pos, BlockFacing onBlockFace, LCGRandom worldGenRand)
        {
            Block block = blockAccessor.GetBlock(pos);


            if (block.IsReplacableBy(this) && block.SideSolid[BlockFacing.UP.Index])
            {
                blockAccessor.SetBlock(rndGearBlock().BlockId, pos);
                return(true);
            }

            pos   = pos.DownCopy();
            block = blockAccessor.GetBlock(pos);

            if (block.IsReplacableBy(this) && block.SideSolid[BlockFacing.UP.Index])
            {
                blockAccessor.SetBlock(rndGearBlock().BlockId, pos);
                return(true);
            }

            pos.Down();
            block = blockAccessor.GetBlock(pos);

            if (block.IsReplacableBy(this) && block.SideSolid[BlockFacing.UP.Index])
            {
                blockAccessor.SetBlock(rndGearBlock().BlockId, pos);
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        private bool TryPlace(Block block, int dx, int dy, int dz)
        {
            IBlockAccessor blockAccess = entity.World.BlockAccessor;
            BlockPos       pos         = entity.ServerPos.XYZ.AsBlockPos.Add(dx, dy, dz);
            Block          blockAtPos  = blockAccess.GetBlock(pos);

            pos.Y--;
            if (blockAtPos.IsReplacableBy(block) && blockAccess.GetSolidBlock(pos.X, pos.Y, pos.Z).CanAttachBlockAt(blockAccess, block, pos, BlockFacing.UP))
            {
                pos.Y++;
                blockAccess.SetBlock(block.BlockId, pos);

                // Instantly despawn the block again if it expired already
                BlockEntityTransient betran = blockAccess.GetBlockEntity(pos) as BlockEntityTransient;
                betran?.SetPlaceTime(TotalHoursUntilPlace);

                if (betran?.IsDueTransition() == true)
                {
                    blockAccess.SetBlock(0, pos);
                }

                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
        private bool TryPlace(Block block, int dx, int dy, int dz)
        {
            IBlockAccessor blockAccess = entity.World.BlockAccessor;
            BlockPos       pos         = entity.ServerPos.XYZ.AsBlockPos.Add(dx, dy, dz);
            Block          blockAtPos  = blockAccess.GetBlock(pos);

            if (blockAtPos.IsReplacableBy(block) && blockAccess.GetBlock(pos.X, pos.Y - 1, pos.Z).SideSolid[BlockFacing.UP.Index])
            {
                blockAccess.SetBlock(block.BlockId, pos);

                // Not the most elegant solution, but should work either way
                BlockEntityTransient betran = blockAccess.GetBlockEntity(pos) as BlockEntityTransient;
                if (betran != null)
                {
                    if (!betran.WasPlacedAtTotalHours(TotalHoursUntilPlace))
                    {
                        blockAccess.SetBlock(0, pos);
                    }
                }

                return(true);
            }

            return(false);
        }
Exemplo n.º 4
0
        public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref string failureCode)
        {
            BlockPos       abovePos = blockSel.Position.AddCopy(0, 1, 0);
            IBlockAccessor ba       = world.BlockAccessor;

            if (ba.GetBlockId(abovePos) == 0 && CanPlaceBlock(world, byPlayer, blockSel, ref failureCode))
            {
                BlockFacing[] horVer = SuggestedHVOrientation(byPlayer, blockSel);

                string knobOrientation = GetSuggestedKnobOrientation(ba, blockSel.Position, horVer[0]);

                AssetLocation downBlockCode = CodeWithVariants(new Dictionary <string, string>()
                {
                    { "horizontalorientation", horVer[0].Code },
                    { "part", "down" },
                    { "state", "closed" },
                    { "knobOrientation", knobOrientation }
                });

                Block downBlock = ba.GetBlock(downBlockCode);

                AssetLocation upBlockCode = downBlock.CodeWithVariant("part", "up");
                Block         upBlock     = ba.GetBlock(upBlockCode);

                ba.SetBlock(downBlock.BlockId, blockSel.Position);
                ba.SetBlock(upBlock.BlockId, abovePos);
                return(true);
            }

            return(false);
        }
Exemplo n.º 5
0
        public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel)
        {
            if (!world.TestPlayerAccessBlock(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak))
            {
                byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty();
                return(false);
            }

            BlockPos       abovePos = blockSel.Position.AddCopy(0, 1, 0);
            IBlockAccessor ba       = world.BlockAccessor;

            if (ba.GetBlockId(abovePos) == 0 && IsSuitablePosition(world, blockSel.Position))
            {
                BlockFacing[] horVer = SuggestedHVOrientation(byPlayer, blockSel);

                string knobOrientation = GetSuggestedKnobOrientation(ba, blockSel.Position, horVer[0]);

                AssetLocation downBlockCode = CodeWithParts(horVer[0].Code, "down", "closed", knobOrientation);
                Block         downBlock     = ba.GetBlock(downBlockCode);

                AssetLocation upBlockCode = CodeWithParts(horVer[0].Code, "up", "closed", knobOrientation);
                Block         upBlock     = ba.GetBlock(upBlockCode);

                ba.SetBlock(downBlock.BlockId, blockSel.Position);
                ba.SetBlock(upBlock.BlockId, abovePos);
                return(true);
            }

            return(false);
        }
Exemplo n.º 6
0
        private void GenHere(IBlockAccessor blockAccessor, BlockPos pos, LCGRandom worldGenRand)
        {
            int rnd = worldGenRand.NextInt(bases.Length);

            Block placeblock = api.World.GetBlock(CodeWithVariant("type", bases[rnd]));

            blockAccessor.SetBlock(placeblock.Id, pos);

            if (segments[rnd] != null)
            {
                placeblock = api.World.GetBlock(CodeWithVariant("type", segments[rnd]));

                int len = worldGenRand.NextInt(3);
                while (len-- > 0)
                {
                    pos.Down();
                    if (blockAccessor.GetBlock(pos).Replaceable > 6000)
                    {
                        blockAccessor.SetBlock(placeblock.Id, pos);
                    }
                }

                pos.Down();
                placeblock = api.World.GetBlock(CodeWithVariant("type", ends[rnd]));
                if (blockAccessor.GetBlock(pos).Replaceable > 6000)
                {
                    blockAccessor.SetBlock(placeblock.Id, pos);
                }
            }
        }
Exemplo n.º 7
0
        public void GenFrondAndFruits(BlockPos pos, IBlockAccessor blockAccessor, double treesize, int f)
        {
            double scalar  = (treesize - parts.Length) / maxTreeSize;
            int    palmnum = (int)Math.Round((scalar * 3.0));

            for (int i = 0; i < cardinaloffsets.Length; i++)
            {
                BlockPos vPos   = new BlockPos(pos.X + cardinaloffsets[i].X, pos.Y + cardinaloffsets[i].Y, pos.Z + cardinaloffsets[i].Z);
                BlockPos dPos   = new BlockPos(pos.X + cardinaloffsets[i].X, pos.Y + cardinaloffsets[i].Y - 1, pos.Z + cardinaloffsets[i].Z);
                Block    block  = blockAccessor.GetBlock(vPos);
                Block    dblock = blockAccessor.GetBlock(dPos);

                if (block.IsReplacableBy(this))
                {
                    Block zBlock = blockAccessor.GetBlock(frond[i].CodeWithPart(palmnum.ToString(), 1));

                    if (zBlock != null)
                    {
                        blockAccessor.SetBlock(zBlock.BlockId, vPos);
                    }
                }

                if (dblock.IsReplacableBy(this) && fruits[f] != null)
                {
                    blockAccessor.SetBlock(fruits[f][i].BlockId, dPos);
                }
            }
        }
Exemplo n.º 8
0
        public override bool TryPlaceBlockForWorldGen(IBlockAccessor blockAccessor, BlockPos pos, BlockFacing onBlockFace, Random worldgenRand)
        {
            //blockAccessor.SetBlock(blockAccessor.GetBlock(new AssetLocation("creativeblock-60")).BlockId, pos);

            for (int i = 1; i < 4; i++)
            {
                Block aboveBlock = blockAccessor.GetBlock(pos.X, pos.Y - i, pos.Z);

                if (
                    (aboveBlock.BlockMaterial == EnumBlockMaterial.Wood || aboveBlock.BlockMaterial == EnumBlockMaterial.Plant) && aboveBlock.SideSolid[BlockFacing.DOWN.Index]
                    )
                {
                    BlockPos atpos = new BlockPos(pos.X, pos.Y - i - 1, pos.Z);

                    Block block = blockAccessor.GetBlock(atpos);

                    if (
                        block.BlockMaterial == EnumBlockMaterial.Wood &&
                        aboveBlock.BlockMaterial == EnumBlockMaterial.Wood &&
                        blockAccessor.GetBlock(pos.X, pos.Y - i - 2, pos.Z).BlockMaterial == EnumBlockMaterial.Wood &&
                        aboveBlock.LastCodePart() == "ud"
                        )
                    {
                        blockAccessor.SetBlock(blockAccessor.GetBlock(new AssetLocation("wildbeehive-inlog-" + aboveBlock.FirstCodePart(2))).BlockId, atpos);
                        if (EntityClass != null)
                        {
                            blockAccessor.SpawnBlockEntity(EntityClass, atpos);
                        }

                        return(true);
                    }

                    if (block.BlockMaterial != EnumBlockMaterial.Plant && block.BlockMaterial != EnumBlockMaterial.Air)
                    {
                        continue;
                    }

                    int dx       = pos.X % blockAccessor.ChunkSize;
                    int dz       = pos.Z % blockAccessor.ChunkSize;
                    int surfacey = blockAccessor.GetMapChunkAtBlockPos(atpos).WorldGenTerrainHeightMap[dz * blockAccessor.ChunkSize + dx];

                    if (pos.Y - surfacey < 4)
                    {
                        return(false);
                    }

                    blockAccessor.SetBlock(BlockId, atpos);
                    if (EntityClass != null)
                    {
                        blockAccessor.SpawnBlockEntity(EntityClass, atpos);
                    }
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 9
0
        public override bool TryPlaceBlockForWorldGen(IBlockAccessor blockAccessor, BlockPos pos, BlockFacing onBlockFace, LCGRandom worldGenRand)
        {
            blockAccessor.SetBlock(BlockId, pos);

            if (soilBlockId > 0 && blockAccessor.GetBlock(pos.X, pos.Y - 1, pos.Z).BlockMaterial == EnumBlockMaterial.Stone)
            {
                blockAccessor.SetBlock(soilBlockId, pos.DownCopy());
            }

            return(true);
        }
Exemplo n.º 10
0
        //mostly copied from BlockBeehive
        public override bool TryPlaceBlockForWorldGen(IBlockAccessor blockAccessor, BlockPos pos, BlockFacing onBlockFace, LCGRandom worldgenRand)
        {
            Block cinnamon = blockAccessor.GetBlock(new AssetLocation("harvestcraftloader:fruits-cinnamon-ripe"));

            for (int i = 1; i < 4; i++)
            {
                Block aboveBlock = blockAccessor.GetBlock(pos.X, pos.Y - i, pos.Z);

                if ((aboveBlock.BlockMaterial == EnumBlockMaterial.Wood || aboveBlock.BlockMaterial == EnumBlockMaterial.Leaves) && aboveBlock.SideSolid[BlockFacing.DOWN.Index])
                {
                    BlockPos atpos = new BlockPos(pos.X, pos.Y - i - 1, pos.Z);

                    Block block = blockAccessor.GetBlock(atpos);

                    if (block.BlockMaterial == EnumBlockMaterial.Wood && aboveBlock.BlockMaterial == EnumBlockMaterial.Wood && blockAccessor.GetBlock(pos.X, pos.Y - i - 2, pos.Z).BlockMaterial == EnumBlockMaterial.Wood && aboveBlock.LastCodePart() == "ud")
                    {
                        blockAccessor.SetBlock(cinnamon.BlockId, atpos);
                        if (EntityClass != null)
                        {
                            blockAccessor.SpawnBlockEntity(EntityClass, atpos);
                        }

                        return(true);
                    }

                    if (aboveBlock.BlockMaterial == EnumBlockMaterial.Wood || Id == cinnamon.Id || (block.BlockMaterial != EnumBlockMaterial.Leaves && block.BlockMaterial != EnumBlockMaterial.Air))
                    {
                        continue;
                    }

                    int dx       = pos.X % blockAccessor.ChunkSize;
                    int dz       = pos.Z % blockAccessor.ChunkSize;
                    int surfacey = blockAccessor.GetMapChunkAtBlockPos(atpos).WorldGenTerrainHeightMap[dz * blockAccessor.ChunkSize + dx];

                    if (pos.Y - surfacey < 4)
                    {
                        return(false);
                    }

                    blockAccessor.SetBlock(BlockId, atpos);
                    if (EntityClass != null)
                    {
                        blockAccessor.SpawnBlockEntity(EntityClass, atpos);
                    }

                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 11
0
        private void CmdGenHouse(IServerPlayer player, int groupId, CmdArgs args)
        {
            IBlockAccessor blockAccessor = api.World.GetBlockAccessorBulkUpdate(true, true);
            int            blockID       = api.WorldManager.GetBlockId(new AssetLocation("log-placed-oak-ud"));

            BlockPos pos = player.Entity.Pos.AsBlockPos;

            for (int dx = -3; dx <= 3; dx++)
            {
                for (int dz = -3; dz <= 3; dz++)
                {
                    for (int dy = 0; dy <= 3; dy++)
                    {
                        if (Math.Abs(dx) != 3 && Math.Abs(dz) != 3 && dy < 3)
                        {
                            continue;                                                   // Hollow
                        }
                        if (dx == -3 && dz == 0 && dy < 2)
                        {
                            continue;                                // Door
                        }
                        blockAccessor.SetBlock(blockID, pos.AddCopy(dx, dy, dz));
                    }
                }
            }

            blockAccessor.Commit();
        }
Exemplo n.º 12
0
        private void tryPlaceDecoDown(BlockPos blockPos, IBlockAccessor blockAccessor, Random worldGenRand)
        {
            if (blockAccessor.GetBlockId(blockPos) != 0)
            {
                return;
            }

            int tries = 7;

            while (tries-- > 0)
            {
                blockPos.Y--;
                Block block = blockAccessor.GetBlock(blockPos);
                if (block.IsLiquid())
                {
                    return;
                }
                if (block.SideSolid[BlockFacing.DOWN.Index])
                {
                    blockPos.Y++;
                    blockAccessor.SetBlock(DecoBlocksFloor[worldGenRand.Next(DecoBlocksFloor.Length)].BlockId, blockPos);
                    return;
                }
            }
        }
Exemplo n.º 13
0
        public override bool TryPlaceBlockForWorldGen(IBlockAccessor blockAccessor, BlockPos pos, BlockFacing onBlockFace)
        {
            Block block = blockAccessor.GetBlock(pos);

            if (!block.IsReplacableBy(this))
            {
                return(false);
            }

            Block belowBlock = blockAccessor.GetBlock(pos.X, pos.Y - 1, pos.Z);

            if (belowBlock.Fertility > 0)
            {
                if (block.IsWater())
                {
                    return(TryPlaceBlockInWater(blockAccessor, pos.UpCopy()));
                }

                Block placingBlock = blockAccessor.GetBlock(CodeWithParts("free", "normal"));
                if (placingBlock == null)
                {
                    return(false);
                }
                blockAccessor.SetBlock(placingBlock.BlockId, pos);
                return(true);
            }

            if (belowBlock.IsWater())
            {
                return(TryPlaceBlockInWater(blockAccessor, pos));
            }

            return(false);
        }
Exemplo n.º 14
0
        public override bool TryPlaceBlockForWorldGen(IBlockAccessor blockAccessor, BlockPos pos, BlockFacing onBlockFace, LCGRandom worldGenRand)
        {
            if (!HasBeachyGround(blockAccessor, pos))
            {
                return(false);
            }


            tmpDict["type"] = types[worldGenRand.NextInt(types.Length)];

            if (worldGenRand.NextInt(100) < 8)
            {
                tmpDict["color"] = rarecolors[worldGenRand.NextInt(rarecolors.Length)];
            }
            else
            {
                tmpDict["color"] = colors[worldGenRand.NextInt(colors.Length)];
            }


            Block block = blockAccessor.GetBlock(CodeWithVariants(tmpDict));

            if (block == null)
            {
                return(false);
            }

            if (blockAccessor.GetBlock(pos).IsReplacableBy(this))
            {
                blockAccessor.SetBlock(block.BlockId, pos);
                return(true);
            }

            return(false);
        }
Exemplo n.º 15
0
        private void BlockLineup(BlockPos pos)
        {
            IBlockAccessor blockAccess = api.WorldManager.GetBlockAccessorBulkUpdate(true, true);

            Block[] blocks = api.WorldManager.BlockTypes;


            List <Block> existingBlocks = new List <Block>();

            for (int i = 0; i < blocks.Length; i++)
            {
                if (blocks[i] == null || blocks[i].Code == null)
                {
                    continue;
                }
                existingBlocks.Add(blocks[i]);
            }

            int width = (int)Math.Sqrt(existingBlocks.Count);

            FillArea(0, pos.AddCopy(0, 0, 0), pos.AddCopy(width + 1, 10, width + 1));

            for (int i = 0; i < existingBlocks.Count; i++)
            {
                if (existingBlocks[i] == null || existingBlocks[i].Code == null)
                {
                    continue;
                }

                blockAccess.SetBlock(blocks[i].BlockId, pos.AddCopy(i / width, 0, i % width));
            }

            blockAccess.Commit();
        }
Exemplo n.º 16
0
        private void tryPlaceDecoUp(BlockPos blockPos, IBlockAccessor blockAccessor, LCGRandom worldgenRand)
        {
            if (blockAccessor.GetBlockId(blockPos) != 0)
            {
                return;
            }

            int tries = 7;

            while (tries-- > 0)
            {
                blockPos.Y++;
                Block block = blockAccessor.GetBlock(blockPos);
                if (block.IsLiquid())
                {
                    return;
                }
                if (block.SideSolid[BlockFacing.DOWN.Index])
                {
                    blockPos.Y--;
                    Block placeblock = DecoBlocksCeiling[worldgenRand.NextInt(DecoBlocksCeiling.Length)];
                    blockAccessor.SetBlock(placeblock.BlockId, blockPos);
                    return;
                }
            }
        }
Exemplo n.º 17
0
        public override bool ApplyToolBuild(WorldEdit worldEdit, Block block, BlockPos pos, ushort oldBlockId, BlockFacing onBlockFace, Vec3f hitPos, bool didOffset)
        {
            if (heights == null)
            {
                return(false);
            }

            worldEdit.Good("Ok, placing blocks, this may take a while");

            int      width  = heights.GetLength(0);
            int      length = heights.GetLength(1);
            BlockPos tmpPos = new BlockPos();

            IBlockAccessor blockAccessorBulk = worldEdit.sapi.World.BulkBlockAccessor;

            for (int x = 0; x < width; x++)
            {
                for (int z = 0; z < length; z++)
                {
                    int height = heights[x, z];

                    tmpPos.Set(pos.X + x - width / 2, pos.Y, pos.Z + z - length / 2);

                    for (int y = 0; y < height; y++)
                    {
                        blockAccessorBulk.SetBlock(block.BlockId, tmpPos);
                        tmpPos.Up();
                    }
                }
            }

            blockAccessorBulk.Commit();

            return(false);
        }
        public override bool TryPlaceBlockForWorldGen(IBlockAccessor blockAccessor, BlockPos pos, BlockFacing onBlockFace, LCGRandom worldgenRandom)
        {
            var dBlock = blockAccessor.GetBlock(pos.X, pos.Y - 1, pos.Z);

            if (dBlock.Fertility <= 20)
            {
                return(false);
            }

            var climate = blockAccessor.GetClimateAt(pos, EnumGetClimateMode.WorldGenValues);
            int rnd     = worldgenRandom.NextInt(WorldGenConds.Length);

            int len = WorldGenConds.Length;

            for (int i = 0; i < len; i++)
            {
                var conds = WorldGenConds[(i + rnd) % len];
                if (conds.MinTemp <= climate.Temperature && conds.MaxTemp >= climate.Temperature && conds.MinRain <= climate.Rainfall && conds.MaxRain >= climate.Rainfall && worldgenRandom.NextFloat() <= conds.Chance)
                {
                    blockAccessor.SetBlock(BlockId, pos);
                    blockAccessor.SpawnBlockEntity(EntityClass, pos);
                    var be = blockAccessor.GetBlockEntity(pos) as BlockEntityFruitTreeBranch;

                    be.TreeType          = conds.Type;
                    be.InitAfterWorldGen = true;

                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 19
0
        void TreeLineup(IServerPlayer player, CmdArgs arguments)
        {
            if (arguments.Length < 2)
            {
                player.SendMessage(groupId, "/wgen treelineup {treeWorldPropertyCode} [0.1 - 3]", EnumChatType.CommandError);
                return;
            }

            EntityPos      pos           = player.Entity.Pos;
            BlockPos       center        = pos.HorizontalAheadCopy(25).AsBlockPos;
            IBlockAccessor blockAccessor = api.WorldManager.GetBlockAccessorBulkUpdate(true, true, true);

            int size = 12;

            for (int dx = -2 * size; dx < 2 * size; dx++)
            {
                for (int dz = -size; dz < size; dz++)
                {
                    for (int dy = 0; dy < 2 * size; dy++)
                    {
                        blockAccessor.SetBlock(0, center.AddCopy(dx, dy, dz));
                    }
                }
            }


            treeGenerators.ReloadTreeGenerators();
            treeGenerators.RunGenerator(new AssetLocation(arguments[1]), blockAccessor, center.AddCopy(0, -1, 0));
            treeGenerators.RunGenerator(new AssetLocation(arguments[1]), blockAccessor, center.AddCopy(-9, -1, 0));
            treeGenerators.RunGenerator(new AssetLocation(arguments[1]), blockAccessor, center.AddCopy(9, -1, 0));

            blockAccessor.Commit();
        }
Exemplo n.º 20
0
        public override bool TryPlaceBlockForWorldGen(IBlockAccessor blockAccessor, BlockPos pos, BlockFacing onBlockFace, LCGRandom worldGenRand)
        {
            Block block = blockAccessor.GetBlock(pos);

            if (!block.IsReplacableBy(this))
            {
                return(false);
            }

            Block belowBlock = blockAccessor.GetBlock(pos.X, pos.Y - 1, pos.Z);

            if (belowBlock.Fertility > 0)
            {
                Block placingBlock = blockAccessor.GetBlock(CodeWithParts("free"));
                if (placingBlock == null)
                {
                    return(false);
                }
                blockAccessor.SetBlock(placingBlock.BlockId, pos);
                return(true);
            }

            if (belowBlock.LiquidCode == "water")
            {
                return(TryPlaceBlockInWater(blockAccessor, pos));
            }

            return(false);
        }
Exemplo n.º 21
0
        public void GenPalmTree(IBlockAccessor bA, BlockPos pos, double?sizeRnd1 = null, double?fruitRnd1 = null, double?frondRnd1 = null, int?fruitNum = null)
        {
            double sizeRnd  = sizeRnd1 ?? api.World.Rand.NextDouble();
            double fruitRnd = fruitRnd1 ?? api.World.Rand.NextDouble();
            double frondRnd = frondRnd1 ?? api.World.Rand.NextDouble();
            int    fruiti   = fruitNum ?? (int)Math.Round(fruitRnd * 2.0);

            while (!CanGenPalm(bA, pos.UpCopy(), sizeRnd))
            {
                sizeRnd -= 0.01;
                if (sizeRnd < 0)
                {
                    bA.SetBlock(saplings[fruiti], pos.UpCopy());
                    return;
                }
            }

            int[] stretched = trunk.Stretch((int)(sizeRnd * maxTreeSize));
            for (int i = 0; i < stretched.Length; i++)
            {
                if (bA.GetBlock(pos).IsReplacableBy(bA.GetBlock(tip)))
                {
                    bA.SetBlock(stretched[i], pos);
                }
                pos.Y++;
            }
            bA.SetBlock(tip, pos);
            int frondi = (int)Math.Round(frondRnd * 3.0);

            for (int i = 0; i < cardinaloffsets.Length; i++)
            {
                var      c      = cardinaloffsets[i];
                BlockPos offset = pos.AddCopy(c.X, c.Y, c.Z);
                if (bA.GetBlock(offset).Id != 0)
                {
                    continue;
                }

                int frondID = bA.GetBlock(bA.GetBlock(frond[i]).CodeWithPart(frondi.ToString(), 1)).Id;

                bA.SetBlock(frondID, offset);
                if (fruits[fruiti] != null)
                {
                    bA.SetBlock(fruits[fruiti][i], offset.Add(0, -1, 0));
                }
            }
        }
Exemplo n.º 22
0
        public override bool TryPlaceBlockForWorldGen(IBlockAccessor blockAccessor, BlockPos pos, BlockFacing onBlockFace, LCGRandom worldGenRand)
        {
            if (blockAccessor.GetBlockId(pos) != 0)
            {
                return(false);
            }

            int surfaceY = blockAccessor.GetTerrainMapheightAt(pos);

            if (surfaceY - pos.Y < 30 || pos.Y < 25)
            {
                return(false);
            }

            BlockPos cavepos = getSemiLargeCavePos(blockAccessor, pos);

            if (cavepos == null)
            {
                return(false);
            }

            int dy = 0;

            while (dy < 15 && !blockAccessor.GetBlock(cavepos.X, cavepos.Y + dy, cavepos.Z).SideSolid[BlockFacing.UP.Index])
            {
                dy++;
            }
            if (dy >= 15)
            {
                return(false);
            }
            blockAccessor.SetBlock(this.BlockId, cavepos.AddCopy(0, dy, 0));
            if (EntityClass != null)
            {
                blockAccessor.SpawnBlockEntity(EntityClass, cavepos.AddCopy(0, dy, 0));
            }

            BlockPos tmppos = new BlockPos();
            int      tries  = 55 + worldGenRand.NextInt(55);

            while (tries-- > 0)
            {
                int offX = worldGenRand.NextInt(15) - 7;
                int offY = worldGenRand.NextInt(15) - 7;
                int offZ = worldGenRand.NextInt(15) - 7;

                if (worldGenRand.NextDouble() < 0.4)
                {
                    tryPlaceDecoUp(tmppos.Set(cavepos.X + offX, cavepos.Y + offY, cavepos.Z + offZ), blockAccessor, worldGenRand);
                }
                else
                {
                    tryPlaceDecoDown(tmppos.Set(cavepos.X + offX, cavepos.Y + offY, cavepos.Z + offZ), blockAccessor, worldGenRand);
                }
            }

            return(true);
        }
Exemplo n.º 23
0
        private void GenerateGeode(Block quartzblock, IBlockAccessor blockAccessor, BlockPos pos)
        {
            float rx = 3;
            float ry = 3;
            float rz = 3;

            float xRadSq = rx * rx;
            float yRadSq = ry * ry;
            float zRadSq = rz * rz;

            int cnt = 0;

            for (float dx = -rx; dx <= rx; dx++)
            {
                float xdistrel = (dx * dx) / xRadSq;

                for (float dy = -ry; dy <= ry; dy++)
                {
                    float ydistrel = (dy * dy) / yRadSq;

                    for (float dz = -rz; dz <= rz; dz++)
                    {
                        float zdistrel = (dz * dz) / zRadSq;

                        if (xdistrel + ydistrel + zdistrel > 1)
                        {
                            continue;
                        }

                        blockAccessor.SetBlock(0, pos);
                        cnt++;
                    }
                }
            }



            for (float dx = -rx; dx < rx; dx++)
            {
                float xdist = (dx * dx) / (rx * rx);

                for (float dy = -ry; dy < ry; dy++)
                {
                    float ydist = (dy * dy) / (ry * ry);

                    for (float dz = -rz; dz < rz; dz++)
                    {
                        float zdist = (dz * dz) / (rz * rz);
                        if (xdist + ydist + zdist > 1)
                        {
                            continue;
                        }

                        TryPlaceInsideGeode(blockAccessor, pos);
                    }
                }
            }
        }
        public void GrowTree(IBlockAccessor blockAccessor, BlockPos pos, string type)
        {
            blockAccessor.SetBlock(BlockId, pos);
            blockAccessor.SpawnBlockEntity(EntityClass, pos);
            var be = blockAccessor.GetBlockEntity(pos) as BlockEntityFruitTreeBranch;

            be.TreeType          = type;
            be.InitAfterWorldGen = true;
        }
Exemplo n.º 25
0
 protected virtual int PlaceReplaceOnlyAirReplaceMeta(IBlockAccessor blockAccessor, BlockPos pos, Block oldBlock, Block newBlock)
 {
     if (oldBlock.BlockId == 0)
     {
         blockAccessor.SetBlock((newBlock == fillerBlock || newBlock == pathwayBlock) ? empty : newBlock.BlockId, pos);
         return(1);
     }
     return(0);
 }
Exemplo n.º 26
0
 protected virtual int PlaceReplaceOnlyAirKeepMeta(IBlockAccessor blockAccessor, BlockPos pos, Block oldBlock, Block newBlock)
 {
     if (oldBlock.BlockId == 0)
     {
         blockAccessor.SetBlock(newBlock.BlockId, pos);
         return(1);
     }
     return(0);
 }
Exemplo n.º 27
0
        protected virtual bool TryPlaceBlockInWater(IBlockAccessor blockAccessor, BlockPos pos)
        {
            Block belowBlock = blockAccessor.GetBlock(pos.X, pos.Y - 2, pos.Z);

            if (belowBlock.Fertility > 0)
            {
                blockAccessor.SetBlock(blockAccessor.GetBlock(CodeWithParts("water")).BlockId, pos.AddCopy(0, -1, 0));
                return(true);
            }
            return(false);
        }
Exemplo n.º 28
0
        public override bool TryPlaceBlockForWorldGen(IBlockAccessor blockAccessor, BlockPos pos, BlockFacing onBlockFace)
        {
            string facings = getSolidFacesAtPos(blockAccessor, pos);

            if (facings.Length > 0)
            {
                Block block = blockAccessor.GetBlock(CodeWithPath(FirstCodePart() + "-" + facings));
                blockAccessor.SetBlock(block.BlockId, pos);
            }

            return(true);
        }
Exemplo n.º 29
0
        void TryPlaceInsideGeode(IBlockAccessor blockAccessor, BlockPos pos)
        {
            for (int i = 0; i < 6; i++)
            {
                BlockFacing facing = BlockFacing.ALLFACES[5 - i];

                if (blockAccessor.GetBlock(pos.UpCopy()).SideSolid[facing.Index])
                {
                    blockAccessor.SetBlock(FacingBlocks[facing.Index].BlockId, pos);
                    return;
                }
            }
        }
Exemplo n.º 30
0
        public bool TryPlace(IBlockAccessor bA, BlockPos pos, EntityItem item)
        {
            Block rBlock = bA.GetBlock(pos);
            Block dBlock = bA.GetBlock(pos.DownCopy());

            if (rBlock.IsReplacableBy(this) && !dBlock.IsReplacableBy(this))
            {
                bA.SetBlock(BlockId, pos);
                item.Die(EnumDespawnReason.Removed, null);
                return(true);
            }
            return(false);
        }