Example #1
0
        public NativeTreeDefinition ToNative(VoxelTypeManager typeManager)
        {
            NativeTreeDefinition def = new NativeTreeDefinition();

            def.maxHeight        = maxHeight;
            def.minHeight        = minHeight;
            def.minLeafClearance = minLeafClearance;
            def.leafID           = (leafType == null) ? (VoxelTypeID)VoxelTypeID.AIR_ID : typeManager.GetId(leafType);
            def.logID            = (logType == null) ? (VoxelTypeID)VoxelTypeID.AIR_ID : typeManager.GetId(logType);
            def.style            = Style;
            return(def);
        }
Example #2
0
        private void MakeOak(ChunkNeighbourhood neighbourhood, int x, int y, int z, NativeTreeDefinition treeDef)
        {
            int numLeavesOnTop  = 2;
            int minCanopyHeight = numLeavesOnTop + 2;
            var height          = random.NextInt(treeDef.minHeight, treeDef.maxHeight);
            var leafStart       = random.NextInt(treeDef.minLeafClearance, height - minCanopyHeight);

            for (int i = 0; i < height - numLeavesOnTop; i++, y++)
            {
                neighbourhood[x, y, z] = treeDef.logID;

                if (i > leafStart)
                {
                    for (int j = -2; j <= 2; j++)
                    {
                        for (int k = -2; k <= 2; k++)
                        {
                            if (j == 0 && k == 0)
                            {
                                continue;
                            }

                            neighbourhood.SetIfUnoccupied(x + j, y, z + k, treeDef.leafID);
                        }
                    }
                }
            }

            //Top Leaves
            for (int i = 0; i < numLeavesOnTop; i++, y++)
            {
                for (int j = -1; j <= 1; j++)
                {
                    for (int k = -1; k <= 1; k++)
                    {
                        neighbourhood.SetIfUnoccupied(x + j, y, z + k, treeDef.leafID);
                    }
                }
            }
        }
Example #3
0
        private void MakeCactus(ChunkNeighbourhood neighbourhood, int x, int y, int z, NativeTreeDefinition treeDef)
        {
            var height = random.NextInt(treeDef.minHeight, treeDef.maxHeight);

            for (int i = 0; i < height; i++, y++)
            {
                neighbourhood[x, y, z] = treeDef.logID;
            }
        }
Example #4
0
        private void MakeSpruce(ChunkNeighbourhood neighbourhood, int x, int y, int z, NativeTreeDefinition treeDef)
        {
            int numLeavesOnTop = 2;
            var height         = random.NextInt(treeDef.minHeight, treeDef.maxHeight);
            var leafStart      = treeDef.minLeafClearance;
            var leafRadius     = height / 3;

            var toggle = true;

            for (int i = 0; i < height - numLeavesOnTop; i++, y++)
            {
                neighbourhood[x, y, z] = treeDef.logID;

                if (i > leafStart)
                {
                    if (toggle)
                    {
                        foreach (var item in Utils.Helpers.ManhattanCircle(new Vector3Int(x, y, z), leafRadius))
                        {
                            neighbourhood.SetIfUnoccupied(item.x, item.y, item.z, treeDef.leafID);
                        }
                        leafRadius = math.max(leafRadius - 1, 1);
                    }
                    toggle = !toggle;
                }
            }

            //Top Leaves
            for (int i = 0; i < numLeavesOnTop; i++, y++)
            {
                neighbourhood.SetIfUnoccupied(x, y, z, treeDef.leafID);
                //neighbourhood.SetIfUnoccupied(x + 1, y, z, treeDef.leafID);
                //neighbourhood.SetIfUnoccupied(x, y, z+1, treeDef.leafID);
                //neighbourhood.SetIfUnoccupied(x-1, y, z, treeDef.leafID);
                //neighbourhood.SetIfUnoccupied(x, y, z-1, treeDef.leafID);
            }
        }