Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
        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);
        }
Ejemplo n.º 4
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);
        }
        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;
        }
Ejemplo n.º 6
0
        public override bool TryPlaceBlockForWorldGen(IBlockAccessor blockAccessor, BlockPos pos, BlockFacing onBlockFace, LCGRandom worldGenRand)
        {
            BlockPos rootPos = onBlockFace.IsHorizontal ? pos.AddCopy(onBlockFace) : pos.AddCopy(onBlockFace.Opposite);

            var block = blockAccessor.GetBlock(rootPos);

            if (!block.HasBehavior <BehaviorMyceliumHost>())
            {
                rootPos.Down();
                block = blockAccessor.GetBlock(rootPos);
                if (!block.HasBehavior <BehaviorMyceliumHost>())
                {
                    return(false);
                }
            }

            blockAccessor.SpawnBlockEntity("Mycelium", rootPos);
            (blockAccessor.GetBlockEntity(rootPos) as BlockEntityMycelium).OnGenerated(blockAccessor, worldGenRand, this);
            return(true);
        }
Ejemplo n.º 7
0
        public void GenPalmTree(IBlockAccessor blockAccessor, BlockPos pos, int fruit)
        {
            Block block = blockAccessor.GetBlock(pos.DownCopy());

            if (block.FirstCodePart() == "sand")
            {
                for (int i = 0; i < bottomOffsets.Length; i++)
                {
                    Block d = blockAccessor.GetBlock(pos.X + bottomOffsets[i].X, pos.Y + bottomOffsets[i].Y, pos.Z + bottomOffsets[i].Z);
                    if (d.LiquidCode == "water")
                    {
                        for (int k = 0; k < offsets.Length; k++)
                        {
                            Block c = blockAccessor.GetBlock(pos.X + offsets[i].X, pos.Y + offsets[i].Y, pos.Z + offsets[i].Z);
                            if (c.Class == Class)
                            {
                                return;
                            }
                        }
                        rand.InitPositionSeed(pos.X, pos.Y);
                        Block[] stretchedTrunk = trunk.Stretch((int)(rand.NextDouble() * (maxTreeSize)));

                        BlockPos top = new BlockPos(pos.X, pos.Y + stretchedTrunk.Length, pos.Z);
                        for (int j = 0; j < stretchedTrunk.Length; j++)
                        {
                            blockAccessor.SetBlock(stretchedTrunk[j].BlockId, new BlockPos(pos.X, pos.Y + j, pos.Z));
                        }
                        blockAccessor.SetBlock(tip.BlockId, top);
                        blockAccessor.SpawnBlockEntity("PalmTree", top);

                        GenFrondAndFruits(top, blockAccessor, stretchedTrunk.Length, fruit);
                        break;
                    }
                }
            }
            return;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Places all the entities and blocks in the schematic at the position.
        /// </summary>
        /// <param name="blockAccessor"></param>
        /// <param name="worldForCollectibleResolve"></param>
        /// <param name="startPos"></param>
        public void PlaceEntitiesAndBlockEntities(IBlockAccessor blockAccessor, IWorldAccessor worldForCollectibleResolve, BlockPos startPos)
        {
            BlockPos curPos = new BlockPos();

            int schematicSeed = worldForCollectibleResolve.Rand.Next();

            foreach (var val in BlockEntities)
            {
                uint index = val.Key;
                int  dx    = (int)(index & 0x1ff);
                int  dy    = (int)((index >> 20) & 0x1ff);
                int  dz    = (int)((index >> 10) & 0x1ff);

                curPos.Set(dx + startPos.X, dy + startPos.Y, dz + startPos.Z);

                BlockEntity be = blockAccessor.GetBlockEntity(curPos);


                // Block entities need to be manually initialized for world gen block access
                if (be == null && blockAccessor is IWorldGenBlockAccessor)
                {
                    Block block = blockAccessor.GetBlock(curPos);

                    if (block.EntityClass != null)
                    {
                        blockAccessor.SpawnBlockEntity(block.EntityClass, curPos);
                        be = blockAccessor.GetBlockEntity(curPos);
                    }
                }

                if (be != null)
                {
                    Block block = blockAccessor.GetBlock(curPos);
                    if (block.EntityClass != worldForCollectibleResolve.ClassRegistry.GetBlockEntityClass(be.GetType()))
                    {
                        worldForCollectibleResolve.Logger.Warning("Could not import block entity data for schematic at {0}. There is already {1}, expected {2}. Probably overlapping ruins.", curPos, be.GetType(), block.EntityClass);
                        continue;
                    }

                    ITreeAttribute tree = DecodeBlockEntityData(val.Value);
                    tree.SetInt("posx", curPos.X);
                    tree.SetInt("posy", curPos.Y);
                    tree.SetInt("posz", curPos.Z);

                    be.FromTreeAttributes(tree, worldForCollectibleResolve);
                    be.OnLoadCollectibleMappings(worldForCollectibleResolve, BlockCodes, ItemCodes, schematicSeed);
                    be.Pos = curPos.Copy();
                }
            }

            foreach (string entityData in Entities)
            {
                using (MemoryStream ms = new MemoryStream(Ascii85.Decode(entityData)))
                {
                    BinaryReader reader = new BinaryReader(ms);

                    string className = reader.ReadString();
                    Entity entity    = worldForCollectibleResolve.ClassRegistry.CreateEntity(className);

                    entity.FromBytes(reader, false);
                    entity.DidImportOrExport(startPos);

                    // Not ideal but whatever
                    if (blockAccessor is IWorldGenBlockAccessor)
                    {
                        (blockAccessor as IWorldGenBlockAccessor).AddEntity(entity);
                    }
                    else
                    {
                        worldForCollectibleResolve.SpawnEntity(entity);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public override bool TryPlaceBlockForWorldGen(IBlockAccessor blockAccessor, BlockPos pos, BlockFacing onBlockFace, LCGRandom worldgenRand)
        {
            //blockAccessor.SetBlock(blockAccessor.GetBlock(new AssetLocation("creativeblock-60")).BlockId, pos);

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

                var abovemat = aboveBlock.GetBlockMaterial(blockAccessor, atPos);

                if ((abovemat == EnumBlockMaterial.Wood || abovemat == EnumBlockMaterial.Leaves) && aboveBlock.SideSolid[BlockFacing.DOWN.Index])
                {
                    atPos.Set(pos.X, pos.Y - i - 1, pos.Z);

                    Block block = blockAccessor.GetBlock(atPos);
                    var   mat   = block.GetBlockMaterial(blockAccessor, atPos);

                    BlockPos belowPos = new BlockPos(pos.X, pos.Y - i - 2, pos.Z);

                    if (
                        mat == EnumBlockMaterial.Wood &&
                        abovemat == EnumBlockMaterial.Wood &&
                        blockAccessor.GetBlock(belowPos).GetBlockMaterial(blockAccessor, belowPos) == EnumBlockMaterial.Wood &&
                        aboveBlock.LastCodePart() == "ud"
                        )
                    {
                        Block inlogblock = blockAccessor.GetBlock(new AssetLocation("wildbeehive-inlog-" + aboveBlock.Variant["wood"]));

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

                        return(true);
                    }

                    if (mat != EnumBlockMaterial.Leaves && mat != 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);
                    }

                    //BlockPos test = pos.Copy();
                    //test.Y = 160;
                    //blockAccessor.SetBlock(blockAccessor.GetBlock(new AssetLocation("creativeblock-60")).BlockId, test);

                    return(true);
                }
            }

            return(false);
        }