示例#1
0
        public override void OnTick(Level level, bool isRandom)
        {
            if (!isRandom)
            {
                return;
            }

            var lightLevel = level.GetSubtractedLight(Coordinates);

            if (lightLevel >= 9 && new Random().Next(7) == 0)
            {
                SmallTreeGenerator generator = null;
                Block log    = null;
                Block leaves = null;
                if (Metadata == 0)                 // Oak
                {
                    log = new Log()
                    {
                        Metadata = 0
                    };
                    leaves = new Leaves()
                    {
                        Metadata = 0
                    };
                    generator = new SmallTreeGenerator(log, leaves, 4);
                }
                else if (Metadata == 1)                 // Spruce
                {
                    log = new Log()
                    {
                        Metadata = 1
                    };
                    leaves = new Leaves()
                    {
                        Metadata = 1
                    };
                    //generator = new SmallTreeGenerator(log, leaves, 4);
                }
                else if (Metadata == 2)                 // Birch
                {
                    log = new Log()
                    {
                        Metadata = 2
                    };
                    leaves = new Leaves()
                    {
                        Metadata = 2
                    };
                    generator = new SmallTreeGenerator(log, leaves, 5);
                }
                else if (Metadata == 3)                 // Jungle
                {
                    log = new Log()
                    {
                        Metadata = 3
                    };
                    leaves = new Leaves()
                    {
                        Metadata = 3
                    };
                    //generator = new SmallTreeGenerator(log, leaves, 4 + new Random().Next(7));
                }
                else if (Metadata == 4)                 // Acacia
                {
                    log = new Log2()
                    {
                        Metadata = 0
                    };
                    leaves = new Leaves2()
                    {
                        Metadata = 0
                    };
                    //generator = new SmallTreeGenerator(log, leaves, 5);
                }
                else if (Metadata == 5)                 // Dark oak
                {
                    log = new Log2()
                    {
                        Metadata = 1
                    };
                    leaves = new Leaves2()
                    {
                        Metadata = 1
                    };
                    //generator = new SmallTreeGenerator(log, leaves, 5);
                }

                if (generator == null)
                {
                    return;
                }

                level.SetAir(Coordinates);

                if (!generator.Generate(level, Coordinates))
                {
                    level.SetBlock(this);
                }
            }
        }
示例#2
0
        //[StateBit] public bool AgeBit { get; set; } = false;
        //[StateEnum("oak", "spruce", "birch", "jungle", "acacia", "dark_oak")]
        //public string SaplingType { get; set; } = "oak";

        public override void OnTick(Level level, bool isRandom)
        {
            if (!isRandom)
            {
                return;
            }

            var lightLevel = level.GetSubtractedLight(Coordinates);

            if (lightLevel >= 9 && new Random().Next(7) == 0)
            {
                SmallTreeGenerator generator = null;
                Block log    = null;
                Block leaves = null;
                switch (SaplingType)
                {
                case "oak":
                    log = new Log {
                        OldLogType = SaplingType
                    };
                    leaves = new Leaves {
                        OldLeafType = SaplingType
                    };
                    generator = new SmallTreeGenerator(log, leaves, 4);
                    break;

                case "spruce":
                    log = new Log {
                        OldLogType = SaplingType
                    };
                    leaves = new Leaves {
                        OldLeafType = SaplingType
                    };
                    //generator = new SmallTreeGenerator(log, leaves, 4);
                    break;

                case "birch":
                    log = new Log {
                        OldLogType = SaplingType
                    };
                    leaves = new Leaves {
                        OldLeafType = SaplingType
                    };
                    generator = new SmallTreeGenerator(log, leaves, 5);
                    break;

                case "jungle":
                    log = new Log {
                        OldLogType = SaplingType
                    };
                    leaves = new Leaves {
                        OldLeafType = SaplingType
                    };
                    //generator = new SmallTreeGenerator(log, leaves, 4 + new Random().Next(7));
                    break;

                case "acacia":
                    log = new Log {
                        OldLogType = SaplingType
                    };
                    leaves = new Leaves {
                        OldLeafType = SaplingType
                    };
                    //generator = new SmallTreeGenerator(log, leaves, 5);
                    break;

                case "dark_oak":
                    log = new Log {
                        OldLogType = SaplingType
                    };
                    leaves = new Leaves {
                        OldLeafType = SaplingType
                    };
                    //generator = new SmallTreeGenerator(log, leaves, 5);
                    break;
                }

                if (generator == null)
                {
                    return;
                }

                level.SetAir(Coordinates);

                if (!generator.Generate(level, Coordinates))
                {
                    level.SetBlock(this);
                }
            }
        }